Skip to content

Commit

Permalink
fix: first plug vehicles from queue, then handle arriving vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
tschlenther committed Nov 14, 2023
1 parent ce0528f commit cb2b79f
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit cb2b79f

Please sign in to comment.