From 2f79b3e170976521eb7b24d3747aead4bb3ca841 Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Fri, 20 Oct 2023 15:19:47 +0200 Subject: [PATCH 1/6] reduce public footprint --- .../edrt/run/EDrtModeOptimizerQSimModule.java | 6 +- .../ev/charging/VehicleChargingHandler.java | 4 +- .../discharging/DriveDischargingHandler.java | 2 +- .../contrib/ev/example/RunEvExample.java | 7 +- ...tteryImpl.java => BatteryDefaultImpl.java} | 4 +- .../ConvertInitialChargeToInitialSoc.java | 51 ----------- .../contrib/ev/fleet/ElectricFleetModule.java | 14 +-- ...lectricFleetSpecificationDefaultImpl.java} | 2 +- .../contrib/ev/fleet/ElectricFleetUtils.java | 91 +++++++++++++++++++ .../contrib/ev/fleet/ElectricFleets.java | 43 --------- ...l.java => ElectricVehicleDefaultImpl.java} | 23 ++--- ...ctricVehicleSpecificationDefaultImpl.java} | 20 +--- .../fleet/ElectricVehicleSpecifications.java | 36 -------- ...argerImpl.java => ChargerDefaultImpl.java} | 4 +- .../ev/infrastructure/ChargerReader.java | 2 +- .../ev/infrastructure/ChargerWriter.java | 2 +- .../ChargingInfrastructureModule.java | 8 +- ...frastructureSpecificationDefaultImpl.java} | 2 +- ....java => ChargingInfrastructureUtils.java} | 10 +- .../ImmutableChargerSpecification.java | 24 ++--- .../ev/routing/EvNetworkRoutingModule.java | 9 +- ...OccupancyTimeProfileCollectorProvider.java | 4 +- .../ChargerOccupancyXYDataCollector.java | 4 +- .../ev/stats/ChargerPowerCollector.java | 4 +- .../ChargerPowerTimeProfileCalculator.java | 4 +- .../ev/stats/ChargerPowerTimeProfileView.java | 4 +- .../ev/stats/EnergyConsumptionCollector.java | 2 + ...ualChargeTimeProfileCollectorProvider.java | 4 +- .../ev/temperature/TemperatureManager.java | 2 +- .../ev/charging/FastThenSlowChargingTest.java | 6 +- .../charging/VariableSpeedChargingTest.java | 6 +- .../ETaxiModeOptimizerQSimModule.java | 6 +- .../vsp/ev/ElectricFleetUpdater.java | 4 +- .../playground/vsp/ev/RunUrbanEVExample.java | 6 +- .../vsp/ev/UrbanEVTripsPlanner.java | 9 +- .../vsp/ev/UrbanVehicleChargingHandler.java | 4 +- .../ev/TransferFinalSocToNextIterTest.java | 9 +- 37 files changed, 191 insertions(+), 251 deletions(-) rename contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/{BatteryImpl.java => BatteryDefaultImpl.java} (94%) delete mode 100644 contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ConvertInitialChargeToInitialSoc.java rename contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/{ElectricFleetSpecificationImpl.java => ElectricFleetSpecificationDefaultImpl.java} (96%) create mode 100644 contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java delete mode 100644 contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleets.java rename contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/{ElectricVehicleImpl.java => ElectricVehicleDefaultImpl.java} (74%) rename contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/{ElectricVehicleSpecificationImpl.java => ElectricVehicleSpecificationDefaultImpl.java} (73%) delete mode 100644 contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecifications.java rename contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/{ChargerImpl.java => ChargerDefaultImpl.java} (95%) rename contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/{ChargingInfrastructureSpecificationImpl.java => ChargingInfrastructureSpecificationDefaultImpl.java} (95%) rename contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/{ChargingInfrastructures.java => ChargingInfrastructureUtils.java} (90%) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java index 6239ca5a240..d84aa00e156 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/run/EDrtModeOptimizerQSimModule.java @@ -60,7 +60,7 @@ import org.matsim.contrib.dvrp.schedule.ScheduleTimingUpdater; import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic; import org.matsim.contrib.ev.infrastructure.ChargingInfrastructure; -import org.matsim.contrib.ev.infrastructure.ChargingInfrastructures; +import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureUtils; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.mobsim.framework.MobsimTimer; import org.matsim.core.modal.ModalProviders; @@ -95,8 +95,8 @@ protected void configureQSim() { getter.getModal(DrtRequestInsertionRetryQueue.class)))).asEagerSingleton(); bindModal(ChargingInfrastructure.class).toProvider(modalProvider( - getter -> ChargingInfrastructures.createModalNetworkChargers(getter.get(ChargingInfrastructure.class), - getter.getModal(Network.class), getMode()))).asEagerSingleton(); + getter -> ChargingInfrastructureUtils.createModalNetworkChargers(getter.get(ChargingInfrastructure.class ), + getter.getModal(Network.class), getMode() ))).asEagerSingleton(); // XXX if overridden to something else, make sure that the depots are equipped with chargers // otherwise vehicles will not re-charge diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/VehicleChargingHandler.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/VehicleChargingHandler.java index 81f6682c3ff..4a2655a5ccf 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/VehicleChargingHandler.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/charging/VehicleChargingHandler.java @@ -42,7 +42,7 @@ 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.ev.infrastructure.ChargingInfrastructures; +import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureUtils; import org.matsim.core.config.groups.ScoringConfigGroup; import org.matsim.core.events.MobsimScopeEventHandler; import org.matsim.vehicles.Vehicle; @@ -73,7 +73,7 @@ public class VehicleChargingHandler VehicleChargingHandler(ChargingInfrastructure chargingInfrastructure, ElectricFleet electricFleet) { this.chargingInfrastructure = chargingInfrastructure; this.electricFleet = electricFleet; - chargersAtLinks = ChargingInfrastructures.getChargersAtLinks(chargingInfrastructure); + chargersAtLinks = ChargingInfrastructureUtils.getChargersAtLinks(chargingInfrastructure ); } /** diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DriveDischargingHandler.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DriveDischargingHandler.java index eae4a115384..ca8508a0e74 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DriveDischargingHandler.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DriveDischargingHandler.java @@ -44,7 +44,7 @@ * calculating the drive-related energy consumption. However, the time spent on the first link is used by the time-based * idle discharge process (see {@link IdleDischargingHandler}). */ -public class DriveDischargingHandler +public final class DriveDischargingHandler implements LinkLeaveEventHandler, VehicleEntersTrafficEventHandler, VehicleLeavesTrafficEventHandler, MobsimScopeEventHandler { private static class EvDrive { private final Id vehicleId; diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExample.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExample.java index 406f0e647dc..e4980391db6 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExample.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExample.java @@ -71,8 +71,11 @@ public void run( String[] args ) { install( new EvModule() ); addRoutingModuleBinding( TransportMode.car ).toProvider(new EvNetworkRoutingProvider(TransportMode.car) ); - // a router that inserts charging activities when the battery is run empty. there may be some other way to insert - // charging activities, based on the situation. kai, dec'22 + // a router that inserts charging activities INTO THE ROUTE when the battery is run empty. This assumes that a full + // charge at the start of the route is not sufficient to drive the route. There are other settings where the + // situation is different, e.g. urban, where there may be a CHAIN of activities, and charging in general is done in + // parallel with some of these activities. That second situation is adressed by some "ev" code in the vsp contrib. + // kai, dec'22 } } ); diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/BatteryImpl.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/BatteryDefaultImpl.java similarity index 94% rename from contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/BatteryImpl.java rename to contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/BatteryDefaultImpl.java index b3be0ab8a02..a9629018dfc 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/BatteryImpl.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/BatteryDefaultImpl.java @@ -23,11 +23,11 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -public class BatteryImpl implements Battery { +final class BatteryDefaultImpl implements Battery { private final double capacity; private double charge; - public BatteryImpl(double capacity, double charge) { + BatteryDefaultImpl( double capacity, double charge ) { this.capacity = capacity; this.charge = charge; } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ConvertInitialChargeToInitialSoc.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ConvertInitialChargeToInitialSoc.java deleted file mode 100644 index 2f1475f964e..00000000000 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ConvertInitialChargeToInitialSoc.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) 2022 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** * - */ - -package org.matsim.contrib.ev.fleet; - -import static org.matsim.contrib.ev.fleet.ElectricVehicleSpecificationImpl.INITIAL_SOC; - -import org.matsim.vehicles.MatsimVehicleReader; -import org.matsim.vehicles.MatsimVehicleWriter; -import org.matsim.vehicles.VehicleUtils; - -/** - * @author Michal Maciejewski (michalm) - */ -public class ConvertInitialChargeToInitialSoc { - private static final String INITIAL_ENERGY_kWh = "initialEnergyInKWh"; - - public static void run(String file) { - var vehicles = VehicleUtils.createVehiclesContainer(); - var reader = new MatsimVehicleReader(vehicles); - reader.readFile(file); - - for (var v : vehicles.getVehicles().values()) { - double battery_kWh = VehicleUtils.getEnergyCapacity(v.getType().getEngineInformation()); - double initial_kWh = (double)v.getAttributes().getAttribute(INITIAL_ENERGY_kWh); - double initial_soc = initial_kWh / battery_kWh; - v.getAttributes().removeAttribute(INITIAL_ENERGY_kWh); - v.getAttributes().putAttribute(INITIAL_SOC, initial_soc); - } - - var writer = new MatsimVehicleWriter(vehicles); - writer.writeFile(file); - } -} diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetModule.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetModule.java index fc6493ae3b8..179a6ec9116 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetModule.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetModule.java @@ -37,7 +37,7 @@ /** * @author Michal Maciejewski (michalm) */ -public class ElectricFleetModule extends AbstractModule { +public final class ElectricFleetModule extends AbstractModule { @Inject private EvConfigGroup evCfg; @@ -46,9 +46,9 @@ public void install() { bind(ElectricFleetSpecification.class).toProvider(new Provider<>() { @Inject private Vehicles vehicles; @Override public ElectricFleetSpecification get() { - ElectricFleetSpecification fleetSpecification = new ElectricFleetSpecificationImpl(); - ElectricVehicleSpecificationImpl.createAndAddVehicleSpecificationsFromMatsimVehicles(fleetSpecification, - vehicles.getVehicles().values()); + ElectricFleetSpecification fleetSpecification = new ElectricFleetSpecificationDefaultImpl(); + ElectricFleetUtils.createAndAddVehicleSpecificationsFromMatsimVehicles(fleetSpecification, + vehicles.getVehicles().values() ); return fleetSpecification; } }).asEagerSingleton(); @@ -64,8 +64,8 @@ protected void configureQSim() { @Override public ElectricFleet get() { - return ElectricFleets.createDefaultFleet(fleetSpecification, driveConsumptionFactory, auxConsumptionFactory, - chargingPowerFactory); + return ElectricFleetUtils.createDefaultFleet(fleetSpecification, driveConsumptionFactory, auxConsumptionFactory, + chargingPowerFactory ); } }).asEagerSingleton(); @@ -77,7 +77,7 @@ public ElectricFleet get() { for (var oldSpec : electricFleetSpecification.getVehicleSpecifications().values()) { var matsimVehicle = oldSpec.getMatsimVehicle(); double socAtEndOfCurrentIteration = electricFleet.getElectricVehicles().get(oldSpec.getId()).getBattery().getSoc(); - ElectricVehicleSpecifications.setInitialSoc(matsimVehicle, socAtEndOfCurrentIteration); + ElectricFleetUtils.setInitialSoc(matsimVehicle, socAtEndOfCurrentIteration ); } } }); diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetSpecificationImpl.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetSpecificationDefaultImpl.java similarity index 96% rename from contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetSpecificationImpl.java rename to contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetSpecificationDefaultImpl.java index 14a70682741..b24583feb13 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetSpecificationImpl.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetSpecificationDefaultImpl.java @@ -30,7 +30,7 @@ /** * @author Michal Maciejewski (michalm) */ -public final class ElectricFleetSpecificationImpl implements ElectricFleetSpecification { +final class ElectricFleetSpecificationDefaultImpl implements ElectricFleetSpecification { private final Map, ElectricVehicleSpecification> specifications = new LinkedHashMap<>(); @Override diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java new file mode 100644 index 00000000000..11d272a4129 --- /dev/null +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java @@ -0,0 +1,91 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) 2022 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** * + */ + +package org.matsim.contrib.ev.fleet; + +import java.util.Collection; +import java.util.Objects; + +import com.google.common.collect.ImmutableMap; +import org.matsim.api.core.v01.Id; +import org.matsim.contrib.ev.charging.ChargingPower; +import org.matsim.contrib.ev.discharging.AuxEnergyConsumption; +import org.matsim.contrib.ev.discharging.DriveEnergyConsumption; +import org.matsim.vehicles.*; + +public final class ElectricFleetUtils { + public static final String EV_ENGINE_HBEFA_TECHNOLOGY = "electricity"; + public static final String INITIAL_SOC = "initialSoc";// in [0, 1] + public static final String CHARGER_TYPES = "chargerTypes"; + private static final String INITIAL_ENERGY_kWh = "initialEnergyInKWh"; + private ElectricFleetUtils(){} // do not instantiate + public static void setInitialSoc(Vehicle vehicle, double initialSoc) { + vehicle.getAttributes().putAttribute( INITIAL_SOC, initialSoc ); + } + + public static void setChargerTypes(EngineInformation engineInformation, Collection chargerTypes) { + engineInformation.getAttributes().putAttribute( CHARGER_TYPES, chargerTypes ); + } + public static void run(String file) { + var vehicles = VehicleUtils.createVehiclesContainer(); + var reader = new MatsimVehicleReader(vehicles); + reader.readFile(file); + + for (var v : vehicles.getVehicles().values()) { + double battery_kWh = VehicleUtils.getEnergyCapacity(v.getType().getEngineInformation()); + double initial_kWh = (double)v.getAttributes().getAttribute(INITIAL_ENERGY_kWh); + double initial_soc = initial_kWh / battery_kWh; + v.getAttributes().removeAttribute(INITIAL_ENERGY_kWh); + v.getAttributes().putAttribute(INITIAL_SOC, initial_soc); + } + + var writer = new MatsimVehicleWriter(vehicles); + writer.writeFile(file); + } + public static ElectricVehicle create( ElectricVehicleSpecification vehicleSpecification, + DriveEnergyConsumption.Factory driveFactory, AuxEnergyConsumption.Factory auxFactory, + ChargingPower.Factory chargingFactory ) { + ElectricVehicleDefaultImpl ev = new ElectricVehicleDefaultImpl(vehicleSpecification); + ev.driveEnergyConsumption = Objects.requireNonNull(driveFactory.create(ev ) ); + ev.auxEnergyConsumption = Objects.requireNonNull(auxFactory.create(ev)); + ev.chargingPower = Objects.requireNonNull(chargingFactory.create(ev)); + return ev; + } + public static void createAndAddVehicleSpecificationsFromMatsimVehicles(ElectricFleetSpecification fleetSpecification, Collection vehicles) { + vehicles.stream() + .filter(vehicle -> EV_ENGINE_HBEFA_TECHNOLOGY.equals(VehicleUtils.getHbefaTechnology(vehicle.getType().getEngineInformation()))) + .map( ElectricVehicleSpecificationDefaultImpl::new ) + .forEach(fleetSpecification::addVehicleSpecification); + } + public static ElectricVehicleSpecification createElectricVehicleSpecificationDefaultImpl( Vehicle matsimVehicle ){ + return new ElectricVehicleSpecificationDefaultImpl( matsimVehicle ); + } + public static ElectricFleet createDefaultFleet(ElectricFleetSpecification fleetSpecification, + DriveEnergyConsumption.Factory driveConsumptionFactory, AuxEnergyConsumption.Factory auxConsumptionFactory, + ChargingPower.Factory chargingFactory) { + ImmutableMap, ElectricVehicle> vehicles = fleetSpecification.getVehicleSpecifications() + .values() + .stream() + .map(s -> create(s, driveConsumptionFactory, auxConsumptionFactory, + chargingFactory )) + .collect(ImmutableMap.toImmutableMap(ElectricVehicle::getId, v -> v)); + return () -> vehicles; + } +} diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleets.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleets.java deleted file mode 100644 index fbe29db0ab3..00000000000 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleets.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) 2019 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** * - */ - -package org.matsim.contrib.ev.fleet; - -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.ev.charging.ChargingPower; -import org.matsim.contrib.ev.discharging.AuxEnergyConsumption; -import org.matsim.contrib.ev.discharging.DriveEnergyConsumption; -import org.matsim.vehicles.Vehicle; - -import com.google.common.collect.ImmutableMap; - -public class ElectricFleets { - public static ElectricFleet createDefaultFleet(ElectricFleetSpecification fleetSpecification, - DriveEnergyConsumption.Factory driveConsumptionFactory, AuxEnergyConsumption.Factory auxConsumptionFactory, - ChargingPower.Factory chargingFactory) { - ImmutableMap, ElectricVehicle> vehicles = fleetSpecification.getVehicleSpecifications() - .values() - .stream() - .map(s -> ElectricVehicleImpl.create(s, driveConsumptionFactory, auxConsumptionFactory, - chargingFactory)) - .collect(ImmutableMap.toImmutableMap(ElectricVehicle::getId, v -> v)); - return () -> vehicles; - } -} diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleImpl.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleDefaultImpl.java similarity index 74% rename from contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleImpl.java rename to contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleDefaultImpl.java index 91125b6500d..c4da3c65565 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleImpl.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleDefaultImpl.java @@ -20,8 +20,6 @@ package org.matsim.contrib.ev.fleet; -import java.util.Objects; - import org.matsim.api.core.v01.Id; import org.matsim.contrib.ev.charging.ChargingPower; import org.matsim.contrib.ev.discharging.AuxEnergyConsumption; @@ -31,27 +29,18 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; -public class ElectricVehicleImpl implements ElectricVehicle { - public static ElectricVehicle create(ElectricVehicleSpecification vehicleSpecification, - DriveEnergyConsumption.Factory driveFactory, AuxEnergyConsumption.Factory auxFactory, - ChargingPower.Factory chargingFactory) { - ElectricVehicleImpl ev = new ElectricVehicleImpl(vehicleSpecification); - ev.driveEnergyConsumption = Objects.requireNonNull(driveFactory.create(ev)); - ev.auxEnergyConsumption = Objects.requireNonNull(auxFactory.create(ev)); - ev.chargingPower = Objects.requireNonNull(chargingFactory.create(ev)); - return ev; - } +final class ElectricVehicleDefaultImpl implements ElectricVehicle { private final ElectricVehicleSpecification vehicleSpecification; private final Battery battery; - private DriveEnergyConsumption driveEnergyConsumption; - private AuxEnergyConsumption auxEnergyConsumption; - private ChargingPower chargingPower; + DriveEnergyConsumption driveEnergyConsumption; + AuxEnergyConsumption auxEnergyConsumption; + ChargingPower chargingPower; - private ElectricVehicleImpl(ElectricVehicleSpecification vehicleSpecification) { + ElectricVehicleDefaultImpl( ElectricVehicleSpecification vehicleSpecification ) { this.vehicleSpecification = vehicleSpecification; - battery = new BatteryImpl(vehicleSpecification.getBatteryCapacity(), vehicleSpecification.getInitialCharge()); + battery = new BatteryDefaultImpl(vehicleSpecification.getBatteryCapacity(), vehicleSpecification.getInitialCharge()); } @Override diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecificationImpl.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecificationDefaultImpl.java similarity index 73% rename from contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecificationImpl.java rename to contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecificationDefaultImpl.java index 70d4c100f77..ef18ae6cce6 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecificationImpl.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecificationDefaultImpl.java @@ -33,23 +33,11 @@ /** * @author Michal Maciejewski (michalm) */ -public class ElectricVehicleSpecificationImpl implements ElectricVehicleSpecification { - public static final String EV_ENGINE_HBEFA_TECHNOLOGY = "electricity"; - - public static final String INITIAL_SOC = "initialSoc";// in [0, 1] - public static final String CHARGER_TYPES = "chargerTypes"; - - public static void createAndAddVehicleSpecificationsFromMatsimVehicles(ElectricFleetSpecification fleetSpecification, - Collection vehicles) { - vehicles.stream() - .filter(vehicle -> EV_ENGINE_HBEFA_TECHNOLOGY.equals(VehicleUtils.getHbefaTechnology(vehicle.getType().getEngineInformation()))) - .map(ElectricVehicleSpecificationImpl::new) - .forEach(fleetSpecification::addVehicleSpecification); - } +final class ElectricVehicleSpecificationDefaultImpl implements ElectricVehicleSpecification { private final Vehicle matsimVehicle; - public ElectricVehicleSpecificationImpl(Vehicle matsimVehicle) { + ElectricVehicleSpecificationDefaultImpl( Vehicle matsimVehicle ) { this.matsimVehicle = matsimVehicle; //provided per vehicle type (in engine info) Preconditions.checkArgument(getInitialSoc() >= 0 && getInitialSoc() <= 1, "Invalid initialCharge or batteryCapacity of vehicle: %s", getId()); @@ -68,12 +56,12 @@ public Vehicle getMatsimVehicle() { @Override public ImmutableList getChargerTypes() { var engineInfo = matsimVehicle.getType().getEngineInformation(); - return ImmutableList.copyOf((Collection)engineInfo.getAttributes().getAttribute(CHARGER_TYPES)); + return ImmutableList.copyOf((Collection)engineInfo.getAttributes().getAttribute( ElectricFleetUtils.CHARGER_TYPES ) ); } @Override public double getInitialSoc() { - return (double)matsimVehicle.getAttributes().getAttribute(INITIAL_SOC); + return (double)matsimVehicle.getAttributes().getAttribute( ElectricFleetUtils.INITIAL_SOC ); } @Override diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecifications.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecifications.java deleted file mode 100644 index 225d5be689d..00000000000 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricVehicleSpecifications.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) 2022 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** * - */ - -package org.matsim.contrib.ev.fleet; - -import java.util.Collection; - -import org.matsim.vehicles.EngineInformation; -import org.matsim.vehicles.Vehicle; - -public class ElectricVehicleSpecifications { - public static void setInitialSoc(Vehicle vehicle, double initialSoc) { - vehicle.getAttributes().putAttribute(ElectricVehicleSpecificationImpl.INITIAL_SOC, initialSoc); - } - - public static void setChargerTypes(EngineInformation engineInformation, Collection chargerTypes) { - engineInformation.getAttributes().putAttribute(ElectricVehicleSpecificationImpl.CHARGER_TYPES, chargerTypes); - } -} diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerImpl.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerDefaultImpl.java similarity index 95% rename from contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerImpl.java rename to contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerDefaultImpl.java index a37cd181c9e..d2efb68578d 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerImpl.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerDefaultImpl.java @@ -29,13 +29,13 @@ import com.google.common.base.Preconditions; -public class ChargerImpl implements Charger { +class ChargerDefaultImpl implements Charger { private final ChargerSpecification specification; private final Link link; private final ChargingLogic logic; - public ChargerImpl(ChargerSpecification specification, Link link, ChargingLogic logic) { + ChargerDefaultImpl( ChargerSpecification specification, Link link, ChargingLogic logic ) { Preconditions.checkArgument(link.getId().equals(specification.getLinkId()), "link.id != specification.linkId"); this.specification = specification; this.link = link; diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerReader.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerReader.java index 27f21fe2fff..9864622b4cb 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerReader.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerReader.java @@ -28,7 +28,7 @@ import org.matsim.core.utils.io.MatsimXmlParser; import org.xml.sax.Attributes; -public class ChargerReader extends MatsimXmlParser { +public final class ChargerReader extends MatsimXmlParser { private final static String CHARGER = "charger"; private final ChargingInfrastructureSpecification chargingInfrastructure; diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerWriter.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerWriter.java index bb03bc9f063..8955b266984 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerWriter.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargerWriter.java @@ -29,7 +29,7 @@ import org.matsim.core.utils.collections.Tuple; import org.matsim.core.utils.io.MatsimXmlWriter; -public class ChargerWriter extends MatsimXmlWriter { +public final class ChargerWriter extends MatsimXmlWriter { private final Stream chargerSpecifications; public ChargerWriter(Stream chargerSpecifications) { diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureModule.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureModule.java index ea2e2526afb..f44bee53f11 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureModule.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureModule.java @@ -36,7 +36,7 @@ /** * @author Michal Maciejewski (michalm) */ -public class ChargingInfrastructureModule extends AbstractModule { +public final class ChargingInfrastructureModule extends AbstractModule { public static final String CHARGERS = "chargers"; private final Key networkKey; @@ -56,7 +56,7 @@ public void install() { bind(Network.class).annotatedWith(Names.named(CHARGERS)).to(networkKey).asEagerSingleton(); bind(ChargingInfrastructureSpecification.class).toProvider(() -> { - ChargingInfrastructureSpecification chargingInfrastructureSpecification = new ChargingInfrastructureSpecificationImpl(); + ChargingInfrastructureSpecification chargingInfrastructureSpecification = new ChargingInfrastructureSpecificationDefaultImpl(); new ChargerReader(chargingInfrastructureSpecification).parse( ConfigGroup.getInputFileURL(getConfig().getContext(), evCfg.chargersFile)); return chargingInfrastructureSpecification; @@ -76,8 +76,8 @@ protected void configureQSim() { @Override public ChargingInfrastructure get() { - return ChargingInfrastructures.createChargingInfrastructure(chargingInfrastructureSpecification, - network.getLinks()::get, chargingLogicFactory); + return ChargingInfrastructureUtils.createChargingInfrastructure(chargingInfrastructureSpecification, + network.getLinks()::get, chargingLogicFactory ); } }).asEagerSingleton(); } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureSpecificationImpl.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureSpecificationDefaultImpl.java similarity index 95% rename from contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureSpecificationImpl.java rename to contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureSpecificationDefaultImpl.java index ceeba42372f..48a27563616 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureSpecificationImpl.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureSpecificationDefaultImpl.java @@ -28,7 +28,7 @@ /** * @author Michal Maciejewski (michalm) */ -public class ChargingInfrastructureSpecificationImpl implements ChargingInfrastructureSpecification { +final class ChargingInfrastructureSpecificationDefaultImpl implements ChargingInfrastructureSpecification { private final SpecificationContainer container = new SpecificationContainer<>(); @Override diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructures.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureUtils.java similarity index 90% rename from contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructures.java rename to contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureUtils.java index b86a140fcbb..e4e7ca5c4fa 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructures.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ChargingInfrastructureUtils.java @@ -37,8 +37,10 @@ /** * @author Michal Maciejewski (michalm) */ -public class ChargingInfrastructures { - static final Logger log = LogManager.getLogger(ChargingInfrastructures.class); +public class ChargingInfrastructureUtils{ + static final Logger log = LogManager.getLogger( ChargingInfrastructureUtils.class ); + + private ChargingInfrastructureUtils(){} // do not instantiate public static ChargingInfrastructure createChargingInfrastructure( ChargingInfrastructureSpecification infrastructureSpecification, Function, Link> linkProvider, @@ -46,7 +48,7 @@ public static ChargingInfrastructure createChargingInfrastructure( var chargers = infrastructureSpecification.getChargerSpecifications() .values() .stream() - .map(s -> new ChargerImpl(s, linkProvider.apply(s.getLinkId()), chargingLogicFactory.create(s))) + .map(s -> new ChargerDefaultImpl(s, linkProvider.apply(s.getLinkId() ), chargingLogicFactory.create(s )) ) .collect(ImmutableMap.toImmutableMap(Charger::getId, c -> (Charger)c)); return () -> chargers; } @@ -72,7 +74,7 @@ public static ChargingInfrastructure createModalNetworkChargers(ChargingInfrastr var reachableLinks = network.getLinks(); var filteredChargers = infrastructure.getChargers().values().stream().map(c -> { var link = reachableLinks.get(c.getLink().getId()); - return link == null ? null : new ChargerImpl(c.getSpecification(), link, c.getLogic()); + return link == null ? null : new ChargerDefaultImpl(c.getSpecification(), link, c.getLogic()); }).filter(Objects::nonNull).collect(ImmutableMap.toImmutableMap(Charger::getId, c -> (Charger)c)); int chargerCount = infrastructure.getChargers().size(); diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ImmutableChargerSpecification.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ImmutableChargerSpecification.java index aa08f5d6b85..a3d7192b793 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ImmutableChargerSpecification.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/ImmutableChargerSpecification.java @@ -40,7 +40,7 @@ public class ImmutableChargerSpecification implements ChargerSpecification { private final double plugPower; private final int plugCount; - private ImmutableChargerSpecification(Builder builder) { + private ImmutableChargerSpecification( ChargerSpecificationBuilder builder ) { id = Objects.requireNonNull(builder.id); linkId = Objects.requireNonNull(builder.linkId); chargerType = Objects.requireNonNull(builder.chargerType); @@ -51,12 +51,12 @@ private ImmutableChargerSpecification(Builder builder) { Preconditions.checkArgument(plugCount >= 0, "Negative plugCount of charger: %s", id); } - public static Builder newBuilder() { - return new Builder(); + public static ChargerSpecificationBuilder newBuilder() { + return new ChargerSpecificationBuilder(); } - public static Builder newBuilder(ChargerSpecification copy) { - Builder builder = new Builder(); + public static ChargerSpecificationBuilder newBuilder( ChargerSpecification copy ) { + ChargerSpecificationBuilder builder = new ChargerSpecificationBuilder(); builder.id = copy.getId(); builder.linkId = copy.getLinkId(); builder.chargerType = copy.getChargerType(); @@ -101,37 +101,37 @@ public String toString() { .toString(); } - public static final class Builder { + public static final class ChargerSpecificationBuilder{ private Id id; private Id linkId; private String chargerType; private Double plugPower; private Integer plugCount; - private Builder() { + private ChargerSpecificationBuilder() { } - public Builder id(Id val) { + public ChargerSpecificationBuilder id( Id val ) { id = val; return this; } - public Builder linkId(Id val) { + public ChargerSpecificationBuilder linkId( Id val ) { linkId = val; return this; } - public Builder chargerType(String val) { + public ChargerSpecificationBuilder chargerType( String val ) { chargerType = val; return this; } - public Builder plugPower(double val) { + public ChargerSpecificationBuilder plugPower( double val ) { plugPower = val; return this; } - public Builder plugCount(int val) { + public ChargerSpecificationBuilder plugCount( int val ) { plugCount = val; return this; } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/routing/EvNetworkRoutingModule.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/routing/EvNetworkRoutingModule.java index 6d8a0e89f61..10123db4717 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/routing/EvNetworkRoutingModule.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/routing/EvNetworkRoutingModule.java @@ -36,10 +36,7 @@ import org.matsim.contrib.ev.charging.VehicleChargingHandler; import org.matsim.contrib.ev.discharging.AuxEnergyConsumption; import org.matsim.contrib.ev.discharging.DriveEnergyConsumption; -import org.matsim.contrib.ev.fleet.ElectricFleetSpecification; -import org.matsim.contrib.ev.fleet.ElectricVehicle; -import org.matsim.contrib.ev.fleet.ElectricVehicleImpl; -import org.matsim.contrib.ev.fleet.ElectricVehicleSpecification; +import org.matsim.contrib.ev.fleet.*; import org.matsim.contrib.ev.infrastructure.ChargerSpecification; import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureSpecification; import org.matsim.contrib.common.util.StraightLineKnnFinder; @@ -180,10 +177,10 @@ private Map estimateConsumption(ElectricVehicleSpecification ev, L Map consumptions = new LinkedHashMap<>(); NetworkRoute route = (NetworkRoute)basicLeg.getRoute(); List links = NetworkUtils.getLinks(network, route.getLinkIds()); - ElectricVehicle pseudoVehicle = ElectricVehicleImpl.create(ev, driveConsumptionFactory, auxConsumptionFactory, + ElectricVehicle pseudoVehicle = ElectricFleetUtils.create(ev, driveConsumptionFactory, auxConsumptionFactory, v -> charger -> { throw new UnsupportedOperationException(); - }); + } ); DriveEnergyConsumption driveEnergyConsumption = pseudoVehicle.getDriveEnergyConsumption(); AuxEnergyConsumption auxEnergyConsumption = pseudoVehicle.getAuxEnergyConsumption(); double linkEnterTime = basicLeg.getDepartureTime().seconds(); diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyTimeProfileCollectorProvider.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyTimeProfileCollectorProvider.java index 5c13fac0868..a11883f50f2 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyTimeProfileCollectorProvider.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyTimeProfileCollectorProvider.java @@ -34,12 +34,12 @@ import com.google.inject.Inject; import com.google.inject.Provider; -public class ChargerOccupancyTimeProfileCollectorProvider implements Provider { +public final class ChargerOccupancyTimeProfileCollectorProvider implements Provider { private final ChargingInfrastructure chargingInfrastructure; private final MatsimServices matsimServices; @Inject - public ChargerOccupancyTimeProfileCollectorProvider(ChargingInfrastructure chargingInfrastructure, MatsimServices matsimServices) { + ChargerOccupancyTimeProfileCollectorProvider(ChargingInfrastructure chargingInfrastructure, MatsimServices matsimServices) { this.chargingInfrastructure = chargingInfrastructure; this.matsimServices = matsimServices; } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyXYDataCollector.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyXYDataCollector.java index fa2dd8618aa..c0b1c5df506 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyXYDataCollector.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerOccupancyXYDataCollector.java @@ -37,7 +37,7 @@ import com.google.inject.Inject; -public class ChargerOccupancyXYDataCollector implements MobsimInitializedListener, MobsimBeforeSimStepListener, MobsimBeforeCleanupListener { +public final class ChargerOccupancyXYDataCollector implements MobsimInitializedListener, MobsimBeforeSimStepListener, MobsimBeforeCleanupListener { private final ChargingInfrastructure chargingInfrastructure; private final MatsimServices matsimServices; @@ -45,7 +45,7 @@ public class ChargerOccupancyXYDataCollector implements MobsimInitializedListene private CompactCSVWriter writer; @Inject - public ChargerOccupancyXYDataCollector(ChargingInfrastructure chargingInfrastructure, MatsimServices matsimServices) { + ChargerOccupancyXYDataCollector(ChargingInfrastructure chargingInfrastructure, MatsimServices matsimServices) { this.chargingInfrastructure = chargingInfrastructure; this.matsimServices = matsimServices; } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerCollector.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerCollector.java index 14ffb1e84a6..1db79d2ae97 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerCollector.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerCollector.java @@ -53,7 +53,7 @@ /* * created by jbischoff, 26.10.2018 */ -public class ChargerPowerCollector +public final class ChargerPowerCollector implements ChargingStartEventHandler, ChargingEndEventHandler, MobsimScopeEventHandler, MobsimBeforeCleanupListener { @Inject @@ -65,6 +65,8 @@ public class ChargerPowerCollector @Inject private ElectricFleet fleet; + @Inject ChargerPowerCollector(){} // this forces instantiation via guice. kai, oct'23 + private record TimeCharge(double time, double charge) { } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileCalculator.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileCalculator.java index 78e7f6987ef..576d06d4a9e 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileCalculator.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileCalculator.java @@ -19,7 +19,7 @@ import com.google.inject.Inject; -public class ChargerPowerTimeProfileCalculator implements ChargingStartEventHandler, ChargingEndEventHandler { +public final class ChargerPowerTimeProfileCalculator implements ChargingStartEventHandler, ChargingEndEventHandler { private final Map, double[]> chargerProfiles = new HashMap<>(); private final Map, Double> chargingStartTimeMap = new HashMap<>(); @@ -35,7 +35,7 @@ public class ChargerPowerTimeProfileCalculator implements ChargingStartEventHand * @author mattiasingelstrom */ @Inject - public ChargerPowerTimeProfileCalculator(Config config) { + ChargerPowerTimeProfileCalculator(Config config) { int chargeTimeStep = ConfigUtils.addOrGetModule(config, EvConfigGroup.class).chargeTimeStep; qsimEndTime = ConfigUtils.addOrGetModule(config, QSimConfigGroup.class).getEndTime().orElse(0.0); timeDiscretizer = new TimeDiscretizer((int)Math.ceil(qsimEndTime), chargeTimeStep); diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileView.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileView.java index d0941954540..666a1abebe7 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileView.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/ChargerPowerTimeProfileView.java @@ -8,10 +8,10 @@ import java.awt.*; import java.util.Map; -public class ChargerPowerTimeProfileView implements ProfileWriter.ProfileView { +final class ChargerPowerTimeProfileView implements ProfileWriter.ProfileView { private final ChargerPowerTimeProfileCalculator calculator; - public ChargerPowerTimeProfileView(ChargerPowerTimeProfileCalculator calculator) { + ChargerPowerTimeProfileView(ChargerPowerTimeProfileCalculator calculator) { this.calculator = calculator; } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/EnergyConsumptionCollector.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/EnergyConsumptionCollector.java index 4995a3ba41b..2f1a90c1d47 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/EnergyConsumptionCollector.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/EnergyConsumptionCollector.java @@ -56,6 +56,8 @@ public class EnergyConsumptionCollector implements DrivingEnergyConsumptionEvent private final Map, Double> energyConsumptionPerLink = new HashMap<>(); + @Inject EnergyConsumptionCollector(){} // so that class can only be instantiated via guice. kai, oct'23 + @Override public void handleEvent(DrivingEnergyConsumptionEvent event) { energyConsumptionPerLink.merge(event.getLinkId(), event.getEnergy(), Double::sum); diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/IndividualChargeTimeProfileCollectorProvider.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/IndividualChargeTimeProfileCollectorProvider.java index a623b04e6e8..44667aa3e84 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/IndividualChargeTimeProfileCollectorProvider.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/stats/IndividualChargeTimeProfileCollectorProvider.java @@ -39,13 +39,13 @@ import com.google.inject.Inject; import com.google.inject.Provider; -public class IndividualChargeTimeProfileCollectorProvider implements Provider { +public final class IndividualChargeTimeProfileCollectorProvider implements Provider { private final ElectricFleet evFleet; private final MatsimServices matsimServices; private final int maxVehicleColumns; @Inject - public IndividualChargeTimeProfileCollectorProvider(ElectricFleet evFleet, MatsimServices matsimServices, Config config) { + IndividualChargeTimeProfileCollectorProvider(ElectricFleet evFleet, MatsimServices matsimServices, Config config) { this.evFleet = evFleet; this.matsimServices = matsimServices; maxVehicleColumns = ConfigUtils.addOrGetModule(config, EvConfigGroup.class).numberOfIndividualTimeProfiles; diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureManager.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureManager.java index 74bdb5055b6..ffddbf850a6 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureManager.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureManager.java @@ -51,7 +51,7 @@ public class TemperatureManager implements MobsimBeforeSimStepListener, MobsimIn private final EventsManager events; @Inject - public TemperatureManager(Config config, EventsManager events) { + TemperatureManager(Config config, EventsManager events) { this.events = events; TemperatureChangeConfigGroup temperatureChangeConfigGroup = (TemperatureChangeConfigGroup)config.getModules() .get(TemperatureChangeConfigGroup.GROUP_NAME); diff --git a/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/FastThenSlowChargingTest.java b/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/FastThenSlowChargingTest.java index 66e8fd19a87..08eed4fe613 100644 --- a/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/FastThenSlowChargingTest.java +++ b/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/FastThenSlowChargingTest.java @@ -25,8 +25,8 @@ import org.junit.Test; import org.matsim.api.core.v01.Id; import org.matsim.contrib.ev.EvUnits; +import org.matsim.contrib.ev.fleet.ElectricFleetUtils; import org.matsim.contrib.ev.fleet.ElectricVehicle; -import org.matsim.contrib.ev.fleet.ElectricVehicleImpl; import org.matsim.contrib.ev.fleet.ElectricVehicleSpecification; import org.matsim.contrib.ev.infrastructure.Charger; import org.matsim.contrib.ev.infrastructure.ChargerSpecification; @@ -160,11 +160,11 @@ record TestEvSpecification(Id getId, Vehicle getMatsimVehicle, String g var specification = new TestEvSpecification(Id.create("ev_id", Vehicle.class), null, "vt", ImmutableList.of("ct"), EvUnits.kWh_to_J(capacity_kWh), charge_kWh / capacity_kWh); - return ElectricVehicleImpl.create(specification, ev -> (link, travelTime, linkEnterTime) -> { + return ElectricFleetUtils.create(specification, ev -> ( link, travelTime, linkEnterTime) -> { throw new UnsupportedOperationException(); }, ev -> (beginTime, duration, linkId) -> { throw new UnsupportedOperationException(); - }, FastThenSlowCharging::new); + }, FastThenSlowCharging::new ); } @Test diff --git a/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/VariableSpeedChargingTest.java b/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/VariableSpeedChargingTest.java index 06091cae47c..1f0c78ffab9 100644 --- a/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/VariableSpeedChargingTest.java +++ b/contribs/ev/src/test/java/org/matsim/contrib/ev/charging/VariableSpeedChargingTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.matsim.api.core.v01.Id; import org.matsim.contrib.ev.EvUnits; -import org.matsim.contrib.ev.fleet.ElectricVehicleImpl; +import org.matsim.contrib.ev.fleet.ElectricFleetUtils; import org.matsim.contrib.ev.fleet.ElectricVehicleSpecification; import org.matsim.contrib.ev.infrastructure.Charger; import org.matsim.contrib.ev.infrastructure.ChargerSpecification; @@ -96,11 +96,11 @@ record TestEvSpecification(Id getId, Vehicle getMatsimVehicle, String g .plugCount(1) .build(); - var electricVehicle = ElectricVehicleImpl.create(specification, ev -> (link, travelTime, linkEnterTime) -> { + var electricVehicle = ElectricFleetUtils.create(specification, ev -> ( link, travelTime, linkEnterTime) -> { throw new UnsupportedOperationException(); }, ev -> (beginTime, duration, linkId) -> { throw new UnsupportedOperationException(); - }, VariableSpeedCharging::createForTesla); + }, VariableSpeedCharging::createForTesla ); Assertions.assertThat(electricVehicle.getChargingPower().calcChargingPower(charger)) .isCloseTo(EvUnits.kW_to_W(expectedChargingPower_kW), Percentage.withPercentage(1e-13)); } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiModeOptimizerQSimModule.java b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiModeOptimizerQSimModule.java index 3fd984a8a7d..3c42d7111c2 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiModeOptimizerQSimModule.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiModeOptimizerQSimModule.java @@ -35,7 +35,7 @@ import org.matsim.contrib.etaxi.ETaxiScheduler; import org.matsim.contrib.etaxi.util.ETaxiStayTaskEndTimeCalculator; import org.matsim.contrib.ev.infrastructure.ChargingInfrastructure; -import org.matsim.contrib.ev.infrastructure.ChargingInfrastructures; +import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureUtils; import org.matsim.contrib.taxi.analysis.TaxiEventSequenceCollector; import org.matsim.contrib.taxi.optimizer.TaxiOptimizer; import org.matsim.contrib.taxi.run.TaxiConfigGroup; @@ -91,8 +91,8 @@ public TaxiOptimizer get() { }); bindModal(ChargingInfrastructure.class).toProvider(modalProvider( - getter -> ChargingInfrastructures.createModalNetworkChargers(getter.get(ChargingInfrastructure.class), - getter.getModal(Network.class), getMode()))).asEagerSingleton(); + getter -> ChargingInfrastructureUtils.createModalNetworkChargers(getter.get(ChargingInfrastructure.class ), + getter.getModal(Network.class), getMode() ))).asEagerSingleton(); addModalComponent(ETaxiScheduler.class, new ModalProviders.AbstractProvider<>(taxiCfg.getMode(), DvrpModes::mode) { diff --git a/contribs/vsp/src/main/java/playground/vsp/ev/ElectricFleetUpdater.java b/contribs/vsp/src/main/java/playground/vsp/ev/ElectricFleetUpdater.java index e89f9fcf55b..5b5ab616092 100644 --- a/contribs/vsp/src/main/java/playground/vsp/ev/ElectricFleetUpdater.java +++ b/contribs/vsp/src/main/java/playground/vsp/ev/ElectricFleetUpdater.java @@ -24,7 +24,7 @@ import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.Population; import org.matsim.contrib.ev.fleet.ElectricFleetSpecification; -import org.matsim.contrib.ev.fleet.ElectricVehicleSpecificationImpl; +import org.matsim.contrib.ev.fleet.ElectricFleetUtils; import org.matsim.core.controler.events.IterationStartsEvent; import org.matsim.core.controler.listener.IterationStartsListener; import org.matsim.core.router.TripStructureUtils; @@ -56,6 +56,6 @@ private void registerEVs(Plan plan) { var modalVehicles = TripStructureUtils.getLegs(plan).stream() .map(leg -> vehicles.getVehicles().get(VehicleUtils.getVehicleId(plan.getPerson(), leg.getMode()))) .toList(); - ElectricVehicleSpecificationImpl.createAndAddVehicleSpecificationsFromMatsimVehicles(fleetSpecification, modalVehicles); + ElectricFleetUtils.createAndAddVehicleSpecificationsFromMatsimVehicles(fleetSpecification, modalVehicles ); } } diff --git a/contribs/vsp/src/main/java/playground/vsp/ev/RunUrbanEVExample.java b/contribs/vsp/src/main/java/playground/vsp/ev/RunUrbanEVExample.java index e5b374733f6..97d90f45650 100644 --- a/contribs/vsp/src/main/java/playground/vsp/ev/RunUrbanEVExample.java +++ b/contribs/vsp/src/main/java/playground/vsp/ev/RunUrbanEVExample.java @@ -50,7 +50,7 @@ import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.population.Person; import org.matsim.contrib.ev.EvConfigGroup; -import org.matsim.contrib.ev.fleet.ElectricVehicleSpecifications; +import org.matsim.contrib.ev.fleet.ElectricFleetUtils; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.RoutingConfigGroup; @@ -144,11 +144,11 @@ static void createAndRegisterPersonalCarAndBikeVehicles(Scenario scenario) { VehicleType.class)); //TODO should at least have a suffix "_car" VehicleUtils.setHbefaTechnology(carVehicleType.getEngineInformation(), "electricity"); VehicleUtils.setEnergyCapacity(carVehicleType.getEngineInformation(), CAR_BATTERY_CAPACITY_kWh); - ElectricVehicleSpecifications.setChargerTypes(carVehicleType.getEngineInformation(), Arrays.asList("a", "b", "default")); + ElectricFleetUtils.setChargerTypes(carVehicleType.getEngineInformation(), Arrays.asList("a", "b", "default" ) ); scenario.getVehicles().addVehicleType(carVehicleType); Vehicle carVehicle = vehicleFactory.createVehicle(VehicleUtils.createVehicleId(person, TransportMode.car), carVehicleType); - ElectricVehicleSpecifications.setInitialSoc(carVehicle, CAR_INITIAL_SOC); + ElectricFleetUtils.setInitialSoc(carVehicle, CAR_INITIAL_SOC ); scenario.getVehicles().addVehicle(carVehicle); VehicleType bikeVehicleType = vehicleFactory.createVehicleType( diff --git a/contribs/vsp/src/main/java/playground/vsp/ev/UrbanEVTripsPlanner.java b/contribs/vsp/src/main/java/playground/vsp/ev/UrbanEVTripsPlanner.java index 0449190e8f6..b68f4d5bcff 100644 --- a/contribs/vsp/src/main/java/playground/vsp/ev/UrbanEVTripsPlanner.java +++ b/contribs/vsp/src/main/java/playground/vsp/ev/UrbanEVTripsPlanner.java @@ -54,10 +54,7 @@ import org.matsim.contrib.ev.charging.ChargingPower; import org.matsim.contrib.ev.discharging.AuxEnergyConsumption; import org.matsim.contrib.ev.discharging.DriveEnergyConsumption; -import org.matsim.contrib.ev.fleet.ElectricFleetSpecification; -import org.matsim.contrib.ev.fleet.ElectricVehicle; -import org.matsim.contrib.ev.fleet.ElectricVehicleImpl; -import org.matsim.contrib.ev.fleet.ElectricVehicleSpecification; +import org.matsim.contrib.ev.fleet.*; import org.matsim.contrib.ev.infrastructure.ChargerSpecification; import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureSpecification; import org.matsim.core.config.Config; @@ -208,8 +205,8 @@ private void processPlans(Map>> selectedEVPlans) { */ ElectricVehicleSpecification evSpec = electricFleetSpecification.getVehicleSpecifications().get(Id.create(ev, Vehicle.class)); Leg legWithCriticalSOC; - ElectricVehicle pseudoVehicle = ElectricVehicleImpl.create(evSpec, driveConsumptionFactory, auxConsumptionFactory, - chargingPowerFactory); + ElectricVehicle pseudoVehicle = ElectricFleetUtils.create(evSpec, driveConsumptionFactory, auxConsumptionFactory, + chargingPowerFactory ); //TODO: erase hardcoding of car mode! List evCarLegs = TripStructureUtils.getLegs(modifiablePlan) .stream() diff --git a/contribs/vsp/src/main/java/playground/vsp/ev/UrbanVehicleChargingHandler.java b/contribs/vsp/src/main/java/playground/vsp/ev/UrbanVehicleChargingHandler.java index 543080da322..592722998fe 100644 --- a/contribs/vsp/src/main/java/playground/vsp/ev/UrbanVehicleChargingHandler.java +++ b/contribs/vsp/src/main/java/playground/vsp/ev/UrbanVehicleChargingHandler.java @@ -30,7 +30,7 @@ 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.ev.infrastructure.ChargingInfrastructures; +import org.matsim.contrib.ev.infrastructure.ChargingInfrastructureUtils; import org.matsim.core.events.MobsimScopeEventHandler; import org.matsim.core.utils.collections.Tuple; import org.matsim.vehicles.Vehicle; @@ -67,7 +67,7 @@ class UrbanVehicleChargingHandler UrbanVehicleChargingHandler(ChargingInfrastructure chargingInfrastructure, ElectricFleet electricFleet) { this.chargingInfrastructure = chargingInfrastructure; this.electricFleet = electricFleet; - this.chargersAtLinks = ChargingInfrastructures.getChargersAtLinks(chargingInfrastructure); + this.chargersAtLinks = ChargingInfrastructureUtils.getChargersAtLinks(chargingInfrastructure ); } /** diff --git a/contribs/vsp/src/test/java/playground/vsp/ev/TransferFinalSocToNextIterTest.java b/contribs/vsp/src/test/java/playground/vsp/ev/TransferFinalSocToNextIterTest.java index b77b0352fc0..172fc201ad2 100644 --- a/contribs/vsp/src/test/java/playground/vsp/ev/TransferFinalSocToNextIterTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/ev/TransferFinalSocToNextIterTest.java @@ -28,9 +28,8 @@ import org.junit.Test; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.contrib.ev.fleet.ElectricFleetUtils; import org.matsim.contrib.ev.fleet.ElectricVehicleSpecification; -import org.matsim.contrib.ev.fleet.ElectricVehicleSpecificationImpl; -import org.matsim.contrib.ev.fleet.ElectricVehicleSpecifications; import org.matsim.core.controler.Controler; import org.matsim.core.controler.events.AfterMobsimEvent; import org.matsim.core.controler.events.BeforeMobsimEvent; @@ -56,7 +55,7 @@ public void test() { scenario.getConfig().controller().setOutputDirectory("test/output/playground/vsp/ev/FinalSoc2VehicleTypeTest/"); var vehicle1 = scenario.getVehicles().getVehicles().get(Id.create("Triple Charger_car", Vehicle.class)); - ElectricVehicleSpecifications.setInitialSoc(vehicle1, INITIAL_SOC); + ElectricFleetUtils.setInitialSoc(vehicle1, INITIAL_SOC ); //controler Controler controler = RunUrbanEVExample.prepareControler(scenario); @@ -69,7 +68,7 @@ public void test() { // testSOCIsDumpedIntoVehicleType //agent has driven the car so SOC should have changed and should be dumped into the vehicle type var vehicle = scenario.getVehicles().getVehicles().get(Id.create("Triple Charger_car", Vehicle.class)); - var evSpec = new ElectricVehicleSpecificationImpl(vehicle); + var evSpec = ElectricFleetUtils.createElectricVehicleSpecificationDefaultImpl(vehicle ); Assert.assertNotEquals(evSpec.getInitialSoc(), INITIAL_SOC); Assert.assertEquals(0.7273605127621898, evSpec.getInitialSoc(), MatsimTestUtils.EPSILON); //should not be fully charged @@ -86,7 +85,7 @@ private static class SOCHandler implements BeforeMobsimListener, AfterMobsimList SOCHandler(Scenario scenario) { var car = scenario.getVehicles().getVehicles().get(Id.create("Triple Charger_car", Vehicle.class)); - evSpec = new ElectricVehicleSpecificationImpl(car); + evSpec = ElectricFleetUtils.createElectricVehicleSpecificationDefaultImpl(car ); } @Override From 6ced39de251ac3f19780cd07f02b8115bb30fcb1 Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Fri, 20 Oct 2023 15:53:59 +0200 Subject: [PATCH 2/6] make some classes final --- .../org/matsim/contrib/ev/discharging/DischargingModule.java | 2 +- .../contrib/ev/discharging/DrivingEnergyConsumptionEvent.java | 2 +- .../matsim/contrib/ev/discharging/IdleDischargingHandler.java | 2 +- .../contrib/ev/discharging/IdlingEnergyConsumptionEvent.java | 2 +- .../contrib/ev/discharging/LTHDriveEnergyConsumption.java | 2 +- .../org/matsim/contrib/ev/discharging/MissingEnergyEvent.java | 2 +- .../contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java | 2 +- .../ev/discharging/OhdeSlaskiDriveEnergyConsumption.java | 2 +- .../VehicleTypeSpecificDriveEnergyConsumptionFactory.java | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DischargingModule.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DischargingModule.java index c36f95635a9..96078d1eab1 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DischargingModule.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DischargingModule.java @@ -29,7 +29,7 @@ /** * @author Michal Maciejewski (michalm) */ -public class DischargingModule extends AbstractModule { +public final class DischargingModule extends AbstractModule { @Override public void install() { bind(DriveEnergyConsumption.Factory.class).toInstance(ev -> new OhdeSlaskiDriveEnergyConsumption()); diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DrivingEnergyConsumptionEvent.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DrivingEnergyConsumptionEvent.java index f00009b3e7a..3289446a72e 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DrivingEnergyConsumptionEvent.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/DrivingEnergyConsumptionEvent.java @@ -27,7 +27,7 @@ /** * @author Michal Maciejewski (michalm) */ -public class DrivingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent { +public final class DrivingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent { public static final String EVENT_TYPE = "drivingEnergyConsumption"; public DrivingEnergyConsumptionEvent(double time, Id vehicleId, Id linkId, double energy, double endCharge) { diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdleDischargingHandler.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdleDischargingHandler.java index da6fab88948..20a90c08e13 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdleDischargingHandler.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdleDischargingHandler.java @@ -45,7 +45,7 @@ * VehicleProvider is responsible to decide if AUX discharging applies to a given vehicle based on information from * ActivityStartEvent. */ -public class IdleDischargingHandler +public final class IdleDischargingHandler implements MobsimAfterSimStepListener, ActivityStartEventHandler, ActivityEndEventHandler, MobsimScopeEventHandler { public interface VehicleProvider { /** diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdlingEnergyConsumptionEvent.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdlingEnergyConsumptionEvent.java index d992dc363f5..fcb625ad7b6 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdlingEnergyConsumptionEvent.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/IdlingEnergyConsumptionEvent.java @@ -27,7 +27,7 @@ /** * @author Michal Maciejewski (michalm) */ -public class IdlingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent { +public final class IdlingEnergyConsumptionEvent extends AbstractEnergyConsumptionEvent { public static final String EVENT_TYPE = "idlingEnergyConsumption"; public IdlingEnergyConsumptionEvent(double time, Id vehicleId, Id linkId, double energy, double endCharge) { diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/LTHDriveEnergyConsumption.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/LTHDriveEnergyConsumption.java index afc8d17d93a..ea20f84a484 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/LTHDriveEnergyConsumption.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/LTHDriveEnergyConsumption.java @@ -32,7 +32,7 @@ import com.google.common.primitives.Doubles; -public class LTHDriveEnergyConsumption implements DriveEnergyConsumption { +public final class LTHDriveEnergyConsumption implements DriveEnergyConsumption { private final PiecewiseBicubicSplineInterpolatingFunction function; diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/MissingEnergyEvent.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/MissingEnergyEvent.java index a85c043522d..ef120c09fa9 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/MissingEnergyEvent.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/MissingEnergyEvent.java @@ -26,7 +26,7 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.vehicles.Vehicle; -public class MissingEnergyEvent extends Event { +public final class MissingEnergyEvent extends Event { public static final String EVENT_TYPE = "missing_energy"; public static final String ATTRIBUTE_VEHICLE = "vehicle"; public static final String ATTRIBUTE_ENERGY = "energy"; diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java index 39d93db41c0..22ea5316e53 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java @@ -27,7 +27,7 @@ import com.google.common.base.Preconditions; import com.google.inject.Inject; -public class OhdeSlaskiAuxEnergyConsumption implements AuxEnergyConsumption { +public final class OhdeSlaskiAuxEnergyConsumption implements AuxEnergyConsumption { private static final double a = 1.3;// [W] private static final double b = -63.4;// [W] private static final double c = 1748.1;// [W] diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiDriveEnergyConsumption.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiDriveEnergyConsumption.java index dafad6d76d1..44b62145719 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiDriveEnergyConsumption.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiDriveEnergyConsumption.java @@ -30,7 +30,7 @@ * https://www.researchgate.net/profile/Michal-Maciejewski-3/publication/312393169_Statistical_analysis_of_real-world_urban_driving_cycles_for_modelling_energy_consumption_of_electric_vehicles/links/59b7a17faca2722453a5fc7f/Statistical-analysis-of-real-world-urban-driving-cycles-for-modelling-energy-consumption-of-electric-vehicles.pdf * TODO Add (dis-)charging efficiency relative to SOC, temperature, etc... */ -public class OhdeSlaskiDriveEnergyConsumption implements DriveEnergyConsumption { +public final class OhdeSlaskiDriveEnergyConsumption implements DriveEnergyConsumption { private static final double g = 9.81; // g [m/s^2] private static final double m = 1525; // vehicle mass [kg] private static final double m_s = m + 100; // vehicle mass + extra mass [kg] diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/VehicleTypeSpecificDriveEnergyConsumptionFactory.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/VehicleTypeSpecificDriveEnergyConsumptionFactory.java index b905a6f881e..4310d786b80 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/VehicleTypeSpecificDriveEnergyConsumptionFactory.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/VehicleTypeSpecificDriveEnergyConsumptionFactory.java @@ -29,7 +29,7 @@ import org.matsim.contrib.ev.fleet.ElectricVehicle; import org.matsim.vehicles.VehicleType; -public class VehicleTypeSpecificDriveEnergyConsumptionFactory implements DriveEnergyConsumption.Factory { +public final class VehicleTypeSpecificDriveEnergyConsumptionFactory implements DriveEnergyConsumption.Factory { private final Map, DriveEnergyConsumption.Factory> consumptionMap = new HashMap<>(); From 4ed2b9ee05dcaa3f7e5243e88621df10ca148b2c Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Fri, 20 Oct 2023 16:16:29 +0200 Subject: [PATCH 3/6] an example of how to write your own consumption model --- .../RunEvExampleWithLTHConsumptionModel.java | 3 +- .../RunEvExampleWithOwnConsumptionModel.java | 137 ++++++++++++++++++ .../contrib/ev/fleet/ElectricFleetUtils.java | 3 +- .../LTHConsumptionModelReader.java | 5 +- 4 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithOwnConsumptionModel.java diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModel.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModel.java index 15ed10c0627..024bc2e4c54 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModel.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModel.java @@ -89,7 +89,7 @@ public void run( String[] args ) { VehicleTypeSpecificDriveEnergyConsumptionFactory driveEnergyConsumptionFactory = new VehicleTypeSpecificDriveEnergyConsumptionFactory(); var vehicleType = Id.create( "EV_65.0kWh", VehicleType.class ); driveEnergyConsumptionFactory.addEnergyConsumptionModelFactory( vehicleType, - new LTHConsumptionModelReader( vehicleType ).readURL( ConfigGroup.getInputFileURL( config.getContext(), "MidCarMap.csv" ) ) ); + new LTHConsumptionModelReader().readURL( ConfigGroup.getInputFileURL( config.getContext(), "MidCarMap.csv" ) ) ); controler.addOverridingModule( new EvModule() ); controler.addOverridingModule( new AbstractModule(){ @@ -106,6 +106,7 @@ public void install(){ } ); } + controler.run(); } } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithOwnConsumptionModel.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithOwnConsumptionModel.java new file mode 100644 index 00000000000..eacaba778ad --- /dev/null +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/example/RunEvExampleWithOwnConsumptionModel.java @@ -0,0 +1,137 @@ +/* *********************************************************************** * + * project: org.matsim.* + * * + * *********************************************************************** * + * * + * copyright : (C) 2016 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.contrib.ev.example; +/* + * created by jbischoff, 19.03.2019 + */ + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; +import org.matsim.api.core.v01.network.Link; +import org.matsim.contrib.ev.EvConfigGroup; +import org.matsim.contrib.ev.EvModule; +import org.matsim.contrib.ev.discharging.AuxEnergyConsumption; +import org.matsim.contrib.ev.discharging.DriveEnergyConsumption; +import org.matsim.contrib.ev.discharging.LTHDriveEnergyConsumption; +import org.matsim.contrib.ev.fleet.ElectricVehicle; +import org.matsim.contrib.ev.infrastructure.LTHConsumptionModelReader; +import org.matsim.contrib.ev.routing.EvNetworkRoutingProvider; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigGroup; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.controler.AbstractModule; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy; +import org.matsim.core.scenario.ScenarioUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +/** + * Runs a sample EV run using a vehicle consumption model designed at LTH in Lund which takes the speed and the slope of a link into account. + * Link slopes may be added using a double array on the network. + * The consumption maps are based on Domingues, Gabriel. / Modeling, Optimization and Analysis of Electromobility Systems. Lund : Department of Biomedical Engineering, Lund university, 2018. 169 p., PhD thesis + */ +public class RunEvExampleWithOwnConsumptionModel{ + static final String DEFAULT_CONFIG_FILE = "test/input/org/matsim/contrib/ev/example/RunEvExample/config.xml"; + private static final Logger log = LogManager.getLogger( RunEvExampleWithOwnConsumptionModel.class ); + + public static void main(String[] args) throws IOException { + if (args.length > 0) { + log.info("Starting simulation run with the following arguments:"); + log.info("args=" + Arrays.toString( args ) ); + } else { + File localConfigFile = new File(DEFAULT_CONFIG_FILE); + if (localConfigFile.exists()) { + log.info("Starting simulation run with the local example config file"); + args = new String[]{ DEFAULT_CONFIG_FILE }; + } else { + log.info("Starting simulation run with the example config file from GitHub repository"); + args = new String[]{"https://raw.githubusercontent.com/matsim-org/matsim/master/contribs/ev/" + + DEFAULT_CONFIG_FILE }; + } + } + new RunEvExampleWithOwnConsumptionModel().run(args ); + } + + public void run( String[] args ) { + Config config = ConfigUtils.loadConfig(args, new EvConfigGroup()); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + + // === + + Scenario scenario = ScenarioUtils.loadScenario(config); + + // === + + Controler controler = new Controler(scenario); + { + DriveEnergyConsumption.Factory driveEnergyConsumptionFactory = new DriveEnergyConsumption.Factory(){ + @Override public DriveEnergyConsumption create( ElectricVehicle electricVehicle ){ + DriveEnergyConsumption.Factory factory = new LTHConsumptionModelReader().readURL( ConfigGroup.getInputFileURL( config.getContext(), "MidCarMap.csv" ) ); + DriveEnergyConsumption delegate = factory.create( electricVehicle ); + + DriveEnergyConsumption consumption = new DriveEnergyConsumption(){ + @Override public double calcEnergyConsumption( Link link, double travelTime, double linkEnterTime ){ + + // discharge because the link must be driven: + double delta = delegate.calcEnergyConsumption( link, travelTime, linkEnterTime ); + + double desiredSocAtEndOfLink = (double) electricVehicle.getVehicleSpecification().getMatsimVehicle().getAttributes().getAttribute( "whatever" ); + + return electricVehicle.getBattery().getSoc() - desiredSocAtEndOfLink; + // * above will often be negative; this is the purpose: discharging is negative i.e. we are + // charging on the link. ((This is why I am in general against hiding the sign in the method + // name. kai)) + + // * above is in SOC space, needs to be translated into kWh space + + // * need to make sure that the above charging is physically possible + + // * need to make sure that we are not discharging beyond what is needed to drive the link + + } + }; + return consumption; + } + }; + + controler.addOverridingModule( new EvModule() ); + controler.addOverridingModule( new AbstractModule(){ + @Override + public void install(){ + bind( DriveEnergyConsumption.Factory.class ).toInstance( driveEnergyConsumptionFactory ); + bind( AuxEnergyConsumption.Factory.class ).toInstance( + electricVehicle -> ( beginTime, duration, linkId ) -> 0 ); //a dummy factory, as aux consumption is part of the drive consumption in the model + + addRoutingModuleBinding( TransportMode.car ).toProvider( new EvNetworkRoutingProvider( TransportMode.car ) ); + // a router that inserts charging activities when the battery is run empty. there may be some other way to insert + // charging activities, based on the situation. kai, dec'22 + } + } ); + } + + + controler.run(); + } +} diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java index 11d272a4129..0e92b52759c 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/fleet/ElectricFleetUtils.java @@ -83,8 +83,7 @@ public static ElectricFleet createDefaultFleet(ElectricFleetSpecification fleetS ImmutableMap, ElectricVehicle> vehicles = fleetSpecification.getVehicleSpecifications() .values() .stream() - .map(s -> create(s, driveConsumptionFactory, auxConsumptionFactory, - chargingFactory )) + .map(s -> create(s, driveConsumptionFactory, auxConsumptionFactory, chargingFactory )) .collect(ImmutableMap.toImmutableMap(ElectricVehicle::getId, v -> v)); return () -> vehicles; } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/LTHConsumptionModelReader.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/LTHConsumptionModelReader.java index 5cb4e90d129..0b8e732e85a 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/LTHConsumptionModelReader.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/infrastructure/LTHConsumptionModelReader.java @@ -28,6 +28,7 @@ import java.util.List; import org.matsim.api.core.v01.Id; +import org.matsim.contrib.ev.discharging.DriveEnergyConsumption; import org.matsim.contrib.ev.discharging.LTHDriveEnergyConsumption; import org.matsim.core.utils.io.tabularFileParser.TabularFileHandler; import org.matsim.core.utils.io.tabularFileParser.TabularFileParser; @@ -43,10 +44,10 @@ */ public class LTHConsumptionModelReader { - public LTHConsumptionModelReader(Id vehicleTypeId) { + public LTHConsumptionModelReader() { } - public LTHDriveEnergyConsumption.Factory readURL(URL fileUrl) { + public DriveEnergyConsumption.Factory readURL( URL fileUrl ) { List speeds = new ArrayList<>(); List slopes = new ArrayList<>(); TabularFileParserConfig tabularFileParserConfig = new TabularFileParserConfig(); From d73dd40e54a2aa141c942ab548a19d26b0a8026e Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Fri, 20 Oct 2023 16:35:17 +0200 Subject: [PATCH 4/6] change eagerSingleton to regular Singleton.class; add a comment --- .../OhdeSlaskiAuxEnergyConsumption.java | 4 ++-- .../ev/temperature/TemperatureChangeModule.java | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java index 22ea5316e53..b344474bf9d 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/discharging/OhdeSlaskiAuxEnergyConsumption.java @@ -46,7 +46,7 @@ private static double calcPower(double temp) { private final TemperatureService temperatureService; - public OhdeSlaskiAuxEnergyConsumption(TemperatureService temperatureService) { + OhdeSlaskiAuxEnergyConsumption(TemperatureService temperatureService) { this.temperatureService = temperatureService; } @@ -59,7 +59,7 @@ public static class Factory implements AuxEnergyConsumption.Factory { private final TemperatureService temperatureService; @Inject - public Factory(TemperatureService temperatureService) { + Factory(TemperatureService temperatureService) { this.temperatureService = temperatureService; } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java index 697e0437ed2..e5870e52da4 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java @@ -21,14 +21,22 @@ * created by jbischoff, 15.08.2018 */ +import com.google.inject.Singleton; import org.matsim.core.controler.AbstractModule; public class TemperatureChangeModule extends AbstractModule { @Override public void install() { - addMobsimListenerBinding().to(TemperatureManager.class).asEagerSingleton(); - bind(TemperatureServiceImpl.class).asEagerSingleton(); - bind(TemperatureService.class).to(TemperatureServiceImpl.class); - addEventHandlerBinding().to(TemperatureServiceImpl.class); + addMobsimListenerBinding().to(TemperatureManager.class).in( Singleton.class ); + bind(TemperatureServiceImpl.class).in( Singleton.class ); + bind(TemperatureService.class).to(TemperatureServiceImpl.class); + addEventHandlerBinding().to(TemperatureServiceImpl.class); + + // yyyy Shouldn't we think about just having a like + +// bind(TemperatureService.class).to(TemperatureServiceImpl.class)(.in( Singleton.class )); + + // and then make sure that the implementation registers itself? kai, oct'23 + } } From 1b87a433b6848f5696c24473e6947b36345049ab Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Fri, 20 Oct 2023 16:36:46 +0200 Subject: [PATCH 5/6] change comment --- .../matsim/contrib/ev/temperature/TemperatureChangeModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java index e5870e52da4..2398af9cf21 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java @@ -36,7 +36,7 @@ public void install() { // bind(TemperatureService.class).to(TemperatureServiceImpl.class)(.in( Singleton.class )); - // and then make sure that the implementation registers itself? kai, oct'23 + // and then make sure that the implementation registers itself? But how to actually achieve that? kai, oct'23 } } From 9c47c82198a1b6d7b788623f2065aa78a8bf6815 Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Mon, 23 Oct 2023 08:06:32 +0200 Subject: [PATCH 6/6] comment/documentation changes --- .../src/main/java/org/matsim/contrib/ev/package-info.java | 4 ++-- .../contrib/ev/temperature/TemperatureChangeModule.java | 7 +++++++ .../org/matsim/contrib/ev/temperature/package-info.java | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/package-info.java diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/package-info.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/package-info.java index b8acc39a3f7..1ae999170d8 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/package-info.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/package-info.java @@ -17,8 +17,6 @@ * * * *********************************************************************** */ -package org.matsim.contrib.ev; - /** * All values used in this package use SI base and derived units. In particular: *
    @@ -34,3 +32,5 @@ * Consequently, energy consumption is measured in [J/m], rather than [kWh/100km] or [Wh/km], as typically done in * transport. */ +package org.matsim.contrib.ev; + diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java index 2398af9cf21..2a4530061e2 100644 --- a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/TemperatureChangeModule.java @@ -27,7 +27,9 @@ public class TemperatureChangeModule extends AbstractModule { @Override public void install() { + addMobsimListenerBinding().to(TemperatureManager.class).in( Singleton.class ); + bind(TemperatureServiceImpl.class).in( Singleton.class ); bind(TemperatureService.class).to(TemperatureServiceImpl.class); addEventHandlerBinding().to(TemperatureServiceImpl.class); @@ -38,5 +40,10 @@ public void install() { // and then make sure that the implementation registers itself? But how to actually achieve that? kai, oct'23 + // I think that the answer to that last question is to bind the interface rather than the implementation, and have that further "upstairs" in the ev module: + // addEventHandlerBinding().to( TemperatureService.class ); + // for this, evidently, the interface needs to implement the right things (which it currently does not). + + } } diff --git a/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/package-info.java b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/package-info.java new file mode 100644 index 00000000000..bab62cd2b51 --- /dev/null +++ b/contribs/ev/src/main/java/org/matsim/contrib/ev/temperature/package-info.java @@ -0,0 +1,4 @@ +/** + * I think that this is about ambient temperature. And it is here since charging may depend on ambient temperatur. + */ +package org.matsim.contrib.ev.temperature;