This project has been created as part of the 42 curriculum by kmathuri.
Fly-in is a high-performance simulation system designed to route a fleet of drones from a starting hub to a target destination through a complex network of connected zones. The core objective is to minimize the total number of simulation turns while strictly adhering to movement constraints, zone types, and capacity limits.
Built with a focus on Object-Oriented Programming (OOP) and Static Type Safety, this project implements a custom routing engine without the use of external graph libraries like networkx.
- Python 3.10 or later.
- uv package manager for fast and reliable dependency management.
The project includes a Makefile to automate all tasks:
- Install dependencies:
make install
- Run the simulation:
make run
- Run in Debug mode (pdb):
make debug
- Linting & Type Checking:
make lint-strict
The routing engine utilizes a custom Dijkstra-based algorithm adapted for multi-agent simulation. Unlike static pathfinding, our approach uses a Dynamic Cost System:
- Congestion Awareness: The weight of a path is not just its physical distance or zone type (normal, restricted, priority).
- Dynamic Penalties: As a path becomes more "crowded," its traversal cost increases. This forces drones to distribute themselves across different disjoint paths to maximize throughput.
- Capacity Management: The algorithm respects
max_dronesper zone andmax_link_capacityper connection, preventing deadlocks and collisions.
Drones move simultaneously. The system evaluates the state turn-by-turn, ensuring that:
- Drones moving out of a zone free up space for incoming drones in the same turn.
- Restricted zones (2-turn cost) are handled by forcing the drone to occupy the connection during transit.
My implementation significantly beats the "Hard" targets set by the subject.
| Map Type | Map Name | My Score | Target | Status |
|---|---|---|---|---|
| Easy | 01_linear_path | 3 | ✅ | |
| 02_simple_fork | 4 | ✅ | ||
| 03_basic_capacity | 4 | ✅ | ||
| Medium | 01_dead_end_trap | 4 | ✅ | |
| 02_circular_loop | 11 | ✅ | ||
| 03_priority_puzzle | 5 | ✅ | ||
| Hard | 01_maze_nightmare | 10 | ✅ | |
| 02_capacity_hell | 18 | ✅ | ||
| 03_ultimate_challenge | 26 | ✅ | ||
| Challenger | 01_the_impossible_dream | 43 | 45 | ✅ |
The project provides dual-layer feedback for an enhanced user experience:
- Navigation: Click and drag to pan across large maps; use the scroll wheel to zoom.
- Simulation Control: * Right Arrow: Step forward one turn.
- Left Arrow: Step backward to review previous movements.
- Real-time Data: Visualizes drone IDs, zone capacities, and restricted transit paths.
- Standardized output format for drone movements (e.g.,
D1-roof1 D2-corridorA). - Color-coded text for hubs and zones based on the input metadata.
- Python
typingmodule documentation for strict type hinting. - Pygame Library Documentation for GUI development.
AI was utilized as a pedagogical tool during development:
- Learning Pygame: Generated tutorials and code snippets to understand the event loop and coordinate transformation (zoom/drag).
- Knowledge Verification: Consulted to validate the logic of the dynamic penalty system and ensure no edge cases in capacity handling were overlooked.
- README: This README was generated by AI based on detailed technical specifications and logic provided by the author
- Documentation: Generated comprehensive docstrings and internal comments to ensure code maintainability and clarity.
- Logic Optimization: Assisted in rethinking and restructuring the priority system to improve efficiency and decision-making logic.