001/* *********************************************************************** *
002 * project: org.matsim.*
003 * TransitConfigGroup.java
004 *                                                                         *
005 * *********************************************************************** *
006 *                                                                         *
007 * copyright       : (C) 2009 by the members listed in the COPYING,        *
008 *                   LICENSE and WARRANTY file.                            *
009 * email           : info at matsim dot org                                *
010 *                                                                         *
011 * *********************************************************************** *
012 *                                                                         *
013 *   This program is free software; you can redistribute it and/or modify  *
014 *   it under the terms of the GNU General Public License as published by  *
015 *   the Free Software Foundation; either version 2 of the License, or     *
016 *   (at your option) any later version.                                   *
017 *   See also COPYING, LICENSE and WARRANTY file                           *
018 *                                                                         *
019 * *********************************************************************** */
020
021package org.matsim.pt.config;
022
023import java.net.URL;
024import java.util.Collections;
025import java.util.HashSet;
026import java.util.LinkedHashSet;
027import java.util.Map;
028import java.util.Set;
029
030import org.matsim.api.core.v01.TransportMode;
031import org.matsim.core.config.ConfigGroup;
032import org.matsim.core.config.ReflectiveConfigGroup;
033import org.matsim.core.utils.collections.CollectionUtils;
034
035/**
036 * @author mrieser
037 */
038public class TransitConfigGroup extends ReflectiveConfigGroup {
039
040        public static final String GROUP_NAME = "transit";
041
042        /*package*/ static final String TRANSIT_SCHEDULE_FILE = "transitScheduleFile";
043        private static final String TRANSIT_LINES_ATTRIBUTES = "transitLinesAttributesFile";
044        private static final String TRANSIT_STOPS_ATTRIBUTES = "transitStopsAttributesFile";
045        /*package*/ static final String VEHICLES_FILE = "vehiclesFile";
046        /*package*/ static final String TRANSIT_MODES = "transitModes";
047        private static final String SCHEDULE_CRS = "inputScheduleCRS";
048
049        private static final String INSISTING_ON_USING_DEPRECATED_ATTRIBUTE_FILE = "insistingOnUsingDeprecatedAttributeFiles" ;
050        private static final String USING_TRANSIT_IN_MOBSIM = "usingTransitInMobsim" ;
051        
052        public static final String TRANSIT_ATTRIBUTES_DEPRECATION_MESSAGE = "using the separate transit stops and lines attribute files is deprecated." +
053                        "  Add the information directly into each stop or line, using " +
054                        "the Attributable feature.  If you insist on continuing to use the separate attribute files, set " +
055                        "insistingOnUsingDeprecatedAttributeFiles to true.  The files will then be read, but the values " +
056                        "will be entered into each stop or line using Attributable, and written as such to output_transitSchedule.";
057
058        private String transitScheduleFile = null;
059        private String vehiclesFile = null;
060        private String transitLinesAttributesFile = null;
061        private String transitStopsAttributesFile = null;
062        private String inputScheduleCRS = null;
063
064        private Set<String> transitModes;
065        
066        // ---
067        private static final String USE_TRANSIT = "useTransit";
068        private boolean useTransit = false;
069        private boolean insistingOnUsingDeprecatedAttributeFiles = false;
070
071        // ---
072
073        public TransitConfigGroup() {
074                super(GROUP_NAME);
075                Set<String> modes = new LinkedHashSet<>();
076                modes.add(TransportMode.pt);
077                this.transitModes = Collections.unmodifiableSet(modes);
078        }
079
080        @StringSetter( TRANSIT_MODES )
081        private void setTransitModes( final String value ) {
082                this.transitModes = Collections.unmodifiableSet(CollectionUtils.stringToSet(value));
083        }
084
085        @StringGetter( TRANSIT_MODES )
086        private String getTransitModeString() {
087                boolean isFirst = true;
088                StringBuilder str = new StringBuilder();
089                for (String mode : this.transitModes) {
090                        if (!isFirst) {
091                                str.append(',');
092                        }
093                        str.append(mode);
094                        isFirst = false;
095                }
096                return str.toString();
097        }
098
099        @Override
100        public Map<String, String> getComments() {
101                Map<String, String> comments = super.getComments();
102                comments.put(TRANSIT_SCHEDULE_FILE, "Input file containing the transit schedule to be simulated.");
103                comments.put(VEHICLES_FILE, "Input file containing the vehicles used by the departures in the transit schedule.");
104                comments.put(TRANSIT_MODES, "Comma-separated list of transportation modes that are handled as transit. Defaults to 'pt'.");
105                comments.put(TRANSIT_LINES_ATTRIBUTES, "Optional input file containing additional attributes for transit lines, stored as ObjectAttributes.");
106                comments.put(TRANSIT_STOPS_ATTRIBUTES, "Optional input file containing additional attributes for transit stop facilities, stored as ObjectAttributes.");
107                comments.put(USE_TRANSIT, "Set this parameter to true if transit should be simulated, false if not.");
108
109                comments.put( SCHEDULE_CRS , "The Coordinates Reference System in which the coordinates are expressed in the input file." +
110                                " At import, the coordinates will be converted to the coordinate system defined in \"global\", and will" +
111                                "be converted back at export. If not specified, no conversion happens." );
112                return comments;
113        }
114
115        @StringSetter( TRANSIT_SCHEDULE_FILE )
116        public void setTransitScheduleFile(final String filename) {
117                this.testForLocked();
118                this.transitScheduleFile = filename;
119        }
120
121        @StringGetter( TRANSIT_SCHEDULE_FILE )
122        public String getTransitScheduleFile() {
123                return this.transitScheduleFile;
124        }
125
126        public URL getTransitScheduleFileURL(URL context) {
127                return ConfigGroup.getInputFileURL(context, getTransitScheduleFile() ) ;
128        }
129
130        @StringSetter( VEHICLES_FILE )
131        public void setVehiclesFile(final String filename) {
132                this.vehiclesFile = filename;
133        }
134
135        @StringGetter( VEHICLES_FILE )
136        public String getVehiclesFile() {
137                return this.vehiclesFile;
138        }
139
140        public URL getVehiclesFileURL(URL context) {
141                return ConfigGroup.getInputFileURL(context, getVehiclesFile() ) ;
142        }
143
144        public void setTransitModes(final Set<String> modes) {
145                this.transitModes = Collections.unmodifiableSet(new HashSet<>(modes));
146        }
147
148        public Set<String> getTransitModes() {
149                return this.transitModes;
150        }
151
152        @StringGetter( TRANSIT_LINES_ATTRIBUTES )
153        public String getTransitLinesAttributesFile() {
154                return transitLinesAttributesFile;
155        }
156        
157        @StringSetter( TRANSIT_LINES_ATTRIBUTES )
158        public void setTransitLinesAttributesFile(final String transitLinesAttributesFile) {
159                this.transitLinesAttributesFile = transitLinesAttributesFile;
160        }
161
162        @StringGetter( TRANSIT_STOPS_ATTRIBUTES )
163        public String getTransitStopsAttributesFile() {
164                return this.transitStopsAttributesFile;
165        }
166        public URL getTransitStopsAttributesFileURL(URL context) {
167                return ConfigGroup.getInputFileURL(context, getTransitStopsAttributesFile()) ;
168        }
169        
170        @StringSetter( TRANSIT_STOPS_ATTRIBUTES )
171        public void setTransitStopsAttributesFile(final String transitStopsAttributesFile) {
172                this.transitStopsAttributesFile = transitStopsAttributesFile;
173        }
174        
175        @StringGetter( USE_TRANSIT )
176        public boolean isUseTransit() {
177                return this.useTransit;
178        }
179        @StringSetter( USE_TRANSIT )
180        public void setUseTransit( boolean val ) {
181                this.testForLocked();
182                this.useTransit = val ;
183        }
184
185
186        @StringGetter( SCHEDULE_CRS )
187        public String getInputScheduleCRS() {
188                return inputScheduleCRS;
189        }
190
191        @StringSetter( SCHEDULE_CRS )
192        public void setInputScheduleCRS(String inputScheduleCRS) {
193                this.inputScheduleCRS = inputScheduleCRS;
194        }
195        
196        public static final String BOARDING_ACCEPTANCE_CMT="under which conditions agent boards transit vehicle" ;
197        public enum BoardingAcceptance { checkLineAndStop, checkStopOnly }
198        private BoardingAcceptance boardingAcceptance = BoardingAcceptance.checkLineAndStop ;
199        public BoardingAcceptance getBoardingAcceptance() {
200                return this.boardingAcceptance;
201        }
202        public void setBoardingAcceptance(BoardingAcceptance boardingAcceptance) {
203                this.boardingAcceptance = boardingAcceptance;
204        }
205        
206        private boolean usingTransitInMobsim = true ;
207        @StringSetter( USING_TRANSIT_IN_MOBSIM )
208        public final void setUsingTransitInMobsim( boolean val ) {
209                usingTransitInMobsim = val ;
210        }
211        @StringGetter( USING_TRANSIT_IN_MOBSIM )
212        public final boolean isUsingTransitInMobsim(){
213                return usingTransitInMobsim ;
214        }
215
216        @StringSetter(INSISTING_ON_USING_DEPRECATED_ATTRIBUTE_FILE)
217        public final void setInsistingOnUsingDeprecatedAttributeFiles( boolean val ) {
218                this.insistingOnUsingDeprecatedAttributeFiles = val ;
219        }
220        @StringGetter(INSISTING_ON_USING_DEPRECATED_ATTRIBUTE_FILE)
221        public final boolean isInsistingOnUsingDeprecatedAttributeFiles() {
222                return insistingOnUsingDeprecatedAttributeFiles;
223        }
224
225}