diff --git a/matsim/src/main/java/org/matsim/core/config/consistency/VspConfigConsistencyCheckerImpl.java b/matsim/src/main/java/org/matsim/core/config/consistency/VspConfigConsistencyCheckerImpl.java index a7dba48bdb6..0801fca6a51 100644 --- a/matsim/src/main/java/org/matsim/core/config/consistency/VspConfigConsistencyCheckerImpl.java +++ b/matsim/src/main/java/org/matsim/core/config/consistency/VspConfigConsistencyCheckerImpl.java @@ -386,11 +386,6 @@ private static boolean checkPlanCalcScoreConfigGroup( Config config, Level lvl, log.error("found marginal utility of money < 0. You almost certainly want a value > 0 here. " ) ; } - // added feb'16 - if ( config.routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none ) ) { - log.log( lvl, "found `PlansCalcRouteConfigGroup.AccessEgressType.none'; vsp should use `accessEgressModeToLink' or " + - "some other value or talk to Kai." ) ; - } // added oct'17: if ( config.scoring().getFractionOfIterationsToStartScoreMSA() == null || config.scoring().getFractionOfIterationsToStartScoreMSA() >= 1. ) { problem = true ; diff --git a/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java b/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java index c38fba94eec..fcab52f6d59 100644 --- a/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java +++ b/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java @@ -71,7 +71,7 @@ public final class RoutingConfigGroup extends ConfigGroup { private Double beelineDistanceFactor = 1.3 ; public enum AccessEgressType { - @Deprecated none, + none, /** * Euclidian distance from facility to nearest point on link; then teleported walk. In normal cases, all activities that belong to the @@ -92,7 +92,7 @@ public enum AccessEgressType { private static final String ACCESSEGRESSTYPE = "accessEgressType"; private static final String ACCESSEGRESSTYPE_CMT = "Defines how access and egress to main mode is simulated. Either of [none, accessEgressModeToLink, walkConstantTimeToLink, accessEgressModeToLinkPlusTimeConstant], Current default=none which means no access or egress trips are simulated."; - private AccessEgressType accessEgressType = AccessEgressType.none; + private AccessEgressType accessEgressType = AccessEgressType.accessEgressModeToLink; // --- private static final String RANDOMNESS = "routingRandomness" ; diff --git a/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java b/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java index 88e99ba95ce..f99f78c4232 100644 --- a/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java +++ b/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java @@ -63,12 +63,13 @@ public static RoutingModule createTeleportationRouter( String mode, Scenario sce @Deprecated // use AccessEgressNetworkRouter instead public static RoutingModule createPureNetworkRouter( String mode, PopulationFactory popFact, Network net, final LeastCostPathCalculator routeAlgo ) { return new NetworkRoutingModule( - mode, - popFact, - net, - routeAlgo); + mode, + popFact, + net, + routeAlgo); } + // TODO: make package private again // Please use injection (NetworkRoutingProvider) to get a NetworkRoutingInclAccessEgressModule - kn/gl nov'19 public static RoutingModule createAccessEgressNetworkRouter( String mode, diff --git a/matsim/src/main/java/org/matsim/core/router/LinkToLinkRouting.java b/matsim/src/main/java/org/matsim/core/router/LinkToLinkRouting.java index 2d83a752dcb..9adee3b2d82 100644 --- a/matsim/src/main/java/org/matsim/core/router/LinkToLinkRouting.java +++ b/matsim/src/main/java/org/matsim/core/router/LinkToLinkRouting.java @@ -120,18 +120,17 @@ public RoutingModule get() { ); // see NetworkRoutingProvider for some notes - if (!routingConfigGroup.getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none)) { - if (mode.equals(TransportMode.walk)) { - return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, leastCostPathCalculator, scenario, - filteredNetwork, invertedNetwork, null,null, timeInterpretation, multimodalLinkChooser); - } else { - return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, leastCostPathCalculator, scenario, - filteredNetwork, invertedNetwork, walkRouter, walkRouter, timeInterpretation, multimodalLinkChooser); - } + if (mode.equals(TransportMode.walk)) { + return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, leastCostPathCalculator, scenario, + filteredNetwork, invertedNetwork, null,null, timeInterpretation, multimodalLinkChooser); + } else { + return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, leastCostPathCalculator, scenario, + filteredNetwork, invertedNetwork, walkRouter, walkRouter, timeInterpretation, multimodalLinkChooser); + } + + // pure inverted router + // TODO: I have disabled this Link2Link Router and instead make it 100% use AccessEgress. Make sure, that this is okay #aleks + //return new LinkToLinkRoutingModule(mode, populationFactory, filteredNetwork, invertedNetwork, leastCostPathCalculator); - } else { - // pure inverted router - return new LinkToLinkRoutingModule(mode, populationFactory, filteredNetwork, invertedNetwork, leastCostPathCalculator); - } } } diff --git a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModule.java b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModule.java index 39338b527dd..89ba36ff008 100644 --- a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModule.java +++ b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModule.java @@ -114,10 +114,7 @@ public final class NetworkRoutingInclAccessEgressModule implements RoutingModule this.egressFromNetworkRouter = egressFromNetworkRouter; this.accessEgressType = config.routing().getAccessEgressType(); this.timeInterpretation = timeInterpretation; - if (accessEgressType.equals(AccessEgressType.none)) { - throw new RuntimeException("trying to use access/egress but not switched on in config. " - + "currently not supported; there are too many other problems"); - } else if (accessEgressType.equals(AccessEgressType.walkConstantTimeToLink) && !hasWarnedAccessEgress) { + if (accessEgressType.equals(AccessEgressType.walkConstantTimeToLink) && !hasWarnedAccessEgress) { hasWarnedAccessEgress = true; log.warn("you are using AccessEgressType=" + AccessEgressType.walkConstantTimeToLink + ". That means, access and egress won't get network-routed - even if you specified corresponding RoutingModules for access and egress "); @@ -399,7 +396,7 @@ public String toString() { } Id vehicleId = VehicleUtils.getVehicleId(person, leg.getMode()); - Vehicle vehicle = scenario.getVehicles().getVehicles().get(vehicleId); + Vehicle vehicle = scenario.getVehicles().getVehicles().get(vehicleId); // TODO This line creates a lot of problems in the tests: The old router did not need any vehicles, but this one does #aleks Path path = this.routeAlgo.calcLeastCostPath(startNode, endNode, depTime, person, vehicle); if (path == null) { throw new RuntimeException("No route found from node " + startNode.getId() + " to node " + endNode.getId() + " for mode " + mode + "."); @@ -419,7 +416,7 @@ public String toString() { route.setDistance(RouteUtils.calcDistance(route, relPosOnDepartureLink, relPosOnArrivalLink, this.filteredNetwork)); route.setVehicleId(vehicleId); leg.setRoute(route); - travTime = (int) path.travelTime; + travTime = (int) path.travelTime; // yyyy Why are we casting to int here? This causes the link traveltime to be different from the route traveltime. aleks Jan'2025 } else { // create an empty route == staying on place if toLink == endLink diff --git a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java index 7b874593fa1..283146e477d 100644 --- a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java +++ b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java @@ -114,28 +114,24 @@ public RoutingModule get() { travelDisutilityFactory.createTravelDisutility(travelTime), travelTime); - // the following again refers to the (transport)mode, since it will determine the mode of the leg on the network: - if ( !routingConfigGroup.getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - /* - * All network modes should fall back to the TransportMode.walk RoutingModule for access/egress to the Network. - * However, TransportMode.walk cannot fallback on itself for access/egress to the Network, so don't pass a standard - * accessEgressToNetworkRouter RoutingModule for walk.. - */ + /* + * The following again refers to the (transport)mode, since it will determine the mode of the leg on the network: + * + * All network modes should fall back to the TransportMode.walk RoutingModule for access/egress to the Network. + * However, TransportMode.walk cannot fallback on itself for access/egress to the Network, so don't pass a standard + * accessEgressToNetworkRouter RoutingModule for walk.. + */ - //null only works because walk is hardcoded and treated uniquely in the routing module. tschlenther june '20 + //null only works because walk is hardcoded and treated uniquely in the routing module. tschlenther june '20 - // more precisely: If the transport mode is walk, then code is used that does not need the accessEgressToNetwork router. kai, jun'22 - - if (mode.equals(TransportMode.walk)) { - return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, routeAlgo, scenario, filteredNetwork, null, timeInterpretation, multimodalLinkChooser); - } else { - return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, routeAlgo, scenario, filteredNetwork, walkRouter, timeInterpretation, multimodalLinkChooser) ; - } + // more precisely: If the transport mode is walk, then code is used that does not need the accessEgressToNetwork router. kai, jun'22 + if (mode.equals(TransportMode.walk)) { + return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, routeAlgo, scenario, filteredNetwork, null, timeInterpretation, multimodalLinkChooser); } else { - log.warn("[mode: {}; routingMode: {}] Using deprecated routing module without access/egress. Consider using AccessEgressNetworkRouter instead.", mode, routingMode); - return DefaultRoutingModules.createPureNetworkRouter(mode, populationFactory, filteredNetwork, routeAlgo); + return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, routeAlgo, scenario, filteredNetwork, walkRouter, timeInterpretation, multimodalLinkChooser) ; } + } private void checkNetwork(Network filteredNetwork) { diff --git a/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java b/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java index 703ea500d06..ec93a792564 100644 --- a/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java +++ b/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java @@ -141,7 +141,7 @@ void testConstructor_EventsManagerTypeImmutable() { @ParameterizedTest @ValueSource(booleans = {true, false}) void testTravelTimeCalculation(boolean isUsingFastCapacityUpdate) { - Fixture f = new Fixture(ConfigUtils.createConfig()); + Fixture f = new Fixture(this.utils.loadConfig((String) null)); Config config = f.scenario.getConfig(); /* Create 2 persons driving from link 1 to link 3, both starting at the same time at 7am. */ @@ -185,7 +185,7 @@ void testTravelTimeCalculation(boolean isUsingFastCapacityUpdate) { // Complete the configuration for our test case config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); config.controller().setCreateGraphs(false); - config.controller().setWriteEventsInterval(0); + config.controller().setWriteEventsInterval(1); config.controller().setDumpDataAtEnd(false); // - set scoring parameters ActivityParams actParams = new ActivityParams("h"); @@ -222,8 +222,9 @@ void testTravelTimeCalculation(boolean isUsingFastCapacityUpdate) { // test that the plans have the correct travel times // (travel time of the plan does not contain first and last link) + double seconds = ((Leg) (person1.getPlans().get(1).getPlanElements().get(1))).getTravelTime().seconds(); assertEquals(avgTravelTimeLink2, - ((Leg)(person1.getPlans().get(1).getPlanElements().get(1))).getTravelTime().seconds(), MatsimTestUtils.EPSILON, "ReRoute seems to have wrong travel times."); + seconds, MatsimTestUtils.EPSILON, "ReRoute seems to have wrong travel times."); } /** @@ -241,7 +242,7 @@ void testSetScoringFunctionFactory(boolean isUsingFastCapacityUpdate) { config.qsim().setUsingFastCapacityUpdate( isUsingFastCapacityUpdate ); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); - // create a very simple network with one link only and an empty population + // create a very simple network with two links only and an empty population Network network = scenario.getNetwork(); Node node1 = network.getFactory().createNode(Id.create(1, Node.class), new Coord(0, 0)); Node node2 = network.getFactory().createNode(Id.create(2, Node.class), new Coord(100, 0)); @@ -252,6 +253,13 @@ void testSetScoringFunctionFactory(boolean isUsingFastCapacityUpdate) { link.setFreespeed(1); link.setCapacity(3600.0); link.setNumberOfLanes(1); + Link linkOpposite = network.getFactory().createLink(Id.create(2, Link.class), node2, node1); + link.setLength(100); + link.setFreespeed(1); + link.setCapacity(3600.0); + link.setNumberOfLanes(1); + network.addLink(link); + network.addLink(linkOpposite); final Controler controler = new Controler(scenario); controler.getConfig().controller().setCreateGraphs(false); @@ -456,11 +464,7 @@ public Mobsim get() { assertEquals(f.link1.getId(), act2a.getLinkId()); assertEquals(f.link3.getId(), act2b.getLinkId()); - int expectedPlanLength = 3 ; - if ( !f.scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - // now 7 instead of earlier 3: h-wlk-iact-car-iact-walk-h - expectedPlanLength = 7 ; - } + int expectedPlanLength = 7 ; // check that BOTH plans have a route set, even when we only run 1 iteration where only one of them is used. //assertNotNull(leg1.getRoute()); @@ -474,11 +478,9 @@ public Mobsim get() { assertNotNull( ((Leg) plan.getPlanElements().get( 1 )).getRoute(), "null route in plan "+plan.getPlanElements()); - if ( !f.scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - assertNotNull( - ((Leg) plan.getPlanElements().get( 3 )).getRoute(), - "null route in plan "+plan.getPlanElements()); - } + assertNotNull( + ((Leg) plan.getPlanElements().get( 3 )).getRoute(), + "null route in plan "+plan.getPlanElements()); } } 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 0b4cc89e381..961b284a36b 100644 --- a/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java +++ b/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java @@ -412,6 +412,11 @@ void calcAccessTimeFromDistanceToLink() { Assert.equals(0.0,legs.get(2).getTravelTime().seconds()); } + /* + + This test was removed, since AccesEgressType.none is not a valid config-setting anymore. aleks Nov'24 + TODO Check if this is okay #aleks + @Test void noBushwackingLegs() { @@ -433,6 +438,7 @@ void noBushwackingLegs() { Assert.equals(TransportMode.car,legs.get(0).getMode()); } + */ /** * returns the mode of the first leg in a plan, which is not a walk (walk is now used as access/egress mode to network modes, diff --git a/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java b/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java index bd671737a31..be08459ce0b 100644 --- a/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java +++ b/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java @@ -46,6 +46,9 @@ import org.matsim.utils.objectattributes.attributable.AttributesImpl; import jakarta.inject.Provider; +import org.matsim.vehicles.PersonVehicles; +import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; import java.util.Arrays; import java.util.Collections; @@ -102,6 +105,16 @@ private static void testRestrictedNetwork(final Config config) throws Exception net.addLink( l2pt ); net.addLink( l3 ); + // We need to add a vehicle, it however does not affect the results + Id typeId = Id.create(1, VehicleType.class); + scenario.getVehicles().addVehicleType(VehicleUtils.createVehicleType(typeId)); + scenario.getVehicles().addVehicle(VehicleUtils.createVehicle(Id.createVehicleId(1), scenario.getVehicles().getVehicleTypes().get(typeId))); + + Person p = PopulationUtils.getFactory().createPerson(Id.createPersonId("toto")); + PersonVehicles vehicles = new PersonVehicles(); + vehicles.addModeVehicle(TransportMode.car, Id.createVehicleId(1)); + VehicleUtils.insertVehicleIdsIntoPersonAttributes(p, vehicles.getModeVehicles()); + com.google.inject.Injector injector = Injector.createInjector(scenario.getConfig(), new AbstractModule() { @Override public void install() { @@ -127,12 +140,10 @@ public void install() { new LinkFacility( l1 ), new LinkFacility( l3 ), 0, - PopulationUtils.getFactory().createPerson(Id.create("toto", Person.class)), new AttributesImpl()); + p, new AttributesImpl()); + + Leg l = (Leg) trip.get(2) ; - Leg l = (Leg) trip.get( 0 ); - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - l = (Leg) trip.get(2) ; - } // actual test NetworkRoute r = (NetworkRoute) l.getRoute(); @@ -181,6 +192,16 @@ void testMonomodalNetwork() throws Exception { net.addLink( l2short ); net.addLink( l3 ); + // We need to add a vehicle, it however does not affect the results + Id typeId = Id.create(1, VehicleType.class); + scenario.getVehicles().addVehicleType(VehicleUtils.createVehicleType(typeId)); + scenario.getVehicles().addVehicle(VehicleUtils.createVehicle(Id.createVehicleId(1), scenario.getVehicles().getVehicleTypes().get(typeId))); + + Person p = PopulationUtils.getFactory().createPerson(Id.createPersonId("toto")); + PersonVehicles vehicles = new PersonVehicles(); + vehicles.addModeVehicle(TransportMode.car, Id.createVehicleId(1)); + VehicleUtils.insertVehicleIdsIntoPersonAttributes(p, vehicles.getModeVehicles()); + // create the factory, get a router, route. com.google.inject.Injector injector = Injector.createInjector(scenario.getConfig(), new AbstractModule() { @Override @@ -204,12 +225,9 @@ public void install() { new LinkFacility( l1 ), new LinkFacility( l3 ), 0, - PopulationUtils.getFactory().createPerson(Id.create("toto", Person.class)), new AttributesImpl()); + p, new AttributesImpl()); - Leg l = (Leg) trip.get( 0 ); - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - l = (Leg) trip.get(2) ; - } + Leg l = (Leg) trip.get(2) ; // actual test NetworkRoute r = (NetworkRoute) l.getRoute(); diff --git a/matsim/src/test/java/org/matsim/core/router/old/PlanRouterTest.java b/matsim/src/test/java/org/matsim/core/router/old/PlanRouterTest.java index abf9b242c7a..061881c638d 100644 --- a/matsim/src/test/java/org/matsim/core/router/old/PlanRouterTest.java +++ b/matsim/src/test/java/org/matsim/core/router/old/PlanRouterTest.java @@ -27,18 +27,23 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; +import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Injector; +import org.matsim.core.network.NetworkUtils; +import org.matsim.core.network.algorithms.TransportModeNetworkFilter; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.router.*; import org.matsim.core.router.costcalculators.FreespeedTravelTimeAndDisutility; import org.matsim.core.router.costcalculators.OnlyTimeDependentTravelDisutilityFactory; +import org.matsim.core.router.speedy.SpeedyALTFactory; +import org.matsim.core.router.util.LeastCostPathCalculatorFactory; import org.matsim.core.scenario.ScenarioByInstanceModule; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.trafficmonitoring.FreeSpeedTravelTime; @@ -48,10 +53,14 @@ import org.matsim.examples.ExamplesUtils; import org.matsim.facilities.Facility; import org.matsim.testcases.MatsimTestUtils; +import org.matsim.vehicles.PersonVehicles; import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; import java.util.Arrays; import java.util.List; +import java.util.Set; public class PlanRouterTest { @@ -78,14 +87,21 @@ public void install() { Plan plan = scenario.getPopulation().getPersons().get(Id.createPersonId(1)).getSelectedPlan(); Id vehicleId = Id.create(1, Vehicle.class); ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).setVehicleId(vehicleId); + + // We need to add a vehicle, it however does not affect the results + Id typeId = Id.create(1, VehicleType.class); + scenario.getVehicles().addVehicleType(VehicleUtils.createVehicleType(typeId)); + scenario.getVehicles().addVehicle(VehicleUtils.createVehicle(Id.createVehicleId(1), scenario.getVehicles().getVehicleTypes().get(typeId))); + + PersonVehicles vehicles = new PersonVehicles(); + vehicles.addModeVehicle(TransportMode.car, Id.createVehicleId(1)); + VehicleUtils.insertVehicleIdsIntoPersonAttributes(plan.getPerson(), vehicles.getModeVehicles()); + testee.run(plan); - if ( config.routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - Assertions.assertEquals(vehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).getVehicleId(), "Vehicle Id transferred to new Plan"); - } else { - Assertions.assertEquals(vehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(1).getRoute()).getVehicleId(), "Vehicle Id transferred to new Plan"); - // yy I changed get(0) to get(1) since in the input file there is no intervening walk leg, but in the output there is. kai, feb'16 - } + + Assertions.assertEquals(vehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(1).getRoute()).getVehicleId(), "Vehicle Id transferred to new Plan"); + // yy I changed get(0) to get(1) since in the input file there is no intervening walk leg, but in the output there is. kai, feb'16 } @Test @@ -93,7 +109,7 @@ void keepsVehicleIfTripRouterUsesOneAlready() { final Config config = ConfigUtils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml")); config.plans().setInputFile("plans1.xml"); final Scenario scenario = ScenarioUtils.loadScenario(config); - final DijkstraFactory leastCostAlgoFactory = new DijkstraFactory(); + final LeastCostPathCalculatorFactory leastCostAlgoFactory = new SpeedyALTFactory(); final OnlyTimeDependentTravelDisutilityFactory disutilityFactory = new OnlyTimeDependentTravelDisutilityFactory(); final FreeSpeedTravelTime travelTime = new FreeSpeedTravelTime(); @@ -101,22 +117,50 @@ void keepsVehicleIfTripRouterUsesOneAlready() { Id oldVehicleId = Id.create(1, Vehicle.class); ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).setVehicleId(oldVehicleId); - // A trip router which provides vehicle ids by itself. + // We need to add a vehicle, it however does not affect the results + Id typeId = Id.create(1, VehicleType.class); + scenario.getVehicles().addVehicleType(VehicleUtils.createVehicleType(typeId)); + scenario.getVehicles().addVehicle(VehicleUtils.createVehicle(Id.createVehicleId(1), scenario.getVehicles().getVehicleTypes().get(typeId))); + + PersonVehicles vehicles = new PersonVehicles(); + vehicles.addModeVehicle(TransportMode.car, Id.createVehicleId(1)); + VehicleUtils.insertVehicleIdsIntoPersonAttributes(plan.getPerson(), vehicles.getModeVehicles()); + + // A trip router which provides vehicle ids by itself. final Id newVehicleId = Id.create(2, Vehicle.class); final RoutingModule routingModule = new RoutingModule() { @Override public List calcRoute(RoutingRequest request) { - final Facility fromFacility = request.getFromFacility(); - final Facility toFacility = request.getToFacility(); - final double departureTime = request.getDepartureTime(); - final Person person = request.getPerson(); - - List trip = DefaultRoutingModules.createPureNetworkRouter("car", scenario.getPopulation().getFactory(), - scenario.getNetwork(), - leastCostAlgoFactory.createPathCalculator(scenario.getNetwork(), disutilityFactory.createTravelDisutility(travelTime), travelTime) - ).calcRoute(DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, departureTime, person)); - ((NetworkRoute) TripStructureUtils.getLegs(trip).get(0).getRoute()).setVehicleId(newVehicleId); - return trip; + final Facility fromFacility = request.getFromFacility(); + final Facility toFacility = request.getToFacility(); + final double departureTime = request.getDepartureTime(); + final Person person = request.getPerson(); + + + TransportModeNetworkFilter filter = new TransportModeNetworkFilter(scenario.getNetwork()); + Network carOnlyNetwork = NetworkUtils.createNetwork(); + filter.filter(carOnlyNetwork, Set.of("car")); + + // We create a teleport with beelineDistanceFactor 0, so that the access and egress do not change the overall plan-stats + RoutingModule teleportModule = new TeleportationRoutingModule( + "walk", + scenario, + 1, + 0); + + // TODO I have used the default impls for all needed interfaces. Check if this is okay # aleks + List trip = DefaultRoutingModules.createAccessEgressNetworkRouter( + "car", + leastCostAlgoFactory.createPathCalculator(scenario.getNetwork(), disutilityFactory.createTravelDisutility(travelTime), travelTime), + scenario, + carOnlyNetwork, + teleportModule, + teleportModule, + TimeInterpretation.create(config), + RouterUtils.getMultimodalLinkChooserDefault() + ).calcRoute(DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, departureTime, person)); + ((NetworkRoute) TripStructureUtils.getLegs(trip).get(1).getRoute()).setVehicleId(newVehicleId); + return trip; } }; @@ -138,12 +182,10 @@ public void install() { PlanRouter testee = new PlanRouter(tripRouter, TimeInterpretation.create(config)); testee.run(plan); - if ( config.routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - Assertions.assertEquals(newVehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(0).getRoute()).getVehicleId(), "Vehicle Id from TripRouter used"); - } else { - Assertions.assertEquals(newVehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(1).getRoute()).getVehicleId(), "Vehicle Id from TripRouter used"); - // yy I changed get(0) to get(1) since in the input file there is no intervening walk leg, but in the output there is. kai, feb'16 - } + + Assertions.assertEquals(newVehicleId, ((NetworkRoute) TripStructureUtils.getLegs(plan).get(1).getRoute()).getVehicleId(), "Vehicle Id from TripRouter used"); + // yy I changed get(0) to get(1) since in the input file there is no intervening walk leg, but in the output there is. kai, feb'16 + } diff --git a/matsim/src/test/java/org/matsim/modules/ScoreStatsModuleTest.java b/matsim/src/test/java/org/matsim/modules/ScoreStatsModuleTest.java index 5735acd4d8f..ae7fe21d0bf 100644 --- a/matsim/src/test/java/org/matsim/modules/ScoreStatsModuleTest.java +++ b/matsim/src/test/java/org/matsim/modules/ScoreStatsModuleTest.java @@ -54,11 +54,11 @@ public static Stream arguments () { @ParameterizedTest @MethodSource("arguments") - void testScoreStats(boolean isUsingFastCapacityUpdate, boolean isInsertingAccessEgressWalk) { + void testScoreStats(boolean isUsingFastCapacityUpdate) { Config config = utils.loadConfig("test/scenarios/equil/config.xml"); config.qsim().setUsingFastCapacityUpdate(isUsingFastCapacityUpdate); - config.routing().setAccessEgressType(isInsertingAccessEgressWalk? AccessEgressType.accessEgressModeToLink : AccessEgressType.none); + config.routing().setAccessEgressType(AccessEgressType.accessEgressModeToLink); config.controller().setLastIteration(1); Controler controler = new Controler(config); @@ -90,65 +90,44 @@ public void notifyShutdown(ShutdownEvent event) { // } // yy the following is retrofitted from an older double[][] data structure and thus messy. Please improve it. kai, nov'16 - if ( config.routing().getAccessEgressType().equals(AccessEgressType.none) ) { + // yyyy these change with the access/egress car router, but I cannot say if the magnitude of change is plausible. kai, feb'16 +// if(config.qsim().isUsingFastCapacityUpdate()) { { - Double[] array = result.get(ScoreItem.worst).values().toArray(new Double[0]) ; - Assertions.assertEquals(64.75686659291274, array[0], DELTA); - Assertions.assertEquals(64.78366379257605, array[1], DELTA); - } { - Double[] array = result.get(ScoreItem.best).values().toArray(new Double[0]) ; - Assertions.assertEquals(64.75686659291274, array[0], DELTA); - Assertions.assertEquals(64.84180132563583, array[1], DELTA); + Double[] array = result.get(ScoreItem.worst).values().toArray(new Double[0]) ; + Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[0], array[0], DELTA); + Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[1], array[1], DELTA); }{ - Double[] array = result.get(ScoreItem.average).values().toArray(new Double[0]) ; - Assertions.assertEquals(64.75686659291274, array[0], DELTA); - Assertions.assertEquals(64.81273255910591, array[1], DELTA); + Double[] array = result.get(ScoreItem.best).values().toArray(new Double[0]) ; + Assertions.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[0], array[0], DELTA); + Assertions.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[1], array[1], DELTA); }{ - Double[] array = result.get(ScoreItem.executed).values().toArray(new Double[0]) ; - Assertions.assertEquals(64.75686659291274, array[0], DELTA); - Assertions.assertEquals(64.84180132563583, array[1], DELTA); - } - } else { - // yyyy these change with the access/egress car router, but I cannot say if the magnitude of change is plausible. kai, feb'16 -// if(config.qsim().isUsingFastCapacityUpdate()) { - { - Double[] array = result.get(ScoreItem.worst).values().toArray(new Double[0]) ; - Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[0], array[0], DELTA); - Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[1], array[1], DELTA); - }{ - Double[] array = result.get(ScoreItem.best).values().toArray(new Double[0]) ; - Assertions.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[0], array[0], DELTA); - Assertions.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[1], array[1], DELTA); - }{ - Double[] array = result.get(ScoreItem.average).values().toArray(new Double[0]) ; - Assertions.assertEquals(new double[]{53.18953957492432, 45.9741777194131}[0], array[0], DELTA); - Assertions.assertEquals(new double[]{53.18953957492432, 45.9741777194131}[1], array[1], DELTA); - }{ - Double[] array = result.get(ScoreItem.executed).values().toArray(new Double[0]) ; - Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[0], array[0], DELTA); - Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[1], array[1], DELTA); - } -// } else { -// { -// Double[] array = result.get(ScoreItem.worst).values().toArray(new Double[0]) ; -// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[0], array[0], DELTA); -// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[1], array[1], DELTA); -// }{ -// Double[] array = result.get(ScoreItem.best).values().toArray(new Double[0]) ; -// Assert.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[0], array[0], DELTA); -// Assert.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[1], array[1], DELTA); -// }{ -// Double[] array = result.get(ScoreItem.average).values().toArray(new Double[0]) ; -// Assert.assertEquals(new double[]{53.18953957492432, 45.97376498301028}[0], array[0], DELTA); -// Assert.assertEquals(new double[]{53.18953957492432, 45.97376498301028}[1], array[1], DELTA); -// }{ -// Double[] array = result.get(ScoreItem.executed).values().toArray(new Double[0]) ; -// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[0], array[0], DELTA); -// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[1], array[1], DELTA); -// } -// } + Double[] array = result.get(ScoreItem.average).values().toArray(new Double[0]) ; + Assertions.assertEquals(new double[]{53.18953957492432, 45.9741777194131}[0], array[0], DELTA); + Assertions.assertEquals(new double[]{53.18953957492432, 45.9741777194131}[1], array[1], DELTA); + }{ + Double[] array = result.get(ScoreItem.executed).values().toArray(new Double[0]) ; + Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[0], array[0], DELTA); + Assertions.assertEquals(new double[]{53.18953957492432, 38.73201822323088}[1], array[1], DELTA); } - } +// } else { +// { +// Double[] array = result.get(ScoreItem.worst).values().toArray(new Double[0]) ; +// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[0], array[0], DELTA); +// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[1], array[1], DELTA); +// }{ +// Double[] array = result.get(ScoreItem.best).values().toArray(new Double[0]) ; +// Assert.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[0], array[0], DELTA); +// Assert.assertEquals(new double[]{53.18953957492432, 53.2163372155953}[1], array[1], DELTA); +// }{ +// Double[] array = result.get(ScoreItem.average).values().toArray(new Double[0]) ; +// Assert.assertEquals(new double[]{53.18953957492432, 45.97376498301028}[0], array[0], DELTA); +// Assert.assertEquals(new double[]{53.18953957492432, 45.97376498301028}[1], array[1], DELTA); +// }{ +// Double[] array = result.get(ScoreItem.executed).values().toArray(new Double[0]) ; +// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[0], array[0], DELTA); +// Assert.assertEquals(new double[]{53.18953957492432, 38.73119275042525}[1], array[1], DELTA); +// } +// } } - } +} diff --git a/matsim/src/test/java/org/matsim/withinday/utils/EditRoutesTest.java b/matsim/src/test/java/org/matsim/withinday/utils/EditRoutesTest.java index 5b0d8f2883b..e1b19e9b7ee 100644 --- a/matsim/src/test/java/org/matsim/withinday/utils/EditRoutesTest.java +++ b/matsim/src/test/java/org/matsim/withinday/utils/EditRoutesTest.java @@ -65,6 +65,9 @@ import org.matsim.core.utils.timing.TimeInterpretation; import org.matsim.core.utils.timing.TimeInterpretationModule; import org.matsim.testcases.MatsimTestUtils; +import org.matsim.vehicles.PersonVehicles; +import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; public class EditRoutesTest { @@ -94,12 +97,8 @@ void testReplanFutureLegRoute() { createScenario(); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory() ); @@ -153,16 +152,10 @@ void testRelocateFutureLegRoute() { createScenario(); - int firstCarLeg = 1 ; // 1-->3 - int scndAct = 2 ; - int scndCarLeg = 3 ; // 3-->9 - int thrdAct = 4 ; - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndAct = 6 ; - scndCarLeg = 9 ; // 3-->9 - thrdAct = 12 ; - } + int firstCarLeg = 3 ; // 1-->3 + int scndAct = 6 ; + int scndCarLeg = 9 ; // 3-->9 + int thrdAct = 12 ; EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory() ); @@ -233,12 +226,8 @@ void testReplanCurrentLegRouteOne() // this is ok (we can still replan a single leg with the computer science router). kai, dec'15 { createScenario(); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 @@ -283,12 +272,8 @@ void testReplanCurrentLegRouteTwo() // create new routes for HW-trip createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityW1; @@ -309,12 +294,8 @@ void testReplanCurrentLegRouteThree() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityW1; @@ -331,12 +312,8 @@ void testReplanCurrentLegRouteFour() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityW1; @@ -354,12 +331,8 @@ void testReplanCurrentLegRouteFive() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityH2; @@ -375,12 +348,8 @@ void testReplanCurrentLegRouteSix() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityH2; @@ -396,12 +365,8 @@ void testReplanCurrentLegRouteSeven() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityH2; @@ -417,12 +382,8 @@ void testReplanCurrentLegRouteEight() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityH2; @@ -438,12 +399,8 @@ void testReplanCurrentLegRouteNine() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Activity activityH2; @@ -461,12 +418,8 @@ void testReplanCurrentLegRouteTen() createScenario(); // reset scenario EditRoutes ed = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); - int firstCarLeg = 1 ; // 1-->3 - int scndCarLeg = 3 ; // 3-->9 - if ( !scenario.getConfig().routing().getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none) ) { - firstCarLeg = 3 ; // 1-->3 - scndCarLeg = 9 ; // 3-->9 - } + int firstCarLeg = 3 ; // 1-->3 + int scndCarLeg = 9 ; // 3-->9 Leg legHW = (Leg) plan.getPlanElements().get(firstCarLeg); @@ -547,7 +500,16 @@ private void createSampleNetwork() { * @author cdobler */ private void createSamplePlan() { - plan = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(1, Person.class))); + // We need to add a vehicle, it however does not affect the results + Id typeId = Id.create(1, VehicleType.class); + scenario.getVehicles().addVehicleType(VehicleUtils.createVehicleType(typeId)); + scenario.getVehicles().addVehicle(VehicleUtils.createVehicle(Id.createVehicleId(1), scenario.getVehicles().getVehicleTypes().get(typeId))); + + Person p = PopulationUtils.getFactory().createPerson(Id.createPersonId(1)); + PersonVehicles vehicles = new PersonVehicles(); + vehicles.addModeVehicle(TransportMode.car, Id.createVehicleId(1)); + VehicleUtils.insertVehicleIdsIntoPersonAttributes(p, vehicles.getModeVehicles()); + plan = PopulationUtils.createPlan(p); Activity activityH1 = PopulationUtils.createAndAddActivityFromLinkId(((Plan) plan), "h", Id.create("l1", Link.class)); PopulationUtils.createAndAddLeg( ((Plan) plan), TransportMode.car );