private Leg getDriverLegIfItIs(final Trip subtrip) { if ( !mainModeIdentifier.identifyMainMode( subtrip.getTripElements() ).equals( JointActingTypes.DRIVER ) ) return null; if ( subtrip.getLegsOnly().size() != 1 ) throw new RuntimeException( "unexpected driver subtrip length: "+subtrip ); return subtrip.getLegsOnly().get( 0 ); }
private Activity findLastDestinationOfMode( final List<Trip> tripsToSearch, final String mode) { final List<Trip> reversed = new ArrayList<>(tripsToSearch); Collections.reverse( reversed ); for (Trip trip : reversed) { if ( mode.equals( mainModeIdentifier.identifyMainMode( trip.getTripElements() ) ) ) { return trip.getDestinationActivity(); } } return null; }
private List<TripStructureUtils.Trip> getDriverTrip( final JointTrip toRemove, final Plan driverPlan) { final TripStructureUtils.Trip driverTrip = getTripWithLeg( driverPlan , toRemove.getDriverLegs().get( 0 ) , stagesWithJointTypes ); assert driverTrip.getTripElements().containsAll( toRemove.getDriverLegs() ); final List<PlanElement> elements = new ArrayList<PlanElement>(); elements.add( driverTrip.getOriginActivity() ); elements.addAll( driverTrip.getTripElements() ); elements.add( driverTrip.getDestinationActivity() ); return TripStructureUtils.getTrips( elements , stages ); }
@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 void applyChange( final Candidate whatToDo, final Plan plan) { for (Trip trip : whatToDo.subtour.getTrips()) { if ( behavior== SubtourModeChoice.Behavior.fromSpecifiedModesToSpecifiedModes ) { if (!modes.contains(mainModeIdentifier.identifyMainMode(trip.getTripElements()))) { // (ignore trips with modes that are not in "modes". MATSIM-809) continue; } } TripRouter.insertTrip( plan, trip.getOriginActivity(), Collections.singletonList(PopulationUtils.createLeg(whatToDo.newTransportMode)), trip.getDestinationActivity()); } }
@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 Trip findTripAtPlanElement(MobsimAgent agent, PlanElement pe) { log.debug("plan element to be found=" + pe ) ; List<Trip> trips = TripStructureUtils.getTrips( WithinDayAgentUtils.getModifiablePlan(agent), tripRouter.getStageActivityTypes() ) ; for ( Trip trip : trips ) { for ( PlanElement te : trip.getTripElements() ) { log.debug("trip element to be compared with=" + te ) ; if ( te==pe ) { log.debug("found trip element") ; return trip; } } } throw new ReplanningException("trip not found") ; } public Trip findTripAtPlanElementIndex( MobsimAgent agent, int index ) {
@Override public boolean doReplanning(MobsimAgent withinDayAgent) { Plan executedPlan = WithinDayAgentUtils.getModifiablePlan(withinDayAgent); // If we don't have an executed plan if (executedPlan == null) return false; // Get the activity currently performed by the agent as well as the subsequent trip. Activity currentActivity = (Activity) WithinDayAgentUtils.getCurrentPlanElement(withinDayAgent); Trip trip = TripStructureUtils.findTripStartingAtActivity(currentActivity, executedPlan, this.tripRouter.getStageActivityTypes() ); // If there is no trip after the activity. if (trip == null) return false; String mainMode = this.tripRouter.getMainModeIdentifier().identifyMainMode(trip.getTripElements()); double departureTime = TripStructureUtils.getDepartureTime(trip); new EditTrips(this.tripRouter, scenario).replanFutureTrip(trip, executedPlan, mainMode, departureTime); return true; }
private static Iterable<Record> countTrips(final Population population) { final QueryableSet records = new QueryableSet(); for ( Person person : population.getPersons().values() ) { final Plan plan = person.getSelectedPlan(); for ( Trip trip : TripStructureUtils.getTrips( plan , STAGES ) ) { final Record r = records.getOrAddIfNotThere( new Record( trip.getOriginActivity().getType(), trip.getDestinationActivity().getType(), MODE_IDENTIFIER.identifyMainMode( trip.getTripElements() ) ) ); r.count++; } } return records; }
private String getTransportMode(final Subtour subtour) { return mainModeIdentifier.identifyMainMode( subtour.getTrips().get( 0 ).getTripElements() ); }
public static Trip findCurrentTrip( PlanElement currentPlanElement, Plan plan, StageActivityTypes stageActivities ) { if ( currentPlanElement instanceof Activity ) { Gbl.assertIf( stageActivities.isStageActivity( ((Activity)currentPlanElement).getType() ) ) ; } List<Trip> trips = getTrips(plan.getPlanElements(), stageActivities ) ; for ( Trip trip : trips ) { int index = trip.getTripElements().indexOf( currentPlanElement ) ; if ( index != -1 ) { return trip ; } } return null ; } public static Trip findTripEndingAtActivity(Activity activity, Plan plan, StageActivityTypes stageActivities ) {
private String identifyMainMode(final Trip t) { return tripRouter.getMainModeIdentifier().identifyMainMode( t.getTripElements() ); }
private boolean containsMode( final Subtour s ) { for ( Trip t : s.getTrips() ) { if ( tripRouter.getMainModeIdentifier().identifyMainMode( t.getTripElements() ).equals( mode ) ) { return true; } } return false; } }
public String getModeOfCurrentOrNextTrip(MobsimAgent agent) { Trip trip ; if ( isAtRealActivity( agent ) ) { Activity activity = (Activity) WithinDayAgentUtils.getCurrentPlanElement(agent) ; trip = editTrips.findTripAfterActivity(WithinDayAgentUtils.getModifiablePlan(agent), activity) ; } else { trip = editTrips.findCurrentTrip(agent) ; } return tripRouter.getMainModeIdentifier().identifyMainMode(trip.getTripElements()) ; } public void flushEverythingBeyondCurrent(MobsimAgent agent) {
/** * Convenience method, clarifying that this can be called without giving the mode. */ public void insertActivity(MobsimAgent agent, int index, Activity activity ) { String mode = tripRouter.getMainModeIdentifier().identifyMainMode( editTrips.findCurrentTrip(agent).getTripElements() ) ; insertActivity( agent, index, activity, mode, mode ) ; }
private Activity findFirstOriginOfMode( final List<Trip> tripsToSearch, final String mode) { for (Trip trip : tripsToSearch) { if ( mode.equals( mainModeIdentifier.identifyMainMode( trip.getTripElements() ) ) ) { return trip.getOriginActivity(); } } return null; }
private static Trip getTripWithLeg( final Plan plan, final Leg leg, final StageActivityTypes stages) { for ( Trip t : TripStructureUtils.getTrips( plan , stages ) ) { if ( t.getTripElements().contains( leg ) ) return t; } throw new RuntimeException( plan.getPlanElements() +" doesn't contain "+leg ); }
@Override public String identifyMode(final Subtour subtour) { return modeIdentifier.identifyMainMode( subtour.getTrips().get( 0 ).getTripElements() ); } }
private boolean containsUnknownMode(final Subtour subtour) { for (Trip trip : subtour.getTrips()) { if (!modes.contains( mainModeIdentifier.identifyMainMode( trip.getTripElements() ))) { return true; } } return false; }
/** * @param trip * @return the departure time of the first leg of the trip */ public static double getDepartureTime(Trip trip) { // does this always make sense? Leg leg = (Leg) trip.getTripElements().get(0); return leg.getDepartureTime(); }