@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 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 ); }
public SubtourRecord( final Subtour subtour, final List<VehicleRecord> possibleVehicles) { this.possibleVehicles = possibleVehicles; this.subtour = subtour; final Trip firstTrip = subtour.getTrips().get( 0 ); this.startTime = firstTrip.getOriginActivity().getEndTime(); if ( startTime == Time.UNDEFINED_TIME ) throw new RuntimeException( "no end time in "+firstTrip.getOriginActivity() ); final Trip lastTrip = subtour.getTrips().get( subtour.getTrips().size() - 1 ); this.endTime = calcArrivalTime( lastTrip ); } }
PopulationUtils.createActivityFromLinkId(JointActingTypes.INTERACTION, route != null ? route.getStartLinkId() : subtrip.getOriginActivity().getLinkId()) ); subtrips.get( 0 ).getOriginActivity(), newTrip, subtrips.get( subtrips.size() - 1 ).getDestinationActivity() );
trips.addCarTrip( new Trip( trip.getOriginActivity(), trip.getDestinationActivity(), calcEndOfActivity( trip.getOriginActivity() , plan ), id) ); trips.addNonChainBasedTrip( new Trip( trip.getOriginActivity(), trip.getDestinationActivity(), calcEndOfActivity( trip.getOriginActivity() , plan ), id) );
trip.getOriginActivity() ); final int indexOfEnd = fixture.plan.getPlanElements().indexOf(
String originActivityType = trip.getOriginActivity().getType(); 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 ) {
private static double calcArrivalTime(final Trip trip) { double now = trip.getOriginActivity().getEndTime(); for ( final PlanElement pe : trip.getTripElements() ) { if ( pe instanceof Activity ) { final double end = ((Activity) pe).getEndTime(); now = end != Time.UNDEFINED_TIME ? end : now + ((Activity) pe).getMaximumDuration(); // TODO: do not fail *that* badly, but just revert to random alloc if ( now == Time.UNDEFINED_TIME ) throw new RuntimeException( "could not get time from "+pe ); } else if ( pe instanceof Leg ) { final Route r = ((Leg) pe).getRoute(); if ( r != null && r.getTravelTime() != Time.UNDEFINED_TIME ) { now += r.getTravelTime(); } else { now += ((Leg) pe).getTravelTime() != Time.UNDEFINED_TIME ? ((Leg) pe).getTravelTime() : 0; // no info: just assume instantaneous. This will give poor results! } } } return now; } }
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()); } } }
@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()); } }
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) { 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() ); } } }
/** * 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() ); }
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; }
/** * 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) {
public static Trip findTripStartingAtActivity( final Activity activity, final Plan plan, StageActivityTypes stageActivities ) { Gbl.assertIf( ! stageActivities.isStageActivity( activity.getType()) ) ; List<Trip> trips = getTrips( plan, stageActivities ) ; for ( Trip trip : trips ) { if ( trip.getOriginActivity().equals( activity ) ) { return trip ; } } return null ; }
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; }