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 /****************************************************************************/
20 // Main object of the ActivityGen application
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #ifdef HAVE_VERSION_H
30 #include <version.h>
31 #endif
32 
33 #include <iostream>
34 #include <exception>
35 #include <typeinfo>
36 #include <router/RONet.h>
37 #include <router/ROLoader.h>
38 #include <router/RONetHandler.h>
41 #include <utils/common/ToString.h>
42 #include <utils/xml/XMLSubSys.h>
49 //ActivityGen
50 #include "AGFrame.h"
51 #include "AGActivityGen.h"
52 #include "city/AGTime.h"
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
58 
60 void
63  std::string file = oc.getString("net-file");
64  if (file == "") {
65  throw ProcessError("Missing definition of network to load!");
66  }
67  if (!FileHelpers::isReadable(file)) {
68  throw ProcessError("The network file '" + file + "' could not be accessed.");
69  }
70  PROGRESS_BEGIN_MESSAGE("Loading net");
71  RONetHandler handler(toFill, eb, true, 0);
72  handler.setFileName(file);
73  if (!XMLSubSys::runParser(handler, file, true)) {
75  throw ProcessError();
76  } else {
78  }
79  if (!deprecatedVehicleClassesSeen.empty()) {
80  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
82  }
83 }
84 
85 
86 int
87 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"));
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("\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("\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 
OutputDevice::createDeviceByOption
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.
Definition: OutputDevice.cpp:101
OptionsCont::getInt
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
Definition: OptionsCont.cpp:215
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:557
ToString.h
XMLSubSys::runParser
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:112
RONet::getEdgeNumber
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:648
RONetHandler
The handler that parses a SUMO-network for its usage in a router.
Definition: RONetHandler.h:52
SystemFrame::close
static void close()
Closes all of an applications subsystems.
Definition: SystemFrame.cpp:133
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MsgHandler::initOutputOptions
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:216
AGActivityGen
Central object handling City, Activities and Trips.
Definition: AGActivityGen.h:48
RONetHandler.h
PROGRESS_FAILED_MESSAGE
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:282
OptionsCont.h
AGStreet::Builder
Definition: AGStreet.h:54
MsgHandler.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
FileHelpers.h
MsgHandler::inform
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
RONet
The router's network representation.
Definition: RONet.h:63
ROLoader.h
OptionsCont::addCopyrightNotice
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
Definition: OptionsCont.cpp:507
AGTime
Definition: AGTime.h:36
AGFrame::fillOptions
static void fillOptions()
Inserts options used by ActivityGen into the OptionsCont singleton.
Definition: AGFrame.cpp:44
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:481
SystemFrame.h
XMLSubSys::setValidation
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:58
RONet.h
OutputDevice.h
ProcessError
Definition: UtilExceptions.h:39
AGTime.h
XMLSubSys::init
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:47
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
AGActivityGen.h
RandHelper::initRandGlobal
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance.
Definition: RandHelper.cpp:77
OptionsIO::getOptions
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:75
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:489
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:54
PROGRESS_BEGIN_MESSAGE
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:278
deprecatedVehicleClassesSeen
std::set< std::string > deprecatedVehicleClassesSeen
Definition: SUMOVehicleClass.cpp:84
PROGRESS_DONE_MESSAGE
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:279
loadNet
void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Definition: activitygen_main.cpp:61
OptionsIO::setArgs
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:54
FileHelpers::isReadable
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:49
config.h
RandHelper.h
SystemFrame::checkOptions
static bool checkOptions()
checks shared options and sets StdDefs
Definition: SystemFrame.cpp:120
main
int main(int argc, char *argv[])
Definition: activitygen_main.cpp:87
MsgHandler::getErrorInstance
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
VERSION_STRING
#define VERSION_STRING
Definition: config.h:210
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
AGFrame.h
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:277
ROAbstractEdgeBuilder
Interface for building instances of router-edges.
Definition: ROAbstractEdgeBuilder.h:53
OptionsIO.h
GenericSAXHandler::setFileName
void setFileName(const std::string &name)
Sets the current file name.
Definition: GenericSAXHandler.cpp:68
XMLSubSys.h