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 
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:102
OptionsCont::getInt
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
Definition: OptionsCont.cpp:216
OptionsCont::processMetaOptions
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
Definition: OptionsCont.cpp:561
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:113
RONet::getEdgeNumber
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition: RONet.cpp:649
RONetHandler
The handler that parses a SUMO-network for its usage in a router.
Definition: RONetHandler.h:53
SystemFrame::close
static void close()
Closes all of an applications subsystems.
Definition: SystemFrame.cpp:131
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
MsgHandler::initOutputOptions
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:208
AGActivityGen
Central object handling City, Activities and Trips.
Definition: AGActivityGen.h:49
RONetHandler.h
PROGRESS_FAILED_MESSAGE
#define PROGRESS_FAILED_MESSAGE()
Definition: MsgHandler.h:244
OptionsCont.h
AGStreet::Builder
Definition: AGStreet.h:55
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:202
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:223
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
RONet
The router's network representation.
Definition: RONet.h:64
ROLoader.h
OptionsCont::addCopyrightNotice
void addCopyrightNotice(const std::string &copyrightLine)
Adds a copyright notice to the help output.
Definition: OptionsCont.cpp:511
AGTime
Definition: AGTime.h:37
AGFrame::fillOptions
static void fillOptions()
Inserts options used by ActivityGen into the OptionsCont singleton.
Definition: AGFrame.cpp:45
OptionsCont::setApplicationName
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
Definition: OptionsCont.cpp:485
SystemFrame.h
XMLSubSys::setValidation
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:59
RONet.h
OutputDevice.h
ProcessError
Definition: UtilExceptions.h:40
AGTime.h
XMLSubSys::init
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
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:72
OptionsIO::getOptions
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:76
OptionsCont::setApplicationDescription
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
Definition: OptionsCont.cpp:493
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:55
PROGRESS_BEGIN_MESSAGE
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:241
deprecatedVehicleClassesSeen
std::set< std::string > deprecatedVehicleClassesSeen
Definition: SUMOVehicleClass.cpp:85
PROGRESS_DONE_MESSAGE
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:242
loadNet
void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Definition: activitygen_main.cpp:62
OptionsIO::setArgs
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
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:118
main
int main(int argc, char *argv[])
Definition: activitygen_main.cpp:88
MsgHandler::getErrorInstance
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
VERSION_STRING
#define VERSION_STRING
Definition: config.h:207
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
AGFrame.h
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:240
ROAbstractEdgeBuilder
Interface for building instances of router-edges.
Definition: ROAbstractEdgeBuilder.h:54
OptionsIO.h
GenericSAXHandler::setFileName
void setFileName(const std::string &name)
Sets the current file name.
Definition: GenericSAXHandler.cpp:69
XMLSubSys.h