@Override public void run(final Plan plan) { final List<PlanElement> planElements = plan.getPlanElements(); final List<Trip> trips = TripStructureUtils.getTrips( plan , blackList ); for ( Trip trip : trips ) { final List<PlanElement> fullTrip = planElements.subList( planElements.indexOf( trip.getOriginActivity() ) + 1, planElements.indexOf( trip.getDestinationActivity() )); final String mode = mainModeIdentifier.identifyMainMode( fullTrip ); fullTrip.clear(); fullTrip.add( PopulationUtils.createLeg(mode) ); if ( fullTrip.size() != 1 ) throw new RuntimeException( fullTrip.toString() ); } } }
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 ); }
if (trip.getDestinationActivity().getFacilityId()!=null ) { destinationId = trip.getDestinationActivity().getFacilityId(); } else { destinationId = trip.getDestinationActivity().getLinkId(); throw new NullPointerException( "Both facility id and link id for destination activity "+trip.getDestinationActivity()+ " are null!" );
EditTrips.insertEmptyTrip(plan, newAct, tripAfterAct.getDestinationActivity(), currentMainMode, pf); } else { EditTrips.insertEmptyTrip(plan, newAct, tripAfterAct.getDestinationActivity(), downstreamMode, pf);
subtrips.get( 0 ).getOriginActivity(), newTrip, subtrips.get( subtrips.size() - 1 ).getDestinationActivity() );
new Trip( trip.getOriginActivity(), trip.getDestinationActivity(), calcEndOfActivity( trip.getOriginActivity() , plan ), id) ); new Trip( trip.getOriginActivity(), trip.getDestinationActivity(), calcEndOfActivity( trip.getOriginActivity() , plan ), id) );
final int indexOfEnd = fixture.plan.getPlanElements().indexOf( trip.getDestinationActivity() ); final List<PlanElement> inPlan = fixture.plan.getPlanElements().subList(
String destinationActivityType = trip.getDestinationActivity().getType(); String mainMode = mainModeIdentifier.identifyMainMode(trip.getTripElements());
public PlanElement removeActivity(MobsimAgent agent, int index, String mode) { Plan plan = WithinDayAgentUtils.getModifiablePlan(agent) ; List<PlanElement> planElements = plan.getPlanElements() ; checkIfNotInPastOrCurrent(agent, index); final Trip tripBefore = TripStructureUtils.findTripEndingAtActivity( (Activity) planElements.get(index),plan,tripRouter.getStageActivityTypes() ); final Trip tripAfter = TripStructureUtils.findTripStartingAtActivity( (Activity)planElements.get(index),plan,tripRouter.getStageActivityTypes() ); if ( mode==null ) { final String mainModeBefore = tripRouter.getMainModeIdentifier().identifyMainMode( tripBefore.getTripElements() ); final String mainModeAfter = tripRouter.getMainModeIdentifier().identifyMainMode( tripAfter.getTripElements() ); if ( mainModeBefore.equals( mainModeAfter ) ) { mode = mainModeBefore ; } else { throw new ReplanningException("mode not given and mode before removed activity != mode after removed activity; don't know which mode to use") ; } } PlanElement pe = planElements.remove(index) ; if ( checkIfTripHasAlreadyStarted( agent, tripBefore.getTripElements() ) ) { editTrips.replanCurrentTrip(agent, mobsim.getSimTimer().getTimeOfDay() , mode); } else { editTrips.insertEmptyTrip(plan, tripBefore.getOriginActivity(), tripAfter.getDestinationActivity(), mode ) ; } WithinDayAgentUtils.resetCaches(agent); this.mobsim.rescheduleActivityEnd(agent); return pe ; } public final void rescheduleActivityEndtime( MobsimAgent agent, int index, double newEndTime ) {
public final boolean replanCurrentTrip(MobsimAgent agent, double now, String routingMode ) { log.debug("entering replanCurrentTrip with routingMode=" + routingMode) ; // I will treat that in the way that it will make the trip consistent with the activities. So if the activity in the // plan has changed, the trip will go to a new location. // what matters is the external interface, which is the method call. Everything below is internal so it does not matter so much. Trip trip = findCurrentTrip( agent ) ; final PlanElement currentPlanElement = WithinDayAgentUtils.getCurrentPlanElement(agent) ; final List<PlanElement> tripElements = trip.getTripElements(); int tripElementsIndex = tripElements.indexOf( currentPlanElement ) ; // final String currentMode = tripRouter.getMainModeIdentifier().identifyMainMode( tripElements ) ; if ( currentPlanElement instanceof Activity ) { // we are on a stage activity. Take it from there: replanCurrentTripFromStageActivity(tripElements, tripElementsIndex, agent, routingMode); } else { // we are on a leg replanCurrentTripFromLeg(trip.getDestinationActivity(), currentPlanElement, routingMode, now, agent); } WithinDayAgentUtils.resetCaches(agent); return true ; } private void replanCurrentTripFromLeg(Activity newAct, final PlanElement currentPlanElement, final String routingMode,
private Subchain getRandomSubchain( final Plan plan, final Collection<String> types) { final List<Subchain> potentialSubchains = new ArrayList<Subchain>(); Trip accessTrip = null; for ( Trip trip : TripStructureUtils.getTrips( plan , stages ) ) { if ( accessTrip != null ) { assert accessTrip.getDestinationActivity() == trip.getOriginActivity() : accessTrip.getDestinationActivity()+" != "+trip.getOriginActivity(); potentialSubchains.add( new Subchain( accessTrip.getOriginActivity(), accessTrip.getDestinationActivity(), trip.getDestinationActivity() ) ); } accessTrip = types.contains( trip.getDestinationActivity().getType() ) ? trip : null; } return potentialSubchains.isEmpty() ? null : potentialSubchains.get( random.nextInt( potentialSubchains.size() ) ); }
@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()); } }
/** * 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 void run(final Plan plan) { for ( Subtour subtour : TripStructureUtils.getSubtours( plan , stages ) ) { // not clear what we should do with open tours if ( !subtour.isClosed() ) continue; // only consider "root" tours: tours without (closed) parent if ( subtour.getParent() != null && subtour.getParent().isClosed() ) continue; final String mode = modeIdentifier.identifyMode( subtour ); for ( Trip trip : subtour.getTrips() ) { TripRouter.insertTrip( plan, trip.getOriginActivity(), Collections.singletonList( PopulationUtils.createLeg(mode) ), trip.getDestinationActivity() ); } } }
final void removePassengerTrip( final JointTrip toRemove, final JointPlan jointPlan) { final Plan passengerPlan = jointPlan.getIndividualPlan( toRemove.getPassengerId() ); final Trip tripWithLeg = getTripWithLeg( passengerPlan, toRemove.getPassengerLeg(), stagesWithJointTypes ); TripRouter.insertTrip( passengerPlan , tripWithLeg.getOriginActivity(), Collections.singletonList( PopulationUtils.createLeg(TransportMode.pt) ), tripWithLeg.getDestinationActivity() ); }
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; }
public static Trip findTripEndingAtActivity(Activity activity, Plan plan, StageActivityTypes stageActivities ) { Gbl.assertIf( ! stageActivities.isStageActivity( activity.getType()) ) ; List<Trip> trips = getTrips(plan.getPlanElements(), stageActivities ) ; for ( Trip trip : trips ) { if ( activity.equals( trip.getDestinationActivity() ) ) { return trip; } } return null ; } public static Trip findTripStartingAtActivity( final Activity activity, final Plan plan, StageActivityTypes stageActivities ) {