public EditRoutes( Network network, LeastCostPathCalculator pathCalculator, PopulationFactory popFactory ) { this.network = network ; this.pathCalculator = pathCalculator ; this.routeFactories = popFactory.getRouteFactories() ; }
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"))); } }
public TransitScheduleReaderV2( final String externalInputCRS, final String targetCRS, final Scenario scenario) { this( externalInputCRS, targetCRS , scenario.getTransitSchedule() , scenario.getPopulation().getFactory().getRouteFactories() ); }
public TransitScheduleReaderV1( final CoordinateTransformation coordinateTransformation, final Scenario scenario) { this( coordinateTransformation, scenario.getTransitSchedule(), scenario.getPopulation().getFactory().getRouteFactories() ); }
public TransitScheduleReaderV1(final Scenario scenario) { this( scenario.getTransitSchedule(), scenario.getPopulation().getFactory().getRouteFactories() ); }
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"))); } }
protected Leg createLeg(DriveTask task) { Leg leg = populFactory.createLeg(TransportMode.car); leg.setRoute(VrpPaths.createNetworkRoute(task.getPath(), populFactory.getRouteFactories())); return leg; }
RouteFactories factory = this.scenario.getPopulation().getFactory().getRouteFactories(); 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); }
public static Scenario createScenario(final Config config) { final Scenario sc = ScenarioUtils.createScenario( config ); final RouteFactories rFactory = ((PopulationFactory) sc.getPopulation().getFactory()).getRouteFactories(); rFactory.setRouteFactory( DriverRoute.class,//JointActingTypes.DRIVER, new DriverRouteFactory()); rFactory.setRouteFactory( PassengerRoute.class,//JointActingTypes.PASSENGER, new PassengerRouteFactory()); return sc; }
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); }
@Deprecated // use TripRouter instead. kai, dec'13 public PlanRouterAdapter( final MatsimServices controler) { this.planRouter = new PlanRouter( controler.getTripRouterProvider().get(), controler.getScenario().getActivityFacilities() ); TravelTime time = controler.getLinkTravelTimes(); TravelDisutility disutility = controler.getTravelDisutilityFactory().createTravelDisutility( time); LeastCostPathCalculatorFactory factory = controler.getLeastCostPathCalculatorFactory(); Network network = controler.getScenario().getNetwork(); this.routeAlgo = factory.createPathCalculator(network, disutility, time); PopulationFactory populationFactory = controler.getScenario().getPopulation().getFactory(); this.routeFactory = ((PopulationFactory) populationFactory).getRouteFactories(); }
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; }
@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()); }
/*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; }
@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()); }
/* 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; }
public void testReadFileV1() throws SAXException, ParserConfigurationException, IOException { final String inputDir = getClassInputDirectory(); Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); Network network = scenario.getNetwork(); new MatsimNetworkReader(scenario.getNetwork()).readFile(inputDir + INPUT_TEST_FILE_NETWORK); TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = builder.createTransitSchedule(); new TransitScheduleReaderV1(schedule, scenario.getPopulation().getFactory().getRouteFactories()).readFile(inputDir + INPUT_TEST_FILE_TRANSITSCHEDULE); assertEquals("wrong number of transit lines.", 1, schedule.getTransitLines().size()); assertEquals("wrong line id.", Id.create("T1", TransitLine.class), schedule.getTransitLines().keySet().iterator().next()); TransitLine lineT1 = schedule.getTransitLines().get(Id.create("T1", TransitLine.class)); assertNotNull("could not find line with id T1.", lineT1); TransitRoute route1 = lineT1.getRoutes().get(Id.create("1", TransitRoute.class)); assertNotNull("could not find route 1 in line T1.", route1); Map<Id<Departure>, Departure> departures = route1.getDepartures(); assertNotNull("could not get departures of route 1 in line T1.", departures); assertEquals("wrong number of departures.", 3, departures.size()); List<TransitRouteStop> stops = route1.getStops(); assertNotNull("could not get transit route stops.", stops); assertEquals("wrong number of stops.", 6, stops.size()); NetworkRoute route = route1.getRoute(); assertNotNull("could not get route.", route); assertEquals("wrong start link.", network.getLinks().get(Id.create("1", Link.class)).getId(), route.getStartLinkId()); assertEquals("wrong end link.", network.getLinks().get(Id.create("8", Link.class)).getId(), route.getEndLinkId()); assertEquals("wrong number of links in route.", 4, route.getLinkIds().size()); }
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; }