SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NWWriter_MATSim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Exporter writing networks using the MATSim format
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 #include "NWWriter_MATSim.h"
33 #include <netbuild/NBEdge.h>
34 #include <netbuild/NBEdgeCont.h>
35 #include <netbuild/NBNode.h>
36 #include <netbuild/NBNodeCont.h>
37 #include <netbuild/NBNetBuilder.h>
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 // ---------------------------------------------------------------------------
51 // static methods
52 // ---------------------------------------------------------------------------
53 void
55  // check whether a matsim-file shall be generated
56  if (!oc.isSet("matsim-output")) {
57  return;
58  }
59  OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
60  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
61  device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
62  device << "<network name=\"NAME\">\n"; // !!! name
63  // write nodes
64  device << " <nodes>\n";
65  NBNodeCont& nc = nb.getNodeCont();
66  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
67  device << " <node id=\"" << (*i).first
68  << "\" x=\"" << (*i).second->getPosition().x()
69  << "\" y=\"" << (*i).second->getPosition().y()
70  << "\"/>\n";
71  }
72  device << " </nodes>\n";
73  // write edges
74  device << " <links capperiod=\"01:00:00\">\n";
75  NBEdgeCont& ec = nb.getEdgeCont();
76  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
77  device << " <link id=\"" << (*i).first
78  << "\" from=\"" << (*i).second->getFromNode()->getID()
79  << "\" to=\"" << (*i).second->getToNode()->getID()
80  << "\" length=\"" << (*i).second->getLoadedLength()
81  << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
82  << "\" freespeed=\"" << (*i).second->getSpeed()
83  << "\" permlanes=\"" << (*i).second->getNumLanes()
84  << "\"/>\n";
85  }
86  device << " </links>\n";
87  //
88  device << "</network>\n"; // !!! name
89  device.close();
90 }
91 
92 
93 /****************************************************************************/
94