MATSIM
VspPlansCleaner.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * VspPlansCleaner.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2011 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 package org.matsim.core.population;
21 
31 
32 import com.google.inject.Inject;
33 
39 /* deliberately package */ class VspPlansCleaner implements BeforeMobsimListener {
40 
41  @Inject
42  private PlansConfigGroup plansConfigGroup;
43  @Inject
44  private Population population;
45 
46  @Override
47  public void notifyBeforeMobsim(BeforeMobsimEvent event) {
48  PlansConfigGroup.ActivityDurationInterpretation actDurInterp = (plansConfigGroup.getActivityDurationInterpretation() ) ;
49  for ( Person person : population.getPersons().values() ) {
50 
51  Plan plan = person.getSelectedPlan() ;
52  // do this only for the selected plan in the assumption that the other ones are clean
53 
54  for ( PlanElement pe : plan.getPlanElements() ) {
55  if ( pe instanceof Activity ) {
56  Activity act = (Activity) pe ;
57 
58  if ( actDurInterp == PlansConfigGroup.ActivityDurationInterpretation.minOfDurationAndEndTime ) {
59 
60  // person stays at the activity either until its duration is over or until its end time, whatever comes first
61  // do nothing
62 
63  } else if ( actDurInterp == PlansConfigGroup.ActivityDurationInterpretation.endTimeOnly ) {
64 
65  // always set duration to undefined:
66  act.setMaximumDurationUndefined() ;
67 
68  } else if ( actDurInterp == PlansConfigGroup.ActivityDurationInterpretation.tryEndTimeThenDuration) {
69 
70  // set duration to undefined if there is an activity end time:
71  if (act.getEndTime().isDefined()) {
72  act.setMaximumDurationUndefined();
73  }
74 
75  } else {
76  throw new IllegalStateException("should not happen") ;
77  }
78 
79  if (plansConfigGroup.isRemovingUnneccessaryPlanAttributes()) {
80  act.setStartTimeUndefined() ;
81  }
82 
83  } else if ( pe instanceof Leg ) {
84  Leg leg = (Leg) pe ;
85  if (plansConfigGroup.isRemovingUnneccessaryPlanAttributes()) {
86 // leg.setDepartureTimeUndefined() ;
87  //this information is not unneccesary, but may be used, e.g., by DRTRoutes and others.
88  if ( leg.getRoute()!=null ) {
89  leg.setTravelTimeUndefined();
90  }
91 
92  }
93  }
94  }
95 
96  }
97  }
98 
99 }