A full-stack web application for designing and simulating traffic patterns in road interchanges. This project provides both a design interface for creating custom road layouts and a simulation engine to visualize traffic flow.
Real-time traffic simulation with adjustable parameters
Interactive road layout design interface
- Design Mode: Create and customize road layouts with an intuitive visual interface
- Simulation Mode: Real-time traffic simulation with adjustable parameters
- Interactive Controls: Modify traffic flow, vehicle speeds, and road settings
- JSON Import/Export: Save and load custom road layouts
- Clone the repository:
git clone <repository-url>
cd traffic_simulator
- Install dependencies:
npm install
- Run the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:3000
-
Click on Traffic Simulator or Designer to to respective pages. If you do not want the app to be at a specific route comment out the lines of basePath, assetPrefix, trailingSlash, env properties in next.config.ts file
The design interface allows you to create custom road layouts:
-
Adding Roads:
- Click "Add Road" to create a new road section
- Drag roads to position them
- Adjust properties (size, rotation, z-index) in the sidebar
-
Creating Lines:
- Click "Add Line" to create a new traffic lane
- Click on the canvas to add points to the line
- Link lines to create traffic flow paths
-
Customization:
- Set road properties (dimensions, rotation, z-index)
- Configure line attributes (visibility, height)
- Link lines to create traffic flow patterns
-
Saving/Loading:
- Use "Download JSON" to save your design
- Use "Upload JSON" to load existing designs
The simulation interface lets you visualize traffic flow:
-
Controls:
- Pause/Resume simulation
- Adjust global vehicle speed
- Modify road-specific settings (inflow rate, turn probability)
-
Road Settings:
- Set inflow rates for each road
- Configure turn probabilities
- Upload custom road layouts
-
Visualization:
- Real-time traffic flow visualization
- Vehicle movement and interaction
- Interactive hover information
The vehicles update their positions at a fixed interval. Vehicles are created randomly and assigned input road and output road. Then it calculates its path based on the linking of lane lines. Vehicles are assigned a speed based on settings. Then the speed adjusts based on vehicle in front, and vehicles that are about to cross its path. Deadlock situations are handles, so that two vehicles do not wait for each other indefinitely.
/src/app/
: Main application componentspage.tsx
: Main simulation viewdesign/page.tsx
: Design interfaceSimulationCanvas.tsx
: Canvas rendering componentSimulationSettingsBar.tsx
: Settings control panelTrafficSimulation.tsx
: Main simulation componentsimulationEngine.ts
: Logic of vehicle movement
- Next.js
- React
- TypeScript
- Tailwind css
- Canvas API
- Web Workers (for simulation)