Eclipse SUMO - Simulation of Urban MObility
ROJTRFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // Sets and checks options for jtr-routing
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <iostream>
25 #include <fstream>
26 #include <ctime>
28 #include <utils/options/Option.h>
31 #include <utils/common/ToString.h>
32 #include "ROJTRFrame.h"
33 #include <router/ROFrame.h>
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 void
45  oc.addCallExample("-c <CONFIGURATION>", "run with routing options defined in file");
46 
47  // insert options sub-topics
49  oc.addOptionSubTopic("Input");
50  oc.addOptionSubTopic("Output");
51  oc.addOptionSubTopic("Processing");
52  oc.addOptionSubTopic("Defaults");
53  oc.addOptionSubTopic("Time");
54 
56 
57  oc.doRegister("turn-ratio-files", 't', new Option_FileName());
58  oc.addSynonyme("turn-ratio-files", "turns");
59  oc.addDescription("turn-ratio-files", "Input", TL("Read turning ratios from FILE(s)"));
60 
61  oc.doRegister("exit-times", new Option_Bool(false));
62  oc.addDescription("exit-times", "Output", TL("Write exit times (weights) for each edge"));
63 
64  oc.doRegister("max-edges-factor", new Option_Float(2.0));
65  oc.addDescription("max-edges-factor", "Processing",
66  "Routes are cut off when the route edges to net edges ratio is larger than FLOAT");
67 
68  oc.doRegister("turn-defaults", 'T', new Option_StringVector(StringVector({ "30", "50", "20" })));
69  oc.addDescription("turn-defaults", "Processing", TL("Use STR[] as default turn definition"));
70 
71  oc.doRegister("sink-edges", new Option_StringVector());
72  oc.addSynonyme("sink-edges", "sinks");
73  oc.addDescription("sink-edges", "Processing", TL("Use STR[] as list of sink edges"));
74 
75  oc.doRegister("accept-all-destinations", 'A', new Option_Bool(false));
76  oc.addDescription("accept-all-destinations", "Processing", TL("Whether all edges are allowed as sink edges"));
77 
78  oc.doRegister("ignore-vclasses", 'i', new Option_Bool(false));
79  oc.addDescription("ignore-vclasses", "Processing", TL("Ignore road restrictions based on vehicle class"));
80 
81  oc.doRegister("allow-loops", new Option_Bool(false));
82  oc.addDescription("allow-loops", "Processing", TL("Allow to re-use a road"));
83 
84  oc.doRegister("sources-are-sinks", 'S', new Option_Bool(false));
85  oc.addDescription("sources-are-sinks", "Processing", TL("Use all source edges as sink edges."));
86 
87  oc.doRegister("discount-sources", 'D', new Option_Bool(false));
88  oc.addDescription("discount-sources", "Processing", TL("Subtract upstream flow when inserting a new flow. When option --sources-are-sinks is set, the upstream flow is limited to the value of the source flow and the remaining part terminates."));
89 
90  // add rand options
92 }
93 
94 
95 bool
98  bool ok = ROFrame::checkOptions(oc);
99  if (oc.isDefault("no-internal-links")) {
100  oc.setDefault("no-internal-links", "true");
101  }
102 
104  std::string error;
105  if (oc.isSet("departlane") && !SUMOVehicleParameter::parseDepartLane(oc.getString("departlane"), "option", "departlane", p.departLane, p.departLaneProcedure, error)) {
106  WRITE_ERROR(error);
107  ok = false;
108  }
109  if (oc.isSet("departpos") && !SUMOVehicleParameter::parseDepartPos(oc.getString("departpos"), "option", "departpos", p.departPos, p.departPosProcedure, error)) {
110  WRITE_ERROR(error);
111  ok = false;
112  }
113  if (oc.isSet("departspeed") && !SUMOVehicleParameter::parseDepartSpeed(oc.getString("departspeed"), "option", "departspeed", p.departSpeed, p.departSpeedProcedure, error)) {
114  WRITE_ERROR(error);
115  ok = false;
116  }
117  if (oc.isSet("arrivallane") && !SUMOVehicleParameter::parseArrivalLane(oc.getString("arrivallane"), "option", "arrivallane", p.arrivalLane, p.arrivalLaneProcedure, error)) {
118  WRITE_ERROR(error);
119  ok = false;
120  }
121  if (oc.isSet("arrivalpos") && !SUMOVehicleParameter::parseArrivalPos(oc.getString("arrivalpos"), "option", "arrivalpos", p.arrivalPos, p.arrivalPosProcedure, error)) {
122  WRITE_ERROR(error);
123  ok = false;
124  }
125  if (oc.isSet("arrivalspeed") && !SUMOVehicleParameter::parseArrivalSpeed(oc.getString("arrivalspeed"), "option", "arrivalspeed", p.arrivalSpeed, p.arrivalSpeedProcedure, error)) {
126  WRITE_ERROR(error);
127  ok = false;
128  }
129  return ok;
130 }
131 
132 
133 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:304
#define TL(string)
Definition: MsgHandler.h:315
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition: Option.h:42
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
Definition: OptionsCont.cpp:76
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
static bool checkOptions(OptionsCont &oc)
Checks whether options are valid.
Definition: ROFrame.cpp:233
static void fillOptions(OptionsCont &oc, const bool isDUA=false, const bool isMA=false)
Inserts options used by routing applications into the OptionsCont-singleton.
Definition: ROFrame.cpp:42
static void fillOptions()
Inserts options used by jtrrouter into the OptionsCont-singleton.
Definition: ROJTRFrame.cpp:43
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid for usage within jtrrouter.
Definition: ROJTRFrame.cpp:96
static void insertRandOptions(OptionsCont &oc)
Initialises the given options container with random number options.
Definition: RandHelper.cpp:59
Structure representing possible vehicle parameter.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
double departSpeed
(optional) The initial speed of the vehicle
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
double departPos
(optional) The position the vehicle shall depart from
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
double arrivalPos
(optional) The position the vehicle shall arrive on
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:38