MATSIM
NextLegReplanner.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * NextLegReplanner.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2010 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.withinday.replanning.replanners;
22 
23 import org.matsim.api.core.v01.Id;
24 import org.matsim.api.core.v01.Scenario;
38 
47 
48  private final TripRouter tripRouter;
50 
52  super(id, scenario, internalInterface);
53  this.tripRouter = tripRouter;
54  this.timeInterpretation = timeInterpretation;
55  }
56 
57  @Override
58  public boolean doReplanning(MobsimAgent withinDayAgent) {
59 
60  Plan executedPlan = WithinDayAgentUtils.getModifiablePlan(withinDayAgent);
61 
62  // If we don't have an executed plan
63  if (executedPlan == null) return false;
64 
65  // Get the activity currently performed by the agent as well as the subsequent trip.
66  Activity currentActivity = (Activity) WithinDayAgentUtils.getCurrentPlanElement(withinDayAgent);
67  Trip trip = TripStructureUtils.findTripStartingAtActivity( currentActivity, executedPlan );
68 
69  // If there is no trip after the activity.
70  if (trip == null) return false;
71 
72  String routingMode = TripStructureUtils.identifyMainMode(trip.getTripElements());
73  OptionalTime departureTime = TripStructureUtils.getDepartureTime(trip);
74  // To replan pt legs, we would need internalInterface of type InternalInterface.class
75  new EditTrips( this.tripRouter, scenario, null, timeInterpretation ).replanFutureTrip(trip, executedPlan, routingMode, departureTime.seconds() );
76 
77  return true;
78  }
79 
80 }
static String identifyMainMode(final List<? extends PlanElement > tripElements)
static PlanElement getCurrentPlanElement(MobsimAgent agent)
final List<? extends PlanElement > replanFutureTrip(Trip trip, Plan plan, String mainMode)
Definition: EditTrips.java:615
static OptionalTime getDepartureTime(Trip trip)
static Trip findTripStartingAtActivity(final Activity activity, final Plan plan)