Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/activitygen_main.cpp
169665 views
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
#include <utils/iodevices/OutputDevice.h>
48
//ActivityGen
49
#include "AGFrame.h"
50
#include "AGActivityGen.h"
51
#include "city/AGTime.h"
52
53
54
// ===========================================================================
55
// method definitions
56
// ===========================================================================
57
58
/// Loads the network
59
void
60
loadNet(RONet& toFill, ROAbstractEdgeBuilder& eb) {
61
OptionsCont& oc = OptionsCont::getOptions();
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, 0);
71
handler.setFileName(file);
72
if (!XMLSubSys::runParser(handler, file, true)) {
73
PROGRESS_FAILED_MESSAGE();
74
throw ProcessError();
75
} else {
76
PROGRESS_DONE_MESSAGE();
77
}
78
if (!deprecatedVehicleClassesSeen.empty()) {
79
WRITE_WARNINGF(TL("Deprecated vehicle classes '%' in input network."), toString(deprecatedVehicleClassesSeen));
80
deprecatedVehicleClassesSeen.clear();
81
}
82
}
83
84
85
int
86
main(int argc, char* argv[]) {
87
OptionsCont& oc = OptionsCont::getOptions();
88
oc.setApplicationDescription(
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_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
96
XMLSubSys::init();
97
AGFrame::fillOptions();
98
OptionsIO::setArgs(argc, argv);
99
OptionsIO::getOptions();
100
if (oc.processMetaOptions(argc < 2)) {
101
SystemFrame::close();
102
return 0;
103
}
104
XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), "never");
105
MsgHandler::initOutputOptions();
106
RandHelper::initRandGlobal();
107
SystemFrame::checkOptions(oc);
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
}
149
SystemFrame::close();
150
if (ret == 0) {
151
std::cout << "Success." << std::endl;
152
}
153
return ret;
154
}
155
156
157
/****************************************************************************/
158
159