Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(edrt) Allow multi. chargers per link #2919

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@
import org.matsim.contrib.ev.fleet.ElectricVehicle;
import org.matsim.contrib.ev.infrastructure.Charger;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructure;
import org.matsim.core.gbl.MatsimRandom;
import org.matsim.core.mobsim.framework.MobsimTimer;

import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

/**
* @author michalm
*/
public class EmptyVehicleChargingScheduler {
private static final Random RND = MatsimRandom.getLocalInstance();
private final MobsimTimer timer;
private final EDrtTaskFactoryImpl taskFactory;
private final Map<Id<Link>, Charger> linkToChargerMap;
private final Map<Id<Link>, List<Charger>> linkToChargerMap;
steffenaxer marked this conversation as resolved.
Show resolved Hide resolved

public EmptyVehicleChargingScheduler(MobsimTimer timer, DrtTaskFactory taskFactory,
ChargingInfrastructure chargingInfrastructure) {
Expand All @@ -52,14 +56,16 @@ public EmptyVehicleChargingScheduler(MobsimTimer timer, DrtTaskFactory taskFacto
linkToChargerMap = chargingInfrastructure.getChargers()
.values()
.stream()
.collect(Collectors.toMap(c -> c.getLink().getId(), c -> c));
.collect(Collectors.groupingBy(c -> c.getLink().getId()));
}

public void chargeVehicle(DvrpVehicle vehicle) {
DrtStayTask currentTask = (DrtStayTask)vehicle.getSchedule().getCurrentTask();
Link currentLink = currentTask.getLink();
Charger charger = linkToChargerMap.get(currentLink.getId());
if (charger != null) {
List<Charger> chargers = linkToChargerMap.get(currentLink.getId());
if (chargers != null) {
// Pick a random charger of all available chargers at this link
Charger charger = chargers.get(RND.nextInt(chargers.size()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead take the one with highest number of unused plugs. If there is none with unused plugs, take the one with shortest queue or lowest queue.size/plugCount. You could also include charger power in choosing the charger.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Thanks.

ElectricVehicle ev = ((EvDvrpVehicle)vehicle).getElectricVehicle();
if (!charger.getLogic().getChargingStrategy().isChargingCompleted(ev)) {
chargeVehicleImpl(vehicle, charger);
Expand Down