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[]) {
89  // give some application descriptions
91  "Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO.");
92  oc.setApplicationName("activitygen", "Eclipse SUMO activitygen Version " VERSION_STRING);
93  oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
94  int ret = 0;
95  RONet* net = nullptr;
96  try {
97  // Initialise subsystems and process options
100  OptionsIO::setArgs(argc, argv);
102  if (oc.processMetaOptions(argc < 2)) {
104  return 0;
105  }
106  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
110 
111  // Load network
112  net = new RONet();
113  AGStreet::Builder builder;
114  loadNet(*net, builder);
115  WRITE_MESSAGE("Loaded " + toString(net->getEdgeNumber()) + " edges.");
116  if (oc.getBool("debug")) {
117  WRITE_MESSAGE(TL("\n\t ---- begin AcitivtyGen ----\n"));
118  }
119 
120  std::string statFile = oc.getString("stat-file");
121  OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
122  AGTime duration(oc.getInt("duration-d"), 0, 0);
123  AGTime begin(oc.getInt("begin") % 86400);
124  AGTime end(oc.getInt("end") % 86400);
125  AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
126  actiGen.importInfoCity();
127  actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
128 
129  if (oc.getBool("debug")) {
130  WRITE_MESSAGE(TL("\n\t ---- end of ActivityGen ----\n"));
131  }
132  ret = 0;
133  } catch (const ProcessError& e) {
134  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
135  WRITE_ERROR(e.what());
136  }
137  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
138  ret = 1;
139 #ifndef _DEBUG
140  } catch (const std::exception& e) {
141  if (std::string(e.what()) != std::string("")) {
142  WRITE_ERROR(e.what());
143  }
144  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
145  ret = 1;
146  } catch (...) {
147  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
148  ret = 1;
149 #endif
150  }
152  if (ret == 0) {
153  std::cout << "Success." << std::endl;
154  }
155  return ret;
156 }
157 
158 
159 /****************************************************************************/
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:267
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:274
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:265
#define TL(string)
Definition: MsgHandler.h:282
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:270
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:273
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:269
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:51
void setFileName(const std::string &name)
Sets the current file name.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:79
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:116
static void setupI18n(const std::string &locale="")
set up gettext stuff
Definition: MsgHandler.cpp:228
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:255
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:59
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:74
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, bool usePrefix=true)
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:759
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
Definition: RandHelper.cpp:87
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:137