{"id":32747881,"url":"https://github.com/mshirazkamran/swarm-intelligence-example","last_synced_at":"2026-05-17T03:31:42.691Z","repository":{"id":320417021,"uuid":"1082025700","full_name":"mshirazkamran/swarm-intelligence-example","owner":"mshirazkamran","description":"This repo shows the usage of PSO to sovle the problem the putting N warehouses in an MxN grid with various contraints such as army zones, residential areas ","archived":false,"fork":false,"pushed_at":"2025-10-24T03:12:53.000Z","size":9273,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-03T20:11:22.819Z","etag":null,"topics":["example","matplotlib","numpy","optimization-algorithms","particle-swarm-optimization","pso","pso-algorithm","python3","swarm-intelligence"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mshirazkamran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-23T16:16:01.000Z","updated_at":"2025-10-29T06:15:10.000Z","dependencies_parsed_at":"2025-10-23T18:26:45.689Z","dependency_job_id":null,"html_url":"https://github.com/mshirazkamran/swarm-intelligence-example","commit_stats":null,"previous_names":["mshirazkamran/swarm-intelligence-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mshirazkamran/swarm-intelligence-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshirazkamran%2Fswarm-intelligence-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshirazkamran%2Fswarm-intelligence-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshirazkamran%2Fswarm-intelligence-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshirazkamran%2Fswarm-intelligence-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mshirazkamran","download_url":"https://codeload.github.com/mshirazkamran/swarm-intelligence-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mshirazkamran%2Fswarm-intelligence-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33126436,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T18:38:32.183Z","status":"online","status_checked_at":"2026-05-17T02:00:05.366Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","matplotlib","numpy","optimization-algorithms","particle-swarm-optimization","pso","pso-algorithm","python3","swarm-intelligence"],"created_at":"2025-11-03T20:01:26.155Z","updated_at":"2026-05-17T03:31:42.685Z","avatar_url":"https://github.com/mshirazkamran.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Warehouse Location Optimizer\n\nA Python program that uses Particle Swarm Optimization (PSO) to find the best locations for warehouses in a city while avoiding restricted areas and staying safe distance from homes.\n\n## What Does This Program Do?\n\nThis program helps to place warehouses in a city by:\n- Avoiding army restricted zones\n- Keeping minimum distance from residential areas (homes)\n- Keeping warehouses separated from each other\n- Placing warehouses near city center (not on edges)\n\n## Quick Start\n\n### Clone and Run\n\n1. **Clone this repository:**\n```bash\ngit clone https://github.com/mshirazkamran/swarm-intelligence-example.git\n```\n\n2. **Navigate to the project directory:**\n```bash\ncd swarm-intelligence-example\n```\n\n3. **Install dependencies:**\n```bash\npip install -r requirements.txt\n```\n\n4. **Run the program:**\n```bash\npython src/main.py\n```\n\n5. **Check the output:**\n   - View the generated image: `warehouse_solution.png`\n   - See warehouse coordinates in the terminal output\n\n### Get Started with Docker\n\n**🚧 Docker support is currently in development and will be available soon!**\n\nStay tuned for containerized deployment options that will make setup even easier.\n\n## Requirements\n\nYou need to install these Python libraries:\n\n```bash\npip install numpy matplotlib\n```\n\nOr install from the requirements file:\n\n```bash\npip install -r requirements.txt\n```\n\n## How to Run\n\nIf you already have the project set up, simply run:\n\n```bash\npython src/main.py\n```\n\n**Note:** The program takes about 1-2 minutes to complete. Output will be saved as `warehouse_solution.png`.\n\n## Basic Settings (Variables You Can Change)\n\nOpen `src/main.py` and look at **Section 1: BASIC SETTINGS**. Here are the main variables you can adjust:\n\n### City Settings\n```python\nCITY_SIZE = 1000  # Size of city (1000 x 1000 km)\n```\n\n### Number of Warehouses\n```python\nN_WAREHOUSES = 3  # How many warehouses to place (default: 3)\n```\n\n### Safety Distances\n```python\nD_MIN_RESIDENTIAL = 50.0   # Minimum distance from homes (km)\nD_MIN_WAREHOUSE = 100.0    # Minimum distance between warehouses (km)\n```\n\n### PSO Algorithm Settings\n```python\nN_PARTICLES = 40     # How many possible solutions to test at once\nN_ITERATIONS = 200   # How many times to improve the solution\n```\n- **More particles** = explores more possibilities but runs slower\n- **More iterations** = better solution but takes more time\n\n### Importance Weights\n```python\nALPHA_WEIGHT = 0.5   # Importance of staying away from homes (0-1)\nBETA_WEIGHT = 0.3    # Importance of warehouse separation (0-1)\nGAMMA_WEIGHT = 1.0   # Importance of staying near city center (0-1)\n```\n- Higher weight = more important goal\n- Lower weight = less important goal\n\n### Random Locations\n```python\nN_RESIDENTIAL = 15   # How many residential areas to create\nN_ARMY_ZONES = 5     # How many army zones to create\n```\n\n## Understanding the Output\n\n### Console Output\nThe program prints:\n1. Progress updates every 20 iterations\n2. Final fitness score (lower is better)\n3. Coordinates of each warehouse\n\nExample:\n```\nIteration 20/200, Best Fitness: 1.2108\n...\nFinal Best Fitness (Cost): 1.1995\nBest Warehouse Locations:\n  Warehouse 1: (x=669.79, y=597.26)\n  Warehouse 2: (x=202.25, y=350.06)\n  Warehouse 3: (x=420.57, y=618.10)\n```\n\n### Image Output\nFile: `warehouse_solution.png`\n\n**Left chart** shows:\n- **Green circles** = Residential areas\n- **Red rectangles** = Army restricted zones\n- **Blue stars** = Optimized warehouse positions\n- **Dashed green circles** = Safety zones around homes\n- **Dotted blue circles** = Minimum distance between warehouses\n\n**Right chart** shows:\n- How the fitness (cost) improved over iterations\n- Line goes down = solution getting better\n\n## Troubleshooting\n\n### Problem: \"No valid solution found\"\n**Cause:** Constraints are too strict (impossible to satisfy)\n\n**Solution:**\n- Reduce `D_MIN_RESIDENTIAL` (allow closer to homes)\n- Reduce `D_MIN_WAREHOUSE` (allow warehouses closer together)\n- Reduce `N_WAREHOUSES` (place fewer warehouses)\n- Increase `N_ITERATIONS` (give more time to search)\n\n### Problem: \"Warehouses at city edges\"\n**Cause:** GAMMA_WEIGHT is too low\n\n**Solution:**\n- Increase `GAMMA_WEIGHT` to 1.5 or 2.0\n\n### Problem: \"Program is very slow\"\n**Cause:** Too many particles or iterations\n\n**Solution:**\n- Reduce `N_PARTICLES` to 20-30\n- Reduce `N_ITERATIONS` to 100-150\n\n### Problem: \"Fitness not improving\"\n**Cause:** Algorithm stuck at local minimum\n\n**Solution:**\n- Increase `W_MAX` to 1.0 (more exploration)\n- Increase `c1` and `c2` to 2.0\n- Run the program multiple times (results are random)\n\n## Example Modifications\n\n### To place 5 warehouses instead of 3:\n```python\nN_WAREHOUSES = 5\n```\n\n### To make algorithm faster (but less accurate):\n```python\nN_PARTICLES = 20\nN_ITERATIONS = 100\n```\n\n### To prioritize safety over center placement:\n```python\nALPHA_WEIGHT = 2.0   # very important\nGAMMA_WEIGHT = 0.3   # less important\n```\n\n### To create denser city with more obstacles:\n```python\nN_RESIDENTIAL = 30\nN_ARMY_ZONES = 10\n```\n\n\n## Additional Notes\n\n- Each time you run the program, you get different results (because locations are random)\n- The algorithm uses randomness, so running it multiple times may give slightly different warehouse positions\n- If you want same results every time, add this line at top of main.py:\n  ```python\n  np.random.seed(42)  # any number works\n  ```\n\n## Need Help?\n\nIf something is not working:\n1. Check if you installed all requirements (`numpy`, `matplotlib`)\n2. Make sure you are in correct folder when running\n3. Try with default settings first\n4. Check if Python version is 3.6 or higher\n\n---\n\n**Good luck optimizing your warehouse locations!** \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshirazkamran%2Fswarm-intelligence-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmshirazkamran%2Fswarm-intelligence-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshirazkamran%2Fswarm-intelligence-example/lists"}