{"id":51220755,"url":"https://github.com/sankhya007/t.r.a.g.i.c","last_synced_at":"2026-06-28T07:01:17.284Z","repository":{"id":361347768,"uuid":"1253016773","full_name":"sankhya007/T.R.A.G.I.C","owner":"sankhya007","description":"Simulate crowd evacuations from any floorplan image — 4 algorithms, scored output","archived":false,"fork":false,"pushed_at":"2026-06-20T11:18:30.000Z","size":29811,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-20T11:23:55.423Z","etag":null,"topics":["architecture","computer-vision","evacuation","pyqt6","pytorch","safety","simulation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sankhya007.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":"2026-05-29T04:47:13.000Z","updated_at":"2026-06-20T11:18:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/sankhya007/T.R.A.G.I.C","commit_stats":null,"previous_names":["sankhya007/t.r.a.g.i.c"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sankhya007/T.R.A.G.I.C","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sankhya007%2FT.R.A.G.I.C","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sankhya007%2FT.R.A.G.I.C/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sankhya007%2FT.R.A.G.I.C/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sankhya007%2FT.R.A.G.I.C/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sankhya007","download_url":"https://codeload.github.com/sankhya007/T.R.A.G.I.C/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sankhya007%2FT.R.A.G.I.C/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34880189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"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":["architecture","computer-vision","evacuation","pyqt6","pytorch","safety","simulation"],"created_at":"2026-06-28T07:01:14.033Z","updated_at":"2026-06-28T07:01:17.275Z","avatar_url":"https://github.com/sankhya007.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# T.R.A.G.I.C.\n### Tactical Risk Assessment \u0026 Grid-based Intelligent Crowd Simulation\n\n\u003e Feed it a floorplan. It tells you where people die.\n\n![Hero — TRAGIC launcher showing a completed SFM simulation with agent trails, bottleneck markers, and a score overlay](docs/hero_launcher.png)\n\n---\n\n## The Why\n\nMost building safety tools either cost a fortune or require you to hand-draw every wall and corridor into a proprietary format. TRAGIC takes a floorplan image — a photo, a scan, an architect's PNG — runs it through a trained U-Net to extract walkable space automatically, then simulates a crowd evacuation using four different algorithms. At the end you get a score, a heatmap, and a concrete recommendation like \"the corridor at (420, 310) is your worst chokepoint, widen it.\"\n\nBuilt for architects and students who want to understand whether a layout is actually safe, not just compliant on paper.\n\n---\n\n## How It's Structured\n\n```\nT.R.A.G.I.C/\n├── Tragic_launcher.py           # Main GUI — 3-view pipeline\n├── predict_tiled.py             # Standalone map parser (no GUI)\n├── model.py                     # U-Net definition\n├── unet.pth                     # Trained weights (you need this)\n├── zone_detector.py             # Standalone zone editor (no GUI)\n├── SFM_evacuation.py            # Social Force Model\n├── RVO_evacuation.py            # Reciprocal Velocity Obstacles\n├── continuum_evacuation_path.py # Continuum Crowds (Treuille 2006)\n├── continuum_evacuation_sim.py  # Interactive continuum viewer (This is not connected to the code, kinda unnecessary. lol)\n├── CA_evacuation.py             # Cellular Automata\n└── output/                      # Everything written here at runtime\n    ├── sfm_agent_paths.png\n    ├── rvo_agent_paths.png\n    ├── continuum_agent_paths.png\n    ├── ca_paths.png\n    └── *.txt                    # per-model text reports\n```\n\nThe pipeline has three stages:\n\n![Flow diagram — floorplan image → U-Net tiled inference → binary mask → watershed zone segmentation → agent spawn + BFS flow field → simulation loop → scored output image + text report](docs/pipeline_diagram.png)\n\n**Stage 1 — Map Parser**: Tiles the input image with 50% overlap, runs each patch through the U-Net, Gaussian-blends predictions back, binarizes to `stitched_mask.png` (black = walkable, white = wall).\n\n**Stage 2 — Zone Editor**: Watershed segmentation splits walkable area into rooms/corridors. You click zones to set agent density, place exit markers, and optionally drop a hazard. Saves to a JSON config.\n\n**Stage 3 — Simulation**: Launches one of the four simulation scripts as a subprocess, streams output to the UI, displays the result image and report.\n\n---\n\n## Quick Start\n\n**Prerequisites:** Python 3.10+, and `unet.pth` placed in the project root.\n\n```bash\ngit clone https://github.com/sankhya007/T.R.A.G.I.C\ncd T.R.A.G.I.C\npip install torch\u003e=2.0.0 opencv-python\u003e=4.8.0 numpy\u003e=1.24.0 scipy\u003e=1.11.0 scikit-image\u003e=0.21.0 PyQt6\u003e=6.5.0\n```\n\nNo GPU? Use the CPU-only torch wheel:\n```bash\npip install torch --index-url https://download.pytorch.org/whl/cpu\npip install opencv-python numpy scipy scikit-image PyQt6\n```\n\n```bash\npython Tragic_launcher.py\n```\n\nDon't want to train the Model yourself? No problem here is the lin to download:\n\n[Hugging Face Link](https://huggingface.co/sankhya007/Floorplan_parser_STITCH/tree/main)\n\n\n\n\nNo config files, no environment variables. Everything is driven through the UI.\n\n---\n\n## Feature Walkthrough\n\n### 1. Tiled Map Parsing\n\nThe U-Net was trained on 256×256 patches, but real floorplans can be 3000×2000px. The parser computes a window size backwards from a patch budget — so you never exceed 40 tiles regardless of input resolution. Bigger image, bigger window, same patch count.\n\n```python\naspect = pW / pH\nn_cols_est = math.sqrt(MAX_PATCHES * aspect)\nn_rows_est = math.sqrt(MAX_PATCHES / aspect)\nWINDOW = max(WINDOW_MIN, int(math.ceil(max(pW / (n_cols_est * 0.5),\n                                           pH / (n_rows_est * 0.5)))))\n```\n\nEach patch gets a Gaussian weight map so edges blend smoothly instead of leaving hard seams.\n\n![Map Parser view — tiling parameters on the left, stitched binary mask on the right with white walls and black walkable space](docs/view1_parser.png)\n\n---\n\n### 2. Zone Editor \u0026 Agent Config\n\nWatershed segmentation automatically splits the walkable area into rooms and corridors. Click a zone, set its density index, and agent count is:\n\n```python\nagents = int(area_px * density_index * base_density / 1000)\n```\n\nA 5000px² room at density 1.0 with base 1.0 gets 5 agents. Set density to 0 to exclude a zone entirely. Exits are placed by clicking the map in Exit Mode, saved as `{\"x\": int, \"y\": int}` in the JSON — the same format every simulation script reads.\n\n![Zone Editor — colored watershed regions, exit markers labeled E1/E2, zone list with density indices on the left](docs/view2_zones.png)\n\n---\n\n### 3. Hazard \u0026 Fire Spread\n\nHazard Mode drops a single point hazard on the map, saved as `{\"x\": int, \"y\": int}` under `\"hazard\"` in the zone config. All four models read it the same way and split the response into two layers:\n\n- **Routing (permanent, hard)** — a fixed-radius circle around the hazard is carved out of the walkable mask *before* the flow field / BFS cost / potential field is built. Agents never path through it, full stop. No per-tick rerouting, no extra cost — it's baked into pathing once at setup.\n- **Fire (growing, soft)** — a separate `fire_intensity` field grows and diffuses outward through the real walkable area every simulation tick, purely for visuals and a soft repulsion nudge near the flame front. This is what you actually see spreading in the output PNG.\n\nIf an agent somehow ends up stuck inside the hazard radius with nowhere lower-cost to go, it gets pushed straight away from the hazard center rather than freezing in place.\n\nTwo runtime params control fire behavior, exposed as sliders in the launcher for SFM, RVO, Continuum, and CA alike:\n\n```python\n\"fire_spread_speed\":     1.0,   # multiplier on diffusion rate\n\"fire_intensity_factor\": 1.0,   # multiplier on growth-to-saturation rate\n```\n\nBump either one up and the burning area visibly grows faster within the same sim duration — both flow through the existing `CONFIG`/`apply_runtime_args()` param pickup, so no per-model special-casing was needed.\n\nCA doesn't have a velocity field to push agents around with, so its version of fire repulsion is a tiebreak: among equally-good candidate cells, it picks the cooler one instead of adding a force vector.\n\n---\n\n### 4. Four Simulation Algorithms\n\nAll four models take the same inputs and produce the same output structure: scored image with agent trails, exit utilization percentages, and bottleneck markers.\n\n| Model | Core mechanic | Best for |\n|---|---|---|\n| SFM | Attractive/repulsive force fields | General-purpose |\n| RVO | ORCA half-plane collision avoidance | Dense crowds, lane formation |\n| Continuum | Treuille 2006 potential field + density | Large crowds, fluid behavior |\n| CA | Grid cells, Moore neighbourhood, BFS cost | Fast, discrete, good bottleneck detection |\n\nScore is 0–100 across four components (same formula in all four scripts):\n\n```python\nscore_rate    = (evacuated / total) * 50\nscore_time    = max(0, 20 * (1 - (mean_t - 20) / 60)) if mean_t \u003e 20 else 20.0\nscore_balance = max(0, 15 * (1 - max_exit_deviation / ideal))\nscore_bn      = max(0, 15 * (1 - (bn_fraction - 0.05) / 0.45))\nfinal_score   = int(score_rate + score_time + score_balance + score_bn)\n```\n\n![Simulation output — green/orange agent trails, red bottleneck circles labeled B1/B2, cyan exit circles with utilization percentages, score box top-left](docs/view3_output.png)\n\n---\n\n## Gotchas\n\n**\"Output image not found\" after simulation runs**\nThe launcher copies mask and zone config to hardcoded filenames in the project root before launching any subprocess. Always launch `Tragic_launcher.py` from the project root, not from a subdirectory.\n\n**Continuum model is slow on large masks**\n`grid_res` controls potential field resolution (default 4px per cell). If the sim is crawling, push it to 6 or 8 in the config panel. You lose some path accuracy but it becomes usable.\n\n**Agents spawn but zero evacuate**\nEither (a) exit markers landed on a wall pixel — place them clearly inside a corridor, or (b) you saved the zone config before placing any exits so the `\"exits\"` array in the JSON is empty. Open the JSON and check. Exit radius defaults to 22px; if exits are in tight spaces, increase it.\n\n**Hazard placed but nothing seems to route around it**\nCheck the hazard didn't land in a spot where the carved-out radius swallows the only corridor to an exit — if there's no walkable path left, agents just sit at max BFS cost and never evacuate. Either move the hazard or widen the layout.\n\n---\n\n## Contributing\n\nBug reports, feature requests, and PRs welcome — see `CONTRIBUTING.md` for the project layout and the patterns new code is expected to follow (SFM is the reference model, `output/` hygiene rules, that kind of thing). Issue and PR templates are under `.github/` if you want a starting point.\n\n---\n\n## License\n\nMIT — do whatever you want with it.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsankhya007%2Ft.r.a.g.i.c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsankhya007%2Ft.r.a.g.i.c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsankhya007%2Ft.r.a.g.i.c/lists"}