Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 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 : /****************************************************************************/
16 : /// @file activitygen_main.cpp
17 : /// @author Piotr Woznica
18 : /// @author Walter Bamberger
19 : /// @author Daniel Krajzewicz
20 : /// @author Jakob Erdmann
21 : /// @author Michael Behrisch
22 : /// @date Tue, 20 Jul 2010
23 : ///
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>
38 : #include <utils/options/OptionsIO.h>
39 : #include <utils/common/MsgHandler.h>
40 : #include <utils/common/ToString.h>
41 : #include <utils/xml/XMLSubSys.h>
42 : #include <utils/common/FileHelpers.h>
43 : #include <utils/common/RandHelper.h>
44 : #include <utils/common/SystemFrame.h>
45 : #include <utils/options/OptionsCont.h>
46 : #include <utils/iodevices/OutputDevice.h>
47 : //ActivityGen
48 : #include "AGFrame.h"
49 : #include "AGActivityGen.h"
50 : #include "city/AGTime.h"
51 :
52 :
53 : // ===========================================================================
54 : // method definitions
55 : // ===========================================================================
56 :
57 : /// Loads the network
58 : void
59 10 : loadNet(RONet& toFill, ROAbstractEdgeBuilder& eb) {
60 10 : OptionsCont& oc = OptionsCont::getOptions();
61 10 : std::string file = oc.getString("net-file");
62 10 : if (file == "") {
63 0 : throw ProcessError(TL("Missing definition of network to load!"));
64 : }
65 20 : if (!FileHelpers::isReadable(file)) {
66 0 : throw ProcessError(TLF("The network file '%' could not be accessed.", file));
67 : }
68 20 : PROGRESS_BEGIN_MESSAGE(TL("Loading net"));
69 10 : RONetHandler handler(toFill, eb, true, 0, 0, 0);
70 10 : handler.setFileName(file);
71 10 : if (!XMLSubSys::runParser(handler, file, true)) {
72 0 : PROGRESS_FAILED_MESSAGE();
73 0 : throw ProcessError();
74 : } else {
75 10 : PROGRESS_DONE_MESSAGE();
76 : }
77 10 : if (!deprecatedVehicleClassesSeen.empty()) {
78 0 : WRITE_WARNINGF(TL("Deprecated vehicle classes '%' in input network."), toString(deprecatedVehicleClassesSeen));
79 : deprecatedVehicleClassesSeen.clear();
80 : }
81 20 : }
82 :
83 :
84 : int
85 14 : main(int argc, char* argv[]) {
86 14 : OptionsCont& oc = OptionsCont::getOptions();
87 14 : oc.setApplicationDescription(
88 14 : TL("Generates trips of persons throughout a day for the microscopic, multi-modal traffic simulation SUMO."));
89 28 : oc.setApplicationName("activitygen", "Eclipse SUMO activitygen " VERSION_STRING);
90 14 : 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
95 14 : XMLSubSys::init();
96 14 : AGFrame::fillOptions();
97 14 : OptionsIO::setArgs(argc, argv);
98 14 : OptionsIO::getOptions();
99 14 : if (oc.processMetaOptions(argc < 2)) {
100 4 : SystemFrame::close();
101 4 : return 0;
102 : }
103 30 : XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
104 10 : MsgHandler::initOutputOptions();
105 10 : RandHelper::initRandGlobal();
106 10 : SystemFrame::checkOptions(oc);
107 :
108 : // Load network
109 10 : net = new RONet();
110 : AGStreet::Builder builder;
111 10 : loadNet(*net, builder);
112 20 : WRITE_MESSAGEF(TL("Loaded % edges."), toString(net->getEdgeNumber()));
113 20 : if (oc.getBool("debug")) {
114 0 : WRITE_MESSAGE("\n\t ---- begin ActivityGen ----\n");
115 : }
116 :
117 10 : std::string statFile = oc.getString("stat-file");
118 20 : OutputDevice::createDeviceByOption("output-file", "routes", "routes_file.xsd");
119 10 : AGTime duration(oc.getInt("duration-d"), 0, 0);
120 10 : AGTime begin(oc.getInt("begin") % 86400);
121 10 : AGTime end(oc.getInt("end") % 86400);
122 32 : AGActivityGen actiGen(statFile, OutputDevice::getDevice(oc.getString("output-file")), net);
123 10 : actiGen.importInfoCity();
124 9 : actiGen.makeActivityTrips(duration.getDay(), begin.getTime(), end.getTime());
125 :
126 16 : if (oc.getBool("debug")) {
127 2 : WRITE_MESSAGE("\n\t ---- end of ActivityGen ----\n");
128 : }
129 : ret = 0;
130 2 : } catch (const ProcessError& e) {
131 4 : if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
132 2 : WRITE_ERROR(e.what());
133 : }
134 2 : MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
135 : ret = 1;
136 : #ifndef _DEBUG
137 2 : } catch (const std::exception& e) {
138 0 : if (std::string(e.what()) != std::string("")) {
139 0 : WRITE_ERROR(e.what());
140 : }
141 0 : MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
142 : ret = 1;
143 0 : } catch (...) {
144 0 : MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
145 : ret = 1;
146 : #endif
147 0 : }
148 10 : SystemFrame::close();
149 : if (ret == 0) {
150 : std::cout << "Success." << std::endl;
151 : }
152 : return ret;
153 : }
154 :
155 :
156 : /****************************************************************************/
|