Merge pull request #34 from davidalves04/dev

testing
This commit is contained in:
2025-11-22 21:43:33 +00:00
committed by GitHub
3 changed files with 59 additions and 5 deletions

View File

@@ -227,6 +227,32 @@ public class SimulationConfig {
return Double.parseDouble(properties.getProperty("vehicle.crossing.time.heavy", "4.0")); 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 --- // --- Statistics ---
/** /**

View File

@@ -81,6 +81,26 @@ public class SimulationEngine {
this.currentTime = 0.0; this.currentTime = 0.0;
this.vehicleCounter = 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: * Initializes the simulation. This involves:
@@ -302,8 +322,8 @@ public class SimulationEngine {
// Schedule arrival at first intersection // Schedule arrival at first intersection
String firstIntersection = vehicle.getCurrentDestination(); String firstIntersection = vehicle.getCurrentDestination();
if (firstIntersection != null && !firstIntersection.equals("S")) { if (firstIntersection != null && !firstIntersection.equals("S")) {
// Assume minimal travel time to first intersection (e.g., 1-3 seconds) double travelTime = calculateTravelTime(vehicle.getType());
double arrivalTime = currentTime + 1.0 + Math.random() * 2.0; double arrivalTime = currentTime + travelTime;
Event arrivalEvent = new Event(arrivalTime, EventType.VEHICLE_ARRIVAL, vehicle, firstIntersection); Event arrivalEvent = new Event(arrivalTime, EventType.VEHICLE_ARRIVAL, vehicle, firstIntersection);
eventQueue.offer(arrivalEvent); eventQueue.offer(arrivalEvent);
} }
@@ -469,8 +489,8 @@ public class SimulationEngine {
String nextDest = vehicle.getCurrentDestination(); String nextDest = vehicle.getCurrentDestination();
if (nextDest != null && !nextDest.equals("S")) { if (nextDest != null && !nextDest.equals("S")) {
// Route to the *next* intersection // Route to the *next* intersection
// Assume 5-10 seconds travel time between intersections // Travel time varies by vehicle type: tmoto = 0.5 × tcarro, tcaminhão = 4 × tmoto
double travelTime = 5.0 + Math.random() * 5.0; double travelTime = calculateTravelTime(vehicle.getType());
double arrivalTime = currentTime + travelTime; double arrivalTime = currentTime + travelTime;
Event arrivalEvent = new Event(arrivalTime, EventType.VEHICLE_ARRIVAL, vehicle, nextDest); Event arrivalEvent = new Event(arrivalTime, EventType.VEHICLE_ARRIVAL, vehicle, nextDest);
eventQueue.offer(arrivalEvent); eventQueue.offer(arrivalEvent);

View File

@@ -103,10 +103,18 @@ vehicle.probability.light=0.6
vehicle.probability.heavy=0.2 vehicle.probability.heavy=0.2
# Average crossing times (in seconds) # 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.light=2.0
vehicle.crossing.time.heavy=4.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 === # === STATISTICS ===
# Interval between dashboard updates (seconds) # Interval between dashboard updates (seconds)