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