From 3c6c0fc1d46f523bb8fcbcc68b0e741aec8329ae Mon Sep 17 00:00:00 2001 From: Lennart Adenaw Date: Tue, 7 Nov 2023 14:05:33 +0100 Subject: [PATCH] No charging starts at soc greater than end soc --- .../charging/VehicleChargingHandler.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/tum/mw/ftm/matsim/contrib/urban_ev/charging/VehicleChargingHandler.java b/src/main/java/de/tum/mw/ftm/matsim/contrib/urban_ev/charging/VehicleChargingHandler.java index bb542a4..4e72c63 100644 --- a/src/main/java/de/tum/mw/ftm/matsim/contrib/urban_ev/charging/VehicleChargingHandler.java +++ b/src/main/java/de/tum/mw/ftm/matsim/contrib/urban_ev/charging/VehicleChargingHandler.java @@ -42,6 +42,7 @@ import de.tum.mw.ftm.matsim.contrib.urban_ev.scoring.ChargingBehaviourScoringEvent; import de.tum.mw.ftm.matsim.contrib.urban_ev.scoring.ChargingBehaviourScoringEvent.ScoreTrigger; import de.tum.mw.ftm.matsim.contrib.urban_ev.utils.PlanUtils; +import de.tum.mw.ftm.matsim.contrib.urban_ev.charging.ChargeUpToTypeMaxSocStrategy; import org.apache.log4j.Logger; import org.matsim.api.core.v01.Coord; @@ -78,6 +79,8 @@ public class VehicleChargingHandler public static final Integer SECONDS_PER_MINUTE = 60; public static final Integer SECONDS_PER_HOUR = 60*SECONDS_PER_MINUTE; public static final Integer SECONDS_PER_DAY = 24*SECONDS_PER_HOUR; + + // State variables private Map, Id> vehiclesAtChargers = new HashMap<>(); private final ChargingInfrastructure chargingInfrastructure; @@ -130,7 +133,8 @@ public void handleEvent(ActivityStartEvent event) { ElectricVehicle ev = electricFleet.getElectricVehicles().get(evId); Person person = population.getPersons().get(personId); double walkingDistance = 0.0; - double time = event.getTime(); + double soc = ev.getBattery().getSoc() / ev.getBattery().getCapacity(); + double time = event.getTime(); if (PlanUtils.isCharging(actType)) { @@ -149,22 +153,21 @@ public void handleEvent(ActivityStartEvent event) { { selectedCharger = selectCharger(suitableChargers, activityCoord, ChargerSelectionMethod.CLOSEST); } - - // Start charging if possible - if (selectedCharger != null) { // if charger was found, start charging + + // Start charging if charger was found and soc is lower than anticipated end soc + if (selectedCharger != null && soc vehiclesAtChargers = chargingInfrastructure.getChargers().values().stream().map(c -> c.getLogic().getPluggedVehicles()).collect(Collectors.toList()); + + //List vehiclesAtChargers = chargingInfrastructure.getChargers().values().stream().flatMap(a -> a.getLogic().getPluggedVehicles().stream()).collect(Collectors.toList()); + + // Map, Id> vehiclesAtChargers = chargingInfrastructure.getChargers().values().stream() + // .flatMap(a -> a.getLogic().getPluggedVehicles().stream()) + // .collect(Collectors.toMap(ElectricVehicle::getId, a -> a.getId())); + // If the vehicle is currently plugged in if(vehiclesAtChargers.containsKey(evId)) {