private void endRoute(final String content) { this.routeDescription = content; Id<Link> startLinkId = this.currRoute.getStartLinkId(); Id<Link> endLinkId = this.currRoute.getEndLinkId(); this.currRoute.setStartLinkId(startLinkId); this.currRoute.setEndLinkId(endLinkId); this.currRoute.setRouteDescription(this.routeDescription.trim()); if (Double.isNaN(this.currRoute.getDistance())) { 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.getTravelTime() == Time.UNDEFINED_TIME) { this.currRoute.setTravelTime(this.currleg.getTravelTime()); if (this.currRoute.getEndLinkId() != null) {
public GenericRouteSerializable(Route route) { distance = route.getDistance(); endLinkIdString = route.getEndLinkId().toString(); routeDescription = route.getRouteDescription(); startLinkIdString = route.getStartLinkId().toString(); travelTime = route.getTravelTime(); }
private Leg(Leg leg) { this.expTransportTime = leg.getExpectedTransportTime(); this.departureTime = leg.getExpectedDepartureTime(); this.route = leg.getRoute().clone(); }
@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 void run(final Plan plan) { for (PlanElement pe : plan.getPlanElements()) { if (pe instanceof Leg) { Leg leg = (Leg) pe; Route route = leg.getRoute(); if (route != null) { double dist = RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) route, this.network); if (route.getEndLinkId() != null && route.getStartLinkId() != route.getEndLinkId()) { dist += this.network.getLinks().get(route.getEndLinkId()).getLength(); } this.sumLength += dist; this.cntTrips++; } } } }
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"))); } }
Route route = RouteUtils.createGenericRouteImpl(idFrom, idTo); final double travTime = 60.0 * 60.0; route.setTravelTime(travTime); final double dist = 100.0; route.setDistance(dist); leg.setRoute(route); plan.addLeg(leg); Route route2 = leg2.getRoute(); Assert.assertEquals("wrong start link", startLinkId, route2.getStartLinkId().toString()); Assert.assertEquals("wrong end link", endLinkId, route2.getEndLinkId().toString()); Assert.assertEquals("wrong travel time", travTime, route2.getTravelTime(), 1e-9); Assert.assertEquals("wrong distance", dist, route2.getDistance(), 1e-9);
@Override public Double getExpectedTravelDistance() { return route.getDistance(); } }
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; }
@Override public void handleEvent(PersonEntersVehicleEvent event) { Double startWaitingTime = agentsWaitingData.get(event.getPersonId()); if(startWaitingTime!=null) { int legs = 0, currentLeg = agentsCurrentLeg.get(event.getPersonId()); PLAN_ELEMENTS: for(PlanElement planElement:population.getPersons().get(event.getPersonId()).getSelectedPlan().getPlanElements()) if(planElement instanceof Leg) { if(currentLeg==legs) { Route route = (((Leg)planElement).getRoute()); ExperimentalTransitRoute eRoute = (ExperimentalTransitRoute) new ExperimentalTransitRouteFactory().createRoute(route.getStartLinkId(), route.getEndLinkId()); eRoute.setStartLinkId(route.getStartLinkId()); eRoute.setEndLinkId(route.getEndLinkId()); eRoute.setRouteDescription(route.getRouteDescription()); WaitTimeData data = waitTimes.get(new Tuple<Id<TransitLine>, Id<TransitRoute>>(eRoute.getLineId(), eRoute.getRouteId())).get(eRoute.getAccessStopId()); data.addWaitTime((int) (startWaitingTime/timeSlot), event.getTime()-startWaitingTime); agentsWaitingData.remove(event.getPersonId()); break PLAN_ELEMENTS; } else legs++; } } }
@Override public void startRoute(final Route route, final BufferedWriter out) throws IOException { out.write("\t\t\t\t<route"); if (!Double.isNaN(route.getDistance())) { out.write(" dist=\""); out.write(Double.toString(route.getDistance())); out.write("\""); } if (route.getTravelTime() != Time.UNDEFINED_TIME) { out.write(" trav_time=\""); out.write(Time.writeTime(route.getTravelTime())); out.write("\""); } out.write(">\n"); out.write("\t\t\t\t\t"); if (route instanceof NetworkRoute) { for (Node n : RouteUtils.getNodes((NetworkRoute) route, this.network)) { out.write(n.getId().toString()); out.write(" "); } } else { String rd = route.getRouteDescription(); if (rd != null) { out.write(rd); out.write(" "); // this is at the moment only to maintain binary compatibility } } out.write("\n"); }
public void testWriteGenericRoute() { MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(super.loadConfig(null)); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); Link link1 = network.getLinks().get(Id.create(1, Link.class)); Link link2 = network.getLinks().get(Id.create(2, Link.class)); Scenario tmpScenario = new ScenarioBuilder(ConfigUtils.createConfig()).setNetwork(network).build() ; Population pop = tmpScenario.getPopulation(); PopulationFactory pb = pop.getFactory(); Person person = pb.createPerson(Id.create(1, Person.class)); Plan plan = (Plan) pb.createPlan(); plan.setPerson(person); plan.addActivity(pb.createActivityFromLinkId("h", link1.getId())); Leg leg = pb.createLeg("undefined"); Route route = RouteUtils.createGenericRouteImpl(link1.getId(), link2.getId()); route.setTravelTime(123); leg.setRoute(route); plan.addLeg(leg); plan.addActivity(pb.createActivityFromLinkId("h", Id.create(1, Link.class))); person.addPlan(plan); pop.addPerson(person); String filename = getOutputDirectory() + "population.xml"; new PopulationWriter(pop, network).writeV4(filename); Population pop2 = scenario.getPopulation(); new PopulationReader(scenario).readFile(filename); Person person2 = pop2.getPersons().get(Id.create(1, Person.class)); Leg leg2 = (Leg) person2.getPlans().get(0).getPlanElements().get(1); Route route2 = leg2.getRoute(); assertEquals(123, route2.getTravelTime(), EPSILON); // if this succeeds, we know that writing/reading the data works }
@Override public Double getExpectedTravelTime() { return route.getTravelTime(); }
@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; } }
private void calculateDirectDistance(Link startLink, Link endLink, double beelineDistanceFactor) { double distance = CoordUtils.calcEuclideanDistance(startLink.getCoord(), endLink.getCoord()); this.route.setDistance(beelineDistanceFactor * distance); } }
private Id findVehicleLink(final Person p) { // A more careful way to decide where this agent should have its vehicles created // than to ask agent.getCurrentLinkId() after creation. for (PlanElement planElement : p.getSelectedPlan().getPlanElements()) { if (planElement instanceof Activity) { Activity activity = (Activity) planElement; if (activity.getLinkId() != null) { return activity.getLinkId(); } } else if (planElement instanceof Leg) { Leg leg = (Leg) planElement; if (leg.getRoute().getStartLinkId() != null) { return leg.getRoute().getStartLinkId(); } } } throw new RuntimeException("Don't know where to put a vehicle for this agent."); }
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); }
@Override public Id<Link> getDestinationLinkId() { return route.getEndLinkId(); }
endLinkId = this.curract.getLinkId(); this.currRoute.setStartLinkId(startLinkId); this.currRoute.setEndLinkId(endLinkId); if (this.currRoute instanceof NetworkRoute) { ((NetworkRoute) this.currRoute).setLinkIds(startLinkId, endLinkId); } else { this.currRoute.setRouteDescription(this.routeDescription.trim());
protected final List<Leg> createDirectWalkLegList(Person person, Coord fromCoord, Coord toCoord) { List<Leg> legs = new ArrayList<>(); Leg leg = PopulationUtils.createLeg(TransportMode.transit_walk); double walkTime = getWalkTime(person, fromCoord, toCoord); leg.setTravelTime(walkTime); Route walkRoute = RouteUtils.createGenericRouteImpl(null, null); walkRoute.setTravelTime(walkTime); leg.setRoute(walkRoute); legs.add(leg); return legs; }