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 ) {
/** * 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); }
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()); } }
/** * 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; }
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() ); }
TripRouter.insertTrip( plan.getIndividualPlan( toRemove.getDriverId() ), subtrips.get( 0 ).getOriginActivity(),
TripRouter.insertTrip( driverPlan, match.tripDriver.departure, TripRouter.insertTrip( passengerPlan, match.tripPassenger.departure,
@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() ); } } }
@Test public void testReturnedOldTrip() throws Exception { List<PlanElement> expected = new ArrayList<PlanElement>(); Plan plan = PopulationUtils.createPlan(); PopulationUtils.createAndAddActivity(plan, "-4"); PopulationUtils.createAndAddLeg( plan, "-3" ); PopulationUtils.createAndAddActivity(plan, "-2"); PopulationUtils.createAndAddLeg( plan, "-1" ); Activity o = PopulationUtils.createAndAddActivity(plan, "1"); expected.add( PopulationUtils.createAndAddLeg( plan, "some mode" ) ); expected.add( PopulationUtils.createAndAddActivity(plan, "stage") ); expected.add( PopulationUtils.createAndAddLeg( plan, "some other mode" ) ); expected.add( PopulationUtils.createAndAddActivity(plan, "another stage") ); expected.add( PopulationUtils.createAndAddLeg( plan, "yet another mode" ) ); Activity d = PopulationUtils.createAndAddActivity(plan, "5"); PopulationUtils.createAndAddLeg( plan, "6" ); PopulationUtils.createAndAddActivity(plan, "7"); PopulationUtils.createAndAddLeg( plan, "8" ); PopulationUtils.createAndAddActivity(plan, "9"); List<PlanElement> trip = new ArrayList<PlanElement>(); trip.add( PopulationUtils.createLeg("2") ); trip.add( PopulationUtils.createActivityFromLinkId("3", Id.create( "coucou", Link.class )) ); trip.add( PopulationUtils.createLeg("4") ); assertEquals( "wrong old trip", expected, TripRouter.insertTrip( plan , o , trip , d ) ); }
@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()); } } }
trip.add( PopulationUtils.createLeg("4") ); TripRouter.insertTrip( plan , o , trip , d );
@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()); } }
trip.add( PopulationUtils.createLeg("4") ); TripRouter.insertTrip( plan , o , trip , d );