A DEVS-based discrete event simulation modeling a three-bridge traffic system with bidirectional flow and traffic light control.
This project implements a bridge traffic simulation system. 1. The system consists of three bridge segments connecting east and west, with traffic lights controlling bidirectional vehicle flow.
- BridgeSegment: Atomic DEVS model representing a single bridge with traffic lights
- BridgeSystem: Coupled model connecting three bridge segments
- CarGenerator: Generates vehicles at configurable intervals
- Transducer: Collects and records exit events for analysis
West East
| |
WestGen → [Bridge3] → [Bridge2] → [Bridge1] → EastGen
| ↓ ↓ ↓ |
| (outputs) (outputs) (outputs) |
| ↓ ↓ ↓ |
└─────── Transducer (collects all exit events) ←┘
- WestGen: Generates eastbound traffic (west → east)
- EastGen: Generates westbound traffic (east → west)
- Vehicles flow through all three bridges sequentially
- Each bridge takes 10 seconds to cross
States:
idle: Waiting for vehicles or light switchcrossing: Vehicle currently crossing (10 seconds)
Behavior:
- Traffic lights switch at fixed intervals (configurable per bridge)
- Vehicles can only cross when:
- Their direction has green light
- Sufficient time remains before next light switch (≥10 seconds)
- Supports back-to-back crossings during green phases
- Independent queues for eastbound and westbound traffic
Key Algorithm:
timeUntilSwitch = lightSwitchTime - currentSimulationTime
if (timeUntilSwitch >= 10 seconds && correct_direction && vehicle_available) {
start_crossing();
}Each bridge can be configured with:
- Initial State:
WEST_TO_EASTorEAST_TO_WEST - Traffic Light Duration: Time in seconds (e.g., 30, 100)
Example configuration:
AbstractBridgeSystem.BridgeSystemSetting.Bridge1InitialState =
AbstractBridgeSystem.BridgeState.WEST_TO_EAST;
AbstractBridgeSystem.BridgeSystemSetting.Bridge1TrafficLightDurationTime = 100;Case 1: Long green phases (100s)
All bridges: WEST_TO_EAST, 100s green time
Result: ~34-36 events, efficient throughputCase 2: Short green phases (5s)
All bridges: WEST_TO_EAST, 5s green time
Result: 0 events (insufficient time to cross)Case 3: Mixed configuration
Bridge3: EAST_TO_WEST, 100s
Bridge2: EAST_TO_WEST, 5s
Bridge1: EAST_TO_WEST, 100s
Result: Testing asymmetric flowCase 4: Medium green phases (30s)
All bridges: EAST_TO_WEST, 30s green time
Result: ~48 events, high frequency switching- Absolute Time Tracking: Uses
lightSwitchTimeas absolute simulation time for precise light switching - Time Calculation:
timeUntilSwitch = lightSwitchTime - getSimulationTime() - Safety Check: Only start crossing if
timeUntilSwitch >= crossTime - Independent Timing: Traffic light schedule is independent of crossing events
IDLE State:
- External: Vehicle arrives → try crossing if sufficient time
- Internal: Light switch time reached → switch direction
CROSSING State:
- Internal: Crossing completes → try next crossing or switch light
- DEVSJAVA framework
- Java 8 or higher
HAkhtar/
├── BridgeSegment.java
└── BridgeSystem.java
BridgeSegment/
├── AbstractBridgeSystem.java
├── CarGenerator.java
├── Transducer.java
└── Test.java
- Green Time = 100s: Optimal throughput, ~34 events
- Green Time = 30s: Higher frequency switching, ~48 events
- Green Time = 5s: No throughput (insufficient crossing time)
- Crossing Time: Fixed at 10 seconds per vehicle
- Road segments between bridges have zero travel time (instant transfer)
- Infinite queue capacity at each bridge
- Random car generation may produce slightly different event counts
- Single lane (no passing or parallel crossing)