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; }
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"))); } }
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); }
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.setTravelTime(Time.parseTime(atts.getValue("trav_time")));
@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; }
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; }
route.setTravelTime(Double.NaN);
this.currRoute.setTravelTime(this.currleg.getTravelTime());
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 ); }
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 }
PopulationUtils.createAndAddActivityFromCoord(plan, "w", new Coord(100, 200)); Route route = RouteUtils.createGenericRouteImpl(link1.getId(), link2.getId()); route.setTravelTime(98.76); leg.setRoute(route);
/** * Tests that no Exception occurs if the last activity of an agent has an end time set (which is wrong). * * @author mrieser */ @Test public void testAgentWithLastActWithEndtime() { Fixture f = new Fixture(isUsingFastCapacityUpdate); Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan plan = PersonUtils.createAndAddPlan(person, true); Activity act = PopulationUtils.createAndAddActivityFromLinkId(plan, "home", f.link1.getId()); act.setEndTime(6.0 * 3600); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.walk ); leg.setRoute(RouteUtils.createGenericRouteImpl(f.link1.getId(), f.link2.getId())); leg.getRoute().setTravelTime(0.); // retrofitting to repair failing test. kai, apr'15 act = PopulationUtils.createAndAddActivityFromLinkId(plan, "work", f.link2.getId()); act.setEndTime(6.0 * 3600 + 60); f.plans.addPerson(person); /* build events */ EventsManager events = EventsUtils.createEventsManager(); LinkEnterEventCollector collector = new LinkEnterEventCollector(); events.addHandler(collector); /* run sim */ QSim sim = createQSim(f, events); sim.run(); /* finish */ Assert.assertEquals("wrong number of link enter events.", 0, collector.events.size()); }
@Test public void testCopyPlan_NetworkRoute() { Network network = NetworkUtils.createNetwork(); Node node1 = NetworkUtils.createAndAddNode(network, Id.create(1, Node.class), new Coord(0, 0)); Node node2 = NetworkUtils.createAndAddNode(network, Id.create(2, Node.class), new Coord(1000, 0)); Node node3 = NetworkUtils.createAndAddNode(network, Id.create(3, Node.class), new Coord(2000, 0)); final Node fromNode = node1; final Node toNode = node2; Link link1 = NetworkUtils.createAndAddLink(network,Id.create(1, Link.class), fromNode, toNode, 1000.0, 100.0, 3600.0, 1.0 ); final Node fromNode1 = node2; final Node toNode1 = node3; Link link2 = NetworkUtils.createAndAddLink(network,Id.create(2, Link.class), fromNode1, toNode1, 1000.0, 100.0, 3600.0, 1.0 ); Plan plan = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(1, Person.class))); PopulationUtils.createAndAddActivityFromCoord(plan, "h", new Coord(0, 0)); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); PopulationUtils.createAndAddActivityFromCoord(plan, "w", new Coord(100, 200)); Route route = RouteUtils.createLinkNetworkRouteImpl(link1.getId(), link2.getId()); route.setTravelTime(98.76); leg.setRoute(route); Plan plan2 = PopulationUtils.createPlan(PopulationUtils.getFactory().createPerson(Id.create(2, Person.class))); PopulationUtils.copyFromTo(plan, plan2); assertEquals("person must not be copied.", Id.create(2, Person.class), plan2.getPerson().getId()); assertEquals("wrong number of plan elements.", plan.getPlanElements().size(), plan2.getPlanElements().size()); Route route2 = ((Leg) plan.getPlanElements().get(1)).getRoute(); assertTrue(route2 instanceof NetworkRoute); assertEquals(98.76, route2.getTravelTime(), 1e-8); }