From cb2b79f7fca74c2b2a8c2523874d5f5c937ceb5d Mon Sep 17 00:00:00 2001 From: tschlenther Date: Tue, 14 Nov 2023 17:55:56 +0100 Subject: [PATCH] fix: first plug vehicles from queue, then handle arriving vehicles --- .../charging/ChargingWithQueueingLogic.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/ChargingWithQueueingLogic.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/ChargingWithQueueingLogic.java index 5a5d829ee32..8cf57733532 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/ChargingWithQueueingLogic.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/ChargingWithQueueingLogic.java @@ -19,23 +19,15 @@ package org.matsim.contrib.ev.charging; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Objects; -import java.util.Queue; -import java.util.concurrent.LinkedBlockingQueue; - +import com.google.common.base.Preconditions; import org.matsim.api.core.v01.Id; import org.matsim.contrib.ev.fleet.ElectricVehicle; import org.matsim.contrib.ev.infrastructure.ChargerSpecification; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.vehicles.Vehicle; -import com.google.common.base.Preconditions; +import java.util.*; +import java.util.concurrent.LinkedBlockingQueue; public class ChargingWithQueueingLogic implements ChargingLogic { protected final ChargerSpecification charger; @@ -73,6 +65,11 @@ public void chargeVehicles(double chargePeriod, double now) { } } + int queuedToPluggedCount = Math.min(queuedVehicles.size(), charger.getPlugCount() - pluggedVehicles.size()); + for (int i = 0; i < queuedToPluggedCount; i++) { + plugVehicle(queuedVehicles.poll(), now); + } + var arrivingVehiclesIter = arrivingVehicles.iterator(); while (arrivingVehiclesIter.hasNext()) { var ev = arrivingVehiclesIter.next(); @@ -83,11 +80,6 @@ public void chargeVehicles(double chargePeriod, double now) { } arrivingVehiclesIter.remove(); } - - int queuedToPluggedCount = Math.min(queuedVehicles.size(), charger.getPlugCount() - pluggedVehicles.size()); - for (int i = 0; i < queuedToPluggedCount; i++) { - plugVehicle(queuedVehicles.poll(), now); - } } @Override