Skip to content

Commit

Permalink
fix: bug where vehicle is still in the queue but needs to be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
tschlenther committed Nov 14, 2023
1 parent 1d57f82 commit 6358ed3
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
* This is an events based approach to trigger vehicle charging. Vehicles will be charged as soon as a person begins a charging activity.
*/

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableListMultimap;
import jakarta.inject.Inject;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.ActivityEndEvent;
import org.matsim.api.core.v01.events.ActivityStartEvent;
Expand All @@ -47,7 +43,9 @@
import org.matsim.core.events.MobsimScopeEventHandler;
import org.matsim.vehicles.Vehicle;

import com.google.common.collect.ImmutableListMultimap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* This is an events based approach to trigger vehicle charging. Vehicles will be charged as soon as a person begins a charging activity.
Expand All @@ -57,7 +55,7 @@
*/
public class VehicleChargingHandler
implements ActivityStartEventHandler, ActivityEndEventHandler, PersonLeavesVehicleEventHandler,
ChargingEndEventHandler, MobsimScopeEventHandler {
ChargingEndEventHandler, MobsimScopeEventHandler, ChargingListener {

public static final String CHARGING_IDENTIFIER = " charging";
public static final String CHARGING_INTERACTION = ScoringConfigGroup.createStageActivityType(
Expand Down Expand Up @@ -107,10 +105,11 @@ public void handleEvent(ActivityEndEvent event) {
Id<Vehicle> vehicleId = lastVehicleUsed.get(event.getPersonId());
if (vehicleId != null) {
Id<Vehicle> evId = Id.create(vehicleId, Vehicle.class);
ElectricVehicle ev = electricFleet.getElectricVehicles().get(evId);
Id<Charger> chargerId = vehiclesAtChargers.remove(evId);
if (chargerId != null) {
Charger c = chargingInfrastructure.getChargers().get(chargerId);
c.getLogic().removeVehicle(electricFleet.getElectricVehicles().get(evId), event.getTime());
Charger c = chargingInfrastructure.getChargers().get(chargerId);
if(vehiclesAtChargers.remove(evId) != null || c.getLogic().getQueuedVehicles().contains(ev)){
c.getLogic().removeVehicle(ev, event.getTime());
}
}
}
Expand Down

0 comments on commit 6358ed3

Please sign in to comment.