Skip to content

Commit

Permalink
Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksander1234519 committed Jan 6, 2025
1 parent 1b9250d commit cf6a7cc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,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 @@ -417,7 +417,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
16 changes: 12 additions & 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void install() {
// 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
}

//TODO This test will currently not work. The objects needed can only be injected. #aleks
@Test
void keepsVehicleIfTripRouterUsesOneAlready() {
final Config config = ConfigUtils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("equil"), "config.xml"));
Expand Down Expand Up @@ -119,14 +118,23 @@ public List<? extends PlanElement> calcRoute(RoutingRequest request) {
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<? extends PlanElement> trip = DefaultRoutingModules.createAccessEgressNetworkRouter(
"car",
leastCostAlgoFactory.createPathCalculator(scenario.getNetwork(), disutilityFactory.createTravelDisutility(travelTime), travelTime),
scenario,
carOnlyNetwork,
null,
null,
null
teleportModule,
teleportModule,
TimeInterpretation.create(config),
RouterUtils.getMultimodalLinkChooserDefault()
).calcRoute(DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, departureTime, person));
((NetworkRoute) TripStructureUtils.getLegs(trip).get(0).getRoute()).setVehicleId(newVehicleId);
return trip;
Expand Down

0 comments on commit cf6a7cc

Please sign in to comment.