Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netload/NLBuilder.h
169666 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
// 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
123
/** @brief Closes the net building process
124
*
125
* Builds the microsim-structures which belong to a MSNet using the factories
126
* filled while loading. Initialises the network using these structures by calling
127
* MSNet::closeBuilding.
128
* If an error occurs, all built structures are deleted and a ProcessError is thrown.
129
* @exception ProcessError If the loaded structures could not be built
130
*/
131
void buildNet();
132
133
/// @brief build meanData definition based on option
134
void buildDefaultMeanData(const std::string& optionName, const std::string& id, bool useLanes);
135
136
/**
137
* @class EdgeFloatTimeLineRetriever_EdgeTravelTime
138
* @brief Obtains edge efforts from a weights handler and stores them within the edges
139
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever
140
*/
141
class EdgeFloatTimeLineRetriever_EdgeEffort : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {
142
public:
143
/// @brief Constructor
144
EdgeFloatTimeLineRetriever_EdgeEffort(MSNet& net) : myNet(net) {}
145
146
/// @brief Destructor
147
~EdgeFloatTimeLineRetriever_EdgeEffort() { }
148
149
/** @brief Adds an effort for a given edge and time period
150
*
151
* @param[in] id The id of the object to add a weight for
152
* @param[in] val The effort
153
* @param[in] beg The begin of the interval the weight is valid for
154
* @param[in] end The end of the interval the weight is valid for
155
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight
156
*/
157
void addEdgeWeight(const std::string& id,
158
double val, double beg, double end) const;
159
160
private:
161
/// @brief The network edges shall be obtained from
162
MSNet& myNet;
163
164
};
165
166
167
/**
168
* @class EdgeFloatTimeLineRetriever_EdgeTravelTime
169
* @brief Obtains edge travel times from a weights handler and stores them within the edges
170
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever
171
*/
172
class EdgeFloatTimeLineRetriever_EdgeTravelTime : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {
173
public:
174
/// @brief Constructor
175
EdgeFloatTimeLineRetriever_EdgeTravelTime(MSNet& net) : myNet(net) {}
176
177
/// @brief Destructor
178
~EdgeFloatTimeLineRetriever_EdgeTravelTime() { }
179
180
/** @brief Adds a travel time for a given edge and time period
181
*
182
* @param[in] id The id of the object to add a weight for
183
* @param[in] val The travel time
184
* @param[in] beg The begin of the interval the weight is valid for
185
* @param[in] end The end of the interval the weight is valid for
186
* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight
187
*/
188
void addEdgeWeight(const std::string& id,
189
double val, double beg, double end) const;
190
191
private:
192
/// @brief The network edges shall be obtained from
193
MSNet& myNet;
194
195
};
196
197
198
protected:
199
/// @brief The options to get the names of the files to load and further information from
200
OptionsCont& myOptions;
201
202
/// @brief The edge control builder to use
203
NLEdgeControlBuilder& myEdgeBuilder;
204
205
/// @brief The junction control builder to use
206
NLJunctionControlBuilder& myJunctionBuilder;
207
208
/// @brief The detector control builder to use
209
NLDetectorBuilder& myDetectorBuilder;
210
211
/// @brief The net to fill
212
MSNet& myNet;
213
214
/// @brief The handler used to parse the net
215
NLHandler& myXMLHandler;
216
217
218
private:
219
/// @brief invalidated copy operator
220
NLBuilder(const NLBuilder& s);
221
222
/// @brief invalidated assignment operator
223
NLBuilder& operator=(const NLBuilder& s);
224
225
};
226
227