From c8c4bd9ca05dd4c5ca8d4d6a878c7def2ff204d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Mon, 22 Apr 2024 16:20:39 +0200 Subject: [PATCH 1/2] fix: default vehicle type id (#3156) * fix: default vehicle type id * fix unit test in freight * change getDefaultVehicleType to createDefaultVehicleType * fix test --- .../carsharing/qsim/ParkCSVehicles.java | 8 ++-- .../contrib/dvrp/fleet/FleetModule.java | 2 +- .../examples/random/RandomDynAgentSource.java | 2 +- .../passenger/DefaultPassengerEngineTest.java | 2 +- .../dvrp/passenger/PassengerGroupTest.java | 2 +- .../contrib/dvrp/router/DiversionTest.java | 2 +- .../controler/FreightAgentSource.java | 4 +- .../freight/carriers/CarriersUtilsTest.java | 9 ++-- .../sim/ParkingPopulationAgentSource.java | 2 +- .../analysis/skims/NetworkSkimMatrices.java | 2 +- .../run/SharingVehicleSource.java | 2 +- .../PopulationAgentSourceWithVehicles.java | 2 +- ...ilityTollTimeDistanceTravelDisutility.java | 2 +- ...ssionTollTimeDistanceTravelDisutility.java | 2 +- .../core/controler/PrepareForSimImpl.java | 2 +- .../core/mobsim/hermes/ScenarioImporter.java | 2 +- .../leastcostpathtree/LeastCostPathTree.java | 2 +- .../org/matsim/vehicles/VehicleUtils.java | 15 +++---- .../qsim/NetsimRoutingConsistencyTest.java | 8 ++-- ...workRoutingInclAccessEgressModuleTest.java | 6 ++- .../vehicles/DefaultVehicleTypeTest.java | 42 +++++++++++++++++++ 21 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 matsim/src/test/java/org/matsim/vehicles/DefaultVehicleTypeTest.java diff --git a/contribs/carsharing/src/main/java/org/matsim/contrib/carsharing/qsim/ParkCSVehicles.java b/contribs/carsharing/src/main/java/org/matsim/contrib/carsharing/qsim/ParkCSVehicles.java index 666920c2aa9..b40618c00eb 100644 --- a/contribs/carsharing/src/main/java/org/matsim/contrib/carsharing/qsim/ParkCSVehicles.java +++ b/contribs/carsharing/src/main/java/org/matsim/contrib/carsharing/qsim/ParkCSVehicles.java @@ -34,13 +34,13 @@ public ParkCSVehicles(QSim qSim, this.mainModes = qsim.getScenario().getConfig().qsim().getMainModes(); for (String mode : mainModes) { - modeVehicleTypes.put(mode, VehicleUtils.getDefaultVehicleType()); + modeVehicleTypes.put(mode, VehicleUtils.createDefaultVehicleType()); } this.carsharingSupply = carsharingSupply; - modeVehicleTypes.put("twoway", VehicleUtils.getDefaultVehicleType()); - modeVehicleTypes.put("freefloating", VehicleUtils.getDefaultVehicleType()); + modeVehicleTypes.put("twoway", VehicleUtils.createDefaultVehicleType()); + modeVehicleTypes.put("freefloating", VehicleUtils.createDefaultVehicleType()); - modeVehicleTypes.put("oneway", VehicleUtils.getDefaultVehicleType()); + modeVehicleTypes.put("oneway", VehicleUtils.createDefaultVehicleType()); } diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/fleet/FleetModule.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/fleet/FleetModule.java index 2a49ab78f37..a6afe189882 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/fleet/FleetModule.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/fleet/FleetModule.java @@ -52,7 +52,7 @@ public FleetModule(String mode, URL fleetSpecificationUrl, boolean updateVehicle this.fleetSpecificationUrl = fleetSpecificationUrl; this.updateVehicleStartLinkToLastLink = updateVehicleStartLinkToLastLink; - vehicleType = VehicleUtils.getDefaultVehicleType(); + vehicleType = VehicleUtils.createDefaultVehicleType(); } public FleetModule(String mode, URL fleetSpecificationUrl, VehicleType vehicleType) { diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/examples/random/RandomDynAgentSource.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/examples/random/RandomDynAgentSource.java index 373a824f13e..273fb016756 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/examples/random/RandomDynAgentSource.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/examples/random/RandomDynAgentSource.java @@ -61,7 +61,7 @@ public void insertAgentsIntoMobsim() { // qSim.createAndParkVehicleOnLink(qSimVehicleFactory.createVehicle(Id.create(id, Vehicle.class), // VehicleUtils.getDefaultVehicleType()), startLinkId); - final Vehicle vehicle = qSimVehicleFactory.createVehicle( Id.create( id, Vehicle.class ), VehicleUtils.getDefaultVehicleType() ) ; + final Vehicle vehicle = qSimVehicleFactory.createVehicle( Id.create( id, Vehicle.class ), VehicleUtils.createDefaultVehicleType() ) ; QVehicle qVehicle = new QVehicleImpl( vehicle ) ; // yyyyyy should use factory. kai, nov'18 qSim.addParkedVehicle( qVehicle, startLinkId ); diff --git a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngineTest.java b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngineTest.java index 97579d14517..d9664a3aaf8 100644 --- a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngineTest.java +++ b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/DefaultPassengerEngineTest.java @@ -188,7 +188,7 @@ protected void configureQSim() { //supply addQSimComponentBinding(DynActivityEngine.COMPONENT_NAME).to(DynActivityEngine.class); bindModal(Fleet.class).toInstance(fleet); - bindModal(VehicleType.class).toInstance(VehicleUtils.getDefaultVehicleType()); + bindModal(VehicleType.class).toInstance(VehicleUtils.createDefaultVehicleType()); bindModal(VrpOptimizer.class).to(optimizerClass).asEagerSingleton(); bindModal(VrpAgentLogic.DynActionCreator.class).to(OneTaxiActionCreator.class) .asEagerSingleton(); diff --git a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/PassengerGroupTest.java b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/PassengerGroupTest.java index 61a9804b4bf..c10c51eb838 100644 --- a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/PassengerGroupTest.java +++ b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/passenger/PassengerGroupTest.java @@ -120,7 +120,7 @@ protected void configureQSim() { //supply addQSimComponentBinding(DynActivityEngine.COMPONENT_NAME).to(DynActivityEngine.class); bindModal(Fleet.class).toInstance(fleet); - bindModal(VehicleType.class).toInstance(VehicleUtils.getDefaultVehicleType()); + bindModal(VehicleType.class).toInstance(VehicleUtils.createDefaultVehicleType()); bindModal(VrpOptimizer.class).to(optimizerClass).asEagerSingleton(); bindModal(VrpAgentLogic.DynActionCreator.class).to(OneTaxiActionCreator.class) .asEagerSingleton(); diff --git a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java index 2aa72304e53..ed2c0c27587 100644 --- a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java +++ b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java @@ -287,7 +287,7 @@ protected void configureQSim() { return Fleets.createDefaultFleet(fleetSpecification, getter.getModal(Network.class).getLinks()::get); })).in(Singleton.class); - bindModal(VehicleType.class).toInstance(VehicleUtils.getDefaultVehicleType()); + bindModal(VehicleType.class).toInstance(VehicleUtils.createDefaultVehicleType()); install(new VrpAgentSourceQSimModule(getMode())); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/controler/FreightAgentSource.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/controler/FreightAgentSource.java index 71a577d8200..0feadd08226 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/controler/FreightAgentSource.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/controler/FreightAgentSource.java @@ -74,10 +74,10 @@ public final class FreightAgentSource implements AgentSource { Vehicle vehicle; if( CarriersUtils.getVehicle( freightDriverPlan ) == null ){ - vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.getDefaultVehicleType() ); + vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.createDefaultVehicleType() ); log.warn( "vehicle for agent " + freightDriverPlan.getPerson().getId() + " is missing. set default vehicle where maxVelocity is solely defined by link.speed." ); } else if( CarriersUtils.getVehicle( freightDriverPlan ).getType() == null ){ - vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.getDefaultVehicleType() ); + vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.createDefaultVehicleType() ); log.warn( "vehicleType for agent " + freightDriverPlan.getPerson().getId() + " is missing. set default vehicleType where maxVelocity is solely defined by link.speed." ); } else { vehicle = CarriersUtils.getVehicle( freightDriverPlan ); diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java index b57f9d7b884..dbdcacf6eac 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java @@ -28,6 +28,7 @@ import org.matsim.freight.carriers.*; import org.matsim.testcases.MatsimTestUtils; import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; import org.matsim.vehicles.VehicleUtils; import static org.matsim.testcases.MatsimTestUtils.EPSILON; @@ -41,22 +42,24 @@ public class CarriersUtilsTest { @Test void testAddAndGetVehicleToCarrier() { + VehicleType vehicleType = VehicleUtils.createDefaultVehicleType(); + Carrier carrier = new CarrierImpl(Id.create("carrier", Carrier.class)); Id testVehicleId = Id.createVehicleId("testVehicle"); - CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(testVehicleId, Id.createLinkId("link0"),VehicleUtils.getDefaultVehicleType()); + CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(testVehicleId, Id.createLinkId("link0"),vehicleType); // carrierVehicle.setType(VehicleUtils.getDefaultVehicleType()); //add Vehicle CarriersUtils.addCarrierVehicle(carrier, carrierVehicle); Assertions.assertEquals(1, carrier.getCarrierCapabilities().getCarrierVehicles().size()); CarrierVehicle cv = (CarrierVehicle) carrier.getCarrierCapabilities().getCarrierVehicles().values().toArray()[0]; - Assertions.assertEquals(VehicleUtils.getDefaultVehicleType(), cv.getType()); + Assertions.assertEquals(vehicleType, cv.getType()); Assertions.assertEquals(Id.createLinkId("link0"), cv.getLinkId() ); //get Vehicle CarrierVehicle carrierVehicle1 = CarriersUtils.getCarrierVehicle(carrier, testVehicleId ); Assertions.assertEquals(testVehicleId, carrierVehicle1.getId()); - Assertions.assertEquals(VehicleUtils.getDefaultVehicleType(), carrierVehicle1.getType()); + Assertions.assertEquals(vehicleType, carrierVehicle1.getType()); Assertions.assertEquals(Id.createLinkId("link0"), carrierVehicle1.getLinkId() ); } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingPopulationAgentSource.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingPopulationAgentSource.java index 9f99e27a697..4090819c849 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingPopulationAgentSource.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingPopulationAgentSource.java @@ -79,7 +79,7 @@ public ParkingPopulationAgentSource(Population population, AgentFactory agentFac case defaultVehicle: for (String mode : mainModes) { // initialize each mode with default vehicle type: - modeVehicleTypes.put(mode, VehicleUtils.getDefaultVehicleType()); + modeVehicleTypes.put(mode, VehicleUtils.createDefaultVehicleType()); } break; case fromVehiclesData: diff --git a/contribs/sbb-extensions/src/main/java/ch/sbb/matsim/analysis/skims/NetworkSkimMatrices.java b/contribs/sbb-extensions/src/main/java/ch/sbb/matsim/analysis/skims/NetworkSkimMatrices.java index afc16f51ec0..421b9f9f1ef 100644 --- a/contribs/sbb-extensions/src/main/java/ch/sbb/matsim/analysis/skims/NetworkSkimMatrices.java +++ b/contribs/sbb-extensions/src/main/java/ch/sbb/matsim/analysis/skims/NetworkSkimMatrices.java @@ -106,7 +106,7 @@ public static NetworkIndicators calculateSkimMatrices(Network xy2lNetwork private static class RowWorker implements Runnable { - private final static Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.getDefaultVehicleType()); + private final static Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.createDefaultVehicleType()); private final static Person PERSON = PopulationUtils.getFactory().createPerson(Id.create("thePerson", Person.class)); private final ConcurrentLinkedQueue originZones; private final Set destinationZones; diff --git a/contribs/shared_mobility/src/main/java/org/matsim/contrib/shared_mobility/run/SharingVehicleSource.java b/contribs/shared_mobility/src/main/java/org/matsim/contrib/shared_mobility/run/SharingVehicleSource.java index ed1043cc6b0..2e6fe9188d6 100644 --- a/contribs/shared_mobility/src/main/java/org/matsim/contrib/shared_mobility/run/SharingVehicleSource.java +++ b/contribs/shared_mobility/src/main/java/org/matsim/contrib/shared_mobility/run/SharingVehicleSource.java @@ -31,7 +31,7 @@ public void insertAgentsIntoMobsim() { for (SharingVehicleSpecification veh : specification.getVehicles()) { Id startLink = veh.getStartLinkId().get(); Id vehId = Id.createVehicleId(veh.getId().toString()); - Vehicle basicVehicle = factory.createVehicle(vehId, VehicleUtils.getDefaultVehicleType()); + Vehicle basicVehicle = factory.createVehicle(vehId, VehicleUtils.createDefaultVehicleType()); QVehicleImpl qvehicle = new QVehicleImpl(basicVehicle); qvehicle.setCurrentLink(this.qsim.getScenario().getNetwork().getLinks().get(startLink)); qsim.addParkedVehicle(qvehicle, startLink); diff --git a/contribs/socnetsim/src/main/java/org/matsim/contrib/socnetsim/sharedvehicles/qsim/PopulationAgentSourceWithVehicles.java b/contribs/socnetsim/src/main/java/org/matsim/contrib/socnetsim/sharedvehicles/qsim/PopulationAgentSourceWithVehicles.java index b718bd8ca27..64d5eea19d8 100644 --- a/contribs/socnetsim/src/main/java/org/matsim/contrib/socnetsim/sharedvehicles/qsim/PopulationAgentSourceWithVehicles.java +++ b/contribs/socnetsim/src/main/java/org/matsim/contrib/socnetsim/sharedvehicles/qsim/PopulationAgentSourceWithVehicles.java @@ -73,7 +73,7 @@ public PopulationAgentSourceWithVehicles( this.modeVehicleTypes = new HashMap<>(); this.mainModes = qsim.getScenario().getConfig().qsim().getMainModes(); for (String mode : mainModes) { - modeVehicleTypes.put(mode, VehicleUtils.getDefaultVehicleType()); + modeVehicleTypes.put(mode, VehicleUtils.createDefaultVehicleType()); } } diff --git a/contribs/vsp/src/main/java/playground/vsp/airPollution/exposure/EmissionResponsibilityTollTimeDistanceTravelDisutility.java b/contribs/vsp/src/main/java/playground/vsp/airPollution/exposure/EmissionResponsibilityTollTimeDistanceTravelDisutility.java index f1473df3400..42458673fbd 100644 --- a/contribs/vsp/src/main/java/playground/vsp/airPollution/exposure/EmissionResponsibilityTollTimeDistanceTravelDisutility.java +++ b/contribs/vsp/src/main/java/playground/vsp/airPollution/exposure/EmissionResponsibilityTollTimeDistanceTravelDisutility.java @@ -84,7 +84,7 @@ public double getLinkTravelDisutility(final Link link, final double time, final if (person == null){ // additionally, no person is given -> a default vehicle type is used log.warn("No person and no vehicle is given to calculate the link travel disutility. The default vehicle type is used to estimate emission disutility."); - emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.getDefaultVehicleType()); + emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.createDefaultVehicleType()); } else { // a person is given -> use the vehicle for that person given in emissionModule emissionVehicle = this.emissionVehicles.getVehicles().get(Id.createVehicleId(person.getId())); diff --git a/contribs/vsp/src/main/java/playground/vsp/airPollution/flatEmissions/EmissionTollTimeDistanceTravelDisutility.java b/contribs/vsp/src/main/java/playground/vsp/airPollution/flatEmissions/EmissionTollTimeDistanceTravelDisutility.java index ece0910df0b..9dc8d9afdb4 100644 --- a/contribs/vsp/src/main/java/playground/vsp/airPollution/flatEmissions/EmissionTollTimeDistanceTravelDisutility.java +++ b/contribs/vsp/src/main/java/playground/vsp/airPollution/flatEmissions/EmissionTollTimeDistanceTravelDisutility.java @@ -82,7 +82,7 @@ public double getLinkTravelDisutility(final Link link, final double time, final if (person == null){ // additionally, no person is given -> a default vehicle type is used log.warn("No person and no vehicle is given to calculate the link travel disutility. The default vehicle type is used to estimate emission disutility."); - emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.getDefaultVehicleType()); + emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.createDefaultVehicleType()); } else { // a person is given -> use the vehicle for that person given in emissionModule emissionVehicle = this.emissionVehicles.getVehicles().get(Id.createVehicleId(person.getId())); diff --git a/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java b/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java index 3278f06e295..359a812887a 100644 --- a/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java +++ b/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java @@ -291,7 +291,7 @@ private Map getVehicleTypesForAllNetworkAndMainModes() { VehicleType type; switch (qSimConfigGroup.getVehiclesSource()) { case defaultVehicle: - type = VehicleUtils.getDefaultVehicleType(); + type = VehicleUtils.createDefaultVehicleType(); if (!scenario.getVehicles().getVehicleTypes().containsKey(type.getId())){ scenario.getVehicles().addVehicleType( type ); } diff --git a/matsim/src/main/java/org/matsim/core/mobsim/hermes/ScenarioImporter.java b/matsim/src/main/java/org/matsim/core/mobsim/hermes/ScenarioImporter.java index f8480f9647f..7501fcfdeca 100644 --- a/matsim/src/main/java/org/matsim/core/mobsim/hermes/ScenarioImporter.java +++ b/matsim/src/main/java/org/matsim/core/mobsim/hermes/ScenarioImporter.java @@ -369,7 +369,7 @@ private void processPlanNetworkRoute( Id endLId = netroute.getEndLinkId(); Map, Vehicle> vehicles = scenario.getVehicles().getVehicles(); Vehicle v = vehicles.get(VehicleUtils.getVehicleId(person, leg.getMode())); - Id vtypeid = v == null ? VehicleUtils.getDefaultVehicleType().getId() : v.getType().getId(); + Id vtypeid = v == null ? VehicleUtils.createDefaultVehicleType().getId() : v.getType().getId(); int pcuCategory = this.vehicleTypeMapping.get(vtypeid); Id vid = v == null ? Id.createVehicleId("v" + person.getId()) : v.getId(); double velocity = v == null ? diff --git a/matsim/src/main/java/org/matsim/utils/leastcostpathtree/LeastCostPathTree.java b/matsim/src/main/java/org/matsim/utils/leastcostpathtree/LeastCostPathTree.java index 535d9d5ff5c..25416ae7e87 100644 --- a/matsim/src/main/java/org/matsim/utils/leastcostpathtree/LeastCostPathTree.java +++ b/matsim/src/main/java/org/matsim/utils/leastcostpathtree/LeastCostPathTree.java @@ -63,7 +63,7 @@ public class LeastCostPathTree { private final TravelDisutility tcFunction; private IdMap nodeData = null; - private final Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.getDefaultVehicleType()); + private final Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.createDefaultVehicleType()); private final Person PERSON = PopulationUtils.getFactory().createPerson(Id.create("thePerson", Person.class)); // //////////////////////////////////////////////////////////////////// diff --git a/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java b/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java index 6c0a9b289ba..70027f8a0b5 100644 --- a/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java +++ b/matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java @@ -39,7 +39,7 @@ public final class VehicleUtils { private static final Logger log = LogManager.getLogger( VehicleUtils.class ) ; - private static final VehicleType DEFAULT_VEHICLE_TYPE = VehicleUtils.getFactory().createVehicleType(Id.create("defaultVehicleType", VehicleType.class)); + private static final String DEFAULT_VEHICLE_TYPE_ID = "defaultVehicleType"; private static final String VEHICLE_ATTRIBUTE_KEY = "vehicles"; private static final String VEHICLE_TYPES_ATTRIBUTE_KEY = "vehicleTypes"; @@ -62,10 +62,6 @@ public static VehicleType createVehicleType( Id typeId ){ return new VehicleType( typeId ); } - static { - DEFAULT_VEHICLE_TYPE.getCapacity().setSeats( 4 ); - } - public static VehiclesFactory getFactory() { return new VehiclesFactoryImpl(); } @@ -74,8 +70,13 @@ public static Vehicles createVehiclesContainer() { return new VehiclesImpl(); } - public static VehicleType getDefaultVehicleType() { - return DEFAULT_VEHICLE_TYPE; + public static VehicleType createDefaultVehicleType() { + VehicleType defaultVehicleType = VehicleUtils.getFactory() + .createVehicleType(Id.create(DEFAULT_VEHICLE_TYPE_ID, VehicleType.class)); + + defaultVehicleType.getCapacity().setSeats(4); + + return defaultVehicleType; } /** diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java index cbdde36ca58..6899e6c95f1 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java @@ -165,9 +165,9 @@ void testRoutingVsSimulation() { person.addPlan(plan); Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(VehicleUtils.createVehicleId(person, TransportMode.car), - VehicleUtils.getDefaultVehicleType()); + VehicleUtils.createDefaultVehicleType()); VehicleUtils.insertVehicleIdsIntoAttributes(person, Map.of(TransportMode.car, vehicle.getId())); - scenario.getVehicles().addVehicleType(VehicleUtils.getDefaultVehicleType()); + scenario.getVehicles().addVehicleType(VehicleUtils.createDefaultVehicleType()); scenario.getVehicles().addVehicle(vehicle); TravelTime travelTime = new FreeSpeedTravelTime(); @@ -251,8 +251,8 @@ void testRoutingVsSimulationFullStack() { Arrays.asList(link12, link23, link34, link45).forEach(l -> l.setFreespeed(10.0)); Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(Id.createVehicleId("P"), - VehicleUtils.getDefaultVehicleType()); - scenario.getVehicles().addVehicleType(VehicleUtils.getDefaultVehicleType()); + VehicleUtils.createDefaultVehicleType()); + scenario.getVehicles().addVehicleType(VehicleUtils.createDefaultVehicleType()); scenario.getVehicles().addVehicle(vehicle); Population population = scenario.getPopulation(); diff --git a/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java b/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java index be39a4c44ba..392a301d1c4 100644 --- a/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java +++ b/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java @@ -248,10 +248,14 @@ void calcRoute_defaultVehicle_defaultVehicleIsAssigned() { Map> modeId = VehicleUtils.getVehicleIds(person); + VehicleType defaultVehicleType = scenario.getVehicles().getVehicleTypes() + .get(VehicleUtils.createDefaultVehicleType().getId()); + assertNotNull(defaultVehicleType); + // should be only one, but however for (Id vehicleId : modeId.values()) { assertTrue(scenario.getVehicles().getVehicles().containsKey(vehicleId)); - assertEquals(VehicleUtils.getDefaultVehicleType(), scenario.getVehicles().getVehicles().get(vehicleId).getType()); + assertEquals(defaultVehicleType, scenario.getVehicles().getVehicles().get(vehicleId).getType()); } } diff --git a/matsim/src/test/java/org/matsim/vehicles/DefaultVehicleTypeTest.java b/matsim/src/test/java/org/matsim/vehicles/DefaultVehicleTypeTest.java new file mode 100644 index 00000000000..863c235549d --- /dev/null +++ b/matsim/src/test/java/org/matsim/vehicles/DefaultVehicleTypeTest.java @@ -0,0 +1,42 @@ +package org.matsim.vehicles; + +import org.junit.jupiter.api.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; +import org.matsim.vehicles.Vehicles; + +class DefaultVehicleTypeTest { + @Test + void testFirst() { + Config config = ConfigUtils.createConfig(); + Scenario scenario = ScenarioUtils.createScenario(config); + + Vehicles vehicles = scenario.getVehicles(); + + VehicleType vehicleType = VehicleUtils.createDefaultVehicleType(); + vehicles.addVehicleType(vehicleType); + + VehicleType vehicleType2 = vehicles.getFactory().createVehicleType(Id.create("custom", VehicleType.class)); + vehicles.addVehicleType(vehicleType2); + } + + @Test + void testSecond() { + Config config = ConfigUtils.createConfig(); + Scenario scenario = ScenarioUtils.createScenario(config); + + Vehicles vehicles = scenario.getVehicles(); + + VehicleType vehicleType = VehicleUtils.createDefaultVehicleType(); + vehicles.addVehicleType(vehicleType); + + // this caused a clash in IDs before getDefaultVehicleType was fixed + VehicleType vehicleType2 = vehicles.getFactory().createVehicleType(Id.create("custom", VehicleType.class)); + vehicles.addVehicleType(vehicleType2); + } +} \ No newline at end of file From 0d7df13ed631f58f6df9623e18ee1d76ffa7e5b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:42:52 +0000 Subject: [PATCH 2/2] build(deps): bump org.apache.maven.plugins:maven-jar-plugin Bumps [org.apache.maven.plugins:maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/apache/maven-jar-plugin/releases) - [Commits](https://github.com/apache/maven-jar-plugin/compare/maven-jar-plugin-3.4.0...maven-jar-plugin-3.4.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-jar-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7a8d856540e..c04827fbee1 100644 --- a/pom.xml +++ b/pom.xml @@ -421,7 +421,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.4.0 + 3.4.1 org.apache.maven.plugins