Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netload/NLBuilder.h
193674 views
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
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file NLBuilder.h
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @date Mon, 9 Jul 2001
18
///
19
// The main interface for loading a microsim
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <string>
25
#include <map>
26
#include <vector>
27
#include <utils/xml/SAXWeightsHandler.h>
28
29
30
// ===========================================================================
31
// class declarations
32
// ===========================================================================
33
class MSNet;
34
class NLContainer;
35
class MSJunctionLogic;
36
class MSDetectorControl;
37
class OptionsCont;
38
class NLHandler;
39
class NLEdgeControlBuilder;
40
class NLJunctionControlBuilder;
41
class NLDetectorBuilder;
42
class NLTriggerBuilder;
43
class SUMORouteLoader;
44
class SUMORouteLoaderControl;
45
46
47
// ===========================================================================
48
// class definitions
49
// ===========================================================================
50
/**
51
* @class NLBuilder
52
* @brief The main interface for loading a microsim
53
*
54
* It is a black-box where only the options and factories must be supplied
55
* on the constructor call. An (empty) instance of the network must be
56
* supplied, too, and is filled during loading.
57
*/
58
class NLBuilder {
59
public:
60
/** @brief Constructor
61
*
62
* @param[in] oc The options to use
63
* @param[in, out] net The network to fill
64
* @param[in] eb The builder of edges to use
65
* @param[in] jb The builder of junctions to use
66
* @param[in] db The detector builder to use
67
* @param[in] tb The trigger builder to use
68
* @param[in] xmlHandler The xml handler to use
69
*/
70
NLBuilder(OptionsCont& oc, MSNet& net,
71
NLEdgeControlBuilder& eb, NLJunctionControlBuilder& jb,
72
NLDetectorBuilder& db,
73
NLHandler& xmlHandler);
74
75
76
/// @brief Destructor
77
virtual ~NLBuilder();
78
79
80
/** @brief Builds and initialises the simulation
81
*
82
* At first, the network is loaded and the built using "buildNet".
83
* If this could be done, additional information is loaded (state dump,
84
* weight files, route files, and additional files).
85
* If everything could be done, true is returned, otherwise false.
86
*
87
* @see buildNet
88
* @exception ProcessError If something fails on network building
89
* @todo Again, both returning a bool and throwing an exception; quite inconsistent
90
*/
91
virtual bool build();
92
93
/**
94
* loads the net, additional routes and the detectors
95
*/
96
static MSNet* init(const bool isLibsumo = false);
97
98
/// @brief initializes all RNGs
99
static void initRandomness();
100
101
/** @brief Builds the route loader control
102
*
103
* Goes through the list of route files to open defined in the option
104
* "route-files" and builds loaders reading these files
105
* @param[in] oc The options to read the list of route files to open from
106
* @return The built route loader control
107
* @exception ProcessError If an error occurred
108
*/
109
static SUMORouteLoaderControl* buildRouteLoaderControl(const OptionsCont& oc);
110
111
protected:
112
/** @brief Loads a described subpart form the given list of files
113
*
114
* Assuming the given string to be an option name behind which a list of files
115
* is stored, this method invokes an XML reader on all the files set for this option.
116
* @param[in] mmlWhat The option to get the file list from
117
* @param[in] isNet whether a network gets loaded
118
* @return Whether loading of all files was successful
119
*/
120
bool load(const std::string& mmlWhat, const bool isNet = false);
121
122
/// @brief loads meso edge types with a dedicated handler and return whether any were loaded
123
bool loadMesoEdgeTypes(const std::string& mmlWhat);
124
125
126
/** @brief Closes the net building process
127
*
128
* Builds the microsim-structures which belong to a MSNet using the factories
129
* filled while loading. Initialises the network using these structures by calling
130
* MSNet::closeBuilding.
131
* If an error occurs, all built structures are deleted and a ProcessError is thrown.
132
* @exception ProcessError If the loaded structures could not be built
133
*/
134
void buildNet();
135
136
/// @brief build meanData definition based on option
137
void buildDefaultMeanData(const std::string& optionName, const std::string& id, bool useLanes);
138
139
/**
140
* @class EdgeFloatTimeLineRetriever_EdgeTravelTime
141
* @brief Obtains edge efforts from a weights handler and stores them within the edges
142
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever
143
*/
144
class EdgeFloatTimeLineRetriever_EdgeEffort : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {
145
public:
146
/// @brief Constructor
147
EdgeFloatTimeLineRetriever_EdgeEffort(MSNet& net) : myNet(net) {}
148
149
/// @brief Destructor
150
~EdgeFloatTimeLineRetriever_EdgeEffort() { }
151
152
/** @brief Adds an effort for a given edge and time period
153
*
154
* @param[in] id The id of the object to add a weight for
155
* @param[in] val The effort
156
* @param[in] beg The begin of the interval the weight is valid for
157
* @param[in] end The end of the interval the weight is valid for
158
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight
159
*/
160
void addEdgeWeight(const std::string& id,
161
double val, double beg, double end) const;
162
163
private:
164
/// @brief The network edges shall be obtained from
165
MSNet& myNet;
166
167
};
168
169
170
/**
171
* @class EdgeFloatTimeLineRetriever_EdgeTravelTime
172
* @brief Obtains edge travel times from a weights handler and stores them within the edges
173
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever
174
*/
175
class EdgeFloatTimeLineRetriever_EdgeTravelTime : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {
176
public:
177
/// @brief Constructor
178
EdgeFloatTimeLineRetriever_EdgeTravelTime(MSNet& net) : myNet(net) {}
179
180
/// @brief Destructor
181
~EdgeFloatTimeLineRetriever_EdgeTravelTime() { }
182
183
/** @brief Adds a travel time for a given edge and time period
184
*
185
* @param[in] id The id of the object to add a weight for
186
* @param[in] val The travel time
187
* @param[in] beg The begin of the interval the weight is valid for
188
* @param[in] end The end of the interval the weight is valid for
189
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight
190
*/
191
void addEdgeWeight(const std::string& id,
192
double val, double beg, double end) const;
193
194
private:
195
/// @brief The network edges shall be obtained from
196
MSNet& myNet;
197
198
};
199
200
201
protected:
202
/// @brief The options to get the names of the files to load and further information from
203
OptionsCont& myOptions;
204
205
/// @brief The edge control builder to use
206
NLEdgeControlBuilder& myEdgeBuilder;
207
208
/// @brief The junction control builder to use
209
NLJunctionControlBuilder& myJunctionBuilder;
210
211
/// @brief The detector control builder to use
212
NLDetectorBuilder& myDetectorBuilder;
213
214
/// @brief The net to fill
215
MSNet& myNet;
216
217
/// @brief The handler used to parse the net
218
NLHandler& myXMLHandler;
219
220
221
private:
222
/// @brief invalidated copy operator
223
NLBuilder(const NLBuilder& s);
224
225
/// @brief invalidated assignment operator
226
NLBuilder& operator=(const NLBuilder& s);
227
228
};
229
230