diff --git a/main/src/main/java/sd/config/SimulationConfig.java b/main/src/main/java/sd/config/SimulationConfig.java index d11ed42..4c3d599 100644 --- a/main/src/main/java/sd/config/SimulationConfig.java +++ b/main/src/main/java/sd/config/SimulationConfig.java @@ -227,6 +227,32 @@ public class SimulationConfig { return Double.parseDouble(properties.getProperty("vehicle.crossing.time.heavy", "4.0")); } + /** + * Gets the base travel time between intersections for light vehicles. + * @return The base travel time in seconds. + */ + public double getBaseTravelTime() { + return Double.parseDouble(properties.getProperty("vehicle.travel.time.base", "8.0")); + } + + /** + * Gets the travel time multiplier for bike vehicles. + * Bike travel time = base time × this multiplier. + * @return The multiplier for bike travel time. + */ + public double getBikeTravelTimeMultiplier() { + return Double.parseDouble(properties.getProperty("vehicle.travel.time.bike.multiplier", "0.5")); + } + + /** + * Gets the travel time multiplier for heavy vehicles. + * Heavy vehicle travel time = base time × this multiplier. + * @return The multiplier for heavy vehicle travel time. + */ + public double getHeavyTravelTimeMultiplier() { + return Double.parseDouble(properties.getProperty("vehicle.travel.time.heavy.multiplier", "2.0")); + } + // --- Statistics --- /** diff --git a/main/src/main/java/sd/engine/SimulationEngine.java b/main/src/main/java/sd/engine/SimulationEngine.java index 484ae80..b69c7ef 100644 --- a/main/src/main/java/sd/engine/SimulationEngine.java +++ b/main/src/main/java/sd/engine/SimulationEngine.java @@ -81,6 +81,26 @@ public class SimulationEngine { this.currentTime = 0.0; this.vehicleCounter = 0; } + + /** + * Calculates the travel time between intersections based on vehicle type. + * + * @param vehicleType The type of the vehicle. + * @return The travel time in seconds. + */ + private double calculateTravelTime(VehicleType vehicleType) { + double baseTime = config.getBaseTravelTime(); + + switch (vehicleType) { + case BIKE: + return baseTime * config.getBikeTravelTimeMultiplier(); + case HEAVY: + return baseTime * config.getHeavyTravelTimeMultiplier(); + case LIGHT: + default: + return baseTime; + } +} /** * Initializes the simulation. This involves: @@ -302,8 +322,8 @@ public class SimulationEngine { // Schedule arrival at first intersection String firstIntersection = vehicle.getCurrentDestination(); if (firstIntersection != null && !firstIntersection.equals("S")) { - // Assume minimal travel time to first intersection (e.g., 1-3 seconds) - double arrivalTime = currentTime + 1.0 + Math.random() * 2.0; + double travelTime = calculateTravelTime(vehicle.getType()); + double arrivalTime = currentTime + travelTime; Event arrivalEvent = new Event(arrivalTime, EventType.VEHICLE_ARRIVAL, vehicle, firstIntersection); eventQueue.offer(arrivalEvent); } @@ -469,8 +489,8 @@ public class SimulationEngine { String nextDest = vehicle.getCurrentDestination(); if (nextDest != null && !nextDest.equals("S")) { // Route to the *next* intersection - // Assume 5-10 seconds travel time between intersections - double travelTime = 5.0 + Math.random() * 5.0; + // Travel time varies by vehicle type: tmoto = 0.5 × tcarro, tcaminhão = 4 × tmoto + double travelTime = calculateTravelTime(vehicle.getType()); double arrivalTime = currentTime + travelTime; Event arrivalEvent = new Event(arrivalTime, EventType.VEHICLE_ARRIVAL, vehicle, nextDest); eventQueue.offer(arrivalEvent); diff --git a/main/src/main/resources/simulation.properties b/main/src/main/resources/simulation.properties index 278ef08..ffd421d 100644 --- a/main/src/main/resources/simulation.properties +++ b/main/src/main/resources/simulation.properties @@ -103,10 +103,18 @@ vehicle.probability.light=0.6 vehicle.probability.heavy=0.2 # Average crossing times (in seconds) -vehicle.crossing.time.bike=1.5 +vehicle.crossing.time.bike=1.0 vehicle.crossing.time.light=2.0 vehicle.crossing.time.heavy=4.0 +# Travel times between intersections (in seconds) +# Base time for light vehicles (cars) +vehicle.travel.time.base=8.0 +# Bike travel time = 0.5 × car travel time +vehicle.travel.time.bike.multiplier=0.5 +# Heavy vehicle travel time = 4 × bike travel time +vehicle.travel.time.heavy.multiplier=2.0 + # === STATISTICS === # Interval between dashboard updates (seconds)