private static Facility getFacility(Activity activity, Scenario scenario) { ActivityFacility fac = scenario.getActivityFacilities().getFacilities().get( activity.getFacilityId() ) ; return ( fac != null) ? fac : new ActivityWrapperFacility( activity ); } }
private List<? extends PlanElement> computeTravelTimeFromCompleteRouting( final Person person, final Activity fromAct, final Activity toAct, final String mode) { final List<? extends PlanElement> trip = this.router.calcRoute( mode, new ActivityWrapperFacility( fromAct ), new ActivityWrapperFacility( toAct ), fromAct.getEndTime(), person ); fillInLegTravelTimes( fromAct.getEndTime() , trip ); return trip; } }
private Facility toFacility(final Activity act) { if ((act.getLinkId() == null || act.getCoord() == null) && facilities != null && !facilities.getFacilities().isEmpty()) { // use facilities only if the activity does not provides the required fields. return facilities.getFacilities().get( act.getFacilityId() ); } return new ActivityWrapperFacility( act ); }
private Facility toFacility(final Activity act) { // if ( (act.getLinkId() == null && act.getCoord() == null) // yyyy this used to be || instead of && --??? kai, jun'16 // && facilities != null // && !facilities.getFacilities().isEmpty()) { // // use facilities only if the activity does not provide the required fields. // // yyyyyy Seems to me that the Access/EgressRoutingModule only needs either link or coord to start from. So we only go // // to facilities if neither is provided. -- This may, however, be at odds of how it is done in the AccessEgressRoutingModule, so we // // need to conceptually sort this out!! kai, jun'16 // return facilities.getFacilities().get( act.getFacilityId() ); // } // use facility first if available i.e. reversing the logic above Amit July'18 if ( facilities != null && ! facilities.getFacilities().isEmpty() && act.getFacilityId() != null ) { return facilities.getFacilities().get( act.getFacilityId() ); } return new ActivityWrapperFacility( act ); }
/** * In contrast to the other replanFutureLegRoute(...) method, the leg at the given index is replaced * by a new one. This is e.g. necessary when replacing a pt trip which might consists of multiple legs * and pt_interaction activities. */ public static boolean replanFutureTrip(Trip trip, Plan plan, String routingMode, double departureTime, TripRouter tripRouter) { Person person = plan.getPerson(); Facility fromFacility = new ActivityWrapperFacility( trip.getOriginActivity() ) ; Facility toFacility = new ActivityWrapperFacility( trip.getDestinationActivity() ) ; final List<? extends PlanElement> newTrip = tripRouter.calcRoute(routingMode, fromFacility, toFacility, departureTime, person); log.debug("new trip:" + newTrip ) ; for ( PlanElement pe : newTrip ) { log.debug( pe ) ; } TripRouter.insertTrip(plan, trip.getOriginActivity(), newTrip, trip.getDestinationActivity()); return true; }
@Override public Facility getDestinationFacility() { PlanElement pe = this.getCurrentPlanElement() ; if ( pe instanceof Leg ) { Activity activity = (Activity)this.getNextPlanElement() ; ActivityFacility fac = this.scenario.getActivityFacilities().getFacilities().get( activity.getFacilityId() ) ; if ( fac != null ) { return fac ; } else { return new ActivityWrapperFacility( activity ) ; } } else if ( pe instanceof Activity ) { return null ; } throw new RuntimeException("unexpected type of PlanElement") ; }
private List<? extends PlanElement> newTripToNewActivity(Activity newAct, String mainMode, double now, MobsimAgent agent, Person person, Scenario scenario) { log.debug("entering newTripToNewActivity") ; Link currentLink = scenario.getNetwork().getLinks().get( agent.getCurrentLinkId() ) ; Facility fromFacility = new LinkWrapperFacility( currentLink ) ; Facility toFacility = scenario.getActivityFacilities().getFacilities().get( newAct.getFacilityId() ) ; if ( toFacility == null ) { toFacility = new ActivityWrapperFacility( newAct ) ; } List<? extends PlanElement> newTrip = tripRouter.calcRoute(mainMode, fromFacility, toFacility, now, person) ; return newTrip; } // replan from stage activity:
@Override public Facility getCurrentFacility() { PlanElement pe = this.getCurrentPlanElement() ; Activity activity ; if ( pe instanceof Activity ) { activity = (Activity) pe; } else if ( pe instanceof Leg ) { activity = (Activity) this.getPreviousPlanElement() ; } else { throw new RuntimeException("unexpected type of PlanElement") ; } ActivityFacility fac = this.scenario.getActivityFacilities().getFacilities().get( activity.getFacilityId() ) ; if ( fac != null ) { return fac ; } else { return new ActivityWrapperFacility( activity ) ; } // the above assumes alternating acts/legs. I start having the suspicion that we should revoke our decision to give that up. // If not, one will have to use TripUtils to find the preceeding activity ... but things get more difficult. Preferably, the // facility should then sit in the leg (since there it is used for routing). kai, dec'15 }
@Override public void run(final Plan plan) { Iterator<PlanElement> pes = plan.getPlanElements().iterator(); Activity origin = (Activity) pes.next(); double now = 0; while (pes.hasNext()) { // FIXME: relies on the assumption of strict alternance leg/act Leg l = (Leg) pes.next(); Activity dest = (Activity) pes.next(); now = updateTime( now , origin ); if (l.getRoute() != null && l.getRoute() instanceof DriverRoute) { List<? extends PlanElement> trip = router.calcRoute( l.getMode(), new ActivityWrapperFacility( origin ), new ActivityWrapperFacility( dest ), now, plan.getPerson()); if (trip.size() != 1) { throw new RuntimeException( "unexpected trip length "+trip.size()+" for "+trip+" for mode "+l.getMode()); } DriverRoute newRoute = (DriverRoute) ((Leg) trip.get( 0 )).getRoute(); newRoute.setPassengerIds( ((DriverRoute) l.getRoute()).getPassengersIds() ); l.setRoute( newRoute ); } now = updateTime( now , l ); origin = dest; } }
@Deprecated // use TripRouter instead. kai, dec'13 public static double handleLeg(TripRouter tripRouter, final Person person, final Leg leg, final Activity fromAct, final Activity toAct, final double depTime) { List<? extends PlanElement> trip = tripRouter.calcRoute( leg.getMode(), new ActivityWrapperFacility( fromAct ), new ActivityWrapperFacility( toAct ), depTime, person); if ( trip.size() != 1 ) { throw new IllegalStateException( "This method can only be used with "+ "routing modules returning single legs. Got the following trip "+ "for mode "+leg.getMode()+": "+trip ); } Leg tripLeg = (Leg) trip.get( 0 ); leg.setRoute( tripLeg.getRoute() ); leg.setTravelTime( tripLeg.getTravelTime() ); leg.setDepartureTime( tripLeg.getDepartureTime() ); return tripLeg.getRoute() != null && tripLeg.getRoute().getTravelTime() != Time.UNDEFINED_TIME ? tripLeg.getRoute().getTravelTime() : tripLeg.getTravelTime(); }
@Test public void testWrapper() { for (Activity activity : activities) { Facility wrapper = new ActivityWrapperFacility( activity ); Assert.assertEquals( "wrapped activity returns incorrect coordinate!", activity.getCoord(), wrapper.getCoord()); Assert.assertEquals( "wrapped activity returns incorrect link id!", activity.getLinkId(), wrapper.getLinkId()); } } }
@Test public void testRouteLeg() { Fixture f = new Fixture(); FreespeedTravelTimeAndDisutility freespeed = new FreespeedTravelTimeAndDisutility(-6.0/3600, +6.0/3600, 0.0); LeastCostPathCalculator routeAlgo = new Dijkstra(f.s.getNetwork(), freespeed, freespeed); Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Activity fromAct = PopulationUtils.createActivityFromCoord("h", new Coord(0, 0)); fromAct.setLinkId(Id.create("1", Link.class)); Activity toAct = PopulationUtils.createActivityFromCoord("h", new Coord(0, 3000)); toAct.setLinkId(Id.create("3", Link.class)); final NetworkRoutingModule routingModule = new NetworkRoutingModule( TransportMode.car, f.s.getPopulation().getFactory(), f.s.getNetwork(), routeAlgo); Facility fromFacility = new ActivityWrapperFacility( fromAct ) ; Facility toFacility = new ActivityWrapperFacility( toAct ) ; List<? extends PlanElement> result = routingModule.calcRoute(fromFacility, toFacility, 7.0*3600, person) ; Assert.assertEquals(1, result.size() ); Leg leg = (Leg)result.get(0) ; Assert.assertEquals(100.0, leg.getTravelTime(), 1e-8); Assert.assertTrue(leg.getRoute() instanceof NetworkRoute); }
routeAlgo); List<? extends PlanElement> results = router.calcRoute(new ActivityWrapperFacility(fromAct), new ActivityWrapperFacility(toAct), 8.*3600, person) ; Assert.assertEquals( 1, results.size() ); Leg leg = (Leg) results.get(0) ; routeAlgo); List<? extends PlanElement> result = router.calcRoute(new ActivityWrapperFacility(fromAct), new ActivityWrapperFacility(toAct), 7.*3600, person ) ;
Facility fromFacility = new ActivityWrapperFacility(fromAct) ; Facility toFacility = new ActivityWrapperFacility(toAct) ;