Skip to content

Commit

Permalink
introduce modal bindings for charging strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Nov 26, 2024
1 parent 2b706fc commit a6dcc86
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,11 @@ protected void configureQSim() {
@Inject
private MobsimTimer timer;

@Inject
// note: this could also become modal now! /sh, nov'24
private ChargingStrategy.Factory chargingStrategyFactory;

@Override
public EmptyVehicleChargingScheduler get() {
var taskFactory = getModalInstance(DrtTaskFactory.class);
var chargingInfrastructure = getModalInstance(ChargingInfrastructure.class);
ChargingStrategy.Factory chargingStrategyFactory = getModalInstance(ChargingStrategy.Factory.class);
return new EmptyVehicleChargingScheduler(timer, taskFactory, chargingInfrastructure, chargingStrategyFactory);
}
}).asEagerSingleton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@

import java.net.URL;

import org.matsim.contrib.drt.extension.edrt.optimizer.EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.drt.extension.edrt.optimizer.EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider;
import org.matsim.contrib.dvrp.run.DvrpModes;
import org.matsim.contrib.ev.EvConfigGroup;
import org.matsim.contrib.ev.charging.ChargeUpToMaxSocStrategy;
import org.matsim.contrib.ev.charging.ChargingLogic;
import org.matsim.contrib.ev.charging.ChargingPower;
import org.matsim.contrib.ev.charging.ChargingStrategy;
import org.matsim.contrib.ev.charging.ChargingWithQueueingAndAssignmentLogic;
import org.matsim.contrib.ev.charging.ChargingWithQueueingLogic;
import org.matsim.contrib.ev.charging.FixedSpeedCharging;
import org.matsim.contrib.ev.temperature.TemperatureService;
import org.matsim.core.config.Config;
Expand All @@ -42,6 +42,8 @@
import org.matsim.core.controler.Controler;
import org.matsim.vis.otfvis.OTFVisConfigGroup;

import com.google.inject.Key;

/**
* @author Michal Maciejewski (michalm)
*/
Expand Down Expand Up @@ -72,9 +74,12 @@ public void install() {
@Override
public void install() {
bind(ChargingLogic.Factory.class).to(ChargingWithQueueingAndAssignmentLogic.Factory.class);
bind(ChargingStrategy.Factory.class).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_RELATIVE_SOC));
bind(ChargingPower.Factory.class).toInstance(ev -> new FixedSpeedCharging(ev, CHARGING_SPEED_FACTOR));
bind(TemperatureService.class).toInstance(linkId -> TEMPERATURE);

for (DrtConfigGroup drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) {
bind(Key.get(ChargingStrategy.Factory.class, DvrpModes.mode(drtCfg.mode))).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_RELATIVE_SOC));
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ protected void configureQSim() {
getter -> null)
).asEagerSingleton();

// note: the ChargingStrategy.Factory could also become modal! // sh, nov'24
bindModal(DrtShiftDispatcher.class).toProvider(modalProvider(
getter -> new EDrtShiftDispatcherImpl(((EShiftTaskScheduler) getter.getModal(ShiftTaskScheduler.class)),
getter.getModal(ChargingInfrastructure.class), drtShiftParams, getter.getModal(OperationFacilities.class),
Expand All @@ -74,7 +73,7 @@ protected void configureQSim() {
drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()),
new EDrtAssignShiftToVehicleLogic(new DefaultAssignShiftToVehicleLogic(drtShiftParams), drtShiftParams),
getter.getModal(ShiftScheduler.class)),
getter.getModal(Fleet.class), getter.get(ChargingStrategy.Factory.class)))
getter.getModal(Fleet.class), getter.getModal(ChargingStrategy.Factory.class)))
).asEagerSingleton();

bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter ->
Expand All @@ -85,13 +84,12 @@ drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()),
bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftEDrtTaskFactoryImpl(new EDrtTaskFactoryImpl(), getter.getModal(OperationFacilities.class)))).in(Singleton.class);
bindModal(ShiftDrtTaskFactory.class).toProvider(modalProvider(getter -> ((ShiftDrtTaskFactory) getter.getModal(DrtTaskFactory.class))));

// note: the ChargingStrategy.Factory could also become modal! // sh, nov'24
bindModal(ShiftTaskScheduler.class).toProvider(modalProvider(
getter -> new EShiftTaskScheduler(getter.getModal(Network.class), getter.getModal(TravelTime.class),
getter.getModal(TravelDisutilityFactory.class).createTravelDisutility(getter.getModal(TravelTime.class)),
getter.get(MobsimTimer.class), getter.getModal(ShiftDrtTaskFactory.class), drtShiftParams, getter.getModal(ChargingInfrastructure.class),
getter.getModal(OperationFacilities.class), getter.getModal(Fleet.class),
getter.get(ChargingStrategy.Factory.class))
getter.getModal(ChargingStrategy.Factory.class))
)).asEagerSingleton();

// See EDrtModeOptimizerQSimModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpModes;
import org.matsim.contrib.ev.EvConfigGroup;
import org.matsim.contrib.ev.charging.*;
import org.matsim.contrib.ev.temperature.TemperatureService;
Expand All @@ -32,6 +33,8 @@
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.examples.ExamplesUtils;

import com.google.inject.Key;

import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -178,7 +181,7 @@ void test() {
@Override
public void install() {
bind(ChargingLogic.Factory.class).to(ChargingWithQueueingAndAssignmentLogic.Factory.class);
bind(ChargingStrategy.Factory.class).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_RELATIVE_SOC));
bind(Key.get(ChargingStrategy.Factory.class, DvrpModes.mode(drtConfigGroup.mode))).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_RELATIVE_SOC));
bind(ChargingPower.Factory.class).toInstance(FastThenSlowCharging::new);
bind(TemperatureService.class).toInstance(linkId -> TEMPERATURE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.fleet.DvrpVehicle;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule;
import org.matsim.contrib.dvrp.run.DvrpModes;
import org.matsim.contrib.ev.charging.*;
import org.matsim.contrib.ev.temperature.TemperatureService;
import org.matsim.core.config.Config;
Expand All @@ -22,6 +23,8 @@
import org.matsim.core.controler.Controler;
import org.matsim.testcases.MatsimTestUtils;

import com.google.inject.Key;

public class RunEDrtWithServicesScenarioIT {
public static final double MINIMUM_RELATIVE_SOC = 0.2;
public static final double MAX_SOC = 1.0;
Expand Down Expand Up @@ -78,7 +81,7 @@ public void install() {
@Override
public void install() {
bind(ChargingLogic.Factory.class).to(ChargingWithQueueingAndAssignmentLogic.Factory.class);
bind(ChargingStrategy.Factory.class).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_SOC));
bind(Key.get(ChargingStrategy.Factory.class, DvrpModes.mode(drtConfigGroup.mode))).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_SOC));
bind(ChargingPower.Factory.class).toInstance(ev -> new FixedSpeedCharging(ev, RELATIVE_SPEED));
bind(TemperatureService.class).toInstance(linkId -> TEMPERATURE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ public TaxiOptimizer get() {
@Inject
private EventsManager events;

@Inject
// note: this could be modal now! /sh, nov'24
private ChargingStrategy.Factory chargingStrategyFactory;

@Override
public ETaxiScheduler get() {
var travelTime = getModalInstance(TravelTime.class);
Expand All @@ -118,6 +114,7 @@ public ETaxiScheduler get() {
var speedyALTFactory = new SpeedyALTFactory();
Supplier<LeastCostPathCalculator> routerCreator = () -> speedyALTFactory.createPathCalculator(
network, travelDisutility, travelTime);
ChargingStrategy.Factory chargingStrategyFactory = getModalInstance(ChargingStrategy.Factory.class);
return new ETaxiScheduler(taxiCfg, fleet, taxiScheduleInquiry, travelTime, routerCreator,
events, timer, chargingStrategyFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.matsim.contrib.dvrp.fleet.FleetSpecification;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpModes;
import org.matsim.contrib.dvrp.run.DvrpQSimComponents;
import org.matsim.contrib.ev.EvConfigGroup;
import org.matsim.contrib.ev.EvModule;
Expand Down Expand Up @@ -54,6 +55,8 @@
import org.matsim.core.mobsim.qsim.AbstractQSimModule;
import org.matsim.core.scenario.ScenarioUtils;

import com.google.inject.Key;

/**
* For a fair and consistent benchmarking of taxi dispatching algorithms we assume that link travel times are
* deterministic. To simulate this property, we remove (1) all other traffic, and (2) link capacity constraints (e.g. by
Expand Down Expand Up @@ -113,7 +116,7 @@ protected void configureQSim() {
@Override
public void install() {
bind(ChargingLogic.Factory.class).to(ChargingWithQueueingAndAssignmentLogic.Factory.class);
bind(ChargingStrategy.Factory.class).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_SOC));
bind(Key.get(ChargingStrategy.Factory.class, DvrpModes.mode(mode))).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_SOC));
//TODO switch to VariableSpeedCharging for Nissan
bind(ChargingPower.Factory.class).toInstance(ev -> new FixedSpeedCharging(ev, CHARGING_SPEED_FACTOR));
bind(TemperatureService.class).toInstance(linkId -> TEMPERATURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.matsim.api.core.v01.Scenario;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpModes;
import org.matsim.contrib.dvrp.run.DvrpModule;
import org.matsim.contrib.dvrp.run.DvrpQSimComponents;
import org.matsim.contrib.ev.EvConfigGroup;
Expand All @@ -34,9 +35,9 @@
import org.matsim.contrib.ev.charging.ChargingWithQueueingAndAssignmentLogic;
import org.matsim.contrib.ev.charging.FixedSpeedCharging;
import org.matsim.contrib.ev.discharging.IdleDischargingHandler;
import org.matsim.contrib.ev.temperature.TemperatureService;
import org.matsim.contrib.evrp.EvDvrpFleetQSimModule;
import org.matsim.contrib.evrp.OperatingVehicleProvider;
import org.matsim.contrib.ev.temperature.TemperatureService;
import org.matsim.contrib.otfvis.OTFVisLiveModule;
import org.matsim.contrib.taxi.run.MultiModeTaxiConfigGroup;
import org.matsim.contrib.taxi.run.TaxiConfigGroup;
Expand All @@ -49,6 +50,8 @@
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.vis.otfvis.OTFVisConfigGroup;

import com.google.inject.Key;

public class RunETaxiScenario {
private static final double CHARGING_SPEED_FACTOR = 1.5; // > 1 in this example
private static final double MAX_SOC = 0.8; // charge up to 80% SOC
Expand Down Expand Up @@ -93,10 +96,13 @@ protected void configureQSim() {
@Override
public void install() {
bind(ChargingLogic.Factory.class).to(ChargingWithQueueingAndAssignmentLogic.Factory.class);
bind(ChargingStrategy.Factory.class).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_SOC));
//TODO switch to VariableSpeedCharging for Nissan
bind(ChargingPower.Factory.class).toInstance(ev -> new FixedSpeedCharging(ev, CHARGING_SPEED_FACTOR));
bind(TemperatureService.class).toInstance(linkId -> TEMPERATURE);

for (TaxiConfigGroup taxiCfg : multiModeTaxiConfig.getModalElements()) {
bind(Key.get(ChargingStrategy.Factory.class, DvrpModes.mode(taxiCfg.getMode()))).toInstance(new ChargeUpToMaxSocStrategy.Factory(MAX_SOC));
}
}
});

Expand Down

0 comments on commit a6dcc86

Please sign in to comment.