Skip to content

Commit

Permalink
Merge pull request #3017 from matsim-org/simplify-drive-discharge-han…
Browse files Browse the repository at this point in the history
…dling

ev: reduce amount of collected events in DriveDischargingHandler
  • Loading branch information
michalmac authored Dec 27, 2023
2 parents c926974 + db13d2c commit 9b6ef87
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ public void handleEvent(VehicleEntersTrafficEvent event) {

@Override
public void handleEvent(LinkLeaveEvent event) {
linkLeaveEvents.add(event);
if (evDrives.containsKey(event.getVehicleId())) {// handle only our EVs
linkLeaveEvents.add(event);
}
}

@Override
public void handleEvent(VehicleLeavesTrafficEvent event) {
trafficLeaveEvents.add(event);
if (evDrives.containsKey(event.getVehicleId())) {// handle only our EVs
trafficLeaveEvents.add(event);
}
}

@Override
Expand Down Expand Up @@ -128,9 +132,7 @@ public void doSimStep(double time) {
}

EvDrive evDrive = dischargeVehicle(event.getVehicleId(), event.getLinkId(), event.getTime(), time);
if (evDrive != null) {
evDrive.movedOverNodeTime = event.getTime();
}
evDrive.movedOverNodeTime = event.getTime();
linkLeaveIterator.remove();
}

Expand All @@ -142,16 +144,14 @@ public void doSimStep(double time) {
}

EvDrive evDrive = dischargeVehicle(event.getVehicleId(), event.getLinkId(), event.getTime(), time);
if (evDrive != null) {
evDrives.remove(evDrive.vehicleId);
}
evDrives.remove(evDrive.vehicleId);
trafficLeaveIterator.remove();
}
}

private EvDrive dischargeVehicle(Id<Vehicle> vehicleId, Id<Link> linkId, double eventTime, double now) {
EvDrive evDrive = evDrives.get(vehicleId);
if (evDrive != null && !evDrive.isOnFirstLink()) {// handle only our EVs, except for the first link
if (!evDrive.isOnFirstLink()) {// skip the first link
Link link = network.getLinks().get(linkId);
double tt = eventTime - evDrive.movedOverNodeTime;
ElectricVehicle ev = evDrive.ev;
Expand Down

0 comments on commit 9b6ef87

Please sign in to comment.