SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
netgen_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Main for NETGEN
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #ifdef HAVE_VERSION_H
35 #include <version.h>
36 #endif
37 
38 #include <iostream>
39 #include <fstream>
40 #include <string>
41 #include <ctime>
42 #include <netgen/NGNet.h>
44 #include <netgen/NGFrame.h>
45 #include <netbuild/NBNetBuilder.h>
46 #include <netbuild/NBFrame.h>
47 #include <netwrite/NWFrame.h>
50 #include <utils/options/Option.h>
55 #include <utils/common/ToString.h>
57 #include <utils/xml/XMLSubSys.h>
59 
60 #ifdef CHECK_MEMORY_LEAKS
61 #include <foreign/nvwa/debug_new.h>
62 #endif // CHECK_MEMORY_LEAKS
63 
64 
65 // ===========================================================================
66 // method definitions
67 // ===========================================================================
68 void
71  oc.addCallExample("-c <CONFIGURATION>", "create net from given configuration");
72  oc.addCallExample("--grid [grid-network options] -o <OUTPUTFILE>", "create grid net");
73  oc.addCallExample("--spider [spider-network options] -o <OUTPUTFILE>", "create spider net");
74  oc.addCallExample("--rand [random-network options] -o <OUTPUTFILE>", "create random net");
75 
76  oc.setAdditionalHelpMessage(" Either \"--grid\", \"--spider\" or \"--rand\" must be supplied.\n In dependance to these switches other options are used.");
77 
78  // insert options sub-topics
79  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
80  oc.addOptionSubTopic("Grid Network");
81  oc.addOptionSubTopic("Spider Network");
82  oc.addOptionSubTopic("Random Network");
83  oc.addOptionSubTopic("Output");
84  oc.addOptionSubTopic("TLS Building");
85  //oc.addOptionSubTopic("Ramp Guessing");
86  oc.addOptionSubTopic("Edge Removal");
87  oc.addOptionSubTopic("Unregulated Nodes");
88  oc.addOptionSubTopic("Processing");
89  oc.addOptionSubTopic("Building Defaults");
90  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
91 
95  oc.doRegister("default-junction-type", 'j', new Option_String());
96  oc.addSynonyme("default-junction-type", "junctions");
97  oc.addDescription("default-junction-type", "Building Defaults", "[traffic_light|priority|right_before_left] Determines the type of the build junctions");
99 }
100 
101 
102 bool
104  bool ok = NGFrame::checkOptions();
105  ok &= NBFrame::checkOptions();
106  ok &= NWFrame::checkOptions();
107  return ok;
108 }
109 
110 
111 NGNet*
114  // spider-net
115  if (oc.getBool("spider")) {
116  // check values
117  bool hadError = false;
118  if (oc.getInt("spider.arm-number") < 3) {
119  WRITE_ERROR("Spider networks need at least 3 arms.");
120  hadError = true;
121  }
122  if (oc.getInt("spider.circle-number") < 1) {
123  WRITE_ERROR("Spider networks need at least one circle.");
124  hadError = true;
125  }
126  if (oc.getFloat("spider.space-radius") < 10) {
127  WRITE_ERROR("The radius of spider networks must be at least 10m.");
128  hadError = true;
129  }
130  if (hadError) {
131  throw ProcessError();
132  }
133  // build if everything's ok
134  NGNet* net = new NGNet(nb);
135  net->createSpiderWeb(oc.getInt("spider.arm-number"), oc.getInt("spider.circle-number"),
136  oc.getFloat("spider.space-radius"), !oc.getBool("spider.omit-center"));
137  return net;
138  }
139  // grid-net
140  if (oc.getBool("grid")) {
141  // get options
142  int xNo = oc.getInt("grid.x-number");
143  int yNo = oc.getInt("grid.y-number");
144  SUMOReal xLength = oc.getFloat("grid.x-length");
145  SUMOReal yLength = oc.getFloat("grid.y-length");
146  SUMOReal attachLength = oc.getFloat("grid.attach-length");
147  if (oc.isDefault("grid.x-number") && !oc.isDefault("grid.number")) {
148  xNo = oc.getInt("grid.number");
149  }
150  if (oc.isDefault("grid.y-number") && !oc.isDefault("grid.number")) {
151  yNo = oc.getInt("grid.number");
152  }
153  if (oc.isDefault("grid.x-length") && !oc.isDefault("grid.length")) {
154  xLength = oc.getFloat("grid.length");
155  }
156  if (oc.isDefault("grid.y-length") && !oc.isDefault("grid.length")) {
157  yLength = oc.getFloat("grid.length");
158  }
159  // check values
160  bool hadError = false;
161  if (xNo < 2 || yNo < 2) {
162  WRITE_ERROR("The number of nodes must be at least 2 in both directions.");
163  hadError = true;
164  }
165  if (xLength < 10. || yLength < 10.) {
166  WRITE_ERROR("The distance between nodes must be at least 10m in both directions.");
167  hadError = true;
168  }
169  if (attachLength != 0.0 && attachLength < 10.) {
170  WRITE_ERROR("The length of attached streets must be at least 10m.");
171  hadError = true;
172  }
173  if (hadError) {
174  throw ProcessError();
175  }
176  // build if everything's ok
177  NGNet* net = new NGNet(nb);
178  net->createChequerBoard(xNo, yNo, xLength, yLength, attachLength);
179  return net;
180  }
181  // random net
182  TNeighbourDistribution neighborDist;
183  neighborDist.add(1, oc.getFloat("rand.neighbor-dist1"));
184  neighborDist.add(2, oc.getFloat("rand.neighbor-dist2"));
185  neighborDist.add(3, oc.getFloat("rand.neighbor-dist3"));
186  neighborDist.add(4, oc.getFloat("rand.neighbor-dist4"));
187  neighborDist.add(5, oc.getFloat("rand.neighbor-dist5"));
188  neighborDist.add(6, oc.getFloat("rand.neighbor-dist6"));
189  NGNet* net = new NGNet(nb);
190  NGRandomNetBuilder randomNet(*net,
191  oc.getFloat("rand.min-angle"),
192  oc.getFloat("rand.min-distance"),
193  oc.getFloat("rand.max-distance"),
194  oc.getFloat("rand.connectivity"),
195  oc.getInt("rand.num-tries"),
196  neighborDist);
197  randomNet.createNet(oc.getInt("rand.iterations"));
198  return net;
199 }
200 
201 
202 
203 int
204 main(int argc, char** argv) {
206  // give some application descriptions
207  oc.setApplicationDescription("Road network generator for the microscopic road traffic simulation SUMO.");
208  oc.setApplicationName("netgen", "SUMO netgen Version " + (std::string)VERSION_STRING);
209  int ret = 0;
210  try {
211  // initialise the application system (messaging, xml, options)
212  XMLSubSys::init(false);
213  fillOptions();
214  OptionsIO::getOptions(true, argc, argv);
215  if (oc.processMetaOptions(argc < 2)) {
218  return 0;
219  }
221  if (!checkOptions()) {
222  throw ProcessError();
223  }
225  NBNetBuilder nb;
226  nb.applyOptions(oc);
227  // build the netgen-network description
228  NGNet* net = buildNetwork(nb);
229  // ... and we have to do this...
230  oc.resetWritable();
231  // transfer to the netbuilding structures
232  net->toNB();
233  delete net;
234  // report generated structures
235  WRITE_MESSAGE(" Generation done;");
236  WRITE_MESSAGE(" " + toString<int>(nb.getNodeCont().size()) + " nodes generated.");
237  WRITE_MESSAGE(" " + toString<int>(nb.getEdgeCont().size()) + " edges generated.");
238  nb.compute(oc);
239  NWFrame::writeNetwork(oc, nb);
240  } catch (ProcessError& e) {
241  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
242  WRITE_ERROR(e.what());
243  }
244  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
245  ret = 1;
246 #ifndef _DEBUG
247  } catch (...) {
248  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
249  ret = 1;
250 #endif
251  }
254  if (ret == 0) {
255  std::cout << "Success." << std::endl;
256  }
257  return ret;
258 }
259 
260 
261 
262 /****************************************************************************/
263