SUMO - Simulation of Urban MObility
activitygen_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // Main object of the ActivityGen application
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
15 // activitygen module
16 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #ifdef HAVE_VERSION_H
38 #include <version.h>
39 #endif
40 
41 #include <iostream>
42 #include <exception>
43 #include <typeinfo>
44 #include <router/RONet.h>
45 #include <router/ROLoader.h>
46 #include <router/RONetHandler.h>
49 #include <utils/common/ToString.h>
50 #include <utils/xml/XMLSubSys.h>
57 //ActivityGen
58 #include "AGFrame.h"
59 #include "AGActivityGen.h"
60 #include "city/AGTime.h"
61 
62 #ifdef CHECK_MEMORY_LEAKS
63 #include <foreign/nvwa/debug_new.h>
64 #endif // CHECK_MEMORY_LEAKS
65 
66 
67 // ===========================================================================
68 // method definitions
69 // ===========================================================================
70 
72 void
75  std::string file = oc.getString("net-file");
76  if (file == "") {
77  throw ProcessError("Missing definition of network to load!");
78  }
79  if (!FileHelpers::isReadable(file)) {
80  throw ProcessError("The network file '" + file + "' could not be accessed.");
81  }
82  PROGRESS_BEGIN_MESSAGE("Loading net");
83  RONetHandler handler(toFill, eb);
84  handler.setFileName(file);
85  if (!XMLSubSys::runParser(handler, file, true)) {
87  throw ProcessError();
88  } else {
90  }
91  if (!deprecatedVehicleClassesSeen.empty()) {
92  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
94  }
95 }
96 
97 
98 int
99 main(int argc, char* argv[]) {
101  // give some application descriptions
103  "Generates routes of persons throughout a day for the microscopic road traffic simulation SUMO.");
104  oc.setApplicationName("activitygen", "SUMO activitygen Version " VERSION_STRING);
105  oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
106  int ret = 0;
107  RONet* net = 0;
108  try {
109  // Initialise subsystems and process options
110  XMLSubSys::init();
112  OptionsIO::setArgs(argc, argv);
114  if (oc.processMetaOptions(argc < 2)) {
116  return 0;
117  }
118  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
121 
122  // Load network
123  net = new RONet();
124  AGStreet::Builder builder;
125  loadNet(*net, builder);
126  WRITE_MESSAGE("Loaded " + toString(net->getEdgeNo()) + " edges.");
127  if (oc.getBool("debug")) {
128  WRITE_MESSAGE("\n\t ---- begin AcitivtyGen ----\n");
129  }
130 
131  std::string statFile = oc.getString("stat-file");
132  OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
133  AGTime duration(1, 0, 0);
134  AGTime begin(0);
135  AGTime end(0);
136  if (oc.isSet("duration-d")) {
137  duration.setDay(oc.getInt("duration-d"));
138  }
139  if (oc.isSet("begin")) {
140  begin.addSeconds(oc.getInt("begin") % 86400);
141  }
142  if (oc.isSet("end")) {
143  end.addSeconds(oc.getInt("end") % 86400);
144  }
145  AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
146  actiGen.importInfoCity();
147  actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
148 
149  if (oc.getBool("debug")) {
150  WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
151  }
152  ret = 0;
153  } catch (const ProcessError& e) {
154  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
155  WRITE_ERROR(e.what());
156  }
157  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
158  ret = 1;
159 #ifndef _DEBUG
160  } catch (const std::exception& e) {
161  if (std::string(e.what()) != std::string("")) {
162  WRITE_ERROR(e.what());
163  }
164  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
165  ret = 1;
166  } catch (...) {
167  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
168  ret = 1;
169 #endif
170  }
172  if (ret == 0) {
173  std::cout << "Success." << std::endl;
174  }
175  return ret;
176 }
177 
178 /****************************************************************************/
179 
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:58
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
std::set< std::string > deprecatedVehicleClassesSeen
void setDay(int d)
Definition: AGTime.cpp:136
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:72
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:58
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:69
Definition: AGTime.h:44
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)
void makeActivityTrips(int days=1, int beginTime=0, int endTime=0)
build activities and trips of the population and generate routes
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:114
static void close()
Closes all of an applications subsystems.
Interface for building instances of router-edges.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:65
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
static void initRandGlobal(MTRand *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:68
Central object handling City, Activities and Trips.
Definition: AGActivityGen.h:56
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:205
void setFileName(const std::string &name)
Sets the current file name.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
int getEdgeNo() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:631
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
void addSeconds(int sec)
addition of seconds to the current moment
Definition: AGTime.cpp:188
#define VERSION_STRING
Definition: config.h:225
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
The router&#39;s network representation.
Definition: RONet.h:76
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:89
A storage for options typed value containers)
Definition: OptionsCont.h:99
void importInfoCity()
build the internal city
The handler that parses a SUMO-network for its usage in a router.
Definition: RONetHandler.h:60
int getTime()
: returns the number of seconds from the beginning of the first day of simulation this includes ...
Definition: AGTime.cpp:131
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:203
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
static void initOutputOptions()
Definition: MsgHandler.cpp:197
int getDay()
Definition: AGTime.cpp:106
static void fillOptions()
Inserts options used by ActivityGen into the OptionsCont singleton.
Definition: AGFrame.cpp:52
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
int main(int argc, char *argv[])
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.