private void startRoute(final Attributes atts) { this.currroute = this.plans.getFactory().getRouteFactories().createRoute(NetworkRoute.class, this.prevAct.getLinkId(), this.prevAct.getLinkId()); 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 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"))); } }
@Override public void endTag(final String name, final String content, final Stack<String> context) { if (Constants.DESCRIPTION.equals(name) && Constants.TRANSIT_ROUTE.equals(context.peek())) { this.currentTransitRoute.description = content; } else if (Constants.TRANSPORT_MODE.equals(name)) { this.currentTransitRoute.mode = content.intern(); } else if (Constants.TRANSIT_ROUTE.equals(name)) { List<TransitRouteStop> stops = new ArrayList<TransitRouteStop>(this.currentTransitRoute.stops.size()); for (TempStop tStop : this.currentTransitRoute.stops) { TransitRouteStopImpl routeStop = new TransitRouteStopImpl(tStop.stop, tStop.arrival, tStop.departure); stops.add(routeStop); routeStop.setAwaitDepartureTime(tStop.awaitDeparture); } NetworkRoute route = null; if (this.currentRouteProfile.firstLinkId != null) { if (this.currentRouteProfile.lastLinkId == null) { this.currentRouteProfile.lastLinkId = this.currentRouteProfile.firstLinkId; } route = this.routeFactory.createRoute(NetworkRoute.class, this.currentRouteProfile.firstLinkId, this.currentRouteProfile.lastLinkId); route.setLinkIds(this.currentRouteProfile.firstLinkId, this.currentRouteProfile.linkIds, this.currentRouteProfile.lastLinkId); } TransitRoute transitRoute = this.schedule.getFactory().createTransitRoute(this.currentTransitRoute.id, route, stops, this.currentTransitRoute.mode); transitRoute.setDescription(this.currentTransitRoute.description); for (Departure departure : this.currentTransitRoute.departures.values()) { transitRoute.addDeparture(departure); } this.currentTransitLine.addRoute(transitRoute); } }
Class<? extends Route> routeClass = factory.getRouteClassForType(routeType); this.currRoute = this.scenario.getPopulation().getFactory().getRouteFactories().createRoute(routeClass, startLinkId == null ? null : Id.create(startLinkId, Link.class), endLinkId == null ? null : Id.create(endLinkId, Link.class)); this.currleg.setRoute(this.currRoute);
Class<? extends Route> routeClass = factory.getRouteClassForType(routeType); this.currRoute = this.scenario.getPopulation().getFactory().getRouteFactories().createRoute(routeClass, startLinkId == null ? null : Id.create(startLinkId, Link.class), endLinkId == null ? null : Id.create(endLinkId, Link.class)); this.currleg.setRoute(this.currRoute);
private void startRoute() { this.currroute = this.plans.getFactory().getRouteFactories().createRoute(NetworkRoute.class, this.prevAct.getLinkId(), this.prevAct.getLinkId()); this.currleg.setRoute(this.currroute); }
/** * Used for OTFVis. Does not contain info on timing, distance and cost. Can be extended... * * @param path * @param routeFactories * @return */ public static NetworkRoute createNetworkRoute(VrpPath path, RouteFactories routeFactories) { Id<Link> fromLinkId = path.getFromLink().getId(); Id<Link> toLinkId = path.getToLink().getId(); NetworkRoute route = routeFactories.createRoute(NetworkRoute.class, fromLinkId, toLinkId); int length = path.getLinkCount(); if (length >= 2) {// means: fromLink != toLink // all except the first and last ones (== fromLink and toLink) ArrayList<Id<Link>> linkIdList = new ArrayList<>(length - 2); for (int i = 1; i < length - 1; i++) { linkIdList.add(path.getLink(i).getId()); } route.setLinkIds(fromLinkId, linkIdList, toLinkId); } 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; }
/** * Re-locates a future route. The route is given by its leg. It just replaces the route for the given leg, without looking after * overall plan consistency. * * @return true when replacing the route worked, false when something went wrong * */ @Deprecated // not consistent with access/egress approach; can only be used if you know exactly what you are doing. // Maybe replanXxx (which does not have these problems) is already sufficient? Otherwise use EditTrips or EditPlans. kai, nov'17 public boolean relocateFutureLegRoute(Leg leg, Id<Link> fromLinkId, Id<Link> toLinkId, Person person ) { Link fromLink = network.getLinks().get(fromLinkId); Link toLink = network.getLinks().get(toLinkId); Vehicle vehicle = null ; Node startNode = fromLink.getToNode() ; Node endNode = toLink.getFromNode() ; double starttime = leg.getDepartureTime() ; Path path = pathCalculator.calcLeastCostPath(startNode, endNode, starttime, person, vehicle) ; if (path == null) throw new RuntimeException("No route found from node " + startNode.getId() + " to node " + endNode.getId() + "."); NetworkRoute route = this.routeFactories.createRoute(NetworkRoute.class, fromLink.getId(), toLink.getId()); route.setLinkIds(fromLink.getId(), NetworkUtils.getLinkIds(path.links), toLink.getId()); route.setTravelTime((int) path.travelTime); // yyyy why int? kai, dec'15 route.setTravelCost(path.travelCost); route.setDistance(RouteUtils.calcDistance(route,1.,1., this.network)); leg.setRoute(route); return true; }
@Test public void testConstructor_DefaultNetworkRouteType() { Config config = ConfigUtils.createConfig(); Scenario scenario = ScenarioUtils.createScenario(config); PopulationFactory pf = scenario.getPopulation().getFactory(); Id<Link> linkId = Id.create(1, Link.class); final Id<Link> startLinkId = linkId; final Id<Link> endLinkId = linkId; Assert.assertEquals(GenericRouteImpl.class, pf.getRouteFactories().createRoute(Route.class, startLinkId, endLinkId).getClass()); }
public void testSetRouteFactory() { PopulationFactory factory = ScenarioUtils.createScenario(ConfigUtils.createConfig()).getPopulation().getFactory(); // test default Route carRoute = factory.getRouteFactories().createRoute(NetworkRoute.class, null, null); Assert.assertTrue(carRoute instanceof NetworkRoute); Route route = factory.getRouteFactories().createRoute(Route.class, null, null); Assert.assertTrue(route instanceof GenericRouteImpl); // overwrite car-mode factory.getRouteFactories().setRouteFactory(CarRouteMock.class, new CarRouteMockFactory()); // add pt-mode factory.getRouteFactories().setRouteFactory(PtRouteMock.class, new PtRouteMockFactory()); // test car-mode carRoute = factory.getRouteFactories().createRoute(CarRouteMock.class, null, null); Assert.assertTrue(carRoute instanceof CarRouteMock); // add pt-mode Route ptRoute = factory.getRouteFactories().createRoute(PtRouteMock.class, null, null); Assert.assertTrue(ptRoute instanceof PtRouteMock); // remove pt-mode factory.getRouteFactories().setRouteFactory(PtRouteMock.class, null); // test pt again route = factory.getRouteFactories().createRoute(PtRouteMock.class, null, null); Assert.assertTrue(route instanceof GenericRouteImpl); }
/*package (Tests)*/ double routeLeg(Person person, Leg leg, Link fromLink, Link toLink, double depTime) { double travTime = 0; Node startNode = fromLink.getToNode(); // start at the end of the "current" link Node endNode = toLink.getFromNode(); // the target is the start of the link if (toLink != fromLink) { // (a "true" route) Path 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.populationFactory.getRouteFactories().createRoute(NetworkRoute.class, fromLink.getId(), toLink.getId()); route.setLinkIds(fromLink.getId(), NetworkUtils.getLinkIds(path.links), toLink.getId()); route.setTravelTime((int) path.travelTime); route.setTravelCost(path.travelCost); route.setDistance(RouteUtils.calcDistance(route, 1.0,1.0,this.network)); leg.setRoute(route); travTime = (int) path.travelTime; } else { // create an empty route == staying on place if toLink == endLink // note that we still do a route: someone may drive from one location to another on the link. kai, dec'15 NetworkRoute route = this.populationFactory.getRouteFactories().createRoute(NetworkRoute.class, fromLink.getId(), toLink.getId()); route.setTravelTime(0); route.setDistance(0.0); leg.setRoute(route); travTime = 0; } leg.setDepartureTime(depTime); leg.setTravelTime(travTime); return travTime; }
private void createTransitSchedule() { TransitSchedule schedule = this.scenario.getTransitSchedule(); TransitScheduleFactory builder = schedule.getFactory(); TransitStopFacility[] stops = new TransitStopFacility[nOfLinks]; ArrayList<TransitRouteStop> stopList = new ArrayList<>(nOfLinks); for (int i = 0; i < nOfLinks; i++) { stops[i] = builder.createTransitStopFacility(Id.create(i, TransitStopFacility.class), new Coord((i + 1) * 500, 0), stopsBlockLane); stops[i].setLinkId(Id.create(i, Link.class)); schedule.addStopFacility(stops[i]); TransitRouteStop stop = builder.createTransitRouteStop(stops[i], i * 50, i * 50 + 10); stopList.add(stop); } Link startLink = this.scenario.getNetwork().getLinks().get(Id.create(0, Link.class)); Link endLink = this.scenario.getNetwork().getLinks().get(Id.create(nOfLinks - 1, Link.class)); NetworkRoute networkRoute = this.scenario.getPopulation().getFactory().getRouteFactories().createRoute(NetworkRoute.class, startLink.getId(), endLink.getId()); ArrayList<Id<Link>> linkList = new ArrayList<>(nOfLinks - 2); for (int i = 1; i < nOfLinks -1; i++) { linkList.add(Id.create(i, Link.class)); } networkRoute.setLinkIds(startLink.getId(), linkList, endLink.getId()); TransitRoute tRoute = builder.createTransitRoute(Id.create(1, TransitRoute.class), networkRoute, stopList, "bus"); TransitLine tLine = builder.createTransitLine(Id.create(1, TransitLine.class)); tLine.addRoute(tRoute); schedule.addTransitLine(tLine); for (int i = 0; i < nOfBuses; i++ ) { Departure dep = builder.createDeparture(Id.create(i, Departure.class), departureTime + i*heading + (i == delayedBus ? delay : 0)); dep.setVehicleId(Id.create(i, Vehicle.class)); tRoute.addDeparture(dep); } }
@Test public void testConstructor_CompressedNetworkRouteType() { Config config = ConfigUtils.createConfig(); config.plans().setNetworkRouteType(PlansConfigGroup.NetworkRouteType.CompressedNetworkRoute); Scenario scenario = ScenarioUtils.createScenario(config); PopulationFactory pf = scenario.getPopulation().getFactory(); Id<Link> linkId = Id.create(1, Link.class); final Id<Link> startLinkId = linkId; final Id<Link> endLinkId = linkId; Assert.assertEquals(CompressedNetworkRouteImpl.class, pf.getRouteFactories().createRoute(NetworkRoute.class, startLinkId, endLinkId).getClass()); }
@Test public void testConstructor_LinkNetworkRouteType() { Config config = ConfigUtils.createConfig(); config.plans().setNetworkRouteType(PlansConfigGroup.NetworkRouteType.LinkNetworkRoute); Scenario scenario = ScenarioUtils.createScenario(config); PopulationFactory pf = scenario.getPopulation().getFactory(); Id<Link> linkId = Id.create(1, Link.class); final Id<Link> startLinkId = linkId; final Id<Link> endLinkId = linkId; Assert.assertEquals(LinkNetworkRouteImpl.class, pf.getRouteFactories().createRoute(NetworkRoute.class, startLinkId, endLinkId).getClass()); }
NetworkRoute route = this.populationFactory.getRouteFactories().createRoute(NetworkRoute.class, fromFacility.getLinkId(), toFacility.getLinkId()); route.setLinkIds(fromFacility.getLinkId(), NetworkUtils.getLinkIds(path.links), toFacility.getLinkId()); route.setTravelTime(path.travelTime); NetworkRoute route = this.populationFactory.getRouteFactories().createRoute(NetworkRoute.class, fromFacility.getLinkId(), toFacility.getLinkId()); route.setTravelTime(0); route.setDistance(0.0);
/* 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 static Person createPerson(Id<Person> personId, MutableScenario scenario, Link link1, Link link2) { final Id<Person> id = personId; Person p = PopulationUtils.getFactory().createPerson(id); Plan plan = PersonUtils.createAndAddPlan(p, true); PopulationUtils.createAndAddActivityFromLinkId(plan, "h", link1.getId()); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); NetworkRoute route = ((PopulationFactory) scenario.getPopulation().getFactory()).getRouteFactories().createRoute(NetworkRoute.class, link1.getId(), link2.getId()); leg.setRoute(route); route.setLinkIds(link1.getId(), null, link2.getId()); leg.setRoute(route); PopulationUtils.createAndAddActivityFromLinkId(plan, "w", link2.getId()); return p; }
a1.setEndTime(6*3600); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); NetworkRoute route = f.scenario.getPopulation().getFactory().getRouteFactories().createRoute(NetworkRoute.class, f.link1.getId(), f.link3.getId()); route.setLinkIds(f.link1.getId(), f.linkIds2, f.link3.getId()); leg.setRoute(route);
a1.setEndTime(0); Leg leg = PopulationUtils.createAndAddLeg( plan, TransportMode.car ); NetworkRoute route = f.scenario.getPopulation().getFactory().getRouteFactories().createRoute(NetworkRoute.class, f.link1.getId(), f.link3.getId()); route.setLinkIds(f.link1.getId(), f.linkIds2, f.link3.getId()); leg.setRoute(route);