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-2022 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 are made available under the
7 // terms of the Eclipse Public License 2.0 which is available at
8 // https://www.eclipse.org/legal/epl-2.0/
9 // This Source Code may also be made available under the following Secondary
10 // Licenses when the conditions for such availability set forth in the Eclipse
11 // Public License 2.0 are satisfied: GNU General Public License, version 2
12 // or later which is available at
13 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15 /****************************************************************************/
24 // Main object of the ActivityGen application
25 /****************************************************************************/
26 #include <config.h>
27 
28 #ifdef HAVE_VERSION_H
29 #include <version.h>
30 #endif
31 
32 #include <iostream>
33 #include <exception>
34 #include <typeinfo>
35 #include <router/RONet.h>
36 #include <router/ROLoader.h>
37 #include <router/RONetHandler.h>
40 #include <utils/common/ToString.h>
41 #include <utils/xml/XMLSubSys.h>
48 //ActivityGen
49 #include "AGFrame.h"
50 #include "AGActivityGen.h"
51 #include "city/AGTime.h"
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 
59 void
62  std::string file = oc.getString("net-file");
63  if (file == "") {
64  throw ProcessError("Missing definition of network to load!");
65  }
66  if (!FileHelpers::isReadable(file)) {
67  throw ProcessError("The network file '" + file + "' could not be accessed.");
68  }
69  PROGRESS_BEGIN_MESSAGE("Loading net");
70  RONetHandler handler(toFill, eb, true, 0);
71  handler.setFileName(file);
72  if (!XMLSubSys::runParser(handler, file, true)) {
74  throw ProcessError();
75  } else {
77  }
78  if (!deprecatedVehicleClassesSeen.empty()) {
79  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
81  }
82 }
83 
84 
85 int
86 main(int argc, char* argv[]) {
88  // give some application descriptions
90  "Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO.");
91  oc.setApplicationName("activitygen", "Eclipse SUMO activitygen Version " VERSION_STRING);
92  oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
93  int ret = 0;
94  RONet* net = nullptr;
95  try {
96  // Initialise subsystems and process options
99  OptionsIO::setArgs(argc, argv);
101  if (oc.processMetaOptions(argc < 2)) {
103  return 0;
104  }
105  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
109 
110  // Load network
111  net = new RONet();
112  AGStreet::Builder builder;
113  loadNet(*net, builder);
114  WRITE_MESSAGE("Loaded " + toString(net->getEdgeNumber()) + " edges.");
115  if (oc.getBool("debug")) {
116  WRITE_MESSAGE("\n\t ---- begin AcitivtyGen ----\n");
117  }
118 
119  std::string statFile = oc.getString("stat-file");
120  OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
121  AGTime duration(oc.getInt("duration-d"), 0, 0);
122  AGTime begin(oc.getInt("begin") % 86400);
123  AGTime end(oc.getInt("end") % 86400);
124  AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
125  actiGen.importInfoCity();
126  actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
127 
128  if (oc.getBool("debug")) {
129  WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
130  }
131  ret = 0;
132  } catch (const ProcessError& e) {
133  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
134  WRITE_ERROR(e.what());
135  }
136  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
137  ret = 1;
138 #ifndef _DEBUG
139  } catch (const std::exception& e) {
140  if (std::string(e.what()) != std::string("")) {
141  WRITE_ERROR(e.what());
142  }
143  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
144  ret = 1;
145  } catch (...) {
146  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
147  ret = 1;
148 #endif
149  }
151  if (ret == 0) {
152  std::cout << "Success." << std::endl;
153  }
154  return ret;
155 }
156 
157 
158 /****************************************************************************/
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:282
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:284
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:287
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:283
std::set< std::string > deprecatedVehicleClassesSeen
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
int main(int argc, char *argv[])
void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Central object handling City, Activities and Trips.
Definition: AGActivityGen.h:46
void importInfoCity()
build the internal city
void makeActivityTrips(int days=1, int beginTime=0, int endTime=0)
build activities and trips of the population and generate routes
static void fillOptions()
Inserts options used by ActivityGen into the OptionsCont singleton.
Definition: AGFrame.cpp:43
Definition: AGTime.h:34
int getTime()
: returns the number of seconds from the beginning of the first day of simulation this includes
Definition: AGTime.cpp:122
int getDay()
Definition: AGTime.cpp:97
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:49
void setFileName(const std::string &name)
Sets the current file name.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:117
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:228
A storage for options typed value containers)
Definition: OptionsCont.h:89
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
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 OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:58
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:85
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.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Interface for building instances of router-edges.
The handler that parses a SUMO-network for its usage in a router.
Definition: RONetHandler.h:50
The router's network representation.
Definition: RONet.h:62
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:741
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
Definition: RandHelper.cpp:75
static void close()
Closes all of an applications subsystems.
static bool checkOptions()
checks shared options and sets StdDefs
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme, const std::string &routeValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:65
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:54
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:149