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 ) {
double tmp = this.originalTransitRouterConfig.getUtilityOfLineSwitch_utl() ; tmp *= 5. * MatsimRandom.getRandom().nextDouble() ; localUtilityOfLineSwitch_utl = tmp ;
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) return - linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]*this.config.getMarginalUtilityOfTravelTimePt_utl_s()*linkVehicleOccupancy.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]>SIT_PERCENTAGE?NO_SIT_FACTOR:1 - link.getLength() * this.config.getMarginalUtilityOfTravelDistancePt_utl_m(); else if (wrapped.toNode.route!=null) // it's a wait link return - linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]*this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); else if(wrapped.fromNode.route==null) // it's a transfer link (walk) return -wrapped.getLength()/this.config.getBeelineWalkSpeed()*this.config.getMarginalUtilityOfTravelTimeWalk_utl_s(); else //inside link return 0; } @Override
@Override public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager) { boolean cachedTravelDisutility = false; if(previousLink==link && previousTime==time) cachedTravelDisutility = true; TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) return -(cachedTravelDisutility?cachedTravelTime:linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)])*this.config.getMarginalUtilityOfTravelTimePt_utl_s()*linkVehicleOccupancy.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]>SIT_PERCENTAGE?NO_SIT_FACTOR:1 - link.getLength() * this.config.getMarginalUtilityOfTravelDistancePt_utl_m(); else if (wrapped.toNode.route!=null) // it's a wait link return -(cachedTravelDisutility?cachedTravelTime:linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)])*this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); else if(wrapped.fromNode.route==null) // it's a transfer link (walk) return -(cachedTravelDisutility?cachedTravelTime:wrapped.getLength()/this.config.getBeelineWalkSpeed())*this.config.getMarginalUtilityOfTravelTimeWalk_utl_s(); else //inside link return 0; } @Override
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) return - linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)] * this.config.getMarginalUtilityOfTravelTimePt_utl_s() - link.getLength() * this.config.getMarginalUtilityOfTravelDistancePt_utl_m(); else if (wrapped.toNode.route!=null) // it's a wait link return - linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)] * this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); else if(wrapped.fromNode.route==null) // it's a transfer link (walk) return -wrapped.getLength()/this.config.getBeelineWalkSpeed() * this.config.getMarginalUtilityOfTravelTimeWalk_utl_s(); else //inside link return 0; } @Override
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) return - linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]*this.config.getMarginalUtilityOfTravelTimePt_utl_s() - link.getLength() * (this.config.getMarginalUtilityOfTravelDistancePt_utl_m()); else if (wrapped.toNode.route!=null) // it's a wait link return - linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]*this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); else if(wrapped.fromNode.route==null) // it's a transfer link (walk) return -wrapped.getLength()/this.config.getBeelineWalkSpeed()*this.config.getMarginalUtilityOfTravelTimeWalk_utl_s(); else //inside link return 0; } @Override
/** * 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; }
@Override public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager) { boolean cachedTravelDisutility = false; if(previousLink==link && previousTime==time) cachedTravelDisutility = true; TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) return -(cachedTravelDisutility?cachedLinkTime:linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)])*this.config.getMarginalUtilityOfTravelTimePt_utl_s() - link.getLength() * (this.config.getMarginalUtilityOfTravelDistancePt_utl_m()); else if (wrapped.toNode.route!=null) // it's a wait link return -(cachedTravelDisutility?cachedLinkTime:linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)])*this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); else if(wrapped.fromNode.route==null) // it's a transfer link (walk) return -(cachedTravelDisutility?cachedLinkTime:wrapped.getLength()/this.config.getBeelineWalkSpeed())*this.config.getMarginalUtilityOfTravelTimeWalk_utl_s(); else //inside link return 0; } @Override
- walkDistance * this.config.getMarginalUtilityOfTravelDistanceWalk_utl_m() - waittime * this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); return cost;
@Override public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager) { boolean cachedTravelDisutility = false; if(previousLink==link && previousTime==time) cachedTravelDisutility = true; TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) return -(cachedTravelDisutility?cachedTravelTime:linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]) * this.config.getMarginalUtilityOfTravelTimePt_utl_s() - link.getLength() * this.config.getMarginalUtilityOfTravelDistancePt_utl_m(); else if (wrapped.toNode.route!=null) // it's a wait link return -(cachedTravelDisutility?cachedTravelTime:linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]) * this.config.getMarginalUtilityOfWaitingPt_utl_s() - this.config.getUtilityOfLineSwitch_utl(); else if(wrapped.fromNode.route==null) // it's a transfer link (walk) return -(cachedTravelDisutility?cachedTravelTime:wrapped.getLength()/this.config.getBeelineWalkSpeed())*this.config.getMarginalUtilityOfTravelTimeWalk_utl_s(); else //inside link return 0; } @Override
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 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); }
double oldCost = - conf.getUtilityOfLineSwitch_utl(); double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); conf.setUtilityOfLineSwitch_utl(0.0);
double oldCost = - conf.getUtilityOfLineSwitch_utl(); double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); conf.setUtilityOfLineSwitch_utl(0.0);
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(-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);