The Bus Route Simulator is an interactive application developed using Python and Pygame. It allows users to simulate bus routes, generate users, and manage the movement of buses and users within a graphical environment. The application visualizes user activity and bus capacity while providing an engaging and intuitive interface.
- Node Creation: Add nodes to define bus stops on the map by clicking on the screen.
- User Generation: Generate users randomly across the map who will move toward their nearest bus stop.
- Dynamic Bus Routes: Create routes for buses to traverse and manage their movement along the route.
- User Interaction: Users can board and alight from buses at specified stops.
- Capacity Management: Limit the number of users on the bus based on its capacity.
- Visualization: Real-time updates on user positions, bus movements, and statistics for satisfied users.
- Clone this repository or download the source code:
git clone <repository-url> cd <repository-folder>
- Install the required Python dependencies:
pip install pygame
- Place a map image named
map.pngin the same directory as the script. - Run the simulator:
python <script-name>.py
- Interact with the simulation using:
- Mouse Click: Add bus stops (nodes) on the map.
UKey: Generate 100 users randomly on the map.BKey: Start the bus simulation.
| Action | Control |
|---|---|
| Add a Node | Left Mouse Click |
| Generate Users | Press U |
| Start Bus Route | Press B |
Represents a bus stop in the simulation.
- Attributes:
x,y: Coordinates on the map.bus_stopped: Boolean indicating if the bus is currently at the node.stop_time_start: Timestamp of when the bus stopped.
- Method:
draw(): Visualizes the node and its user activity.
Represents a passenger in the simulation.
- Attributes:
position: Current position on the map.target_node: The user's destination node.on_bus: Boolean indicating if the user is on the bus.bus_stops_remaining: Number of stops left for the user.done: Boolean indicating if the user has completed their journey.
- Method:
draw(): Visualizes the user on the map.
- Users on Bus: Displays the number of users currently on the bus.
- Satisfied Users: Shows the count of users who have completed their journey.
- Total Users: Displays the total number of users generated during the simulation.
BUS_CAPACITY: Adjust the maximum capacity of the bus.USER_GENERATE: Modify the number of users generated per click.- Node Radius: Change the size of the nodes by updating the
RADIUSvariable.
- Add support for multiple buses.
- Implement realistic pathfinding for users.
- Provide detailed metrics and analytics for the simulation.
- Enable saving and loading of simulation states.
This project is open-source and available under the MIT License.
Developed using Python and Pygame.