Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old network routing module #3655

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 11 additions & 12 deletions matsim/src/main/java/org/matsim/core/router/LinkToLinkRouting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
Expand Down Expand Up @@ -399,7 +396,7 @@ public String toString() {
}

Id<Vehicle> 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 + ".");
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 16 additions & 14 deletions matsim/src/test/java/org/matsim/core/controler/ControlerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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.");
}

/**
Expand All @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<VehicleType> 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() {
Expand All @@ -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();
Expand Down Expand Up @@ -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<VehicleType> 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
Expand All @@ -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();
Expand Down
Loading
Loading