MATSIM
TransportPlanningMainModeIdentifier.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * TransportPlanningMainModeIdentifier.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.analysis;
23 
24 import java.util.ArrayList;
25 import java.util.List;
26 
32 
41  // I am against other people changing this lightheartedly since some of my analysis depends on it. So either please discuss,
42  // or use your own variant. kai, sep'16
43 
44  // yyyyyy some variant of this (maybe not exactly this one here) should be able to deal with multi-leg trips. kai/amit, mar'17
45 
46  private final List<String> modeHierarchy = new ArrayList<>() ;
47 
49  modeHierarchy.add( TransportMode.non_network_walk ) ;
50  modeHierarchy.add( "undefined" ) ;
51  modeHierarchy.add( TransportMode.other ) ;
52  modeHierarchy.add( TransportMode.transit_walk ) ;
53  modeHierarchy.add( TransportMode.walk ) ;
54  modeHierarchy.add( TransportMode.bike ) ;
55  modeHierarchy.add( TransportMode.drt ) ;
56  modeHierarchy.add( TransportMode.pt ) ;
57  modeHierarchy.add( TransportMode.ride ) ;
58  modeHierarchy.add( TransportMode.car ) ;
59 
60  // NOTE: This hierarchical stuff is not so great: is park-n-ride a car trip or a pt trip? Could weigh it by distance, or by time spent
61  // in respective mode. Or have combined modes as separate modes. In any case, can't do it at the leg level, since it does not
62  // make sense to have the system calibrate towards something where we have counted the car and the pt part of a multimodal
63  // trip as two separate trips. kai, sep'16
64  }
65 
66  @Override public String identifyMainMode( List<? extends PlanElement> planElements ) {
67  int mainModeIndex = -1 ;
68  for ( PlanElement pe : planElements ) {
69  if ( pe instanceof Leg ) {
70  Leg leg = (Leg) pe ;
71  int index = modeHierarchy.indexOf( leg.getMode() ) ;
72  if ( index < 0 ) {
73  throw new RuntimeException("unknown mode=" + leg.getMode() ) ;
74  }
75  if ( index > mainModeIndex ) {
76  mainModeIndex = index ;
77  }
78  }
79  }
80  if ( mainModeIndex <= modeHierarchy.indexOf( TransportMode.transit_walk ) ) {
81  mainModeIndex = modeHierarchy.indexOf( TransportMode.walk ) ;
82  }
83  return modeHierarchy.get( mainModeIndex ) ;
84  }
85 }
String identifyMainMode(List<? extends PlanElement > planElements)