Skip to content

Commit

Permalink
move dvrpMode to Task
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Feb 25, 2024
1 parent 2b80fee commit a5c1f22
Show file tree
Hide file tree
Showing 55 changed files with 163 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public EmptyVehicleChargingScheduler get() {
CostCalculationStrategy.RejectSoftConstraintViolations.class :
CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton();

bindModal(DrtTaskFactory.class).toInstance(new EDrtTaskFactoryImpl());
bindModal(DrtTaskFactory.class).toInstance(new EDrtTaskFactoryImpl(drtCfg.getMode()));

bindModal(EmptyVehicleRelocator.class).toProvider(
new ModalProviders.AbstractProvider<>(drtCfg.getMode(), DvrpModes::mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class EDrtChargingTask extends ChargingTaskImpl {
public static final DrtTaskType TYPE = new DrtTaskType("CHARGING");

public EDrtChargingTask(double beginTime, double endTime, Charger charger, ElectricVehicle ev, double totalEnergy) {
super(TYPE, beginTime, endTime, charger, ev, totalEnergy);
public EDrtChargingTask(String dvrpMode, double beginTime, double endTime, Charger charger, ElectricVehicle ev, double totalEnergy) {
super(dvrpMode, TYPE, beginTime, endTime, charger, ev, totalEnergy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
public class EDrtDriveTask extends DrtDriveTask implements ETask {
private final double consumedEnergy;

public EDrtDriveTask(VrpPathWithTravelData path, DrtTaskType taskType, double consumedEnergy) {
super(path, taskType);
public EDrtDriveTask(String dvrpMode, VrpPathWithTravelData path, DrtTaskType taskType, double consumedEnergy) {
super(dvrpMode, path, taskType);
this.consumedEnergy = consumedEnergy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
public class EDrtStayTask extends DrtStayTask implements ETask {
private final double consumedEnergy;

public EDrtStayTask(double beginTime, double endTime, Link link, double consumedEnergy) {
super(beginTime, endTime, link);
public EDrtStayTask(String dvrpMode, double beginTime, double endTime, Link link, double consumedEnergy) {
super(dvrpMode, beginTime, endTime, link);
this.consumedEnergy = consumedEnergy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
public class EDrtStopTask extends DefaultDrtStopTask implements ETask {
private final double consumedEnergy;

public EDrtStopTask(double beginTime, double endTime, Link link, double consumedEnergy) {
super(beginTime, endTime, link);
public EDrtStopTask(String dvrpMode, double beginTime, double endTime, Link link, double consumedEnergy) {
super(dvrpMode, beginTime, endTime, link);
this.consumedEnergy = consumedEnergy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,30 @@
* @author michalm
*/
public class EDrtTaskFactoryImpl implements DrtTaskFactory {
private final String dvrpMode;

public EDrtTaskFactoryImpl(String dvrpMode) {
this.dvrpMode = dvrpMode;
}

@Override
public EDrtDriveTask createDriveTask(DvrpVehicle vehicle, VrpPathWithTravelData path, DrtTaskType taskType) {
ElectricVehicle ev = ((EvDvrpVehicle)vehicle).getElectricVehicle();
double totalEnergy = VrpPathEnergyConsumptions.calcTotalEnergy(ev, path, path.getDepartureTime());
return new EDrtDriveTask(path, taskType, totalEnergy);
return new EDrtDriveTask(dvrpMode, path, taskType, totalEnergy);
}

@Override
public EDrtStopTask createStopTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link) {
ElectricVehicle ev = ((EvDvrpVehicle)vehicle).getElectricVehicle();
double auxEnergy = ev.getAuxEnergyConsumption()
.calcEnergyConsumption(beginTime, endTime - beginTime, link.getId());
return new EDrtStopTask(beginTime, endTime, link, auxEnergy);
return new EDrtStopTask(dvrpMode, beginTime, endTime, link, auxEnergy);
}

@Override
public EDrtStayTask createStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link) {
return new EDrtStayTask(beginTime, endTime, link, 0);// no energy consumption during STAY
return new EDrtStayTask(dvrpMode, beginTime, endTime, link, 0);// no energy consumption during STAY
}

@Override
Expand All @@ -60,7 +66,7 @@ public DefaultStayTask createInitialTask(DvrpVehicle vehicle, double beginTime,

public EDrtChargingTask createChargingTask(DvrpVehicle vehicle, double beginTime, double endTime, Charger charger,
double totalEnergy) {
return new EDrtChargingTask(beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(),
return new EDrtChargingTask(dvrpMode, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(),
totalEnergy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()),

bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter -> new ShiftVehicleDataEntryFactory(new EDrtVehicleDataEntryFactory(0)))).asEagerSingleton();

bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftEDrtTaskFactoryImpl(new EDrtTaskFactoryImpl(), getter.getModal(OperationFacilities.class)))).in(Singleton.class);
bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftEDrtTaskFactoryImpl(drtCfg.getMode(), new EDrtTaskFactoryImpl(drtCfg.getMode()), getter.getModal(OperationFacilities.class)))).in(Singleton.class);
bindModal(ShiftDrtTaskFactory.class).toProvider(modalProvider(getter -> ((ShiftDrtTaskFactory) getter.getModal(DrtTaskFactory.class))));

bindModal(ShiftTaskScheduler.class).toProvider(modalProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class EDrtShiftBreakTaskImpl extends ShiftBreakTaskImpl implements ShiftB
private final double consumedEnergy;
private final ChargingTask chargingTask;

public EDrtShiftBreakTaskImpl(double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak,
public EDrtShiftBreakTaskImpl(String dvrpMode, double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak,
double consumedEnergy, ChargingTask chargingTask, OperationFacility facility) {
super(beginTime, endTime, link, shiftBreak, facility);
super(dvrpMode, beginTime, endTime, link, shiftBreak, facility);
this.consumedEnergy = consumedEnergy;
this.chargingTask = chargingTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class EDrtShiftChangeoverTaskImpl extends DefaultStayTask implements Shif
private final DrtStopTask delegate;


public EDrtShiftChangeoverTaskImpl(double beginTime, double endTime, Link link,
public EDrtShiftChangeoverTaskImpl(String dvrpMode, double beginTime, double endTime, Link link,
DrtShift shift, double consumedEnergy,
ChargingTask chargingTask, OperationFacility facility) {
super(TYPE, beginTime, endTime, link);
this.delegate = new DefaultDrtStopTask(beginTime, endTime, link);
super(dvrpMode, TYPE, beginTime, endTime, link);
this.delegate = new DefaultDrtStopTask(dvrpMode, beginTime, endTime, link);
this.shift = shift;
this.consumedEnergy = consumedEnergy;
this.chargingTask = chargingTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class EDrtWaitForShiftStayTask extends WaitForShiftStayTask implements ET

private final ChargingTask chargingTask;

public EDrtWaitForShiftStayTask(double beginTime, double endTime, Link link,
public EDrtWaitForShiftStayTask(String dvrpMode, double beginTime, double endTime, Link link,
double consumedEnergy, OperationFacility facility,
ChargingTask chargingTask) {
super(beginTime, endTime, link, facility);
super(dvrpMode, beginTime, endTime, link, facility);
this.consumedEnergy = consumedEnergy;
this.chargingTask = chargingTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
*/
public class ShiftEDrtTaskFactoryImpl implements ShiftDrtTaskFactory {

private final String dvrpMode;
private final EDrtTaskFactoryImpl delegate;
private final OperationFacilities operationFacilities;


public ShiftEDrtTaskFactoryImpl(EDrtTaskFactoryImpl delegate, OperationFacilities operationFacilities) {
this.delegate = delegate;
public ShiftEDrtTaskFactoryImpl(String dvrpMode, EDrtTaskFactoryImpl delegate, OperationFacilities operationFacilities) {
this.dvrpMode = dvrpMode;
this.delegate = delegate;
this.operationFacilities = operationFacilities;

}
Expand Down Expand Up @@ -82,38 +84,38 @@ public DefaultStayTask createInitialTask(DvrpVehicle vehicle, double beginTime,
@Override
public ShiftBreakTask createShiftBreakTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link,
DrtShiftBreak shiftBreak, OperationFacility facility) {
return new EDrtShiftBreakTaskImpl(beginTime, endTime, link, shiftBreak, 0, null, facility);
return new EDrtShiftBreakTaskImpl(dvrpMode, beginTime, endTime, link, shiftBreak, 0, null, facility);
}

@Override
public ShiftChangeOverTask createShiftChangeoverTask(DvrpVehicle vehicle, double beginTime, double endTime,
Link link, DrtShift shift, OperationFacility facility) {
return new EDrtShiftChangeoverTaskImpl(beginTime, endTime, link, shift, 0, null, facility);
return new EDrtShiftChangeoverTaskImpl(dvrpMode, beginTime, endTime, link, shift, 0, null, facility);
}

@Override
public WaitForShiftStayTask createWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link,
OperationFacility facility) {
return new EDrtWaitForShiftStayTask(beginTime, endTime, link, 0, facility, null);
return new EDrtWaitForShiftStayTask(dvrpMode, beginTime, endTime, link, 0, facility, null);
}

public WaitForShiftStayTask createChargingWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime,
double endTime, Link link, OperationFacility facility,
double totalEnergy, Charger charger) {
ChargingTask chargingTask = new ChargingTaskImpl(EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy);
return new EDrtWaitForShiftStayTask(beginTime, endTime, link, totalEnergy, facility, chargingTask);
ChargingTask chargingTask = new ChargingTaskImpl(dvrpMode, EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy);
return new EDrtWaitForShiftStayTask(dvrpMode, beginTime, endTime, link, totalEnergy, facility, chargingTask);
}

public EDrtShiftBreakTaskImpl createChargingShiftBreakTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link,
DrtShiftBreak shiftBreak, Charger charger, double totalEnergy, OperationFacility facility) {
ChargingTask chargingTask = new ChargingTaskImpl(EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy);
return new EDrtShiftBreakTaskImpl(beginTime, endTime, link, shiftBreak, totalEnergy, chargingTask, facility);
ChargingTask chargingTask = new ChargingTaskImpl(dvrpMode, EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy);
return new EDrtShiftBreakTaskImpl(dvrpMode, beginTime, endTime, link, shiftBreak, totalEnergy, chargingTask, facility);
}

public ShiftChangeOverTask createChargingShiftChangeoverTask(DvrpVehicle vehicle, double beginTime, double endTime,
Link link, Charger charger, double totalEnergy,
DrtShift shift, OperationFacility facility) {
ChargingTask chargingTask = new ChargingTaskImpl(EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy);
return new EDrtShiftChangeoverTaskImpl(beginTime, endTime, link, shift, totalEnergy, chargingTask, facility);
ChargingTask chargingTask = new ChargingTaskImpl(dvrpMode, EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy);
return new EDrtShiftChangeoverTaskImpl(dvrpMode, beginTime, endTime, link, shift, totalEnergy, chargingTask, facility);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ shiftsParams, new DefaultShiftStartLogic(), new DefaultAssignShiftToVehicleLogic

bindModal(VehicleEntry.EntryFactory.class).toInstance(new ShiftVehicleDataEntryFactory(new VehicleDataEntryFactoryImpl()));

bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftDrtTaskFactoryImpl(new DrtTaskFactoryImpl(), getter.getModal(OperationFacilities.class))));
bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftDrtTaskFactoryImpl(drtCfg.getMode(), new DrtTaskFactoryImpl(drtCfg.getMode()), getter.getModal(OperationFacilities.class))));
bindModal(ShiftDrtTaskFactory.class).toProvider(modalProvider(getter -> ((ShiftDrtTaskFactory) getter.getModal(DrtTaskFactory.class))));

bindModal(ShiftTaskScheduler.class).toProvider(modalProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class ShiftBreakTaskImpl extends DefaultStayTask implements ShiftBreakTas

private final DrtStopTask delegate;

public ShiftBreakTaskImpl(double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, OperationFacility facility) {
super(TYPE, beginTime, endTime, link);
this.delegate = new DefaultDrtStopTask(beginTime, endTime, link);
public ShiftBreakTaskImpl(String dvrpMode, double beginTime, double endTime, Link link, DrtShiftBreak shiftBreak, OperationFacility facility) {
super(dvrpMode, TYPE, beginTime, endTime, link);
this.delegate = new DefaultDrtStopTask(dvrpMode, beginTime, endTime, link);
this.shiftBreak = shiftBreak;
this.facility = facility;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class ShiftChangeoverTaskImpl extends DefaultStayTask implements ShiftCha

private final DrtStopTask delegate;

public ShiftChangeoverTaskImpl(double beginTime, double endTime, Link link, DrtShift shift, OperationFacility facility) {
super(TYPE, beginTime, endTime, link);
this.delegate = new DefaultDrtStopTask(beginTime, endTime, link);
public ShiftChangeoverTaskImpl(String dvrpMode, double beginTime, double endTime, Link link, DrtShift shift, OperationFacility facility) {
super(dvrpMode, TYPE, beginTime, endTime, link);
this.delegate = new DefaultDrtStopTask(dvrpMode, beginTime, endTime, link);
this.shift = shift;
this.facility = facility;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
*/
public class ShiftDrtTaskFactoryImpl implements ShiftDrtTaskFactory {

private final String dvrpMode;
private final DrtTaskFactory delegate;
private final OperationFacilities operationFacilities;

public ShiftDrtTaskFactoryImpl(DrtTaskFactory delegate, OperationFacilities operationFacilities) {
public ShiftDrtTaskFactoryImpl(String dvrpMode, DrtTaskFactory delegate, OperationFacilities operationFacilities) {
this.dvrpMode = dvrpMode;
this.delegate = delegate;
this.operationFacilities = operationFacilities;
}
Expand All @@ -48,19 +50,19 @@ public DrtStayTask createStayTask(DvrpVehicle vehicle, double beginTime, double
@Override
public ShiftBreakTask createShiftBreakTask(DvrpVehicle vehicle, double beginTime, double endTime,
Link link, DrtShiftBreak shiftBreak, OperationFacility facility) {
return new ShiftBreakTaskImpl(beginTime, endTime, link, shiftBreak, facility);
return new ShiftBreakTaskImpl(dvrpMode, beginTime, endTime, link, shiftBreak, facility);
}

@Override
public ShiftChangeOverTask createShiftChangeoverTask(DvrpVehicle vehicle, double beginTime, double endTime,
Link link, DrtShift shift, OperationFacility facility) {
return new ShiftChangeoverTaskImpl(beginTime, endTime, link, shift, facility);
return new ShiftChangeoverTaskImpl(dvrpMode, beginTime, endTime, link, shift, facility);
}

@Override
public WaitForShiftStayTask createWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime, double endTime,
Link link, OperationFacility facility) {
return new WaitForShiftStayTask(beginTime, endTime, link, facility);
return new WaitForShiftStayTask(dvrpMode, beginTime, endTime, link, facility);
}

public DefaultStayTask createInitialTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class WaitForShiftStayTask extends DefaultStayTask implements Operational

private final OperationFacility facility;

public WaitForShiftStayTask(double beginTime, double endTime, Link link, OperationFacility facility) {
super(TYPE, beginTime, endTime, link);
public WaitForShiftStayTask(String dvrpMode, double beginTime, double endTime, Link link, OperationFacility facility) {
super(dvrpMode, TYPE, beginTime, endTime, link);
this.facility = facility;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void configureQSim() {
getter.getModal(DrtTaskFactory.class), getter.get(EventsManager.class), getter.getModal(Fleet.class),
getter.getModal(ScheduleTimingUpdater.class))));

bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl());
bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl(drtCfg.getMode()));

bindModal(VrpLegFactory.class).toProvider(modalProvider(getter -> {
DvrpConfigGroup dvrpCfg = getter.get(DvrpConfigGroup.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void nextTask(DvrpVehicle vehicle) {
// otherwise we may not be able to get the request and insert it to the stop task
// TODO currently assuming the mobsim time step is 1 s
schedule.addTask(
new WaitForStopTask(currentTime, nextStop.preplannedRequest.earliestStartTime + 1, currentLink));
new WaitForStopTask(mode, currentTime, nextStop.preplannedRequest.earliestStartTime + 1, currentLink));
} else {
nonVisitedPreplannedStops.poll();//remove this stop from queue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class WaitForStopTask extends DefaultStayTask {

public static final DrtTaskType TYPE = new DrtTaskType("WAIT_FOR_STOP", STAY);

public WaitForStopTask(double beginTime, double endTime, Link link) {
super(TYPE, beginTime, endTime, link);
public WaitForStopTask(String dvrpMode, double beginTime, double endTime, Link link) {
super(dvrpMode, TYPE, beginTime, endTime, link);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected void configureQSim() {
CostCalculationStrategy.RejectSoftConstraintViolations.class :
CostCalculationStrategy.DiscourageSoftConstraintViolations.class).asEagerSingleton();

bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl());
bindModal(DrtTaskFactory.class).toInstance(new DrtTaskFactoryImpl(drtCfg.getMode()));

bindModal(EmptyVehicleRelocator.class).toProvider(
new ModalProviders.AbstractProvider<>(drtCfg.getMode(), DvrpModes::mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class DefaultDrtStopTask extends DefaultStayTask implements DrtStopTask {
private final Map<Id<Request>, AcceptedDrtRequest> dropoffRequests = new LinkedHashMap<>();
private final Map<Id<Request>, AcceptedDrtRequest> pickupRequests = new LinkedHashMap<>();

public DefaultDrtStopTask(double beginTime, double endTime, Link link) {
super(TYPE, beginTime, endTime, link);
public DefaultDrtStopTask(String dvrpMode, double beginTime, double endTime, Link link) {
super(dvrpMode, TYPE, beginTime, endTime, link);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class DrtDriveTask extends DefaultDriveTask {
public static final DrtTaskType TYPE = new DrtTaskType(DRIVE);

public DrtDriveTask(VrpPathWithTravelData path, DrtTaskType taskType) {
super(taskType, path);
public DrtDriveTask(String dvrpMode, VrpPathWithTravelData path, DrtTaskType taskType) {
super(dvrpMode, taskType, path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class DrtStayTask extends DefaultStayTask {
public static final DrtTaskType TYPE = new DrtTaskType(STAY);

public DrtStayTask(double beginTime, double endTime, Link link) {
super(TYPE, beginTime, endTime, link);
public DrtStayTask(String dvrpMode, double beginTime, double endTime, Link link) {
super(dvrpMode, TYPE, beginTime, endTime, link);
}
}
Loading

0 comments on commit a5c1f22

Please sign in to comment.