public final static boolean insertEmptyTrip( Plan plan, Activity fromActivity, Activity toActivity, String mainMode, PopulationFactory pf ) { // if ( true ) { // throw new RuntimeException(" this currently does not work, since the EvacAgents do not have the on-demand " // + "replanning switched on. kai, nov'17" ) ; // } List<Leg> list = Collections.singletonList( pf.createLeg( mainMode ) ) ; TripRouter.insertTrip(plan, fromActivity, list, toActivity ) ; return true ; } public final boolean insertEmptyTrip( Plan plan, Activity fromActivity, Activity toActivity, String mainMode ) {
public static Leg createLeg(String transportMode) { return getFactory().createLeg(transportMode) ; }
public static Leg createAndAddLeg(Plan plan, String mode) { verifyCreateLeg( plan ) ; Leg leg = getFactory().createLeg(mode) ; plan.addLeg( leg ); return leg ; } private static void verifyCreateLeg(Plan plan) throws IllegalStateException {
@Override public List<? extends PlanElement> calcRoute( final Facility fromFacility, final Facility toFacility, final double departureTime, final Person person) { Leg l = popFactory.createLeg( modeName ); l.setDepartureTime( departureTime ); Route r = new PassengerRoute( fromFacility.getLinkId() , toFacility.getLinkId() ); l.setRoute( r ); return Collections.singletonList( l ); }
@Override public List<? extends PlanElement> calcRoute( final Facility fromFacility, final Facility toFacility, final double departureTime, final Person person) { List<? extends PlanElement> trip = carRoutingModule.calcRoute( fromFacility, toFacility, departureTime, person); if (trip.size() != 1) { throw new RuntimeException( "unexpected trip size for trip "+trip+" for mode "+mode ); } Leg carLeg = (Leg) trip.get( 0 ); NetworkRoute netRoute = (NetworkRoute) carLeg.getRoute(); Leg leg = popFactory.createLeg( mode ); DriverRoute dRoute = new DriverRoute( netRoute , Collections.<Id<Person>>emptyList() ); leg.setRoute( dRoute ); leg.setDepartureTime( departureTime ); leg.setTravelTime( dRoute.getTravelTime() ); return Collections.singletonList( leg ); }
protected Leg createLeg(DriveTask task) { Leg leg = populFactory.createLeg(TransportMode.car); leg.setRoute(VrpPaths.createNetworkRoute(task.getPath(), populFactory.getRouteFactories())); return leg; }
@Override public List<? extends PlanElement> calcRoute( final Facility fromFacility, final Facility toFacility, final double departureTime, final Person person) { Leg newLeg = this.populationFactory.createLeg( this.mode ); newLeg.setDepartureTime( departureTime ); double travTime = routeLeg( person, newLeg, new FacilityWrapperActivity( fromFacility ), new FacilityWrapperActivity( toFacility ), departureTime); // otherwise, information may be lost newLeg.setTravelTime( travTime ); return Arrays.asList( newLeg ); }
@Override public List<? extends PlanElement> calcRoute( final Facility fromFacility, final Facility toFacility, final double departureTime, final Person person) { Leg newLeg = this.populationFactory.createLeg( this.mode ); newLeg.setDepartureTime( departureTime ); double travTime = routeLeg( person, newLeg, new FacilityWrapperActivity( fromFacility ), new FacilityWrapperActivity( toFacility ), departureTime); // otherwise, information may be lost newLeg.setTravelTime( travTime ); return Arrays.asList(newLeg); }
public boolean addActivityAtEnd(MobsimAgent agent, Activity activity, String routingMode) { log.debug("entering addActivityAtEnd with routingMode=" + routingMode) ; Plan plan = WithinDayAgentUtils.getModifiablePlan(agent); List<PlanElement> planElements = plan.getPlanElements(); boolean retVal1 = false; if (isAtRealActivity(agent)) { retVal1 = planElements.add(pf.createLeg(routingMode)); } final boolean retVal = planElements.add(activity); // (need the terminating activity in order to find the current trip. kai, nov'17) if (!isAtRealActivity(agent)) { retVal1 = editTrips.replanCurrentTrip(agent,mobsim.getSimTimer().getTimeOfDay(),routingMode); } WithinDayAgentUtils.resetCaches(agent); this.mobsim.rescheduleActivityEnd(agent); return (retVal1 && retVal); } public PlanElement removeActivity(MobsimAgent agent, int index, String mode) {
public static void addBushwhackingLegFromLinkToFacilityIfNecessary( final Facility toFacility, final Person person, final Link egressActLink, double now, final List<PlanElement> result, final PopulationFactory populationFactory, final String stageActivityType ) { if ( toFacility.getCoord() != null ) { // otherwise the trip ends directly on the link; no need to bushwhack Coord egressActCoord = egressActLink.getToNode().getCoord() ; Gbl.assertNotNull( egressActCoord ); final Activity interactionActivity = createInteractionActivity( egressActCoord, egressActLink.getId(), stageActivityType ); result.add( interactionActivity ) ; // log.warn( interactionActivity ); Leg egressLeg = populationFactory.createLeg( TransportMode.egress_walk ) ; egressLeg.setDepartureTime( now ); routeBushwhackingLeg(person, egressLeg, egressActCoord, toFacility.getCoord(), now, egressActLink.getId(), egressActLink.getId(), populationFactory ) ; result.add( egressLeg ) ; // log.warn( egressLeg ); } // log.warn( "===" ); }
public static double addBushwhackingLegFromFacilityToLinkIfNecessary( final Facility fromFacility, final Person person, final Link accessActLink, double now, final List<PlanElement> result, final PopulationFactory populationFactory, final String stageActivityType ) { if ( fromFacility.getCoord() != null ) { // otherwise the trip starts directly on the link; no need to bushwhack Coord accessActCoord = accessActLink.getToNode().getCoord() ; // yyyy think about better solution: this may generate long walks along the link. // (e.g. orthogonal projection) Gbl.assertNotNull(accessActCoord); Leg accessLeg = populationFactory.createLeg( TransportMode.access_walk ) ; accessLeg.setDepartureTime( now ); now += routeBushwhackingLeg(person, accessLeg, fromFacility.getCoord(), accessActCoord, now, accessActLink.getId(), accessActLink.getId(), populationFactory ) ; // yyyy might be possible to set the link ids to null. kai & dominik, may'16 result.add( accessLeg ) ; // log.warn( accessLeg ); final Activity interactionActivity = createInteractionActivity(accessActCoord, accessActLink.getId(), stageActivityType ); result.add( interactionActivity ) ; // log.warn( interactionActivity ); } return now; }
@Override public List<? extends PlanElement> calcRoute(Facility fromFacility, Facility toFacility, double departureTime, Person person) { Leg newLeg = scenario.getPopulation().getFactory().createLeg( TransportMode.pt ); Id<Link> startLinkId = fromFacility.getLinkId(); Id<Link> endLinkId = toFacility.getLinkId(); newLeg.setDepartureTime( departureTime ); double travelTime = this.ptMatrix.getTotalTravelTime_seconds(fromFacility.getCoord(), toFacility.getCoord()); newLeg.setTravelTime( travelTime ); final Route route = genericRouteFactory.createRoute(startLinkId, endLinkId); double distance = this.ptMatrix.getTotalTravelDistance_meter(fromFacility.getCoord(), toFacility.getCoord()) ; route.setDistance(distance) ; newLeg.setRoute(route); return Arrays.asList( newLeg ); }
@Override public Plan createNewPlanInstance() { final PopulationFactory fact = createPopulationFactory(); final Id<Link> id1 = Id.create( 1, Link.class ); final Id<Link> id3 = Id.create( 3, Link.class ); final Plan plan = fact.createPlan(); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) ); plan.addLeg( fact.createLeg( TransportMode.walk ) ); plan.addActivity( fact.createActivityFromLinkId( "w" , id3 ) ); plan.addLeg( fact.createLeg( TransportMode.walk ) ); plan.addActivity( fact.createActivityFromLinkId( "h" , id1 ) ); return plan; } };
private Person createPersonWithPlan(PopulationFactory factory, String id, double homeX, double homeY, double workX, double workY) { Person person = factory.createPerson(Id.create(id, Person.class)); Plan plan = factory.createPlan(); person.addPlan(plan); Activity home1 = factory.createActivityFromCoord("home", new Coord(homeX, homeY)); home1.setEndTime(8*3600); Activity work = factory.createActivityFromCoord("work", new Coord(workX, workY)); work.setEndTime(17*3600); Activity home2 = factory.createActivityFromCoord("home", new Coord(homeX, homeY)); plan.addActivity(home1); plan.addLeg(factory.createLeg("car")); plan.addActivity(work); plan.addLeg(factory.createLeg("car")); plan.addActivity(home2); return person; }
@Test( expected=NullPointerException.class ) public void testNPEWhenLocationNullInSubtourAnalysis() { // this may sound surprising, but for a long time the algorithm // was perfectly fine with that if assertions were disabled... final Plan plan = populationFactory.createPlan(); // link ids are null plan.addActivity( populationFactory.createActivityFromCoord( "type", new Coord((double) 0, (double) 0)) ); plan.addLeg( populationFactory.createLeg( "mode" ) ); plan.addActivity( populationFactory.createActivityFromCoord( "type", new Coord((double) 0, (double) 0)) ); TripStructureUtils.getSubtours( plan , EmptyStageActivityTypes.INSTANCE ); } }
private void createPopulation() { Population pop = this.scenario.getPopulation(); PopulationFactory f = pop.getFactory(); Person p = f.createPerson(Id.create(1, Person.class)); pop.addPerson(p); Plan plan = f.createPlan(); p.addPlan(plan); Activity act = f.createActivityFromLinkId("home", Id.create(1, Link.class)); act.setEndTime(2000.0); plan.addActivity(act); Leg leg = f.createLeg(TransportMode.car); plan.addLeg(leg); act = f.createActivityFromLinkId("home", Id.create(34, Link.class)); plan.addActivity(act); }
private void createPopulation(){ for(int i=1;i<3;i++){ Id<Person> id = Id.createPersonId(i); Person p = population.getFactory().createPerson(id); Plan plan = population.getFactory().createPlan(); p.addPlan(plan); Activity a1 = population.getFactory().createActivityFromLinkId("h", link1.getId()); a1.setEndTime(0*3600); Leg leg = population.getFactory().createLeg(TransportMode.car); plan.addActivity(a1); plan.addLeg(leg); LinkNetworkRouteFactory factory = new LinkNetworkRouteFactory(); NetworkRoute route; List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); route= (NetworkRoute) factory.createRoute(link1.getId(), link3.getId()); linkIds.add(link2.getId()); route.setLinkIds(link1.getId(), linkIds, link3.getId()); leg.setRoute(route); Activity a2 = population.getFactory().createActivityFromLinkId("w", link3.getId()); plan.addActivity(a2); population.addPerson(p); } } }
private Person createPerson(Scenario scenario, String id) { Person person = scenario.getPopulation().getFactory().createPerson(Id.create(id, Person.class)); Activity from = scenario.getPopulation().getFactory().createActivityFromLinkId("home", Id.create("l0", Link.class)); Leg leg = scenario.getPopulation().getFactory().createLeg(TransportMode.car); Activity to = scenario.getPopulation().getFactory().createActivityFromLinkId("home", Id.create("l2", Link.class)); from.setEndTime(8*3600); leg.setDepartureTime(8*3600); RouteFactory routeFactory = new LinkNetworkRouteFactory(); Id<Link> startLinkId = Id.create("l0", Link.class); Id<Link> endLinkId = Id.create("l2", Link.class); NetworkRoute route = (NetworkRoute) routeFactory.createRoute(startLinkId, endLinkId); List<Id<Link>> linkIds = new ArrayList<Id<Link>>(); linkIds.add(Id.create("l1", Link.class)); route.setLinkIds(startLinkId, linkIds, endLinkId); leg.setRoute(route); Plan plan = scenario.getPopulation().getFactory().createPlan(); plan.addActivity(from); plan.addLeg(leg); plan.addActivity(to); person.addPlan(plan); return person; }
@Test public void testLegAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final Plan plan = population.getFactory().createPlan(); person.addPlan( plan ); final Leg leg = population.getFactory().createLeg( "SUV" ); plan.addActivity( population.getFactory().createActivityFromLinkId( "speech" , Id.createLinkId( 1 ))); plan.addLeg( leg ); plan.addActivity( population.getFactory().createActivityFromLinkId( "tweet" , Id.createLinkId( 2 ))); leg.getAttributes().putAttribute( "mpg" , 0.000001d ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); final Leg readLeg = (Leg) readPerson.getSelectedPlan().getPlanElements().get( 1 ); Assert.assertEquals( "Unexpected Double attribute in " + readLeg.getAttributes(), leg.getAttributes().getAttribute( "mpg" ) , readLeg.getAttributes().getAttribute( "mpg" ) ); }
@Test public void testPlanAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); final Plan plan = population.getFactory().createPlan(); person.addPlan( plan ); final Leg leg = population.getFactory().createLeg( "SUV" ); plan.addActivity( population.getFactory().createActivityFromLinkId( "speech" , Id.createLinkId( 1 ))); plan.addLeg( leg ); plan.addActivity( population.getFactory().createActivityFromLinkId( "tweet" , Id.createLinkId( 2 ))); plan.getAttributes().putAttribute( "beauty" , 0.000001d ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); final Plan readPlan = readPerson.getSelectedPlan() ; Assert.assertEquals( plan.getAttributes().getAttribute( "beauty" ) , readPlan.getAttributes().getAttribute( "beauty" ) ); }