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 ) {
@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
double tmp = this.originalTransitRouterConfig.getMarginalUtilityOfTravelTimePt_utl_s() ; tmp *= 5. * MatsimRandom.getRandom().nextDouble(); localMarginalUtilityOfTravelTimePt_utl_s = tmp;
@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
@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
@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
@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; }
/** * Note that there is no off vehicle wait time. */ protected double getInVehicleTravelDisutility(final RouteSegment routeSegment) { double cost = 0.0; // this assumes dwell time as in-vehicle time double inVehicleTravelTime = routeSegment.getTravelTime(); double inVehicleBeelineDistance = CoordUtils.calcEuclideanDistance(routeSegment.getFromStop().getCoord(), routeSegment.getToStop().getCoord()); cost += - inVehicleTravelTime * this.config.getMarginalUtilityOfTravelTimePt_utl_s(); cost += - inVehicleBeelineDistance * this.config.getMarginalUtilityOfTravelDistancePt_utl_m(); // fare cost += this.costPerBoarding; cost += inVehicleBeelineDistance * this.costPerMeterTraveled; return cost; }
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());
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(-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);