public TripsToLegsAlgorithm(final TripRouter router) { this( router.getStageActivityTypes(), router.getMainModeIdentifier() ); }
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 TripRouter build() { return new TripRouter( routingModuleProviders, mainModeIdentifier, config ) ; } }
@Override public void run(final Plan plan) { final List<Trip> trips = TripStructureUtils.getTrips( plan , tripRouter.getStageActivityTypes() ); for (Trip oldTrip : trips) { final List<? extends PlanElement> newTrip = tripRouter.calcRoute( tripRouter.getMainModeIdentifier().identifyMainMode( oldTrip.getTripElements() ), toFacility( oldTrip.getOriginActivity() ), toFacility( oldTrip.getDestinationActivity() ), calcEndOfActivity( oldTrip.getOriginActivity() , plan, tripRouter.getConfig() ), plan.getPerson() ); putVehicleFromOldTripIntoNewTripIfMeaningful(oldTrip, newTrip); TripRouter.insertTrip( plan, oldTrip.getOriginActivity(), newTrip, oldTrip.getDestinationActivity()); } }
public StageActivityTypes getStageActivities() { return tripRouter.getStageActivityTypes() ; }
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:
/** * 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; }
private String identifyMainMode(final Trip t) { return tripRouter.getMainModeIdentifier().identifyMainMode( t.getTripElements() ); }
/** * Convenience method that estimates the trip departure time rather than explicitly requesting it. * * @param trip * @param plan * @param mainMode * @return */ public final boolean replanFutureTrip(Trip trip, Plan plan, String mainMode) { double departureTime = PlanRouter.calcEndOfActivity( trip.getOriginActivity(), plan, tripRouter.getConfig() ) ; return replanFutureTrip( trip, plan, mainMode, departureTime ) ; } public final boolean replanFutureTrip(Trip trip, Plan plan, String routingMode, double departureTime) {
@Override public void run(final Plan plan) { final List<Trip> trips = TripStructureUtils.getTrips( plan , routingHandler.getStageActivityTypes() ); for (Trip trip : trips) { /** That's the only check that got added.... **/ if (routingHandler.getMainModeIdentifier().identifyMainMode(trip.getTripElements()).equals(TransportMode.pt)) { final List<? extends PlanElement> newTrip = routingHandler.calcRoute( routingHandler.getMainModeIdentifier().identifyMainMode( trip.getTripElements() ), toFacility( trip.getOriginActivity() ), toFacility( trip.getDestinationActivity() ), calcEndOfActivity( trip.getOriginActivity() , plan ), plan.getPerson() ); TripRouter.insertTrip( plan, trip.getOriginActivity(), newTrip, trip.getDestinationActivity()); } } }
private StageActivityTypes getStageActivities() { if (this.stageActivityTypes == null) { if (this.tripRouter !=null ) { this.stageActivityTypes = this.tripRouter.getStageActivityTypes() ; } else { this.stageActivityTypes = new StageActivityTypes() { @Override public boolean isStageActivity( final String activityType ) { if ( activityType.contains( "_interaction" ) ) { return true; } else { return false; } } }; // yyyyyy this is really terrible, needs to come from global data structure instead. } } return this.stageActivityTypes; }
/** * Re-locates a future route. The route is given by its leg. * * @return true when replacing the route worked, false when something went wrong * * @deprecated switch this to relocateFutureTrip, since with egress legs relocating the destination of a single leg leads to disconnected trips. kai, dec'15 */ @Deprecated // not consistent with access/egress approach; can only be used if you know exactly what you are doing. // Maybe replanXxx is already sufficient? Otherwise use EditTrips or EditPlans. kai, nov'17 public static boolean relocateFutureLegRoute(Leg leg, Id<Link> fromLinkId, Id<Link> toLinkId, Person person, Network network, TripRouter tripRouter) { // TripRouter variant; everything else uses the PathCalculator Link fromLink = network.getLinks().get(fromLinkId); Link toLink = network.getLinks().get(toLinkId); Facility fromFacility = new LinkWrapperFacility(fromLink); Facility toFacility = new LinkWrapperFacility(toLink); List<? extends PlanElement> planElements = tripRouter.calcRoute(leg.getMode(), fromFacility, toFacility, leg.getDepartureTime(), person); if (planElements.size() != 1) { throw new RuntimeException("Expected a list of PlanElements containing exactly one element, " + "but the returned list contained " + planElements.size() + " elements."); } Leg newLeg = (Leg) planElements.get(0); leg.setTravelTime(newLeg.getTravelTime()); leg.setRoute(newLeg.getRoute()); return true; }
private boolean containsMode( final Subtour s ) { for ( Trip t : s.getTrips() ) { if ( tripRouter.getMainModeIdentifier().identifyMainMode( t.getTripElements() ).equals( mode ) ) { return true; } } return false; } }
@Override public void notifyStartup(final StartupEvent event) { this.minIteration = controlerConfigGroup.getFirstIteration(); TripRouter tripRouter = tripRouterFactory.get(); this.stageActivities = tripRouter.getStageActivityTypes() ; this.mainModeIdentifier = tripRouter.getMainModeIdentifier() ; }
@Inject final void setTripRouter( TripRouter val ) { // (not user settable) stageActivities = val.getStageActivityTypes() ; } @Override
@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; } }
/** * Inserts a trip between two activities in the sequence of plan elements * returned by the {@link Plan#getPlanElements()} method of a plan. Note * that the plan will be modified only if the returned list is the internal * reference! * <p></p> * Note that this methods returns a unique solution because it expects the activity object references as arguments, which are unique. * * @param plan the plan to modify * @param origin the activity to use as origin. It must be a member of the list of plan elements. * @param trip the trip to insert * @param destination the destination activity. It must be a member of the list. * @return the "old trip": the sequence of plan elements originally existing between the origin and the destination */ public static List<PlanElement> insertTrip( final Plan plan, final Activity origin, final List<? extends PlanElement> trip, final Activity destination) { return insertTrip( plan.getPlanElements(), origin, trip, destination); }
@Override public String identifyMainMode( final List<? extends PlanElement> tripElements) { for ( PlanElement pe : tripElements ) { if ( pe instanceof Leg && ((Leg) pe).getMode().equals( JointActingTypes.PASSENGER ) ) { return TransportMode.pt; } if ( pe instanceof Leg && ((Leg) pe).getMode().equals( JointActingTypes.DRIVER ) ) { return TransportMode.car; } } return router.getMainModeIdentifier().identifyMainMode( tripElements ); } }) );
@Override public PlanAlgorithm getPlanAlgoInstance() { final TripRouter tripRouter = tripRouterProvider.get(); final ChooseRandomLegModeForSubtour chooseRandomLegMode = new ChooseRandomLegModeForSubtour( tripRouter.getStageActivityTypes(), tripRouter.getMainModeIdentifier(), this.permissibleModesCalculator, this.modes, this.chainBasedModes, MatsimRandom.getLocalInstance(), behavior, probaForChangeSingleTripMode); return chooseRandomLegMode; }
public Trip findTripAfterActivity( Plan plan, Activity activity ) { return TripStructureUtils.findTripStartingAtActivity( activity, plan, tripRouter.getStageActivityTypes() ) ; }