SUMO - Simulation of Urban MObility
activitygen_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 /****************************************************************************/
7 //
8 // This program and the accompanying materials
9 // are made available under the terms of the Eclipse Public License v2.0
10 // which accompanies this distribution, and is available at
11 // http://www.eclipse.org/legal/epl-v20.html
12 //
13 /****************************************************************************/
23 // Main object of the ActivityGen application
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #ifdef HAVE_VERSION_H
37 #include <version.h>
38 #endif
39 
40 #include <iostream>
41 #include <exception>
42 #include <typeinfo>
43 #include <router/RONet.h>
44 #include <router/ROLoader.h>
45 #include <router/RONetHandler.h>
48 #include <utils/common/ToString.h>
49 #include <utils/xml/XMLSubSys.h>
56 //ActivityGen
57 #include "AGFrame.h"
58 #include "AGActivityGen.h"
59 #include "city/AGTime.h"
60 
61 
62 // ===========================================================================
63 // method definitions
64 // ===========================================================================
65 
67 void
70  std::string file = oc.getString("net-file");
71  if (file == "") {
72  throw ProcessError("Missing definition of network to load!");
73  }
74  if (!FileHelpers::isReadable(file)) {
75  throw ProcessError("The network file '" + file + "' could not be accessed.");
76  }
77  PROGRESS_BEGIN_MESSAGE("Loading net");
78  RONetHandler handler(toFill, eb);
79  handler.setFileName(file);
80  if (!XMLSubSys::runParser(handler, file, true)) {
82  throw ProcessError();
83  } else {
85  }
86  if (!deprecatedVehicleClassesSeen.empty()) {
87  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
89  }
90 }
91 
92 
93 int
94 main(int argc, char* argv[]) {
96  // give some application descriptions
98  "Generates routes of persons throughout a day for the microscopic road traffic simulation SUMO.");
99  oc.setApplicationName("activitygen", "SUMO activitygen Version " VERSION_STRING);
100  oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
101  int ret = 0;
102  RONet* net = 0;
103  try {
104  // Initialise subsystems and process options
105  XMLSubSys::init();
107  OptionsIO::setArgs(argc, argv);
109  if (oc.processMetaOptions(argc < 2)) {
111  return 0;
112  }
113  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
116 
117  // Load network
118  net = new RONet();
119  AGStreet::Builder builder;
120  loadNet(*net, builder);
121  WRITE_MESSAGE("Loaded " + toString(net->getEdgeNumber()) + " edges.");
122  if (oc.getBool("debug")) {
123  WRITE_MESSAGE("\n\t ---- begin AcitivtyGen ----\n");
124  }
125 
126  std::string statFile = oc.getString("stat-file");
127  OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
128  AGTime duration(oc.getInt("duration-d"), 0, 0);
129  AGTime begin(oc.getInt("begin") % 86400);
130  AGTime end(oc.getInt("end") % 86400);
131  AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
132  actiGen.importInfoCity();
133  actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
134 
135  if (oc.getBool("debug")) {
136  WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
137  }
138  ret = 0;
139  } catch (const ProcessError& e) {
140  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
141  WRITE_ERROR(e.what());
142  }
143  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
144  ret = 1;
145 #ifndef _DEBUG
146  } catch (const std::exception& e) {
147  if (std::string(e.what()) != std::string("")) {
148  WRITE_ERROR(e.what());
149  }
150  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
151  ret = 1;
152  } catch (...) {
153  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
154  ret = 1;
155 #endif
156  }
158  if (ret == 0) {
159  std::cout << "Success." << std::endl;
160  }
161  return ret;
162 }
163 
164 /****************************************************************************/
165 
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:645
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:53
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
std::set< std::string > deprecatedVehicleClassesSeen
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:82
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:53
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:64
Definition: AGTime.h:43
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:109
static void close()
Closes all of an applications subsystems.
Interface for building instances of router-edges.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:61
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
Central object handling City, Activities and Trips.
Definition: AGActivityGen.h:55
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:204
void setFileName(const std::string &name)
Sets the current file name.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:201
void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
#define VERSION_STRING
Definition: config.h:210
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
The router&#39;s network representation.
Definition: RONet.h:74
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:84
A storage for options typed value containers)
Definition: OptionsCont.h:98
The handler that parses a SUMO-network for its usage in a router.
Definition: RONetHandler.h:59
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:76
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:202
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:200
static void initOutputOptions()
Definition: MsgHandler.cpp:192
static void fillOptions()
Inserts options used by ActivityGen into the OptionsCont singleton.
Definition: AGFrame.cpp:51
int main(int argc, char *argv[])
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.