Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NGFrame.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2011-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 netgen
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
25#include "NGFrame.h"
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37void
40 oc.doRegister("type-files", 't', new Option_FileName());
41 oc.addDescription("type-files", "Input", TL("Read edge-type defs from FILE"));
42
43 oc.doRegister("alphanumerical-ids", new Option_Bool(true));
44 oc.addDescription("alphanumerical-ids", "Output", TL("The Ids of generated nodes use an alphanumerical code for easier readability when possible"));
45
46 // register processing options
47 oc.doRegister("turn-lanes", new Option_Integer(0));
48 oc.addDescription("turn-lanes", "Processing", TL("Generate INT left-turn lanes"));
49 oc.doRegister("turn-lanes.length", new Option_Float(20));
50 oc.addDescription("turn-lanes.length", "Processing", TL("Set the length of generated turning lanes to FLOAT"));
51
52 oc.doRegister("perturb-x", new Option_String("0"));
53 oc.addDescription("perturb-x", "Processing", TL("Apply random spatial perturbation in x direction according to the given distribution"));
54 oc.doRegister("perturb-y", new Option_String("0"));
55 oc.addDescription("perturb-y", "Processing", TL("Apply random spatial perturbation in y direction according to the given distribution"));
56 oc.doRegister("perturb-z", new Option_String("0"));
57 oc.addDescription("perturb-z", "Processing", TL("Apply random spatial perturbation in z direction according to the given distribution"));
58
59 oc.doRegister("bidi-probability", new Option_Float(1));
60 oc.addSynonyme("bidi-probability", "rand-bidi-probability", true);
61 oc.addSynonyme("bidi-probability", "rand.bidi-probability");
62 oc.addSynonyme("bidi-probability", "bidi");
63 oc.addDescription("bidi-probability", "Processing", TL("Defines the probability to build a reverse edge"));
64
65 oc.doRegister("random-lanenumber", new Option_Bool(false));
66 oc.addSynonyme("random-lanenumber", "rand.random-lanenumber", false);
67 oc.addDescription("random-lanenumber", "Processing", TL("Draw lane numbers randomly from [1,default.lanenumber]"));
68
69 oc.doRegister("random-priority", new Option_Bool(false));
70 oc.addSynonyme("random-priority", "rand.random-priority", false);
71 oc.addDescription("random-priority", "Processing", TL("Draw edge priority randomly from [1,default.priority]"));
72
73 oc.doRegister("random-type", new Option_Bool(false));
74 oc.addDescription("random-type", "Processing", TL("Draw edge type randomly from all loaded types"));
75
76
77 // register grid-net options
78 oc.doRegister("grid", 'g', new Option_Bool(false));
79 oc.addSynonyme("grid", "grid-net", true);
80 oc.addDescription("grid", "Grid Network", TL("Forces NETGEN to build a grid-like network"));
81
82 oc.doRegister("grid.number", new Option_Integer(5));
83 oc.addSynonyme("grid.number", "grid-number", true);
84 oc.addSynonyme("grid.number", "number");
85 oc.addDescription("grid.number", "Grid Network", TL("The number of junctions in both dirs"));
86
87 oc.doRegister("grid.length", new Option_Float(100));
88 oc.addSynonyme("grid.length", "grid-length", true);
89 oc.addSynonyme("grid.length", "length");
90 oc.addDescription("grid.length", "Grid Network", TL("The length of streets in both dirs"));
91
92 oc.doRegister("grid.x-number", new Option_Integer(5));
93 oc.addSynonyme("grid.x-number", "grid-x-number", true);
94 oc.addSynonyme("grid.x-number", "x-no");
95 oc.addDescription("grid.x-number", "Grid Network", TL("The number of junctions in x-dir; Overrides --grid-number"));
96
97 oc.doRegister("grid.y-number", new Option_Integer(5));
98 oc.addSynonyme("grid.y-number", "grid-y-number", true);
99 oc.addSynonyme("grid.y-number", "y-no");
100 oc.addDescription("grid.y-number", "Grid Network", TL("The number of junctions in y-dir; Overrides --grid-number"));
101
102 oc.doRegister("grid.x-length", new Option_Float(100));
103 oc.addSynonyme("grid.x-length", "grid-x-length", true);
104 oc.addSynonyme("grid.x-length", "x-length");
105 oc.addDescription("grid.x-length", "Grid Network", TL("The length of horizontal streets; Overrides --grid-length"));
106
107 oc.doRegister("grid.y-length", new Option_Float(100));
108 oc.addSynonyme("grid.y-length", "grid-y-length", true);
109 oc.addSynonyme("grid.y-length", "y-length");
110 oc.addDescription("grid.y-length", "Grid Network", TL("The length of vertical streets; Overrides --grid-length"));
111
112 oc.doRegister("grid.attach-length", new Option_Float(0));
113 oc.addSynonyme("grid.attach-length", "attach-length", true);
114 oc.addDescription("grid.attach-length", "Grid Network", TL("The length of streets attached at the boundary; 0 means no streets are attached"));
115
116 oc.doRegister("grid.x-attach-length", new Option_Float(0));
117 oc.addDescription("grid.x-attach-length", "Grid Network", TL("The length of streets attached at the boundary in x direction; 0 means no streets are attached"));
118 oc.doRegister("grid.y-attach-length", new Option_Float(0));
119 oc.addDescription("grid.y-attach-length", "Grid Network", TL("The length of streets attached at the boundary in y direction; 0 means no streets are attached"));
120
121 // register spider-net options
122 oc.doRegister("spider", 's', new Option_Bool(false));
123 oc.addSynonyme("spider", "spider-net", true);
124 oc.addDescription("spider", "Spider Network", TL("Forces NETGEN to build a spider-net-like network"));
125
126 oc.doRegister("spider.arm-number", new Option_Integer(7));
127 oc.addSynonyme("spider.arm-number", "spider-arm-number", true);
128 oc.addSynonyme("spider.arm-number", "arms");
129 oc.addDescription("spider.arm-number", "Spider Network", TL("The number of axes within the net"));
130
131 oc.doRegister("spider.circle-number", new Option_Integer(5));
132 oc.addSynonyme("spider.circle-number", "spider-circle-number", true);
133 oc.addSynonyme("spider.circle-number", "circles");
134 oc.addDescription("spider.circle-number", "Spider Network", TL("The number of circles of the net"));
135
136 oc.doRegister("spider.space-radius", new Option_Float(100));
137 oc.addSynonyme("spider.space-radius", "spider-space-rad", true);
138 oc.addSynonyme("spider.space-radius", "radius");
139 oc.addDescription("spider.space-radius", "Spider Network", TL("The distances between the circles"));
140
141 oc.doRegister("spider.omit-center", new Option_Bool(false));
142 oc.addSynonyme("spider.omit-center", "spider-omit-center", true);
143 oc.addSynonyme("spider.omit-center", "nocenter");
144 oc.addDescription("spider.omit-center", "Spider Network", TL("Omit the central node of the network"));
145
146 oc.doRegister("spider.attach-length", new Option_Float(0));
147 oc.addDescription("spider.attach-length", "Spider Network", TL("The length of streets attached at the boundary; 0 means no streets are attached"));
148
149 // register random-net options
150 oc.doRegister("rand", 'r', new Option_Bool(false));
151 oc.addSynonyme("rand", "random-net", true);
152 oc.addDescription("rand", "Random Network", TL("Forces NETGEN to build a random network"));
153
154 oc.doRegister("rand.iterations", new Option_Integer(100));
155 oc.addSynonyme("rand.iterations", "rand-iterations", true);
156 oc.addSynonyme("rand.iterations", "iterations");
157 oc.addDescription("rand.iterations", "Random Network", TL("Describes how many times an edge shall be added to the net"));
158
159 oc.doRegister("rand.max-distance", new Option_Float(250));
160 oc.addSynonyme("rand.max-distance", "rand-max-distance", true);
161 oc.addSynonyme("rand.max-distance", "max-dist");
162 oc.addDescription("rand.max-distance", "Random Network", TL("The maximum distance for each edge"));
163
164 oc.doRegister("rand.min-distance", new Option_Float(100));
165 oc.addSynonyme("rand.min-distance", "rand-min-distance", true);
166 oc.addSynonyme("rand.min-distance", "min-dist");
167 oc.addDescription("rand.min-distance", "Random Network", TL("The minimum distance for each edge"));
168
169 oc.doRegister("rand.min-angle", new Option_Float(45.0));
170 oc.addSynonyme("rand.min-angle", "rand-min-anglee", true);
171 oc.addSynonyme("rand.min-angle", "min-angle");
172 oc.addDescription("rand.min-angle", "Random Network", TL("The minimum angle for each pair of (bidirectional) roads in DEGREES"));
173
174 oc.doRegister("rand.num-tries", new Option_Integer(50));
175 oc.addSynonyme("rand.num-tries", "rand-num-tries", true);
176 oc.addSynonyme("rand.num-tries", "num-tries");
177 oc.addDescription("rand.num-tries", "Random Network", TL("The number of tries for creating each node"));
178
179 oc.doRegister("rand.connectivity", new Option_Float((double) 0.95));
180 oc.addSynonyme("rand.connectivity", "rand-connectivity", true);
181 oc.addSynonyme("rand.connectivity", "connectivity");
182 oc.addDescription("rand.connectivity", "Random Network", TL("Probability for roads to continue at each node"));
183
184 oc.doRegister("rand.neighbor-dist1", new Option_Float(0));
185 oc.addSynonyme("rand.neighbor-dist1", "rand-neighbor-dist1", true);
186 oc.addSynonyme("rand.neighbor-dist1", "dist1");
187 oc.addDescription("rand.neighbor-dist1", "Random Network", TL("Probability for a node having exactly 1 neighbor"));
188
189 oc.doRegister("rand.neighbor-dist2", new Option_Float(0));
190 oc.addSynonyme("rand.neighbor-dist2", "rand-neighbor-dist2", true);
191 oc.addSynonyme("rand.neighbor-dist2", "dist2");
192 oc.addDescription("rand.neighbor-dist2", "Random Network", TL("Probability for a node having exactly 2 neighbors"));
193
194 oc.doRegister("rand.neighbor-dist3", new Option_Float(10));
195 oc.addSynonyme("rand.neighbor-dist3", "rand-neighbor-dist3", true);
196 oc.addSynonyme("rand.neighbor-dist3", "dist3");
197 oc.addDescription("rand.neighbor-dist3", "Random Network", TL("Probability for a node having exactly 3 neighbors"));
198
199 oc.doRegister("rand.neighbor-dist4", new Option_Float(10));
200 oc.addSynonyme("rand.neighbor-dist4", "rand-neighbor-dist4", true);
201 oc.addSynonyme("rand.neighbor-dist4", "dist4");
202 oc.addDescription("rand.neighbor-dist4", "Random Network", TL("Probability for a node having exactly 4 neighbors"));
203
204 oc.doRegister("rand.neighbor-dist5", new Option_Float(2));
205 oc.addSynonyme("rand.neighbor-dist5", "rand-neighbor-dist5", true);
206 oc.addSynonyme("rand.neighbor-dist5", "dist5");
207 oc.addDescription("rand.neighbor-dist5", "Random Network", TL("Probability for a node having exactly 5 neighbors"));
208
209 oc.doRegister("rand.neighbor-dist6", new Option_Float(1));
210 oc.addSynonyme("rand.neighbor-dist6", "rand-neighbor-dist6", true);
211 oc.addSynonyme("rand.neighbor-dist6", "dist6");
212 oc.addDescription("rand.neighbor-dist6", "Random Network", TL("Probability for a node having exactly 6 neighbors"));
213
214 oc.doRegister("rand.grid", new Option_Bool(false));
215 oc.addDescription("rand.grid", "Random Network", TL("Place nodes on a regular grid with spacing rand.min-distance"));
216}
217
218
219bool
222 bool ok = true;
223 // check whether exactly one type of a network to build was wished
224 int no = 0;
225 if (oc.getBool("spider")) {
226 no++;
227 }
228 if (oc.getBool("grid")) {
229 no++;
230 }
231 if (oc.getBool("rand")) {
232 no++;
233 }
234 if (no == 0) {
235 WRITE_ERROR(TL("You have to specify the type of network to generate."));
236 ok = false;
237 }
238 if (no > 1) {
239 WRITE_ERROR(TL("You may specify only one type of network to generate at once."));
240 ok = false;
241 }
242 // check whether the junction type to use is properly set
243 if (oc.isSet("default-junction-type")) {
244 std::string type = oc.getString("default-junction-type");
257 WRITE_ERROR("Only the following junction types are known: " +
270 ok = false;
271 }
272 }
273 if (oc.getBool("random-type") && !oc.isSet("type-files")) {
274 WRITE_WARNING(TL("Option 'random-type' takes no effect unless 'type-files' are loaded"));
275 }
276 return ok;
277}
278
279
280/****************************************************************************/
#define WRITE_ERROR(msg)
Definition MsgHandler.h:304
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void fillOptions()
Inserts options used by the network generator.
Definition NGFrame.cpp:38
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition NGFrame.cpp:220
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)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.