Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2014-2024 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 1689 : NWWriter_Amitran::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
43 : // check whether an amitran-file shall be generated
44 3378 : if (!oc.isSet("amitran-output")) {
45 1688 : return;
46 : }
47 : NBEdgeCont& ec = nb.getEdgeCont();
48 1 : OutputDevice& device = OutputDevice::getDevice(oc.getString("amitran-output"));
49 1 : device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
50 1 : 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 1 : int index = 0;
53 : NBNodeCont& nc = nb.getNodeCont();
54 : std::set<NBNode*> singleRoundaboutNodes;
55 : std::set<NBNode*> multiRoundaboutNodes;
56 1 : const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
57 2 : for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
58 7 : for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
59 6 : if ((*j)->getNumLanes() > 1) {
60 6 : multiRoundaboutNodes.insert((*j)->getFromNode());
61 : } else {
62 0 : singleRoundaboutNodes.insert((*j)->getFromNode());
63 : }
64 : }
65 : }
66 : std::map<NBNode*, int> nodeIds;
67 333 : for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
68 332 : device << " <node id=\"" << index;
69 332 : nodeIds[i->second] = index++;
70 0 : if (singleRoundaboutNodes.count(i->second) > 0) {
71 0 : device << "\" type=\"roundaboutSingle\"/>\n";
72 0 : continue;
73 : }
74 6 : if (multiRoundaboutNodes.count(i->second) > 0) {
75 6 : device << "\" type=\"roundaboutMulti\"/>\n";
76 6 : continue;
77 : }
78 326 : switch (i->second->getType()) {
79 1 : case SumoXMLNodeType::TRAFFIC_LIGHT:
80 : case SumoXMLNodeType::TRAFFIC_LIGHT_NOJUNCTION:
81 : case SumoXMLNodeType::TRAFFIC_LIGHT_RIGHT_ON_RED:
82 1 : device << "\" type=\"trafficLight";
83 : break;
84 217 : case SumoXMLNodeType::PRIORITY:
85 217 : device << "\" type=\"priority";
86 : break;
87 0 : case SumoXMLNodeType::PRIORITY_STOP:
88 0 : device << "\" type=\"priorityStop";
89 : break;
90 73 : case SumoXMLNodeType::RIGHT_BEFORE_LEFT:
91 73 : device << "\" type=\"rightBeforeLeft";
92 : break;
93 0 : case SumoXMLNodeType::LEFT_BEFORE_RIGHT:
94 0 : device << "\" type=\"leftBeforeRight";
95 : break;
96 0 : case SumoXMLNodeType::ALLWAY_STOP:
97 0 : device << "\" type=\"allwayStop";
98 : break;
99 0 : case SumoXMLNodeType::ZIPPER:
100 0 : device << "\" type=\"zipper";
101 : break;
102 0 : case SumoXMLNodeType::RAIL_SIGNAL:
103 0 : device << "\" type=\"railSignal";
104 : break;
105 0 : case SumoXMLNodeType::RAIL_CROSSING:
106 0 : device << "\" type=\"railCrossing";
107 : break;
108 35 : case SumoXMLNodeType::DEAD_END:
109 : case SumoXMLNodeType::DEAD_END_DEPRECATED:
110 35 : 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 326 : device << "\"/>\n";
119 : }
120 : // write edges
121 1 : index = 0;
122 701 : for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
123 700 : device << " <link id=\"" << index++
124 700 : << "\" from=\"" << nodeIds[i->second->getFromNode()]
125 700 : << "\" to=\"" << nodeIds[i->second->getToNode()]
126 700 : << "\" roadClass=\"" << NWWriter_DlrNavteq::getRoadClass((*i).second)
127 1400 : << "\" length=\"" << int(1000 * i->second->getLoadedLength())
128 700 : << "\" speedLimitKmh=\"" << int(3.6 * (*i).second->getSpeed() + 0.5)
129 1400 : << "\" laneNr=\"" << (*i).second->getNumLanes()
130 700 : << "\"/>\n";
131 : }
132 1 : device << "</network>\n";
133 1 : device.close();
134 : }
135 :
136 :
137 : /****************************************************************************/
|