Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netwrite/NWWriter_MATSim.cpp
169665 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 NWWriter_MATSim.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @date Tue, 04.05.2011
18
///
19
// Exporter writing networks using the MATSim format
20
/****************************************************************************/
21
#include <config.h>
22
#include "NWWriter_MATSim.h"
23
#include <utils/common/MsgHandler.h>
24
#include <netbuild/NBEdge.h>
25
#include <netbuild/NBEdgeCont.h>
26
#include <netbuild/NBNode.h>
27
#include <netbuild/NBNodeCont.h>
28
#include <netbuild/NBNetBuilder.h>
29
#include <utils/options/OptionsCont.h>
30
#include <utils/iodevices/OutputDevice.h>
31
32
33
34
// ===========================================================================
35
// method definitions
36
// ===========================================================================
37
// ---------------------------------------------------------------------------
38
// static methods
39
// ---------------------------------------------------------------------------
40
void
41
NWWriter_MATSim::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
42
// check whether a matsim-file shall be generated
43
if (!oc.isSet("matsim-output")) {
44
return;
45
}
46
OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
47
device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
48
device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
49
device << "<network name=\"NAME\">\n"; // !!! name
50
// write nodes
51
device << " <nodes>\n";
52
NBNodeCont& nc = nb.getNodeCont();
53
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
54
device << " <node id=\"" << (*i).first
55
<< "\" x=\"" << (*i).second->getPosition().x()
56
<< "\" y=\"" << (*i).second->getPosition().y()
57
<< "\"/>\n";
58
}
59
device << " </nodes>\n";
60
// write edges
61
device << " <links capperiod=\"01:00:00\">\n";
62
NBEdgeCont& ec = nb.getEdgeCont();
63
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
64
device << " <link id=\"" << (*i).first
65
<< "\" from=\"" << (*i).second->getFromNode()->getID()
66
<< "\" to=\"" << (*i).second->getToNode()->getID()
67
<< "\" length=\"" << (*i).second->getLoadedLength()
68
<< "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
69
<< "\" freespeed=\"" << (*i).second->getSpeed()
70
<< "\" permlanes=\"" << (*i).second->getNumLanes()
71
<< "\"/>\n";
72
}
73
device << " </links>\n";
74
//
75
device << "</network>\n"; // !!! name
76
device.close();
77
}
78
79
80
/****************************************************************************/
81
82