@Override public Double getExpectedTravelDistance() { return route.getDistance(); } }
protected double getDistance(Route route) { if (route instanceof NetworkRoute) { return RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) route, network); } return route.getDistance(); }
@Override public Double getExpectedTravelDistance() { return ((Leg) this.currentPlanElement).getRoute().getDistance(); }
@Override public final Double getExpectedTravelDistance() { PlanElement currentPlanElement = this.getCurrentPlanElement(); if (!(currentPlanElement instanceof Leg)) { return null; } return ((Leg) currentPlanElement).getRoute().getDistance(); }
private double getAvgLegTravelDistance(final Plan plan) { double planTravelDistance=0.0; int numberOfLegs=0; for (PlanElement pe : plan.getPlanElements()) { if (pe instanceof Leg) { final Leg leg = (Leg) pe; double distance = leg.getRoute().getDistance(); if (!Double.isNaN(distance)) { planTravelDistance += distance; numberOfLegs++; } } } if (numberOfLegs>0) { return planTravelDistance/numberOfLegs; } return 0.0; } }
|| modeParams.monetaryDistanceCostRate != 0.0) { Route route = leg.getRoute(); double dist = route.getDistance(); // distance in meters if ( Double.isNaN(dist) ) { if ( ccc<10 ) {
out.write("\""); out.write(" distance=\""); out.write(Double.toString(route.getDistance())); out.write("\"");
out.write("\""); out.write(" distance=\""); out.write(Double.toString(route.getDistance())); out.write("\""); if ( route instanceof NetworkRoute) {
public GenericRouteSerializable(Route route) { distance = route.getDistance(); endLinkIdString = route.getEndLinkId().toString(); routeDescription = route.getRouteDescription(); startLinkIdString = route.getStartLinkId().toString(); travelTime = route.getTravelTime(); }
public void secondaryActivityFound(Activity act, Leg leg) { /* * No plan starts with secondary activity! */ this.subChains.get(subChainIndex).defineMode(leg.getMode()); this.subChains.get(subChainIndex).addAct(act); this.secondaryActFound = true; this.ttBudget += leg.getTravelTime(); this.totalTravelDistance += leg.getRoute().getDistance(); }
private double getTravelDist(final Person person) { double travelDist=0.0; for (PlanElement pe : person.getSelectedPlan().getPlanElements()) { if (pe instanceof Leg) { travelDist+=((Leg) pe).getRoute().getDistance(); } } return travelDist; }
public void createRoute(final Link startLink, final Link endLink, double beelineDistanceFactor, double speed) { this.route = RouteUtils.createGenericRouteImpl(startLink.getId(), endLink.getId()); this.calculateDirectDistance(startLink, endLink, beelineDistanceFactor); this.route.setTravelTime(this.route.getDistance() / speed); }
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; }
public void primaryActivityFound(Activity act, Leg leg) { /* * close chain */ if (chainStarted) { if (secondaryActFound) { this.subChains.get(subChainIndex).setTotalTravelDistance(this.totalTravelDistance); this.subChains.get(subChainIndex).setTtBudget(this.ttBudget); this.subChains.get(subChainIndex).setEndCoord(act.getCoord()); this.subChains.get(subChainIndex).setLastPrimAct(act); } else { this.subChains.remove(subChainIndex); this.subChainIndex--; } } // it is not the second home act if (!(leg == null)) { //open chain this.subChains.add(new SubChain()); this.subChainIndex++; this.subChains.get(subChainIndex).setFirstPrimAct(act); this.subChains.get(subChainIndex).setStartCoord(act.getCoord()); this.chainStarted = true; this.secondaryActFound = false; this.ttBudget = leg.getTravelTime(); this.totalTravelDistance = leg.getRoute().getDistance(); this.subChains.get(subChainIndex).defineMode(leg.getMode()); } }
private void writeLegs() throws IOException { String outputFile = this.outputDir + "/legs.shp"; ArrayList<SimpleFeature> fts = new ArrayList<SimpleFeature>(); for (Plan plan : this.outputSamplePlans) { String id = plan.getPerson().getId().toString(); for (PlanElement pe : plan.getPlanElements()) { if (pe instanceof Leg) { Leg leg = (Leg) pe; if (leg.getRoute() instanceof NetworkRoute) { if (RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) leg.getRoute(), this.network) > 0) { fts.add(getLegFeature(leg, id)); } } else if (leg.getRoute().getDistance() > 0) { fts.add(getLegFeature(leg, id)); } } } } ShapeFileWriter.writeGeometries(fts, outputFile); }
if (route instanceof NetworkRoute) { distance = RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) route, this.network); } else distance = route.getDistance();
@Override public double computeContributionOfOpportunity(ActivityFacility origin, final AggregationObject destination, Double departureTime) { Person person = null ; // I think that this is ok ActivityFacilitiesFactory activityFacilitiesFactory = new ActivityFacilitiesFactoryImpl(); ActivityFacility destinationFacility = activityFacilitiesFactory.createActivityFacility(null, destination.getNearestNode().getCoord()); Gbl.assertNotNull(tripRouter); List<? extends PlanElement> plan = tripRouter.calcRoute(mode, origin, destinationFacility, departureTime, person); // Vehicle vehicle = null ; // I think that this is ok double utility = 0.; List<Leg> legs = TripStructureUtils.getLegs(plan); // TODO Doing it like this, the pt interaction (e.g. waiting) times will be omitted! Gbl.assertIf(!legs.isEmpty()); for (Leg leg : legs) { // Add up all utility components of leg utility += leg.getRoute().getDistance() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfDistance(); utility += leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getModes().get(leg.getMode()).getMarginalUtilityOfTraveling() / 3600.; utility += -leg.getRoute().getTravelTime() * this.planCalcScoreConfigGroup.getPerforming_utils_hr() / 3600.; } // Utility based on opportunities that are attached to destination node double sumExpVjkWalk = destination.getSum(); // exp(beta * a) * exp(beta * b) = exp(beta * (a+b)) return Math.exp(this.planCalcScoreConfigGroup.getBrainExpBeta() * utility) * sumExpVjkWalk; } }
@Test public void testTransferWalkDistance(){ Fixture f = new Fixture(); f.init(); TransitRouterConfig config = new TransitRouterConfig(f.scenario.getConfig().planCalcScore(), f.scenario.getConfig().plansCalcRoute(), f.scenario.getConfig().transitRouter(), f.scenario.getConfig().vspExperimental()); TransitRouter router = createTransitRouter(f.schedule, config, routerType); Coord fromCoord = new Coord((double) 3800, (double) 5100); Coord toCoord = new Coord((double) 16100, (double) 10050); List<Leg> legs = router.calcRoute(new FakeFacility(fromCoord), new FakeFacility(toCoord), 6.0*3600, null); Leg leg1 = legs.get(1); ExperimentalTransitRoute route1 = (ExperimentalTransitRoute) leg1.getRoute(); Coord coord1 = f.schedule.getFacilities().get(route1.getEgressStopId()).getCoord(); Leg leg3 = legs.get(3); ExperimentalTransitRoute route3 = (ExperimentalTransitRoute) leg3.getRoute(); Coord coord3 = f.schedule.getFacilities().get(route3.getAccessStopId()).getCoord(); double beelineFactor = f.scenario.getConfig().plansCalcRoute().getModeRoutingParams().get(TransportMode.walk).getBeelineDistanceFactor(); assertEquals(CoordUtils.calcEuclideanDistance(coord1, coord3) * beelineFactor, legs.get(2).getRoute().getDistance(), MatsimTestCase.EPSILON); }
@Test public void testCreatesLeg() { Scenario scenario = createTriangularNetwork(); EventsToLegs eventsToLegs = new EventsToLegs(scenario); RememberingLegHandler lh = new RememberingLegHandler(); eventsToLegs.addLegHandler(lh); eventsToLegs.handleEvent(new PersonDepartureEvent(10.0, Id.create("1", Person.class), Id.create("l1", Link.class), "walk")); eventsToLegs.handleEvent(new TeleportationArrivalEvent(30.0, Id.create("1", Person.class), 50.0)); eventsToLegs.handleEvent(new PersonArrivalEvent(30.0, Id.create("1", Person.class), Id.create("l2", Link.class), "walk")); Assert.assertNotNull(lh.handledLeg); Assert.assertEquals(10.0, lh.handledLeg.getLeg().getDepartureTime(), 1e-9); Assert.assertEquals(20.0, lh.handledLeg.getLeg().getTravelTime(), 1e-9); Assert.assertEquals(50.0, lh.handledLeg.getLeg().getRoute().getDistance(), 1e-9); }
@Test public void testCreatesLegWithRoute() { Scenario scenario = createTriangularNetwork(); EventsToLegs eventsToLegs = new EventsToLegs(scenario); RememberingLegHandler lh = new RememberingLegHandler(); eventsToLegs.addLegHandler(lh); Id<Person> agentId = Id.create("1", Person.class); Id<Vehicle> vehId = Id.create("veh1", Vehicle.class); eventsToLegs.handleEvent(new PersonDepartureEvent(10.0, agentId, Id.createLinkId("l1"), "car")); eventsToLegs.handleEvent(new PersonEntersVehicleEvent(10.0, agentId, vehId)); eventsToLegs.handleEvent(new VehicleEntersTrafficEvent(10.0, agentId, Id.createLinkId("l1"), vehId, "car", 1.0)); eventsToLegs.handleEvent(new LinkLeaveEvent(10.0, vehId, Id.createLinkId("l1"))); eventsToLegs.handleEvent(new LinkEnterEvent(11.0, vehId, Id.createLinkId("l2"))); eventsToLegs.handleEvent(new LinkLeaveEvent(15.0, vehId, Id.createLinkId("l2"))); eventsToLegs.handleEvent(new LinkEnterEvent(16.0, vehId, Id.createLinkId("l3"))); eventsToLegs.handleEvent(new VehicleLeavesTrafficEvent(30.0, agentId, Id.createLinkId("l3"), vehId, "car", 1.0)); eventsToLegs.handleEvent(new PersonArrivalEvent(30.0, agentId, Id.createLinkId("l3"), "car")); Assert.assertNotNull(lh.handledLeg); Assert.assertEquals(10.0,lh.handledLeg.getLeg().getDepartureTime(), 1e-9); Assert.assertEquals(20.0,lh.handledLeg.getLeg().getTravelTime(), 1e-9); Assert.assertEquals(20.0,lh.handledLeg.getLeg().getRoute().getTravelTime(), 1e-9); Assert.assertEquals(550.0,lh.handledLeg.getLeg().getRoute().getDistance(), 1e-9); }