@Override public double getWalkTravelTime(Person person, Coord coord, Coord toCoord) { double distance = CoordUtils.calcEuclideanDistance(coord, toCoord); double initialTime = distance / config.getBeelineWalkSpeed(); return initialTime; } }
@Override public double getWalkTravelTime(Person person, Coord coord, Coord toCoord) { double distance = CoordUtils.calcEuclideanDistance(coord, toCoord); double initialTime = distance / config.getBeelineWalkSpeed(); return initialTime; }
protected double getTravelTime(Coord coord, Coord toCoord) { double distance = CoordUtils.calcEuclideanDistance(coord, toCoord); double initialTime = distance / config.getBeelineWalkSpeed(); return initialTime; }
protected double getTransferTime(Coord coord, Coord toCoord) { double distance = CoordUtils.calcEuclideanDistance(coord, toCoord); double initialTime = distance / config.getBeelineWalkSpeed(); return initialTime + this.config.getAdditionalTransferTime(); }
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); }
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; }
@Override public double getLinkTravelTime(final Link link, final double time, Person person, Vehicle vehicle) { previousLink = link; previousTime = time; TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route!=null) //in line link cachedLinkTime = linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]; else if(wrapped.toNode.route!=null) //wait link cachedLinkTime = linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]; else if(wrapped.fromNode.route==null) //walking link cachedLinkTime = wrapped.getLength()/this.config.getBeelineWalkSpeed(); else //inside link cachedLinkTime = 0; return cachedLinkTime; } @Override
@Override public double getLinkTravelTime(final Link link, final double time, Person person, Vehicle vehicle) { previousLink = link; previousTime = time; TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) //in line link cachedTravelTime = linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]; else if(wrapped.toNode.route!=null) //wait link cachedTravelTime = linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]; else if(wrapped.fromNode.route==null) //walking link cachedTravelTime = wrapped.getLength()/this.config.getBeelineWalkSpeed(); else //inside link cachedTravelTime = 0; return cachedTravelTime; } @Override
@Override public double getLinkTravelTime(final Link link, final double time, Person person, Vehicle vehicle) { previousLink = link; previousTime = time; TransitRouterNetworkWW.TransitRouterNetworkLink wrapped = (TransitRouterNetworkWW.TransitRouterNetworkLink) link; if (wrapped.route != null) //in line link cachedTravelTime = linkTravelTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]; else if(wrapped.toNode.route!=null) //wait link cachedTravelTime = linkWaitingTimes.get(wrapped.getId())[time/timeSlot<numSlots?(int)(time/timeSlot):(numSlots-1)]; else if(wrapped.fromNode.route==null) //walking link cachedTravelTime = wrapped.getLength()/this.config.getBeelineWalkSpeed(); else //inside link cachedTravelTime = 0; return cachedTravelTime; } @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()*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
public EventsToTravelDiaries(Scenario scenario) { networkModes.addAll(scenario.getConfig().qsim().getMainModes()); this.network = scenario.getNetwork(); isTransitScenario = scenario.getConfig().transit().isUseTransit(); if (isTransitScenario) { this.transitSchedule = scenario.getTransitSchedule(); this.walkSpeed = new TransitRouterConfig(scenario.getConfig()).getBeelineWalkSpeed(); } }
@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) { 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
double time2 = distance / this.config.getBeelineWalkSpeed() + this.config.getAdditionalTransferTime(); this.cachedTravelTime = time2; return time2;
@Test public void testFromToSameStop() { Fixture f = new Fixture(); f.init(); TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig()); TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); Coord fromCoord = new Coord((double) 3800, (double) 5100); Coord toCoord = new Coord((double) 4100, (double) 5050); List<Leg> legs = router.calcRoute(new FakeFacility(fromCoord), new FakeFacility(toCoord), 5.0*3600, null); assertEquals(1, legs.size()); assertEquals(TransportMode.transit_walk, legs.get(0).getMode()); double actualTravelTime = 0.0; for (Leg leg : legs) { actualTravelTime += leg.getTravelTime(); } double expectedTravelTime = CoordUtils.calcEuclideanDistance(fromCoord, toCoord) / trConfig.getBeelineWalkSpeed(); assertEquals(expectedTravelTime, actualTravelTime, MatsimTestCase.EPSILON); }
@Test public void testDirectWalkCheaper() { 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()); TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); Coord fromCoord = new Coord((double) 4000, (double) 3000); Coord toCoord = new Coord((double) 8000, (double) 3000); List<Leg> legs = router.calcRoute(new FakeFacility(fromCoord), new FakeFacility(toCoord), 5.0*3600, null); assertEquals(1, legs.size()); assertEquals(TransportMode.transit_walk, legs.get(0).getMode()); double actualTravelTime = 0.0; for (Leg leg : legs) { actualTravelTime += leg.getTravelTime(); } double expectedTravelTime = CoordUtils.calcEuclideanDistance(fromCoord, toCoord) / trConfig.getBeelineWalkSpeed(); assertEquals(expectedTravelTime, actualTravelTime, MatsimTestCase.EPSILON); }
@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); }