Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/NIImporter_MATSim.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 NIImporter_MATSim.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @date Tue, 26.04.2011
18
///
19
// Importer for networks stored in MATSim format
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <string>
25
#include <map>
26
#include <netbuild/NBCapacity2Lanes.h>
27
#include <utils/xml/SUMOSAXHandler.h>
28
#include <utils/common/UtilExceptions.h>
29
30
31
// ===========================================================================
32
// class declarations
33
// ===========================================================================
34
class NBEdge;
35
class NBEdgeCont;
36
class NBNetBuilder;
37
class NBNode;
38
class NBNodeCont;
39
class NBTrafficLightLogicCont;
40
class NBTypeCont;
41
class OptionsCont;
42
43
44
// ===========================================================================
45
// class definitions
46
// ===========================================================================
47
/**
48
* @class NIImporter_MATSim
49
* @brief Importer for networks stored in MATSim format
50
*
51
*/
52
class NIImporter_MATSim {
53
public:
54
/** @brief Loads content of the optionally given MATSIM network files
55
*
56
* If the option "matsim-files" is set, the file(s) stored therein is read and
57
* the network definition stored therein is stored within the given network
58
* builder.
59
*
60
* If the option "matsim-files" is not set, this method simply returns.
61
*
62
* @param[in] oc The options to use
63
* @param[in] nb The network builder to fill
64
*/
65
static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
66
67
68
private:
69
/**
70
* @class NodesHandler
71
* @brief A class which extracts MATSIM-nodes from a parsed MATSIM-file
72
*/
73
class NodesHandler : public GenericSAXHandler {
74
public:
75
/** @brief Contructor
76
* @param[in] toFill The nodes container to fill
77
*/
78
NodesHandler(NBNodeCont& toFill);
79
80
81
/// @brief Destructor
82
~NodesHandler();
83
84
85
protected:
86
/// @name inherited from GenericSAXHandler
87
//@{
88
89
/** @brief Called on the opening of a tag;
90
*
91
* @param[in] element ID of the currently opened element
92
* @param[in] attrs Attributes within the currently opened element
93
* @exception ProcessError If something fails
94
* @see GenericSAXHandler::myStartElement
95
*/
96
void myStartElement(int element, const SUMOSAXAttributes& attrs);
97
//@}
98
99
100
private:
101
/// @brief The nodes container to fill
102
NBNodeCont& myNodeCont;
103
104
105
private:
106
/** @brief invalidated copy constructor */
107
NodesHandler(const NodesHandler& s);
108
109
/** @brief invalidated assignment operator */
110
NodesHandler& operator=(const NodesHandler& s);
111
112
};
113
114
115
116
/**
117
* @class EdgesHandler
118
* @brief A class which extracts MATSIM-edges from a parsed MATSIM-file
119
*/
120
class EdgesHandler : public GenericSAXHandler {
121
public:
122
/** @brief Constructor
123
*
124
* @param[in] nc The node container to retrieve nodes form
125
* @param[in, out] toFill The edges container to fill with read edges
126
* @param[in] keepEdgeLengths Whether the loaded lengths shal be used
127
* @param[in] lanesFromCapacity Whether the lane number shall be computed from the capacity
128
* @param[in] capacity2Lanes The converter from flow to lanes
129
*/
130
EdgesHandler(NBNodeCont& nc, NBEdgeCont& toFill,
131
bool keepEdgeLengths, bool lanesFromCapacity,
132
NBCapacity2Lanes capacity2Lanes);
133
134
135
/// @brief Destructor
136
~EdgesHandler();
137
138
139
protected:
140
/// @name inherited from GenericSAXHandler
141
//@{
142
143
/** @brief Called on the opening of a tag;
144
*
145
* @param[in] element ID of the currently opened element
146
* @param[in] attrs Attributes within the currently opened element
147
* @exception ProcessError If something fails
148
* @see GenericSAXHandler::myStartElement
149
*/
150
void myStartElement(int element, const SUMOSAXAttributes& attrs);
151
//@}
152
153
private:
154
void insertEdge(const std::string& id, NBNode* fromNode, NBNode* toNode, double freeSpeed, int numLanes, double capacity, double length, SVCPermissions perm = SVCAll);
155
SVCPermissions computePermission(std::string modes);
156
157
private:
158
/// @brief The previously parsed nodes
159
NBNodeCont& myNodeCont;
160
161
/// @brief The edge container to fill
162
NBEdgeCont& myEdgeCont;
163
164
/// @brief The capacity norming
165
double myCapacityNorm;
166
167
/// @brief Whether the loaded lengths shal be used
168
bool myKeepEdgeLengths;
169
170
/// @brief Whether the lane number shall be computed from the capacity
171
bool myLanesFromCapacity;
172
173
/// @brief The converter from flow to lanes
174
NBCapacity2Lanes myCapacity2Lanes;
175
176
177
private:
178
/** @brief invalidated copy constructor */
179
EdgesHandler(const EdgesHandler& s);
180
181
/** @brief invalidated assignment operator */
182
EdgesHandler& operator=(const EdgesHandler& s);
183
184
};
185
186
187
/**
188
* @enum MatsimXMLTag
189
* @brief Numbers representing MATSIM-XML - element names
190
* @see GenericSAXHandler
191
*/
192
enum MatsimXMLTag {
193
MATSIM_TAG_NOTHING = 0,
194
MATSIM_TAG_NETWORK,
195
MATSIM_TAG_NODE,
196
MATSIM_TAG_LINK,
197
MATSIM_TAG_LINKS
198
};
199
200
201
/**
202
* @enum MatsimXMLAttr
203
* @brief Numbers representing MATSIM-XML - attributes
204
* @see GenericSAXHandler
205
*/
206
enum MatsimXMLAttr {
207
MATSIM_ATTR_NOTHING = 0,
208
MATSIM_ATTR_ID,
209
MATSIM_ATTR_X,
210
MATSIM_ATTR_Y,
211
MATSIM_ATTR_FROM,
212
MATSIM_ATTR_TO,
213
MATSIM_ATTR_LENGTH,
214
MATSIM_ATTR_FREESPEED,
215
MATSIM_ATTR_CAPACITY,
216
MATSIM_ATTR_PERMLANES,
217
MATSIM_ATTR_ONEWAY,
218
MATSIM_ATTR_MODES,
219
MATSIM_ATTR_ORIGID,
220
MATSIM_ATTR_CAPPERIOD,
221
MATSIM_ATTR_CAPDIVIDER
222
};
223
224
/// The names of MATSIM-XML elements (for passing to GenericSAXHandler)
225
static SequentialStringBijection::Entry matsimTags[];
226
227
/// The names of MATSIM-XML attributes (for passing to GenericSAXHandler)
228
static SequentialStringBijection::Entry matsimAttrs[];
229
230
231
};
232
233