SUMO - Simulation of Urban MObility
NIImporter_RobocupRescue.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Importer for networks stored in robocup rescue league format
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 <string>
35 #include <utils/common/ToString.h>
37 #include <netbuild/NBEdge.h>
38 #include <netbuild/NBEdgeCont.h>
39 #include <netbuild/NBNode.h>
40 #include <netbuild/NBNodeCont.h>
41 #include <netbuild/NBNetBuilder.h>
47 #include <utils/xml/XMLSubSys.h>
49 #include "NILoader.h"
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 // ---------------------------------------------------------------------------
57 // static methods (interface in this case)
58 // ---------------------------------------------------------------------------
59 void
61  // check whether the option is set (properly)
62  if (!oc.isSet("robocup-dir")) {
63  return;
64  }
65  // build the handler
67  // parse file(s)
68  std::vector<std::string> files = oc.getStringVector("robocup-dir");
69  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
70  // nodes
71  std::string nodesName = (*file) + "/node.bin";
72  if (!FileHelpers::isReadable(nodesName)) {
73  WRITE_ERROR("Could not open robocup-node-file '" + nodesName + "'.");
74  return;
75  }
76  PROGRESS_BEGIN_MESSAGE("Parsing robocup-nodes from '" + nodesName + "'");
77  handler.loadNodes(nodesName);
79  // edges
80  std::string edgesName = (*file) + "/road.bin";
81  if (!FileHelpers::isReadable(edgesName)) {
82  WRITE_ERROR("Could not open robocup-road-file '" + edgesName + "'.");
83  return;
84  }
85  PROGRESS_BEGIN_MESSAGE("Parsing robocup-roads from '" + edgesName + "'");
86  handler.loadEdges(edgesName);
88  }
89 }
90 
91 
92 
93 // ---------------------------------------------------------------------------
94 // loader methods
95 // ---------------------------------------------------------------------------
97  : myNodeCont(nc), myEdgeCont(ec) {}
98 
99 
101 }
102 
103 
104 void
105 NIImporter_RobocupRescue::loadNodes(const std::string& file) {
106  BinaryInputDevice dev(file);
107  int skip;
108  dev >> skip; // the number in 19_s
109  dev >> skip; // x-offset in 19_s
110  dev >> skip; // y-offset in 19_s
111  //
112  int noNodes;
113  dev >> noNodes;
114  WRITE_MESSAGE("Expected node number: " + toString(noNodes));
115  do {
116  //cout << " left " << (noNodes) << endl;
117  int entrySize, id, posX, posY, numEdges;
118  dev >> entrySize;
119  entrySize /= 4;
120  dev >> id;
121  dev >> posX;
122  dev >> posY;
123  dev >> numEdges;
124 
125  std::vector<int> edges;
126  for (int j = 0; j < numEdges; ++j) {
127  int edge;
128  dev >> edge;
129  edges.push_back(edge);
130  }
131 
132  int signal;
133  dev >> signal;
134 
135  std::vector<int> turns;
136  for (int j = 0; j < numEdges; ++j) {
137  int turn;
138  dev >> turn;
139  turns.push_back(turn);
140  }
141 
142  std::vector<std::pair<int, int> > conns;
143  for (int j = 0; j < numEdges; ++j) {
144  int connF, connT;
145  dev >> connF;
146  dev >> connT;
147  conns.push_back(std::pair<int, int>(connF, connT));
148  }
149 
150  std::vector<std::vector<int> > times;
151  for (int j = 0; j < numEdges; ++j) {
152  int t1, t2, t3;
153  dev >> t1;
154  dev >> t2;
155  dev >> t3;
156  std::vector<int> time;
157  time.push_back(t1);
158  time.push_back(t2);
159  time.push_back(t3);
160  times.push_back(time);
161  }
162 
163  Position pos((double)(posX / 1000.), -(double)(posY / 1000.));
165  NBNode* node = new NBNode(toString(id), pos);
166  myNodeCont.insert(node);
167  --noNodes;
168  } while (noNodes != 0);
169 }
170 
171 
172 void
173 NIImporter_RobocupRescue::loadEdges(const std::string& file) {
174  BinaryInputDevice dev(file);
175  int skip;
176  dev >> skip; // the number in 19_s
177  dev >> skip; // x-offset in 19_s
178  dev >> skip; // y-offset in 19_s
179  //
180  int noEdges;
181  dev >> noEdges;
182  std::cout << "Expected edge number: " << noEdges << std::endl;
183  do {
184  std::cout << " left " << (noEdges) << std::endl;
185  int entrySize, id, begNode, endNode, length, roadKind, carsToHead,
186  carsToTail, humansToHead, humansToTail, width, block, repairCost, median,
187  linesToHead, linesToTail, widthForWalkers;
188  dev >> entrySize >> id >> begNode >> endNode >> length >> roadKind >> carsToHead
189  >> carsToTail >> humansToHead >> humansToTail >> width >> block >> repairCost
190  >> median >> linesToHead >> linesToTail >> widthForWalkers;
191  NBNode* fromNode = myNodeCont.retrieve(toString(begNode));
192  NBNode* toNode = myNodeCont.retrieve(toString(endNode));
193  double speed = (double)(50. / 3.6);
194  int priority = -1;
195  LaneSpreadFunction spread = linesToHead > 0 && linesToTail > 0 ? LANESPREAD_RIGHT : LANESPREAD_CENTER;
196  if (linesToHead > 0) {
197  NBEdge* edge = new NBEdge(toString(id), fromNode, toNode, "", speed, linesToHead, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
198  if (!myEdgeCont.insert(edge)) {
199  WRITE_ERROR("Could not insert edge '" + toString(id) + "'");
200  }
201  }
202  if (linesToTail > 0) {
203  NBEdge* edge = new NBEdge("-" + toString(id), toNode, fromNode, "", speed, linesToTail, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
204  if (!myEdgeCont.insert(edge)) {
205  WRITE_ERROR("Could not insert edge '-" + toString(id) + "'");
206  }
207  }
208  --noEdges;
209  } while (noEdges != 0);
210 }
211 
212 
213 /****************************************************************************/
214 
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
static bool transformCoordinate(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:53
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:70
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:257
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:254
NBEdgeCont & myEdgeCont
The edge container to fill.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:157
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:156
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
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) ...
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:201
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:161
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
A storage for options typed value containers)
Definition: OptionsCont.h:98
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&#39;s lateral offset shal...
NBNodeCont & myNodeCont
The node container to fill.
Represents a single node (junction) during network building.
Definition: NBNode.h:74
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:66
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:202
void loadEdges(const std::string &file)
Loads edges from the given file.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:200
Encapsulates binary reading operations on a file.