You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide the MATSim version you are using. You can find the version in the pom.xml. E.g. 2025.0.
2025.0
Did you build a minimal example to reproduce the issue?
Yes!
Describe the problem you are facing.
I am trying to create a matsim scenario that uses both the freight and EV contribs to create a fleet of electric vehicles to perform both long haul and last mile deliveries. I have set up the EV contrib and can get normal agents in the plans.xml file to use electricity and I have the logistics agents creating carriers to collect shipments but I cannot see my carrier agents in the EV outputs.
Are these two contribs compatible with each other?
importorg.apache.logging.log4j.LogManager;
importorg.apache.logging.log4j.Logger;
importorg.apache.logging.log4j.core.config.Configurator;
importorg.apache.logging.log4j.Level;
importorg.matsim.api.core.v01.Id;
importorg.matsim.api.core.v01.Scenario;
importorg.matsim.api.core.v01.TransportMode;
importorg.matsim.contrib.ev.EvConfigGroup;
importorg.matsim.contrib.ev.EvModule;
importorg.matsim.contrib.ev.discharging.AuxEnergyConsumption;
importorg.matsim.contrib.ev.discharging.DriveEnergyConsumption;
importorg.matsim.contrib.ev.discharging.VehicleTypeSpecificDriveEnergyConsumptionFactory;
importorg.matsim.contrib.ev.infrastructure.LTHConsumptionModelReader;
importorg.matsim.contrib.ev.routing.EvNetworkRoutingProvider;
importorg.matsim.core.config.Config;
importorg.matsim.core.config.ConfigGroup;
importorg.matsim.core.config.ConfigUtils;
importorg.matsim.core.config.ConfigWriter;
importorg.matsim.core.config.groups.VspExperimentalConfigGroup;
importorg.matsim.core.controler.AbstractModule;
importorg.matsim.core.controler.Controler;
importorg.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
importorg.matsim.core.replanning.GenericPlanStrategyImpl;
importorg.matsim.core.replanning.selectors.RandomPlanSelector;
importorg.matsim.core.scenario.ScenarioUtils;
importorg.matsim.freight.carriers.*;
importorg.matsim.freight.carriers.controller.CarrierControllerUtils;
importorg.matsim.freight.carriers.controller.CarrierStrategyManager;
importorg.matsim.freight.logistics.*;
importorg.matsim.freight.logistics.examples.lspReplanning.AssignmentStrategyFactory;
importorg.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils;
importorg.matsim.freight.logistics.shipment.LspShipment;
importorg.matsim.vehicles.VehicleType;
importorg.matsim.vehicles.VehicleUtils;
importorg.transit.logistics.TransitLSPScorer;
importjava.util.Collection;
importjava.util.Collections;
importstaticorg.transit.logistics.createLSP.createInitialLSP;
importstaticorg.transit.logistics.createLSP.createLSPShipments;
importstaticorg.transit.logistics.createLongHaulLSP.createInitialLongHaulLSP;
importstaticorg.transit.logistics.createLongHaulLSP.createLongHaulLSPShipments;
publicclassRunTransit {
// Scale factor (must be same as specified when generating demand)privatestaticfinaldoubleSCALE_FACTOR = 0.04;
privatestaticfinalLoggerlogger = LogManager.getLogger(RunTransit.class);
publicstaticvoidmain(String[] args) throwsException {
// Set global log level to DEBUGConfigurator.setRootLevel(Level.DEBUG);
EvConfigGroupevConfig = newEvConfigGroup();
FreightCarriersConfigGroupcarriersConfig = newFreightCarriersConfigGroup();
carriersConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore);
carriersConfig.setTravelTimeSliceWidth(600);
Configconfig = null;
if (args == null || args.length == 0 || args[0] == null) {
logger.warn("No config file given. Please provide config file as input at command line");
System.exit(0);
} else {
config = ConfigUtils.loadConfig(args, evConfig, carriersConfig);
}
newRunTransit().run(config);
}
publicvoidrun(Configconfig) throwsException {
config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists);
// Specify scale factorconfig.qsim().setFlowCapFactor(SCALE_FACTOR);
config.qsim().setStorageCapFactor(SCALE_FACTOR);
Scenarioscenario = ScenarioUtils.loadScenario(config);
logger.info("Creating Freight Vehicle");
Id<Carrier> carrierId = Id.create("DeliveryCarrier", Carrier.class);
Id<VehicleType> vehicleTypeId = Id.create("EV_65.0kWh_carrier", VehicleType.class);
VehicleTypecollectionVehType = VehicleUtils.createVehicleType(vehicleTypeId, TransportMode.car);
VehicleUtils.setHbefaTechnology(collectionVehType.getEngineInformation(), "electricity");
VehicleUtils.setEnergyCapacity(collectionVehType.getEngineInformation(), 65);
collectionVehType.getCapacity().setOther(10);
collectionVehType.getCostInformation().setCostsPerMeter(0.0004);
collectionVehType.getCostInformation().setCostsPerSecond(0.38);
collectionVehType.getCostInformation().setFixedCost(49.);
collectionVehType.setMaximumVelocity(50 / 3.6);
Id<Carrier> longHaulId = Id.create("HGVCarrier", Carrier.class);
Id<VehicleType> vehicleTypeHGV = Id.create("EV_125.0kWh_HGV", VehicleType.class);
VehicleTypelongHaulVehicle = VehicleUtils.createVehicleType(vehicleTypeHGV, TransportMode.car);
VehicleUtils.setHbefaTechnology(longHaulVehicle.getEngineInformation(), "electricity");
VehicleUtils.setEnergyCapacity(longHaulVehicle.getEngineInformation(), 125);
longHaulVehicle.getCapacity().setOther(50);
longHaulVehicle.getCostInformation().setCostsPerMeter(0.0008);
longHaulVehicle.getCostInformation().setCostsPerSecond(0.58);
longHaulVehicle.getCostInformation().setFixedCost(100.);
longHaulVehicle.setMaximumVelocity(45 / 3.6);
logger.info("Creating LSP");
LSPlsp = createInitialLSP(scenario, carrierId, collectionVehType);
LSPlongHaulLSP = createInitialLongHaulLSP(scenario, longHaulId, longHaulVehicle);
Collection<LspShipment> lspShortHaulShipments = createLSPShipments(scenario.getNetwork());
Collection<LspShipment> lspLongHaulShipments = createLongHaulLSPShipments(scenario.getNetwork());
logger.info("Assigning LSPShipments to LSP");
for (LspShipmentlspShipment : lspShortHaulShipments) {
lsp.assignShipmentToLSP(lspShipment);
}
for (LspShipmentlspShipment : lspLongHaulShipments) {
longHaulLSP.assignShipmentToLSP(lspShipment);
}
logger.info("Schedule to LSP and the shipments");
lsp.scheduleLogisticChains();
longHaulLSP.scheduleLogisticChains();
logger.info("Set up simulation with LSPModule");
LSPUtils.loadLspsIntoScenario(scenario, Collections.singletonList(lsp));
LSPUtils.loadLspsIntoScenario(scenario, Collections.singletonList(longHaulLSP));
Controlercontroller = newControler(scenario);
{
VehicleTypeSpecificDriveEnergyConsumptionFactorydriveEnergyConsumptionFactory = newVehicleTypeSpecificDriveEnergyConsumptionFactory();
varvehicleTypeCar = Id.create("EV_65.0kWh", VehicleType.class);
driveEnergyConsumptionFactory.addEnergyConsumptionModelFactory(vehicleTypeCar,
newLTHConsumptionModelReader().readURL(ConfigGroup.getInputFileURL(config.getContext(), "MidCarMap.csv")));
driveEnergyConsumptionFactory.addEnergyConsumptionModelFactory(vehicleTypeId,
newLTHConsumptionModelReader().readURL(ConfigGroup.getInputFileURL(config.getContext(), "SUVMap.csv")));
driveEnergyConsumptionFactory.addEnergyConsumptionModelFactory(vehicleTypeHGV,
newLTHConsumptionModelReader().readURL(ConfigGroup.getInputFileURL(config.getContext(), "HGV16Map.csv")));
AuxEnergyConsumption.Factorydummy = electricVehicle -> (timeOfDay, period, linkId) -> 0;
newConfigWriter(config).write("output-config.xml");
controller.addOverridingModule(newLSPModule());
controller.addOverridingModule(newEvModule());
controller.addOverridingModule(newAbstractModule() {
@Overridepublicvoidinstall() {
// logger.info("Installing EV module");// install(new EvModule());// logger.info("Installing Logistics module");// install(new LSPModule());bind(DriveEnergyConsumption.Factory.class).toInstance(driveEnergyConsumptionFactory); // TODO find a way to do this in the new style of adding modulesbind(AuxEnergyConsumption.Factory.class).toInstance(dummy); //a dummy factory, as aux consumption is part of the drive consumption in the modeladdRoutingModuleBinding(TransportMode.car).toProvider(newEvNetworkRoutingProvider(TransportMode.car));
bind(LSPScorerFactory.class).toInstance(TransitLSPScorer::new);
bind(LSPStrategyManager.class)
.toProvider(
() -> {
LSPStrategyManagerstrategyManager = newLSPStrategyManagerImpl();
strategyManager.addStrategy(
newAssignmentStrategyFactory().createStrategy(), null, 1);
returnstrategyManager;
});
bind(CarrierStrategyManager.class)
.toProvider(
() -> {
CarrierStrategyManagerstrategyManager =
CarrierControllerUtils.createDefaultCarrierStrategyManager();
strategyManager.addStrategy(
newGenericPlanStrategyImpl<>(newRandomPlanSelector<>()), null, 1);
returnstrategyManager;
});
}
});
controller
.getConfig()
.vspExperimental()
.setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn);
controller.run();
// print the schedules for the assigned LSPShipmentslogger.info("print the schedules for the assigned Last-mile LSPShipments");
ResourceImplementationUtils.printResults_shipmentPlan(
config.controller().getOutputDirectory(), lsp);
// print the schedules for the assigned LongHaulLSPShipmentslogger.info("print the schedules for the assigned Long-haul LSPShipments");
ResourceImplementationUtils.printResults_shipmentPlan(
config.controller().getOutputDirectory(), longHaulLSP);
}
}
}
If possible, provide a link to your minimal example. This might be a GitHub repository.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Provide the MATSim version you are using. You can find the version in the
pom.xml. E.g.2025.0.2025.0
Did you build a minimal example to reproduce the issue?
Describe the problem you are facing.
I am trying to create a matsim scenario that uses both the freight and EV contribs to create a fleet of electric vehicles to perform both long haul and last mile deliveries. I have set up the EV contrib and can get normal agents in the plans.xml file to use electricity and I have the logistics agents creating carriers to collect shipments but I cannot see my carrier agents in the EV outputs.
Are these two contribs compatible with each other?
If possible, provide a link to your minimal example. This might be a GitHub repository.
https://drive.google.com/file/d/1wkEWf3QHBVs-7q3yy_aH86fx0vQRZ_ps/view?usp=sharing
If you want, provide some background information about you and your project. This might help us understand your issue better.
No response
Beta Was this translation helpful? Give feedback.
All reactions