SUMO - Simulation of Urban MObility
NIImporter_RobocupRescue.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Importer for networks stored in robocup rescue league format
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 #include <string>
36 #include <utils/common/ToString.h>
38 #include <netbuild/NBEdge.h>
39 #include <netbuild/NBEdgeCont.h>
40 #include <netbuild/NBNode.h>
41 #include <netbuild/NBNodeCont.h>
42 #include <netbuild/NBNetBuilder.h>
48 #include <utils/xml/XMLSubSys.h>
50 #include "NILoader.h"
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 // ---------------------------------------------------------------------------
62 // static methods (interface in this case)
63 // ---------------------------------------------------------------------------
64 void
66  // check whether the option is set (properly)
67  if (!oc.isSet("robocup-dir")) {
68  return;
69  }
70  // build the handler
72  // parse file(s)
73  std::vector<std::string> files = oc.getStringVector("robocup-dir");
74  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
75  // nodes
76  std::string nodesName = (*file) + "/node.bin";
77  if (!FileHelpers::isReadable(nodesName)) {
78  WRITE_ERROR("Could not open robocup-node-file '" + nodesName + "'.");
79  return;
80  }
81  PROGRESS_BEGIN_MESSAGE("Parsing robocup-nodes from '" + nodesName + "'");
82  handler.loadNodes(nodesName);
84  // edges
85  std::string edgesName = (*file) + "/road.bin";
86  if (!FileHelpers::isReadable(edgesName)) {
87  WRITE_ERROR("Could not open robocup-road-file '" + edgesName + "'.");
88  return;
89  }
90  PROGRESS_BEGIN_MESSAGE("Parsing robocup-roads from '" + edgesName + "'");
91  handler.loadEdges(edgesName);
93  }
94 }
95 
96 
97 
98 // ---------------------------------------------------------------------------
99 // loader methods
100 // ---------------------------------------------------------------------------
102  : myNodeCont(nc), myEdgeCont(ec) {}
103 
104 
106 }
107 
108 
109 void
110 NIImporter_RobocupRescue::loadNodes(const std::string& file) {
111  BinaryInputDevice dev(file);
112  unsigned int skip;
113  dev >> skip; // the number in 19_s
114  dev >> skip; // x-offset in 19_s
115  dev >> skip; // y-offset in 19_s
116  //
117  unsigned int noNodes;
118  dev >> noNodes;
119  WRITE_MESSAGE("Expected node number: " + toString(noNodes));
120  do {
121  //cout << " left " << (noNodes) << endl;
122  unsigned int entrySize, id, posX, posY, numEdges;
123  dev >> entrySize;
124  entrySize /= 4;
125  dev >> id;
126  dev >> posX;
127  dev >> posY;
128  dev >> numEdges;
129 
130  std::vector<int> edges;
131  for (unsigned int j = 0; j < numEdges; ++j) {
132  unsigned int edge;
133  dev >> edge;
134  edges.push_back(edge);
135  }
136 
137  unsigned int signal;
138  dev >> signal;
139 
140  std::vector<int> turns;
141  for (unsigned int j = 0; j < numEdges; ++j) {
142  unsigned int turn;
143  dev >> turn;
144  turns.push_back(turn);
145  }
146 
147  std::vector<std::pair<int, int> > conns;
148  for (unsigned int j = 0; j < numEdges; ++j) {
149  unsigned int connF, connT;
150  dev >> connF;
151  dev >> connT;
152  conns.push_back(std::pair<int, int>(connF, connT));
153  }
154 
155  std::vector<std::vector<int> > times;
156  for (unsigned int j = 0; j < numEdges; ++j) {
157  unsigned int t1, t2, t3;
158  dev >> t1;
159  dev >> t2;
160  dev >> t3;
161  std::vector<int> time;
162  time.push_back(t1);
163  time.push_back(t2);
164  time.push_back(t3);
165  times.push_back(time);
166  }
167 
168  Position pos((SUMOReal)(posX / 1000.), -(SUMOReal)(posY / 1000.));
170  NBNode* node = new NBNode(toString(id), pos);
171  myNodeCont.insert(node);
172  --noNodes;
173  } while (noNodes != 0);
174 }
175 
176 
177 void
178 NIImporter_RobocupRescue::loadEdges(const std::string& file) {
179  BinaryInputDevice dev(file);
180  unsigned int skip;
181  dev >> skip; // the number in 19_s
182  dev >> skip; // x-offset in 19_s
183  dev >> skip; // y-offset in 19_s
184  //
185  unsigned int noEdges;
186  dev >> noEdges;
187  std::cout << "Expected edge number: " << noEdges << std::endl;
188  do {
189  std::cout << " left " << (noEdges) << std::endl;
190  unsigned int entrySize, id, begNode, endNode, length, roadKind, carsToHead,
191  carsToTail, humansToHead, humansToTail, width, block, repairCost, median,
192  linesToHead, linesToTail, widthForWalkers;
193  dev >> entrySize >> id >> begNode >> endNode >> length >> roadKind >> carsToHead
194  >> carsToTail >> humansToHead >> humansToTail >> width >> block >> repairCost
195  >> median >> linesToHead >> linesToTail >> widthForWalkers;
196  NBNode* fromNode = myNodeCont.retrieve(toString(begNode));
197  NBNode* toNode = myNodeCont.retrieve(toString(endNode));
198  SUMOReal speed = (SUMOReal)(50. / 3.6);
199  int priority = -1;
200  LaneSpreadFunction spread = linesToHead > 0 && linesToTail > 0 ? LANESPREAD_RIGHT : LANESPREAD_CENTER;
201  if (linesToHead > 0) {
202  NBEdge* edge = new NBEdge(toString(id), fromNode, toNode, "", speed, linesToHead, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
203  if (!myEdgeCont.insert(edge)) {
204  WRITE_ERROR("Could not insert edge '" + toString(id) + "'");
205  }
206  }
207  if (linesToTail > 0) {
208  NBEdge* edge = new NBEdge("-" + toString(id), toNode, fromNode, "", speed, linesToTail, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
209  if (!myEdgeCont.insert(edge)) {
210  WRITE_ERROR("Could not insert edge '-" + toString(id) + "'");
211  }
212  }
213  --noEdges;
214  } while (noEdges != 0);
215 }
216 
217 
218 /****************************************************************************/
219 
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
static const SUMOReal UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:201
static bool transformCoordinates(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:58
Importer for networks stored in robocup rescue league format.
NIImporter_RobocupRescue(NBNodeCont &nc, NBEdgeCont &ec)
Constructor.
The representation of a single edge during network building.
Definition: NBEdge.h:71
static const SUMOReal UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:203
NBEdgeCont & myEdgeCont
The edge container to fill.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:170
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given RoboCup Rescue League files.
void loadNodes(const std::string &file)
Loads nodes from the given file.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
A storage for options typed value containers)
Definition: OptionsCont.h:108
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
NBNodeCont & myNodeCont
The node container to fill.
Represents a single node (junction) during network building.
Definition: NBNode.h:75
#define SUMOReal
Definition: config.h:218
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
void loadEdges(const std::string &file)
Loads edges from the given file.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
Encapsulates binary reading operations on a file.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.