mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2025-12-08 20:43:32 +00:00
Add configurable travel times by vehicle type
@0x1eo can u check this pls
This commit is contained in:
@@ -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 ---
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user