MATSIM
PersonCalcTimes.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * PersonCalcTimes.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 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.core.population.algorithms;
22 
23 import java.util.List;
24 
31 
46 public final class PersonCalcTimes extends AbstractPersonAlgorithm {
47 
49  // constructors
51 
52  public PersonCalcTimes() {
53  super();
54  }
55 
57  // run methods
59 
60  @Override
61  public void run(Person person) {
62  List<? extends Plan> plans = person.getPlans();
63  for (int i=0; i<plans.size(); i++) {
64  Plan plan = plans.get(i);
65 
66  Activity act = null;
67  Leg leg = null;
68  int cnt = 0;
69  int max = plan.getPlanElements().size();
70  for (PlanElement pe : plan.getPlanElements()) {
71  cnt++;
72  if (pe instanceof Activity) {
73  act = (Activity) pe;
74 
75  if (cnt == 1) {
76  // first activity
77  act.setStartTime(0);
79  } else if (cnt == max) {
80  double time = leg.getDepartureTime().seconds() + leg.getTravelTime().seconds();
81  act.setStartTime(time);
82  if (time < 24*3600) {
83  time = 24*3600;
84  }
85  act.setEndTime(time);
86  act.setMaximumDuration(time - act.getStartTime().seconds());
87  }
88  else {
91  }
92  }
93  if (pe instanceof Leg) {
94  leg = (Leg) pe;
95 
96  leg.setDepartureTime(act.getEndTime().seconds());
97  OptionalTime ttime = leg.getTravelTime();
98  leg.setTravelTime( leg.getDepartureTime().seconds() + ttime.orElse(0) - leg.getDepartureTime()
99  .seconds());
100  }
101  }
102  }
103  }
104 }
void setDepartureTime(final double seconds)
List< PlanElement > getPlanElements()
void setTravelTime(final double seconds)
void setEndTime(final double seconds)
abstract List<? extends T > getPlans()