MATSIM
SubtourModeChoiceConfigGroup.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * SubtourModeChoiceConfigGroup.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2013 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.config.groups;
21 
22 import java.util.Map;
23 
28 
33 
34  public static final String GROUP_NAME = "subtourModeChoice";
35 
36  public final static String MODES = "modes";
37  public final static String CHAINBASEDMODES = "chainBasedModes";
38  public final static String CARAVAIL = "considerCarAvailability";
39  public final static String SINGLE_PROBA = "probaForRandomSingleTripMode";
40  public final static String COORD_DISTANCE = "coordDistance";
41 
42  private static final String BEHAVIOR = "behavior";
43 
44  private String[] chainBasedModes = new String[] { TransportMode.car, TransportMode.bike };
45  private String[] allModes = new String[] { TransportMode.car, TransportMode.pt, TransportMode.bike, TransportMode.walk };
46  // default is false for backward compatibility
47  private boolean considerCarAvailability = false;
49 
50  private double probaForRandomSingleTripMode = 0. ; // yyyyyy backwards compatibility setting; should be change. kai, may'18
51 
52  private double coordDistance = 0;
53 
55  super(GROUP_NAME);
56  }
57 
58  @StringGetter( MODES )
59  private String getModesString() {
60  return toString( allModes );
61  }
62 
64  private String getChainBaseModesString() {
65  return toString( chainBasedModes );
66  }
67 
68  private static String toString( final String[] modes ) {
69  // (not same as toString() because of argument!)
70 
71  StringBuilder b = new StringBuilder();
72 
73  if (modes.length > 0) b.append( modes[ 0 ] );
74  for (int i=1; i < modes.length; i++) {
75  b.append( ',' );
76  b.append( modes[ i ] );
77  }
78 
79  return b.toString();
80  }
81 
82  private static String[] toArray( final String modes ) {
83  String[] parts = StringUtils.explode(modes, ',');
84 
85  for (int i = 0, n = parts.length; i < n; i++) {
86  parts[i] = parts[i].trim().intern();
87  }
88 
89  return parts;
90  }
91 
93  private void setModes( final String value ) {
94  setModes( toArray( value ) );
95  }
96 
98  private void setChainBasedModes( final String value ) {
99  setChainBasedModes( toArray( value ) );
100  }
101 
102  @Override
103  public Map<String, String> getComments() {
104  Map<String, String> comments = super.getComments();
105  comments.put(MODES, "Defines all the modes available, including chain-based modes, seperated by commas" );
106  comments.put(CHAINBASEDMODES, "Defines the chain-based modes, seperated by commas" );
107  comments.put(CARAVAIL, "Defines whether car availability must be considered or not. A agent has no car only if it has no license, or never access to a car" );
108  comments.put(SINGLE_PROBA, "Defines the probability of changing a single trip for a unchained mode instead of subtour.");
109  comments.put(COORD_DISTANCE, "If greater than 0, activities that are closer than coordDistance, to each other, will be considered part of the same subtour." +
110  "i.e. if two activities are close to each other, the agent is allowed to use the same 'chain-based' vehicle for both subtours.");
111 
112  {
113  StringBuilder msg = new StringBuilder("Only for backwards compatibility. Defines if only trips from modes list should change mode, or all trips. Options: ");
115  msg.append(behavior.name());
116  msg.append(' ');
117  }
118  comments.put(BEHAVIOR, msg.toString());
119  }
120  return comments;
121  }
122 
123  /* direct access */
124 
125  public void setModes( final String[] modes ) {
126  this.allModes = modes;
127  }
128 
129  public String[] getModes() {
130  return this.allModes;
131  }
132 
133  public void setChainBasedModes( final String[] modes ) {
134  this.chainBasedModes = modes;
135  }
136 
137  public String[] getChainBasedModes() {
138  return this.chainBasedModes;
139  }
140 
142  public void setConsiderCarAvailability(final boolean value) {
143  this.considerCarAvailability = value;
144  }
145 
147  public boolean considerCarAvailability() {
149  }
151  public final void setBehavior( SubtourModeChoice.Behavior behavior ) {
152  this.behavior = behavior ;
153  }
155  public final SubtourModeChoice.Behavior getBehavior() {
156  return this.behavior ;
157  }
158 
161  return this.probaForRandomSingleTripMode;
162  }
163 
167  }
168 
170  public double getCoordDistance() {
171  return coordDistance;
172  }
173 
175  public void setCoordDistance(double coordDistance) {
177  }
178 }
static String [] explode(final String str, final char delimiter, final int limit)
void setProbaForRandomSingleTripMode(double probaForRandomSingleTripMode)