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 2 commits
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 @@ -21,19 +21,21 @@

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.extension.edrt.schedule.EDrtTaskFactoryImpl;
import org.matsim.contrib.drt.schedule.DrtStayTask;
import org.matsim.contrib.drt.schedule.DrtTaskFactory;
import org.matsim.contrib.dvrp.fleet.DvrpVehicle;
import org.matsim.contrib.dvrp.schedule.Schedule;
import org.matsim.contrib.drt.extension.edrt.schedule.EDrtTaskFactoryImpl;
import org.matsim.contrib.ev.charging.ChargingStrategy;
import org.matsim.contrib.ev.charging.ChargingWithAssignmentLogic;
import org.matsim.contrib.evrp.EvDvrpVehicle;
import org.matsim.contrib.ev.fleet.ElectricVehicle;
import org.matsim.contrib.ev.infrastructure.Charger;
import org.matsim.contrib.ev.infrastructure.ChargingInfrastructure;
import org.matsim.contrib.evrp.EvDvrpVehicle;
import org.matsim.core.mobsim.framework.MobsimTimer;

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

Expand All @@ -43,23 +45,25 @@
public class EmptyVehicleChargingScheduler {
private final MobsimTimer timer;
private final EDrtTaskFactoryImpl taskFactory;
private final Map<Id<Link>, Charger> linkToChargerMap;
private final Map<Id<Link>, List<Charger>> linkToChargersMap;

public EmptyVehicleChargingScheduler(MobsimTimer timer, DrtTaskFactory taskFactory,
ChargingInfrastructure chargingInfrastructure) {
this.timer = timer;
this.taskFactory = (EDrtTaskFactoryImpl)taskFactory;
linkToChargerMap = chargingInfrastructure.getChargers()
linkToChargersMap = 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 = linkToChargersMap.get(currentLink.getId());
if (chargers != null) {
// Take the charger with the smallest queue
Charger charger = chargers.stream().min(Comparator.comparing(e -> e.getLogic().getQueuedVehicles().size())).orElseThrow();
Copy link
Member

Choose a reason for hiding this comment

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

Replace comparing() with comparingInt()

Copy link
Member

Choose a reason for hiding this comment

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

You can also change

min(Comparator.comparing(e -> e.getLogic().getQueuedVehicles().size()))

to something like this:

mapToInt(e -> e.getLogic().getQueuedVehicles().size()).min()

Copy link
Collaborator Author

@steffenaxer steffenaxer Nov 5, 2023

Choose a reason for hiding this comment

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

mapToInt(e -> e.getLogic().getQueuedVehicles().size()).min() but we want to get the Charger with the lowest number of queued vehicles. The object of intreset is charger not the int.

Copy link
Member

Choose a reason for hiding this comment

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

True:-) Suggesting code changes without trying them in an IDE...

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