mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2025-12-07 20:16:36 +00:00
Move vehicle route advancement to intersection arrival
This commit is contained in:
@@ -280,8 +280,7 @@ public class IntersectionProcess {
|
||||
System.out.println("[" + intersectionId + "] Sent vehicle " + vehicle.getId() +
|
||||
" to " + nextDestination);
|
||||
|
||||
// Update vehicle's path - advance to next destination in route
|
||||
vehicle.advanceRoute();
|
||||
// Note: vehicle route is advanced when it arrives at the next intersection
|
||||
|
||||
} catch (IOException | InterruptedException e) {
|
||||
System.err.println("[" + intersectionId + "] Failed to send vehicle " +
|
||||
|
||||
@@ -104,16 +104,28 @@ public class Intersection {
|
||||
* Accepts an incoming vehicle and places it in the correct queue.
|
||||
* * This method:
|
||||
* 1. Increments the {@link #totalVehiclesReceived} counter.
|
||||
* 2. Gets the vehicle's *next* destination (from {@link Vehicle#getCurrentDestination()}).
|
||||
* 3. Uses the {@link #routing} map to find the correct *direction* for that destination.
|
||||
* 4. Adds the vehicle to the queue of the {@link TrafficLight} for that direction.
|
||||
* 2. Advances the vehicle's route (since it just arrived here)
|
||||
* 3. Gets the vehicle's *next* destination (from {@link Vehicle#getCurrentDestination()}).
|
||||
* 4. Uses the {@link #routing} map to find the correct *direction* for that destination.
|
||||
* 5. Adds the vehicle to the queue of the {@link TrafficLight} for that direction.
|
||||
*
|
||||
* @param vehicle The {@link Vehicle} arriving at the intersection.
|
||||
*/
|
||||
public void receiveVehicle(Vehicle vehicle) {
|
||||
totalVehiclesReceived++;
|
||||
|
||||
// Advance route since vehicle just arrived at this intersection
|
||||
vehicle.advanceRoute();
|
||||
|
||||
String nextDestination = vehicle.getCurrentDestination();
|
||||
|
||||
// Check if vehicle reached final destination
|
||||
if (nextDestination == null) {
|
||||
System.out.printf("[%s] Vehicle %s reached final destination%n",
|
||||
this.id, vehicle.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
String direction = routing.get(nextDestination);
|
||||
|
||||
if (direction != null && trafficLights.containsKey(direction)) {
|
||||
|
||||
Reference in New Issue
Block a user