Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 // SPDX-License-Identifier: EPL-2.0
11 /****************************************************************************/
21 // Main object of the ActivityGen application
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #ifdef HAVE_VERSION_H
31 #include <version.h>
32 #endif
33 
34 #include <iostream>
35 #include <exception>
36 #include <typeinfo>
37 #include <router/RONet.h>
38 #include <router/ROLoader.h>
39 #include <router/RONetHandler.h>
42 #include <utils/common/ToString.h>
43 #include <utils/xml/XMLSubSys.h>
50 //ActivityGen
51 #include "AGFrame.h"
52 #include "AGActivityGen.h"
53 #include "city/AGTime.h"
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
59 
61 void
64  std::string file = oc.getString("net-file");
65  if (file == "") {
66  throw ProcessError("Missing definition of network to load!");
67  }
68  if (!FileHelpers::isReadable(file)) {
69  throw ProcessError("The network file '" + file + "' could not be accessed.");
70  }
71  PROGRESS_BEGIN_MESSAGE("Loading net");
72  RONetHandler handler(toFill, eb, true, 0);
73  handler.setFileName(file);
74  if (!XMLSubSys::runParser(handler, file, true)) {
76  throw ProcessError();
77  } else {
79  }
80  if (!deprecatedVehicleClassesSeen.empty()) {
81  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
83  }
84 }
85 
86 
87 int
88 main(int argc, char* argv[]) {
90  // give some application descriptions
92  "Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO.");
93  oc.setApplicationName("activitygen", "Eclipse SUMO activitygen Version " VERSION_STRING);
94  oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
95  int ret = 0;
96  RONet* net = nullptr;
97  try {
98  // Initialise subsystems and process options
101  OptionsIO::setArgs(argc, argv);
103  if (oc.processMetaOptions(argc < 2)) {
105  return 0;
106  }
107  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
111 
112  // Load network
113  net = new RONet();
114  AGStreet::Builder builder;
115  loadNet(*net, builder);
116  WRITE_MESSAGE("Loaded " + toString(net->getEdgeNumber()) + " edges.");
117  if (oc.getBool("debug")) {
118  WRITE_MESSAGE("\n\t ---- begin AcitivtyGen ----\n");
119  }
120 
121  std::string statFile = oc.getString("stat-file");
122  OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
123  AGTime duration(oc.getInt("duration-d"), 0, 0);
124  AGTime begin(oc.getInt("begin") % 86400);
125  AGTime end(oc.getInt("end") % 86400);
126  AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
127  actiGen.importInfoCity();
128  actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
129 
130  if (oc.getBool("debug")) {
131  WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
132  }
133  ret = 0;
134  } catch (const ProcessError& e) {
135  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
136  WRITE_ERROR(e.what());
137  }
138  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
139  ret = 1;
140 #ifndef _DEBUG
141  } catch (const std::exception& e) {
142  if (std::string(e.what()) != std::string("")) {
143  WRITE_ERROR(e.what());
144  }
145  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
146  ret = 1;
147  } catch (...) {
148  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
149  ret = 1;
150 #endif
151  }
153  if (ret == 0) {
154  std::cout << "Success." << std::endl;
155  }
156  return ret;
157 }
158 
159 /****************************************************************************/
160 
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:649
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
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:76
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:49
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:59
Definition: AGTime.h:37
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:113
static void close()
Closes all of an applications subsystems.
Interface for building instances of router-edges.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Central object handling City, Activities and Trips.
Definition: AGActivityGen.h:49
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:244
void setFileName(const std::string &name)
Sets the current file name.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
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:241
static bool checkOptions()
checks shared options and sets StdDefs
void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
#define VERSION_STRING
Definition: config.h:207
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
The router&#39;s network representation.
Definition: RONet.h:64
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
A storage for options typed value containers)
Definition: OptionsCont.h:90
The handler that parses a SUMO-network for its usage in a router.
Definition: RONetHandler.h:53
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:72
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:242
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:240
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:208
static void fillOptions()
Inserts options used by ActivityGen into the OptionsCont singleton.
Definition: AGFrame.cpp:45
int main(int argc, char *argv[])
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.