Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/mesosim/METypeHandler.cpp
193717 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 METypeHandler.cpp
15
/// @author Jakob Erdmann
16
/// @date Jan 2026
17
///
18
// The XML-Handler for loading meso edge types
19
// This is a dedicated handler because meso types must be loaded from additional
20
// files before any other objects are loaded from them
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <string>
25
#include "METypeHandler.h"
26
#include <utils/xml/SUMOXMLDefinitions.h>
27
#include <utils/xml/SUMOSAXHandler.h>
28
#include <microsim/MSNet.h>
29
#include <mesosim/MESegment.h>
30
31
32
// ===========================================================================
33
// method definitions
34
// ===========================================================================
35
METypeHandler::METypeHandler(const std::string& file, MSNet& net) :
36
SUMOSAXHandler(file),
37
myNet(net),
38
myHaveSeenMesoEdgeType(false)
39
{
40
}
41
42
43
METypeHandler::~METypeHandler() {}
44
45
46
void
47
METypeHandler::myStartElement(int element,
48
const SUMOSAXAttributes& attrs) {
49
try {
50
switch (element) {
51
case SUMO_TAG_TYPE: {
52
bool ok = true;
53
myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
54
break;
55
}
56
case SUMO_TAG_MESO: {
57
addMesoEdgeType(attrs);
58
break;
59
}
60
default:
61
break;
62
}
63
} catch (InvalidArgument& e) {
64
WRITE_ERROR(e.what());
65
}
66
}
67
68
69
void
70
METypeHandler::myEndElement(int element) {
71
switch (element) {
72
case SUMO_TAG_TYPE:
73
myCurrentTypeID = "";
74
break;
75
default:
76
break;
77
}
78
}
79
80
81
82
void
83
METypeHandler::addMesoEdgeType(const SUMOSAXAttributes& attrs) {
84
bool ok = true;
85
MESegment::MesoEdgeType edgeType = myNet.getMesoType(""); // init defaults
86
edgeType.tauff = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUFF, myCurrentTypeID.c_str(), ok, edgeType.tauff);
87
edgeType.taufj = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUFJ, myCurrentTypeID.c_str(), ok, edgeType.taufj);
88
edgeType.taujf = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUJF, myCurrentTypeID.c_str(), ok, edgeType.taujf);
89
edgeType.taujj = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUJJ, myCurrentTypeID.c_str(), ok, edgeType.taujj);
90
edgeType.jamThreshold = attrs.getOpt<double>(SUMO_ATTR_JAM_DIST_THRESHOLD, myCurrentTypeID.c_str(), ok, edgeType.jamThreshold);
91
edgeType.junctionControl = attrs.getOpt<bool>(SUMO_ATTR_MESO_JUNCTION_CONTROL, myCurrentTypeID.c_str(), ok, edgeType.junctionControl);
92
edgeType.tlsPenalty = attrs.getOpt<double>(SUMO_ATTR_MESO_TLS_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.tlsPenalty);
93
edgeType.tlsFlowPenalty = attrs.getOpt<double>(SUMO_ATTR_MESO_TLS_FLOW_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.tlsFlowPenalty);
94
edgeType.minorPenalty = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_MINOR_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.minorPenalty);
95
edgeType.overtaking = attrs.getOpt<bool>(SUMO_ATTR_MESO_OVERTAKING, myCurrentTypeID.c_str(), ok, edgeType.overtaking);
96
edgeType.edgeLength = attrs.getOpt<double>(SUMO_ATTR_MESO_EDGELENGHT, myCurrentTypeID.c_str(), ok, edgeType.edgeLength);
97
98
if (ok) {
99
myNet.addMesoType(myCurrentTypeID, edgeType);
100
}
101
myHaveSeenMesoEdgeType = true;
102
}
103
104
105
/****************************************************************************/
106
107