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.dev/sumo
3 // Copyright (C) 2001-2024 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(TL("Missing definition of network to load!"));
65  }
66  if (!FileHelpers::isReadable(file)) {
67  throw ProcessError(TLF("The network file '%' could not be accessed.", file));
68  }
69  PROGRESS_BEGIN_MESSAGE(TL("Loading net"));
70  RONetHandler handler(toFill, eb, true, 0, 0);
71  handler.setFileName(file);
72  if (!XMLSubSys::runParser(handler, file, true)) {
74  throw ProcessError();
75  } else {
77  }
78  if (!deprecatedVehicleClassesSeen.empty()) {
79  WRITE_WARNINGF(TL("Deprecated vehicle classes '%' in input network."), toString(deprecatedVehicleClassesSeen));
81  }
82 }
83 
84 
85 int
86 main(int argc, char* argv[]) {
89  TL("Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO."));
90  oc.setApplicationName("activitygen", "Eclipse SUMO activitygen Version " VERSION_STRING);
91  oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
92  int ret = 0;
93  RONet* net = nullptr;
94  try {
95  // Initialise subsystems and process options
98  OptionsIO::setArgs(argc, argv);
100  if (oc.processMetaOptions(argc < 2)) {
102  return 0;
103  }
104  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
108 
109  // Load network
110  net = new RONet();
111  AGStreet::Builder builder;
112  loadNet(*net, builder);
113  WRITE_MESSAGEF(TL("Loaded % edges."), toString(net->getEdgeNumber()));
114  if (oc.getBool("debug")) {
115  WRITE_MESSAGE("\n\t ---- begin ActivityGen ----\n");
116  }
117 
118  std::string statFile = oc.getString("stat-file");
119  OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
120  AGTime duration(oc.getInt("duration-d"), 0, 0);
121  AGTime begin(oc.getInt("begin") % 86400);
122  AGTime end(oc.getInt("end") % 86400);
123  AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
124  actiGen.importInfoCity();
125  actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
126 
127  if (oc.getBool("debug")) {
128  WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
129  }
130  ret = 0;
131  } catch (const ProcessError& e) {
132  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
133  WRITE_ERROR(e.what());
134  }
135  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
136  ret = 1;
137 #ifndef _DEBUG
138  } catch (const std::exception& e) {
139  if (std::string(e.what()) != std::string("")) {
140  WRITE_ERROR(e.what());
141  }
142  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
143  ret = 1;
144  } catch (...) {
145  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
146  ret = 1;
147 #endif
148  }
150  if (ret == 0) {
151  std::cout << "Success." << std::endl;
152  }
153  return ret;
154 }
155 
156 
157 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define WRITE_MESSAGEF(...)
Definition: MsgHandler.h:298
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:297
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:304
#define TL(string)
Definition: MsgHandler.h:315
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:300
#define TLF(string,...)
Definition: MsgHandler.h:317
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:303
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:299
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:92
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:154
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:316
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:60
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:793
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(OptionsCont &oc)
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:83
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:56
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:148