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 cb2b79f commit 1d57f82
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
package playground.vsp.ev;

import com.google.common.collect.ImmutableListMultimap;
import jakarta.inject.Inject;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.*;
import org.matsim.api.core.v01.events.handler.*;
import org.matsim.api.core.v01.events.ActivityEndEvent;
import org.matsim.api.core.v01.events.ActivityStartEvent;
import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent;
import org.matsim.api.core.v01.events.handler.ActivityEndEventHandler;
import org.matsim.api.core.v01.events.handler.ActivityStartEventHandler;
import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.ev.charging.*;
Expand All @@ -35,8 +40,9 @@
import org.matsim.core.utils.collections.Tuple;
import org.matsim.vehicles.Vehicle;

import jakarta.inject.Inject;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
Expand Down Expand Up @@ -114,10 +120,11 @@ public void handleEvent(ActivityEndEvent event) {
Tuple<Id<Vehicle>, Id<Charger>> tuple = chargingProcedures.get(event.getLinkId()).remove(event.getPersonId());
if (tuple != null) {
Id<Vehicle> evId = Id.create(tuple.getFirst(), Vehicle.class);
if(vehiclesAtChargers.remove(evId) != null){ //if null, vehicle is fully charged and de-plugged already (see handleEvent(ChargingEndedEvent) )
Id<Charger> chargerId = tuple.getSecond();
Charger c = chargingInfrastructure.getChargers().get(chargerId);
c.getLogic().removeVehicle(electricFleet.getElectricVehicles().get(evId), event.getTime());
ElectricVehicle ev = electricFleet.getElectricVehicles().get(evId);
Id<Charger> chargerId = tuple.getSecond();
Charger c = chargingInfrastructure.getChargers().get(chargerId);
if(vehiclesAtChargers.remove(evId) != null || c.getLogic().getQueuedVehicles().contains(ev)){
c.getLogic().removeVehicle(ev, event.getTime());
}
} else {
throw new RuntimeException("there is something wrong with the charging procedure of person=" + event.getPersonId() + " on link= " + event.getLinkId());
Expand Down

0 comments on commit 1d57f82

Please sign in to comment.