Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netwrite/NWWriter_Amitran.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2014-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 NWWriter_Amitran.cpp
15
/// @author Michael Behrisch
16
/// @date 13.03.2014
17
///
18
// Exporter writing networks using the Amitran format
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <utils/common/MsgHandler.h>
23
#include <netbuild/NBEdge.h>
24
#include <netbuild/NBEdgeCont.h>
25
#include <netbuild/NBNode.h>
26
#include <netbuild/NBNodeCont.h>
27
#include <netbuild/NBNetBuilder.h>
28
#include <utils/options/OptionsCont.h>
29
#include <utils/iodevices/OutputDevice.h>
30
#include "NWWriter_DlrNavteq.h"
31
#include "NWWriter_Amitran.h"
32
33
34
35
// ===========================================================================
36
// method definitions
37
// ===========================================================================
38
// ---------------------------------------------------------------------------
39
// static methods
40
// ---------------------------------------------------------------------------
41
void
42
NWWriter_Amitran::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
43
// check whether an amitran-file shall be generated
44
if (!oc.isSet("amitran-output")) {
45
return;
46
}
47
NBEdgeCont& ec = nb.getEdgeCont();
48
OutputDevice& device = OutputDevice::getDevice(oc.getString("amitran-output"));
49
device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
50
device << "<network xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/amitran/network.xsd\">\n";
51
// write nodes
52
int index = 0;
53
NBNodeCont& nc = nb.getNodeCont();
54
std::set<NBNode*> singleRoundaboutNodes;
55
std::set<NBNode*> multiRoundaboutNodes;
56
const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
57
for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
58
for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
59
if ((*j)->getNumLanes() > 1) {
60
multiRoundaboutNodes.insert((*j)->getFromNode());
61
} else {
62
singleRoundaboutNodes.insert((*j)->getFromNode());
63
}
64
}
65
}
66
std::map<NBNode*, int> nodeIds;
67
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
68
device << " <node id=\"" << index;
69
nodeIds[i->second] = index++;
70
if (singleRoundaboutNodes.count(i->second) > 0) {
71
device << "\" type=\"roundaboutSingle\"/>\n";
72
continue;
73
}
74
if (multiRoundaboutNodes.count(i->second) > 0) {
75
device << "\" type=\"roundaboutMulti\"/>\n";
76
continue;
77
}
78
switch (i->second->getType()) {
79
case SumoXMLNodeType::TRAFFIC_LIGHT:
80
case SumoXMLNodeType::TRAFFIC_LIGHT_NOJUNCTION:
81
case SumoXMLNodeType::TRAFFIC_LIGHT_RIGHT_ON_RED:
82
device << "\" type=\"trafficLight";
83
break;
84
case SumoXMLNodeType::PRIORITY:
85
device << "\" type=\"priority";
86
break;
87
case SumoXMLNodeType::PRIORITY_STOP:
88
device << "\" type=\"priorityStop";
89
break;
90
case SumoXMLNodeType::RIGHT_BEFORE_LEFT:
91
device << "\" type=\"rightBeforeLeft";
92
break;
93
case SumoXMLNodeType::LEFT_BEFORE_RIGHT:
94
device << "\" type=\"leftBeforeRight";
95
break;
96
case SumoXMLNodeType::ALLWAY_STOP:
97
device << "\" type=\"allwayStop";
98
break;
99
case SumoXMLNodeType::ZIPPER:
100
device << "\" type=\"zipper";
101
break;
102
case SumoXMLNodeType::RAIL_SIGNAL:
103
device << "\" type=\"railSignal";
104
break;
105
case SumoXMLNodeType::RAIL_CROSSING:
106
device << "\" type=\"railCrossing";
107
break;
108
case SumoXMLNodeType::DEAD_END:
109
case SumoXMLNodeType::DEAD_END_DEPRECATED:
110
device << "\" type=\"deadEnd";
111
break;
112
case SumoXMLNodeType::DISTRICT:
113
case SumoXMLNodeType::NOJUNCTION:
114
case SumoXMLNodeType::INTERNAL:
115
case SumoXMLNodeType::UNKNOWN:
116
break;
117
}
118
device << "\"/>\n";
119
}
120
// write edges
121
index = 0;
122
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
123
device << " <link id=\"" << index++
124
<< "\" from=\"" << nodeIds[i->second->getFromNode()]
125
<< "\" to=\"" << nodeIds[i->second->getToNode()]
126
<< "\" roadClass=\"" << NWWriter_DlrNavteq::getRoadClass((*i).second)
127
<< "\" length=\"" << int(1000 * i->second->getLoadedLength())
128
<< "\" speedLimitKmh=\"" << int(3.6 * (*i).second->getSpeed() + 0.5)
129
<< "\" laneNr=\"" << (*i).second->getNumLanes()
130
<< "\"/>\n";
131
}
132
device << "</network>\n";
133
device.close();
134
}
135
136
137
/****************************************************************************/
138
139