Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2026 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>
41#include <utils/xml/XMLSubSys.h>
47//ActivityGen
48#include "AGFrame.h"
49#include "AGActivityGen.h"
50#include "city/AGTime.h"
51
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56
58void
61 std::string file = oc.getString("net-file");
62 if (file == "") {
63 throw ProcessError(TL("Missing definition of network to load!"));
64 }
65 if (!FileHelpers::isReadable(file)) {
66 throw ProcessError(TLF("The network file '%' could not be accessed.", file));
67 }
68 PROGRESS_BEGIN_MESSAGE(TL("Loading net"));
69 RONetHandler handler(toFill, eb, true, 0, 0, 0);
70 handler.setFileName(file);
71 if (!XMLSubSys::runParser(handler, file, true)) {
73 throw ProcessError();
74 } else {
76 }
77 if (!deprecatedVehicleClassesSeen.empty()) {
78 WRITE_WARNINGF(TL("Deprecated vehicle classes '%' in input network."), toString(deprecatedVehicleClassesSeen));
80 }
81}
82
83
84int
85main(int argc, char* argv[]) {
88 TL("Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO."));
89 oc.setApplicationName("activitygen", "Eclipse SUMO activitygen " VERSION_STRING);
90 oc.addCopyrightNotice("Copyright (C) 2010-2012 Technische Universitaet Muenchen");
91 int ret = 0;
92 RONet* net = nullptr;
93 try {
94 // Initialise subsystems and process options
97 OptionsIO::setArgs(argc, argv);
99 if (oc.processMetaOptions(argc < 2)) {
101 return 0;
102 }
103 XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
107
108 // Load network
109 net = new RONet();
110 AGStreet::Builder builder;
111 loadNet(*net, builder);
112 WRITE_MESSAGEF(TL("Loaded % edges."), toString(net->getEdgeNumber()));
113 if (oc.getBool("debug")) {
114 WRITE_MESSAGE("\n\t ---- begin ActivityGen ----\n");
115 }
116
117 std::string statFile = oc.getString("stat-file");
118 OptionsCont::createDeviceByOption("output-file", "routes", "routes_file.xsd");
119 AGTime duration(oc.getInt("duration-d"), 0, 0);
120 AGTime begin(oc.getInt("begin") % 86400);
121 AGTime end(oc.getInt("end") % 86400);
122 AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
123 actiGen.importInfoCity();
124 actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
125
126 if (oc.getBool("debug")) {
127 WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
128 }
129 ret = 0;
130 } catch (const ProcessError& e) {
131 if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
132 WRITE_ERROR(e.what());
133 }
134 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
135 ret = 1;
136#ifndef _DEBUG
137 } catch (const std::exception& e) {
138 if (std::string(e.what()) != std::string("")) {
139 WRITE_ERROR(e.what());
140 }
141 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
142 ret = 1;
143 } catch (...) {
144 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
145 ret = 1;
146#endif
147 }
149 if (ret == 0) {
150 std::cout << "Success." << std::endl;
151 }
152 return ret;
153}
154
155
156/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_MESSAGEF(...)
Definition MsgHandler.h:301
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:300
#define WRITE_ERROR(msg)
Definition MsgHandler.h:307
#define TL(string)
Definition MsgHandler.h:316
#define PROGRESS_DONE_MESSAGE()
Definition MsgHandler.h:303
#define TLF(string,...)
Definition MsgHandler.h:318
#define PROGRESS_FAILED_MESSAGE()
Definition MsgHandler.h:306
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition MsgHandler.h:302
std::set< std::string > deprecatedVehicleClassesSeen
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
int main(int argc, char *argv[])
void loadNet(RONet &toFill, ROAbstractEdgeBuilder &eb)
Loads the network.
Central object handling City, Activities and Trips.
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:44
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.
void setFileName(const std::string &name)
Sets the current file name.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
A storage for options typed value containers)
Definition OptionsCont.h:92
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)
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="", const int maximumDepth=2)
Creates the device using the output definition stored in the named option.
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.
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:59
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition OptionsIO.cpp:75
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.
The router's network representation.
Definition RONet.h:63
int getEdgeNumber() const
Returns the total number of edges the network contains including internal edges.
Definition RONet.cpp:887
static void close()
Closes all of an applications subsystems.
static bool checkOptions(OptionsCont &oc)
checks shared options and sets StdDefs
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
static void initOutputOptions()
init message output (console and log files) according to the options
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme, const std::string &routeValidationScheme)
Enables or disables validation.
Definition XMLSubSys.cpp:87
static void init()
Initialises the xml-subsystem.
Definition XMLSubSys.cpp:60
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.