public EventsToTravelDiaries(TransitSchedule transitSchedule, Network network, Config config) { networkModes.addAll(config.qsim().getMainModes()); this.network = network; this.walkSpeed = new TransitRouterConfig(config).getBeelineWalkSpeed(); this.transitSchedule = transitSchedule; this.isTransitScenario = true; }
@Inject RandomizingTransitRouterFactory(Config config, TransitSchedule schedule) { this.trConfig = new TransitRouterConfig(config); this.schedule = schedule; this.routerNetwork = TransitRouterNetwork.createFromSchedule(schedule, trConfig.getBeelineWalkConnectionDistance()); }
public RandomizingTransitRouterTravelTimeAndDisutility(TransitRouterConfig routerConfig) { super(routerConfig); prepareDataCollection(); // make sure that some parameters are not zero since otherwise the randomization will not work: // marg utl time wlk should be around -3/h or -(3/3600)/sec. Give warning if not at least 1/3600: if ( -routerConfig.getMarginalUtilityOfTravelTimeWalk_utl_s() < 1./3600. ) { Logger.getLogger(this.getClass()).warn( "marg utl of walk rather close to zero; randomization may not work") ; } // utl of line switch should be around -300sec or -0.5u. Give warning if not at least 0.1u: if ( -routerConfig.getUtilityOfLineSwitch_utl() < 0.1 ) { Logger.getLogger(this.getClass()).warn( "utl of line switch rather close to zero; randomization may not work") ; } this.originalTransitRouterConfig = routerConfig ; this.localMarginalUtilityOfTravelDistancePt_utl_m = routerConfig.getMarginalUtilityOfTravelDistancePt_utl_m(); this.localMarginalUtilityOfTravelTimePt_utl_s = routerConfig.getMarginalUtilityOfTravelTimePt_utl_s() ; this.localMarginalUtilityOfTravelTimeWalk_utl_s = routerConfig.getMarginalUtilityOfTravelTimeWalk_utl_s() ; // this.localMarginalUtilityOfWaitingPt_utl_s = routerConfig.getMarginalUtilityOfTravelTimePt_utl_s() ; this.localMarginalUtilityOfWaitingPt_utl_s = routerConfig.getMarginalUtilityOfWaitingPt_utl_s() ; this.localUtilityOfLineSwitch_utl = routerConfig.getUtilityOfLineSwitch_utl() ; } public final String getDataCollectionString( DataCollection item ) {
protected double getTransferTime(Coord coord, Coord toCoord) { double distance = CoordUtils.calcEuclideanDistance(coord, toCoord); double initialTime = distance / config.getBeelineWalkSpeed(); return initialTime + this.config.getAdditionalTransferTime(); }
@Override public double getWalkTravelDisutility(Person person, Coord coord, Coord toCoord) { // getMarginalUtilityOfTravelTimeWalk INCLUDES the opportunity cost of time. kai, dec'12 double timeCost = - getWalkTravelTime(person, coord, toCoord) * config.getMarginalUtilityOfTravelTimeWalk_utl_s() ; // (sign: margUtl is negative; overall it should be positive because it is a cost.) double distanceCost = - CoordUtils.calcEuclideanDistance(coord,toCoord) * config.getBeelineDistanceFactor() * config.getMarginalUtilityOfTravelDistanceWalk_utl_m(); // (sign: same as above) return timeCost + distanceCost ; }
TransitRouterConfig config = new TransitRouterConfig(planScoring, planRouting, transitRouting, vspConfig ); Assert.assertEquals(-15.0/3600, config.getMarginalUtilityOfTravelTimePt_utl_s(), 1e-8); Assert.assertEquals(-17.0/3600, config.getMarginalUtilityOfTravelTimeWalk_utl_s(), 1e-8); Assert.assertEquals(-19.0/3600, config.getMarginalUtilityOfWaitingPt_utl_s(), 1e-8); Assert.assertEquals(-2.34, config.getUtilityOfLineSwitch_utl(), 1e-8); Assert.assertEquals(1.37 / 1.2, config.getBeelineWalkSpeed(), 1e-8); Assert.assertEquals(128.0, config.getAdditionalTransferTime(), 1e-8); Assert.assertEquals(987.6, config.getSearchRadius(), 1e-8); Assert.assertEquals(123.4, config.getExtensionRadius(), 1e-8); Assert.assertEquals(23.4, config.getBeelineWalkConnectionDistance(), 1e-8); TransitRouterConfig config = new TransitRouterConfig(planScoring, planRouting, transitRouting, vspConfig ); Assert.assertEquals(-15.0/3600, config.getMarginalUtilityOfTravelTimePt_utl_s(), 1e-8); Assert.assertEquals(-17.0/3600, config.getMarginalUtilityOfTravelTimeWalk_utl_s(), 1e-8); Assert.assertEquals(-19.0/3600, config.getMarginalUtilityOfWaitingPt_utl_s(), 1e-8); Assert.assertEquals(-2.34, config.getUtilityOfLineSwitch_utl(), 1e-8); Assert.assertEquals(1.37 / 1.2, config.getBeelineWalkSpeed(), 1e-8); Assert.assertEquals(128.0, config.getAdditionalTransferTime(), 1e-8); Assert.assertEquals(987.6, config.getSearchRadius(), 1e-8); Assert.assertEquals(123.4, config.getExtensionRadius(), 1e-8); Assert.assertEquals(23.4, config.getBeelineWalkConnectionDistance(), 1e-8);
/** * cost of a single transfer. Fare is included in {@link RaptorDisutility.getInVehicleTravelDisutility} */ protected final double getTransferCost(final Coord fromStop, final Coord toStop) { // this is same as defaultTransferCost in TransitRouterNetworkTravelTimeAndDisutility. Amit Oct'17 double cost; double transfertime = getTransferTime(fromStop, toStop); double waittime = this.config.getAdditionalTransferTime(); // say that the effective walk time is the transfer time minus some "buffer" double walktime = transfertime - waittime; if ( walktime < 0. ) { throw new RuntimeException( "negative walk time; should not happen; needs to be repaired" ) ; } double walkDistance = CoordUtils.calcEuclideanDistance(fromStop, toStop); // weigh this "buffer" not with the walk time disutility, but with the wait time disutility: // (note that this is the same "additional disutl of wait" as in the scoring function. Its default is zero. // only if you are "including the opportunity cost of time into the router", then the disutility of waiting will // be the same as the marginal opprotunity cost of time). kai, nov'11 cost = - walktime * this.config.getMarginalUtilityOfTravelTimeWalk_utl_s() - walkDistance * this.config.getMarginalUtilityOfTravelDistancePt_utl_m() - waittime * this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); return cost; }
public void testTravelCostLineSwitch_AdditionalTransferTime() { Fixture f = new Fixture(); f.init(); TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().planCalcScore(), f.scenario.getConfig().plansCalcRoute(), f.scenario.getConfig().transitRouter(), f.scenario.getConfig().vspExperimental()); double oldCost = - conf.getUtilityOfLineSwitch_utl(); double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); conf.setUtilityOfLineSwitch_utl(0.0); double cost2 = tc.getLinkTravelDisutility(testLink, 6.0*3600, null, null, null); // use different time because of internal caching effects assertEquals(oldCost, cost1 - cost2, MatsimTestCase.EPSILON); conf.setAdditionalTransferTime(120.0); double cost3 = tc.getLinkTravelDisutility(testLink, 5.0*3600, null, null, null); assertEquals(-120.0 * conf.getMarginalUtilityOfWaitingPt_utl_s(), cost3 - cost2, MatsimTestCase.EPSILON); conf.setMarginalUtilityOfWaitingPt_utl_s(-12.0 / 3600.0); double cost4 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); assertEquals(120.0 * 12.0 / 3600.0, cost4 - cost2, MatsimTestCase.EPSILON);
createTestSchedule(scenario); TransitRouterConfig trConfig = new TransitRouterConfig(scenario.getConfig().planCalcScore(), scenario.getConfig().plansCalcRoute(), scenario.getConfig().transitRouter(), scenario.getConfig().vspExperimental()); trConfig.setBeelineWalkSpeed(0.1); // something very slow, so the agent does not walk over night trConfig.setSearchRadius(200); TransitRouterNetwork transitNetwork = TransitRouterNetwork.createFromSchedule(scenario.getTransitSchedule(), trConfig.getBeelineWalkConnectionDistance());
double cost; double transfertime = getLinkTravelTime(link, time, person, vehicle); double waittime = this.config.getAdditionalTransferTime(); cost = - walktime * this.config.getMarginalUtilityOfTravelTimeWalk_utl_s() - walkDistance * this.config.getMarginalUtilityOfTravelDistanceWalk_utl_m() - waittime * this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); return cost;
@Inject TransitRouterImplFactory(final TransitSchedule schedule, final EventsManager events, final Config config) { this(schedule, new TransitRouterConfig( config.planCalcScore(), config.plansCalcRoute(), config.transitRouter(), config.vspExperimental())); events.addHandler((TransitScheduleChangedEventHandler) event -> { routerNetwork = null; preparedTransitSchedule = null; }); }
@Override public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager) { double cost; if (((TransitRouterNetworkLink) link).getRoute() == null) { // "route" here means "pt route". If no pt route is attached, it means that it is a transfer link. cost = defaultTransferCost(link, time, person, vehicle); } else { double offVehWaitTime = offVehicleWaitTime(link, time); double inVehTime = getLinkTravelTime(link,time, person, vehicle) - offVehWaitTime; cost = - inVehTime * this.config.getMarginalUtilityOfTravelTimePt_utl_s() -offVehWaitTime * this.config.getMarginalUtilityOfWaitingPt_utl_s() -link.getLength() * this.config.getMarginalUtilityOfTravelDistancePt_utl_m(); } return cost; }
public void testTravelCostLineSwitch() { Fixture f = new Fixture(); f.init(); TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().planCalcScore(), f.scenario.getConfig().plansCalcRoute(), f.scenario.getConfig().transitRouter(), f.scenario.getConfig().vspExperimental()); TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule) ; TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); // find the link connecting C and D on the blue line TransitRouterNetworkLink testLink = null; for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { if ((link.getLine() == null) && (link.fromNode.stop.getStopFacility().getName().equals("C")) && (link.toNode.stop.getStopFacility().getName().equals("C"))) { testLink = link; } } double oldCost = - conf.getUtilityOfLineSwitch_utl(); double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); conf.setUtilityOfLineSwitch_utl(0.0); double cost2 = tc.getLinkTravelDisutility(testLink, 6.0*3600, null, null, null); // use different time because of internal caching effects assertEquals(oldCost, cost1 - cost2, MatsimTestCase.EPSILON); conf.setUtilityOfLineSwitch_utl(-40.125); double cost3 = tc.getLinkTravelDisutility(testLink, 5.0*3600, null, null, null); assertEquals(40.125, cost3 - cost2, MatsimTestCase.EPSILON); }
public Path calcPathRoute(final Coord fromCoord, final Coord toCoord, final double departureTime, final Person person) { // find possible start stops // find possible start stops Map<Node, InitialNode> wrappedFromNodes = this.locateWrappedNearestTransitNodes(person, fromCoord, departureTime); // find possible end stops Map<Node, InitialNode> wrappedToNodes = this.locateWrappedNearestTransitNodes(person, toCoord, departureTime); // find routes between start and end stops Path path = this.dijkstra.calcLeastCostPath(wrappedFromNodes, wrappedToNodes, person); if (path == null) { return null; } double directWalkTime = CoordUtils.calcEuclideanDistance(fromCoord, toCoord) / this.config.getBeelineWalkSpeed(); double directWalkCost = directWalkTime * ( 0 - this.config.getMarginalUtilityOfTravelTimeWalk_utl_s()); double pathCost = path.travelCost + wrappedFromNodes.get(path.nodes.get(0)).initialCost + wrappedToNodes.get(path.nodes.get(path.nodes.size() - 1)).initialCost; if (directWalkCost < pathCost) { return new Path(new ArrayList<Node>(), new ArrayList<Link>(), directWalkTime, directWalkCost); } double pathTime = path.travelTime + wrappedFromNodes.get(path.nodes.get(0)).initialTime + wrappedToNodes.get(path.nodes.get(path.nodes.size() - 1)).initialTime - 2*departureTime; return new Path(path.nodes, path.links, pathTime, pathCost); }
private Map<TransitStopFacility, InitialNode> locateWrappedNearestTransitStops(Person person, Coord coord, double departureTime) { Collection<TransitStopFacility> nearestTransitStops = this.transitRouterQuadTree.getNearestTransitStopFacilities(coord, this.config.getSearchRadius()); if (nearestTransitStops.size() < 2) { // also enlarge search area if only one stop found, maybe a second one is near the border of the search area TransitStopFacility nearestTransitStop = this.transitRouterQuadTree.getNearestTransitStopFacility(coord); double distance = CoordUtils.calcEuclideanDistance(coord, nearestTransitStop.getCoord()); nearestTransitStops = this.transitRouterQuadTree.getNearestTransitStopFacilities(coord, distance + this.config.getExtensionRadius()); } Map<TransitStopFacility, InitialNode> wrappedNearestTransitStops2AccessCost = new LinkedHashMap<>(); for (TransitStopFacility node : nearestTransitStops) { Coord toCoord = node.getCoord(); double initialTime = getWalkTime(null, coord, toCoord); double initialCost = getWalkDisutility(coord, toCoord); wrappedNearestTransitStops2AccessCost.put(node, new InitialNode(initialCost, initialTime + departureTime)); } return wrappedNearestTransitStops2AccessCost; }
TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().planCalcScore(), f.scenario.getConfig().plansCalcRoute(), f.scenario.getConfig().transitRouter(), f.scenario.getConfig().vspExperimental()); trConfig.setUtilityOfLineSwitch_utl(0); assertEquals(0, trConfig.getAdditionalTransferTime(), 1e-8); TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); List<Leg> legs = router.calcRoute(new FakeFacility(new Coord((double) 11900, (double) 5100)), new FakeFacility(new Coord((double) 24100, (double) 4950)), 6.0*3600 - 5.0*60, null); assertEquals(TransportMode.transit_walk, legs.get(4).getMode()); trConfig.setAdditionalTransferTime(3.0*60); // 3 mins already enough, as there is a small distance to walk anyway which adds some time
@Override public double getWalkTravelTime(Person person, Coord coord, Coord toCoord) { double distance = CoordUtils.calcEuclideanDistance(coord, toCoord); double initialTime = distance / config.getBeelineWalkSpeed(); return initialTime; } }
TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().planCalcScore(), f.scenario.getConfig().plansCalcRoute(), f.scenario.getConfig().transitRouter(), f.scenario.getConfig().vspExperimental()); trConfig.setUtilityOfLineSwitch_utl(0); TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); List<Leg> legs = router.calcRoute(new FakeFacility(new Coord((double) 11900, (double) 5100)), new FakeFacility(new Coord((double) 24100, (double) 4950)), 6.0*3600 - 5.0*60, null); assertEquals(TransportMode.transit_walk, legs.get(4).getMode()); trConfig.setUtilityOfLineSwitch_utl(300.0 * trConfig.getMarginalUtilityOfTravelTimePt_utl_s()); // corresponds to 5 minutes transit travel time legs = router.calcRoute(new FakeFacility(new Coord((double) 11900, (double) 5100)), new FakeFacility(new Coord((double) 24100, (double) 4950)), 6.0*3600 - 5.0*60, null); assertEquals(3, legs.size());
@Test public void testAfterMidnight() { Fixture f = new Fixture(); f.init(); TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().planCalcScore(), f.scenario.getConfig().plansCalcRoute(), f.scenario.getConfig().transitRouter(), f.scenario.getConfig().vspExperimental()); trConfig.setBeelineWalkSpeed(0.1); // something very slow, so the agent does not walk over night TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); Coord toCoord = new Coord((double) 16100, (double) 5050); List<Leg> legs = router.calcRoute(new FakeFacility(new Coord((double) 3800, (double) 5100)), new FakeFacility(toCoord), 25.0*3600, null); assertEquals(3, legs.size()); assertEquals(TransportMode.transit_walk, legs.get(0).getMode()); assertEquals(TransportMode.pt, legs.get(1).getMode()); assertEquals(TransportMode.transit_walk, legs.get(2).getMode()); assertTrue("expected TransitRoute in leg.", legs.get(1).getRoute() instanceof ExperimentalTransitRoute); ExperimentalTransitRoute ptRoute = (ExperimentalTransitRoute) legs.get(1).getRoute(); assertEquals(Id.create("0", TransitStopFacility.class), ptRoute.getAccessStopId()); assertEquals(Id.create("6", TransitStopFacility.class), ptRoute.getEgressStopId()); assertEquals(f.blueLine.getId(), ptRoute.getLineId()); assertEquals(Id.create("blue A > I", TransitRoute.class), ptRoute.getRouteId()); double actualTravelTime = 0.0; for (Leg leg : legs) { actualTravelTime += leg.getTravelTime(); } double expectedTravelTime = 4*3600 + 29.0 * 60 + // arrival at 05:29 at D CoordUtils.calcEuclideanDistance(f.schedule.getFacilities().get(Id.create("6", TransitStopFacility.class)).getCoord(), toCoord) / trConfig.getBeelineWalkSpeed(); assertEquals(expectedTravelTime, actualTravelTime, MatsimTestCase.EPSILON); }
@Override public double getWalkTravelDisutility(Person person, Coord coord, Coord toCoord) { // getMarginalUtilityOfTravelTimeWalk INCLUDES the opportunity cost of time. kai, dec'12 double timeCost = - getTravelTime(coord, toCoord) * config.getMarginalUtilityOfTravelTimeWalk_utl_s() ; // (sign: margUtl is negative; overall it should be positive because it is a cost.) double distanceCost = - CoordUtils.calcEuclideanDistance(coord,toCoord) * config.getMarginalUtilityOfTravelDistancePt_utl_m() ; // (sign: same as above) return timeCost + distanceCost ; }