private void calculateDirectDistance(Link startLink, Link endLink, double beelineDistanceFactor) { double distance = CoordUtils.calcEuclideanDistance(startLink.getCoord(), endLink.getCoord()); this.route.setDistance(beelineDistanceFactor * distance); } }
private void startRoute(final Attributes atts) { Class<? extends Route> routeType = Route.class; if ("pt".equals(this.currleg.getMode())) { routeType = ExperimentalTransitRoute.class; } if ("car".equals(this.currleg.getMode())) { routeType = NetworkRoute.class; } this.currRoute = this.plans.getFactory().getRouteFactories().createRoute(routeType, null, null); this.currleg.setRoute(this.currRoute); if (atts.getValue("dist") != null) { this.currRoute.setDistance(Double.parseDouble(atts.getValue("dist"))); } if (atts.getValue("trav_time") != null) { this.currRoute.setTravelTime(Time.parseTime(atts.getValue("trav_time"))); } }
private Route createWalkRoute(final Facility fromFacility, double departureTime, Person person, double travelTime, Facility firstToFacility) { // yyyy I extracted this method to make a bit more transparent that it is used twice. But I don't know why it is done in this way // (take distance from newly computed walk leg, but take travelTime from elsewhere). Possibly, the problem is that the TransitRouter // historically just does not compute the distances. kai, may'17 Route route = RouteUtils.createGenericRouteImpl(fromFacility.getLinkId(), firstToFacility.getLinkId()); final List<? extends PlanElement> walkRoute = walkRouter.calcRoute(fromFacility, firstToFacility, departureTime, person); route.setDistance(((Leg) walkRoute.get(0)).getRoute().getDistance()); route.setTravelTime(travelTime); return route; }
this.currRoute.setDistance(Double.parseDouble(atts.getValue("distance")));
this.currRoute.setDistance(Double.parseDouble(atts.getValue("distance")));
@Override public Route getRoute(String mode) { Route route; Id<Link> startLinkId = Id.createLinkId(startLinkIdString); Id<Link> endLinkId = Id.createLinkId(endLinkIdString); if (mode.equals(TransportMode.pt) && isUseTransit) { route = new ExperimentalTransitRouteFactory().createRoute(startLinkId, endLinkId); } else { route = RouteUtils.createGenericRouteImpl(startLinkId, endLinkId); } route.setDistance(distance); route.setTravelTime(travelTime); route.setStartLinkId(startLinkId); route.setEndLinkId(endLinkId); route.setRouteDescription(routeDescription); return route; }
@Override public List<Leg> calcRoute(final Facility fromFacility, final Facility toFacility, final double departureTime, final Person person) { // find possible start stops Map<Node, InitialNode> wrappedFromNodes = this.locateWrappedNearestTransitNodes(person, fromFacility.getCoord(), departureTime); // find possible end stops Map<Node, InitialNode> wrappedToNodes = this.locateWrappedNearestTransitNodes(person, toFacility.getCoord(), departureTime); // find routes between start and end stops Path p = this.dijkstra.calcLeastCostPath(wrappedFromNodes, wrappedToNodes, person); if (p == null) { return null; } double directWalkCost = CoordUtils.calcEuclideanDistance(fromFacility.getCoord(), toFacility.getCoord()) / this.config.getBeelineWalkSpeed() * ( 0 - this.config.getMarginalUtilityOfTravelTimeWalk_utl_s()); double pathCost = p.travelCost + wrappedFromNodes.get(p.nodes.get(0)).initialCost + wrappedToNodes.get(p.nodes.get(p.nodes.size() - 1)).initialCost; if (directWalkCost < pathCost) { List<Leg> legs = new ArrayList<Leg>(); Leg leg = PopulationUtils.createLeg(TransportMode.transit_walk); double walkDistance = CoordUtils.calcEuclideanDistance(fromFacility.getCoord(), toFacility.getCoord()); Route walkRoute = RouteUtils.createGenericRouteImpl(null, null); walkRoute.setDistance(walkDistance); leg.setRoute(walkRoute); leg.setTravelTime(walkDistance/this.config.getBeelineWalkSpeed()); legs.add(leg); return legs; } return convertPathToLegList( departureTime, p, fromFacility.getCoord(), toFacility.getCoord(), person ) ; }
private static double routeBushwhackingLeg(Person person, Leg leg, Coord fromCoord, Coord toCoord, double depTime, Id<Link> dpLinkId, Id<Link> arLinkId, PopulationFactory pf) { // I don't think that it makes sense to use a RoutingModule for this, since that again makes assumptions about how to // map facilities, and if you follow through to the teleportation routers one even finds activity wrappers, which is yet another // complication which I certainly don't want here. kai, dec'15 // dpLinkId, arLinkId need to be in Route for lots of code to function. So I am essentially putting in the "street address" // for completeness. Note that if we are walking to a parked car, this can be different from the car link id!! kai, dec'15 // make simple assumption about distance and walking speed double dist = CoordUtils.calcEuclideanDistance(fromCoord,toCoord); // create an empty route, but with realistic travel time Route route =pf.getRouteFactories().createRoute(Route.class, dpLinkId, arLinkId ); double beelineDistanceFactor = 1.3 ; double networkTravelSpeed = 2.0 ; // yyyyyy take this from config! double estimatedNetworkDistance = dist * beelineDistanceFactor; int travTime = (int) (estimatedNetworkDistance / networkTravelSpeed); route.setTravelTime(travTime); route.setDistance(estimatedNetworkDistance); leg.setRoute(route); leg.setDepartureTime(depTime); leg.setTravelTime(travTime); return travTime; }
private Leg createAccessTransitWalkLeg(Coord fromCoord, RouteSegment routeSegement) { Leg leg = this.createTransitWalkLeg(fromCoord, routeSegement.fromStop.getCoord()); Route walkRoute = RouteUtils.createGenericRouteImpl(null, routeSegement.fromStop.getLinkId()); walkRoute.setTravelTime(leg.getTravelTime() ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(fromCoord, routeSegement.fromStop.getCoord())); leg.setRoute(walkRoute); return leg; }
private Leg createEgressTransitWalkLeg(RouteSegment routeSegement, Coord toCoord) { Leg leg = this.createTransitWalkLeg(routeSegement.toStop.getCoord(), toCoord); Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.toStop.getLinkId(), null); walkRoute.setTravelTime(leg.getTravelTime() ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.toStop.getCoord(), toCoord)); leg.setRoute(walkRoute); return leg; }
if (this.currRoute instanceof NetworkRoute) { if (!this.scenario.getNetwork().getLinks().isEmpty()) { this.currRoute.setDistance(RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) this.currRoute, this.scenario.getNetwork())); double estimatedNetworkDistance = dist * this.scenario.getConfig().plansCalcRoute(). getModeRoutingParams().get( this.currleg.getMode() ).getBeelineDistanceFactor() ; this.currRoute.setDistance(estimatedNetworkDistance);
if (this.currRoute instanceof NetworkRoute) { if (!this.scenario.getNetwork().getLinks().isEmpty()) { this.currRoute.setDistance(RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) this.currRoute, this.scenario.getNetwork())); double estimatedNetworkDistance = dist * this.scenario.getConfig().plansCalcRoute(). getModeRoutingParams().get( this.currleg.getMode() ).getBeelineDistanceFactor() ; this.currRoute.setDistance(estimatedNetworkDistance);
@Override public List<? extends PlanElement> calcRoute(Facility fromFacility, Facility toFacility, double departureTime, Person person) { Leg newLeg = scenario.getPopulation().getFactory().createLeg( TransportMode.pt ); Id<Link> startLinkId = fromFacility.getLinkId(); Id<Link> endLinkId = toFacility.getLinkId(); newLeg.setDepartureTime( departureTime ); double travelTime = this.ptMatrix.getTotalTravelTime_seconds(fromFacility.getCoord(), toFacility.getCoord()); newLeg.setTravelTime( travelTime ); final Route route = genericRouteFactory.createRoute(startLinkId, endLinkId); double distance = this.ptMatrix.getTotalTravelDistance_meter(fromFacility.getCoord(), toFacility.getCoord()) ; route.setDistance(distance) ; newLeg.setRoute(route); return Arrays.asList( newLeg ); }
route.setDistance(Double.NaN); route.setTravelTime(Double.NaN);
/** * * @param event */ public void handleEvent(PersonArrivalEvent event) { currentLeg.setTravelTime( event.getTime() - currentLeg.getDepartureTime() ); double travelTime = currentLeg.getDepartureTime() + currentLeg.getTravelTime() - currentLeg.getDepartureTime(); currentLeg.setTravelTime(travelTime); if (currentRoute.size() > 1) { NetworkRoute networkRoute = RouteUtils.createNetworkRoute(currentRoute, null); networkRoute.setTravelTime(travelTime); networkRoute.setVehicleId(getVehicle().getVehicleId()); currentLeg.setRoute(networkRoute); currentRoute = null; } else { Id<Link> startLink; if(currentRoute.size() != 0){ startLink = currentRoute.get(0); } else{ startLink = event.getLinkId(); } Route genericRoute = RouteUtils.createGenericRouteImpl(startLink, event.getLinkId()); genericRoute.setDistance(0.0); currentLeg.setRoute(genericRoute); } scoringFunction.handleLeg(currentLeg); }
public void createRoute(Id<Link> fromLinkId, Path path, Id<Link> toLinkId) { NetworkRoute networkRoute = RouteUtils.createLinkNetworkRouteImpl(fromLinkId, toLinkId); if (!fromLinkId.equals(toLinkId)) { // do not drive/walk around, if we stay on the same link // path = this.routeAlgo.calcLeastCostPath(startNode, endNode, depTime, person, null); // if (path == null) throw new RuntimeException("No route found from node " + startNode.getId() + " to node " + endNode.getId() + "."); // NetworkRoute route = this.routeFactory.createRoute(NetworkRoute.class, fromLink.getId(), toLink.getId()); networkRoute.setLinkIds(fromLinkId, NetworkUtils.getLinkIds(path.links), toLinkId); networkRoute.setTravelTime(path.travelTime); networkRoute.setTravelCost(path.travelCost); networkRoute.setDistance(RouteUtils.calcDistanceExcludingStartEndLink(networkRoute, this.network)); } else { // create an empty route == staying on place if toLink == endLink route.setTravelTime(0); route.setDistance(0.0); } this.route = networkRoute; // List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); // for (int i = 1; i < linksAllIncluded.size() - 2; i++) { // linkIds.add(linksAllIncluded.get(i).getId()); // } // this.route = new LinkNetworkRouteImpl(linksAllIncluded.get(0).getId(), linkIds, linksAllIncluded.get(linksAllIncluded.size()-1).getId()); // this.calculateNetworkRouteLength(); // this.route.setTravelTime(traveltime); } }
/* package */ double routeLeg(Person person, Leg leg, Activity fromAct, Activity toAct, double depTime) { // make simple assumption about distance and walking speed final Coord fromActCoord = fromAct.getCoord(); Gbl.assertNotNull( fromActCoord ); final Coord toActCoord = toAct.getCoord(); Gbl.assertNotNull( toActCoord ); double dist = CoordUtils.calcEuclideanDistance( fromActCoord, toActCoord ); // create an empty route, but with realistic travel time Route route = this.populationFactory.getRouteFactories().createRoute(Route.class, fromAct.getLinkId(), toAct.getLinkId()); double estimatedNetworkDistance = dist * this.beelineDistanceFactor; int travTime = (int) (estimatedNetworkDistance / this.networkTravelSpeed); route.setTravelTime(travTime); route.setDistance(estimatedNetworkDistance); leg.setRoute(route); leg.setDepartureTime(depTime); leg.setTravelTime(travTime); Leg r = (leg); r.setTravelTime( depTime + travTime - r.getDepartureTime() ); // yy something needs to be done once there are alternative implementations of the interface. kai, apr'10 return travTime; }
private Leg createTransferTransitWalkLeg(RouteSegment routeSegement) { Leg leg = this.createTransitWalkLeg(routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()); Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.getFromStop().getLinkId(), routeSegement.getToStop().getLinkId()); // walkRoute.setTravelTime(leg.getTravelTime() ); // transit walk leg should include additional transfer time; Amit, Aug'17 leg.setTravelTime( getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); walkRoute.setTravelTime(getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.fromStop.getCoord(), routeSegement.toStop.getCoord())); leg.setRoute(walkRoute); return leg; }
@Test public void testLegsScoredDifferently() { final Scenario sc = createTestScenario(); final CharyparNagelScoringFunctionFactory functionFactory = new CharyparNagelScoringFunctionFactory( sc ); final ScoringFunction function1 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 1 ) ) ); final ScoringFunction function2 = functionFactory.createNewScoringFunction( sc.getPopulation().getPersons().get( Id.createPersonId( 2 ) ) ); final Leg leg = PopulationUtils.createLeg("skateboard"); leg.setDepartureTime( 10 ); leg.setTravelTime(10); final Route route = RouteUtils.createGenericRouteImpl(null, null); route.setDistance( 10 ); route.setTravelTime( 10 ); leg.setRoute( route ); function1.handleLeg(leg); function1.finish(); function2.handleLeg(leg); function2.finish(); Assert.assertFalse( "same score for legs of agents in different subpopulations", Math.abs( function1.getScore() - function2.getScore() ) < 1E-9 ); }
Route route = RouteUtils.createGenericRouteImpl(link.getId(), link.getId()); route.setTravelTime(5.0*3600); route.setDistance(100.0); leg.setRoute(route); plan.addLeg(leg);