MATSIM
Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
org.matsim.analysis.PHbyModeCalculator Class Reference

Private Member Functions

void writeCsv ()
 
void writeValues (CSVPrinter csvPrinter, TreeSet< String > allModes) throws IOException
 
void writePng ()
 
TreeSet< String > getAllModes ()
 
record TravelTimeAndWaitTime (double travelTime, double waitTime)
 

Static Private Member Functions

static AbstractMap.SimpleEntry< String, TravelTimeAndWaitTimemapPlanElementToEntry (PlanElement pe)
 
static void writeHeader (CSVPrinter csvPrinter, TreeSet< String > allModes) throws IOException
 

Private Attributes

final Map< Integer, Map< String, TravelTimeAndWaitTime > > phtPerIteration = new TreeMap<>()
 
final OutputDirectoryHierarchy controllerIO
 
final String delimiter
 

Static Private Attributes

static final String FILENAME = "ph_modestats"
 
static final String TRAVEL_TIME_SUFFIX = "_travel"
 
static final String WAIT_TIME_SUFFIX = "_wait"
 
static final String STAGE_ACTIVITY = "stageActivity"
 

Detailed Description

analyses passenger hours traveled based on experienced plans.

Author
vsp-gleich

Definition at line 49 of file PHbyModeCalculator.java.

Member Function Documentation

◆ mapPlanElementToEntry()

static AbstractMap.SimpleEntry<String, TravelTimeAndWaitTime> org.matsim.analysis.PHbyModeCalculator.mapPlanElementToEntry ( PlanElement  pe)
staticprivate

Definition at line 75 of file PHbyModeCalculator.java.

References org.matsim.core.scoring.EventsToLegs.ENTER_VEHICLE_TIME_ATTRIBUTE_NAME.

75  {
76  if (pe instanceof Leg leg) {
77  double travelTime = 0.0;
78  double waitTime = 0.0;
79  if (leg.getRoute()!=null) {
80  travelTime = leg.getRoute().getTravelTime().seconds();
81  double enterVehicleTime = Double.NaN;
82  Object attr = leg.getAttributes().getAttribute(EventsToLegs.ENTER_VEHICLE_TIME_ATTRIBUTE_NAME);
83  if (attr != null) {
84  enterVehicleTime = (Double) attr;
85  }
86  waitTime = enterVehicleTime - leg.getDepartureTime().seconds();
87  if (!Double.isFinite(waitTime)) {waitTime = 0.0;}
88  if (waitTime >= 0.0) {
89  travelTime -= waitTime;
90  } else {
91  throw new RuntimeException("negative wait time" + enterVehicleTime + " " + leg.getDepartureTime()
92  .seconds());
93  }
94  }
95  if (Double.isNaN(travelTime)) {travelTime = 0.0; }
96  return new AbstractMap.SimpleEntry<>(leg.getMode(), new TravelTimeAndWaitTime(travelTime, waitTime));
97  }
98 
99  if (pe instanceof Activity act) {
100  if (StageActivityTypeIdentifier.isStageActivity(act.getType())) {
101  double duration = act.getEndTime().orElse(0) - act.getStartTime().orElse(0);
102  return new AbstractMap.SimpleEntry<>(STAGE_ACTIVITY, new TravelTimeAndWaitTime(0.0, duration));
103  }
104  }
105 
106  return new AbstractMap.SimpleEntry<>(STAGE_ACTIVITY, new TravelTimeAndWaitTime(0.0, 0.0));
107  }
record TravelTimeAndWaitTime(double travelTime, double waitTime)

◆ writeCsv()

void org.matsim.analysis.PHbyModeCalculator.writeCsv ( )
private

Definition at line 116 of file PHbyModeCalculator.java.

References org.matsim.analysis.PHbyModeCalculator.getAllModes(), org.matsim.core.controler.OutputDirectoryHierarchy.getOutputFilename(), org.matsim.analysis.PHbyModeCalculator.writeHeader(), and org.matsim.analysis.PHbyModeCalculator.writeValues().

116  {
117  TreeSet<String> allModes = getAllModes();
118  try {
119  BufferedWriter writer = Files.newBufferedWriter(Paths.get(controllerIO.getOutputFilename(FILENAME + ".csv")));
120  CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.Builder.create().setDelimiter((this.delimiter.charAt(0))).build());
121  writeHeader(csvPrinter, allModes);
122  writeValues(csvPrinter, allModes);
123  csvPrinter.close();
124  } catch (IOException e) {
125  LogManager.getLogger(getClass()).error("Could not write PH Modestats.");
126  }
127  }
final OutputDirectoryHierarchy controllerIO
void writeValues(CSVPrinter csvPrinter, TreeSet< String > allModes)
static void writeHeader(CSVPrinter csvPrinter, TreeSet< String > allModes)
Here is the call graph for this function:

◆ writeValues()

void org.matsim.analysis.PHbyModeCalculator.writeValues ( CSVPrinter  csvPrinter,
TreeSet< String >  allModes 
) throws IOException
private

Definition at line 129 of file PHbyModeCalculator.java.

References org.matsim.analysis.PHbyModeCalculator.TravelTimeAndWaitTime().

Referenced by org.matsim.analysis.PHbyModeCalculator.writeCsv().

129  {
130  for (Map.Entry<Integer,Map<String,TravelTimeAndWaitTime>> e : phtPerIteration.entrySet()){
131  csvPrinter.print(e.getKey());
132  for (String mode : allModes){
133  TravelTimeAndWaitTime travelTimeAndWaitTime = e.getValue().getOrDefault(mode, new TravelTimeAndWaitTime(0.0, 0.0));
134  csvPrinter.print((int) Math.round(travelTimeAndWaitTime.travelTime / 3600.0));
135  csvPrinter.print((int) Math.round(travelTimeAndWaitTime.waitTime / 3600.0));
136  }
137  csvPrinter.println();
138  }
139  }
record TravelTimeAndWaitTime(double travelTime, double waitTime)
final Map< Integer, Map< String, TravelTimeAndWaitTime > > phtPerIteration
Here is the call graph for this function:

◆ writeHeader()

static void org.matsim.analysis.PHbyModeCalculator.writeHeader ( CSVPrinter  csvPrinter,
TreeSet< String >  allModes 
) throws IOException
staticprivate

Definition at line 141 of file PHbyModeCalculator.java.

Referenced by org.matsim.analysis.PHbyModeCalculator.writeCsv().

141  {
142  csvPrinter.print("Iteration");
143  for (String mode: allModes) {
144  csvPrinter.print(mode + TRAVEL_TIME_SUFFIX);
145  csvPrinter.print(mode + WAIT_TIME_SUFFIX);
146  }
147  csvPrinter.println();
148  }

◆ writePng()

void org.matsim.analysis.PHbyModeCalculator.writePng ( )
private

Definition at line 150 of file PHbyModeCalculator.java.

References org.matsim.core.utils.charts.ChartUtil.addMatsimLogo(), org.matsim.core.utils.charts.StackedBarChart.addSeries(), org.matsim.analysis.PHbyModeCalculator.getAllModes(), org.matsim.core.utils.charts.StackedBarChart.getChart(), org.matsim.core.controler.OutputDirectoryHierarchy.getOutputFilename(), org.matsim.core.utils.charts.ChartUtil.saveAsPng(), and org.matsim.analysis.PHbyModeCalculator.TravelTimeAndWaitTime().

150  {
151  TreeSet<String> allModes = getAllModes();
152  String[] categories = new String[phtPerIteration.size()];
153  int i = 0;
154  for (Integer it : phtPerIteration.keySet()){
155  categories[i++] = it.toString();
156  }
157 
158  StackedBarChart chart = new StackedBarChart("Passenger hours traveled per Mode","Iteration","person hours",categories);
159  //rotate x-axis by 90degrees
160  chart.getChart().getCategoryPlot().getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90);
161 
162  for (String mode : allModes){
163  double[] valueTravelTime = phtPerIteration.values().stream()
164  .mapToDouble(k->k.getOrDefault(mode,new TravelTimeAndWaitTime(0.0, 0.0)).travelTime/3600.0)
165  .toArray();
166  chart.addSeries(mode + TRAVEL_TIME_SUFFIX, valueTravelTime);
167  double[] valueWaitTime = phtPerIteration.values().stream()
168  .mapToDouble(k->k.getOrDefault(mode,new TravelTimeAndWaitTime(0.0, 0.0)).waitTime/3600.0)
169  .toArray();
170  chart.addSeries(mode + WAIT_TIME_SUFFIX, valueWaitTime);
171  }
172  chart.addMatsimLogo();
173  chart.saveAsPng(controllerIO.getOutputFilename(FILENAME+ ".png"), 1024, 768);
174  }
final OutputDirectoryHierarchy controllerIO
record TravelTimeAndWaitTime(double travelTime, double waitTime)
final Map< Integer, Map< String, TravelTimeAndWaitTime > > phtPerIteration
Here is the call graph for this function:

◆ getAllModes()

TreeSet<String> org.matsim.analysis.PHbyModeCalculator.getAllModes ( )
private

Definition at line 176 of file PHbyModeCalculator.java.

Referenced by org.matsim.analysis.PHbyModeCalculator.writeCsv(), and org.matsim.analysis.PHbyModeCalculator.writePng().

176  {
177  return this.phtPerIteration.values()
178  .stream()
179  .flatMap(i -> i.keySet().stream())
180  .collect(Collectors.toCollection(TreeSet::new));
181  }
final Map< Integer, Map< String, TravelTimeAndWaitTime > > phtPerIteration

◆ TravelTimeAndWaitTime()

record org.matsim.analysis.PHbyModeCalculator.TravelTimeAndWaitTime ( double  travelTime,
double  waitTime 
)
private

Definition at line 183 of file PHbyModeCalculator.java.

Referenced by org.matsim.analysis.PHbyModeCalculator.writePng(), and org.matsim.analysis.PHbyModeCalculator.writeValues().

183  {
184  private static TravelTimeAndWaitTime sum(TravelTimeAndWaitTime object1, TravelTimeAndWaitTime object2) {
185  return new TravelTimeAndWaitTime(object1.travelTime + object2.travelTime, object1.waitTime + object2.waitTime);
186  }
187  }
record TravelTimeAndWaitTime(double travelTime, double waitTime)

Member Data Documentation

◆ phtPerIteration

final Map<Integer,Map<String,TravelTimeAndWaitTime> > org.matsim.analysis.PHbyModeCalculator.phtPerIteration = new TreeMap<>()
private

Definition at line 51 of file PHbyModeCalculator.java.

◆ controllerIO

final OutputDirectoryHierarchy org.matsim.analysis.PHbyModeCalculator.controllerIO
private

Definition at line 52 of file PHbyModeCalculator.java.

◆ delimiter

final String org.matsim.analysis.PHbyModeCalculator.delimiter
private

Definition at line 53 of file PHbyModeCalculator.java.

◆ FILENAME

final String org.matsim.analysis.PHbyModeCalculator.FILENAME = "ph_modestats"
staticprivate

Definition at line 54 of file PHbyModeCalculator.java.

◆ TRAVEL_TIME_SUFFIX

final String org.matsim.analysis.PHbyModeCalculator.TRAVEL_TIME_SUFFIX = "_travel"
staticprivate

Definition at line 56 of file PHbyModeCalculator.java.

◆ WAIT_TIME_SUFFIX

final String org.matsim.analysis.PHbyModeCalculator.WAIT_TIME_SUFFIX = "_wait"
staticprivate

Definition at line 57 of file PHbyModeCalculator.java.

◆ STAGE_ACTIVITY

final String org.matsim.analysis.PHbyModeCalculator.STAGE_ACTIVITY = "stageActivity"
staticprivate

Definition at line 58 of file PHbyModeCalculator.java.


The documentation for this class was generated from the following file: