Skip to content

Commit

Permalink
No charging starts at soc greater than end soc
Browse files Browse the repository at this point in the history
  • Loading branch information
ladenaw committed Nov 7, 2023
1 parent b6270fe commit 3c6c0fc
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ElectricVehicle>, Id<Charger>> vehiclesAtChargers = new HashMap<>();

private final ChargingInfrastructure chargingInfrastructure;
Expand Down Expand Up @@ -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)) {

Expand All @@ -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<ChargeUpToTypeMaxSocStrategy.getMaxRelativeSoc(selectedCharger)) {
selectedCharger.getLogic().addVehicle(ev, time);
vehiclesAtChargers.put(evId, selectedCharger.getId());
walkingDistance = DistanceUtils.calculateDistance(
activityCoord, selectedCharger.getCoord());
} else {
// if no charger was found, mark as failed attempt in plan if not already marked
// if no charger was found, or charging would be ineffective, mark as failed attempt in plan if not already marked
if (activity != null) {
PlanUtils.setFailed(activity);
}
}
}

double socUponArrival = ev.getBattery().getSoc() / ev.getBattery().getCapacity();
double startSoc = ev.getBattery().getStartSoc() / ev.getBattery().getCapacity();

// Issue a charging behaviour scoring event
Expand All @@ -173,7 +176,7 @@ public void handleEvent(ActivityStartEvent event) {
time,
personId,
actType,
socUponArrival,
soc,
startSoc,
walkingDistance,
0.0,
Expand All @@ -183,7 +186,7 @@ public void handleEvent(ActivityStartEvent event) {
);
}
}
}
}

@Override
public void handleEvent(ActivityEndEvent event) {
Expand All @@ -196,6 +199,14 @@ public void handleEvent(ActivityEndEvent event) {
double socUponDeparture = ev.getBattery().getSoc() / ev.getBattery().getCapacity();
double time = event.getTime();

//ArrayList<ElectricVehicle> vehiclesAtChargers = chargingInfrastructure.getChargers().values().stream().map(c -> c.getLogic().getPluggedVehicles()).collect(Collectors.toList());

//List<ElectricVehicle> vehiclesAtChargers = chargingInfrastructure.getChargers().values().stream().flatMap(a -> a.getLogic().getPluggedVehicles().stream()).collect(Collectors.toList());

// Map<Id<ElectricVehicle>, Id<Charger>> 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))
{
Expand Down

0 comments on commit 3c6c0fc

Please sign in to comment.