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-2017 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 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 // ---------------------------------------------------------------------------
58 // static methods (interface in this case)
59 // ---------------------------------------------------------------------------
60 void
62  // check whether the option is set (properly)
63  if (!oc.isSet("robocup-dir")) {
64  return;
65  }
66  // build the handler
68  // parse file(s)
69  std::vector<std::string> files = oc.getStringVector("robocup-dir");
70  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
71  // nodes
72  std::string nodesName = (*file) + "/node.bin";
73  if (!FileHelpers::isReadable(nodesName)) {
74  WRITE_ERROR("Could not open robocup-node-file '" + nodesName + "'.");
75  return;
76  }
77  PROGRESS_BEGIN_MESSAGE("Parsing robocup-nodes from '" + nodesName + "'");
78  handler.loadNodes(nodesName);
80  // edges
81  std::string edgesName = (*file) + "/road.bin";
82  if (!FileHelpers::isReadable(edgesName)) {
83  WRITE_ERROR("Could not open robocup-road-file '" + edgesName + "'.");
84  return;
85  }
86  PROGRESS_BEGIN_MESSAGE("Parsing robocup-roads from '" + edgesName + "'");
87  handler.loadEdges(edgesName);
89  }
90 }
91 
92 
93 
94 // ---------------------------------------------------------------------------
95 // loader methods
96 // ---------------------------------------------------------------------------
98  : myNodeCont(nc), myEdgeCont(ec) {}
99 
100 
102 }
103 
104 
105 void
106 NIImporter_RobocupRescue::loadNodes(const std::string& file) {
107  BinaryInputDevice dev(file);
108  int skip;
109  dev >> skip; // the number in 19_s
110  dev >> skip; // x-offset in 19_s
111  dev >> skip; // y-offset in 19_s
112  //
113  int noNodes;
114  dev >> noNodes;
115  WRITE_MESSAGE("Expected node number: " + toString(noNodes));
116  do {
117  //cout << " left " << (noNodes) << endl;
118  int entrySize, id, posX, posY, numEdges;
119  dev >> entrySize;
120  entrySize /= 4;
121  dev >> id;
122  dev >> posX;
123  dev >> posY;
124  dev >> numEdges;
125 
126  std::vector<int> edges;
127  for (int j = 0; j < numEdges; ++j) {
128  int edge;
129  dev >> edge;
130  edges.push_back(edge);
131  }
132 
133  int signal;
134  dev >> signal;
135 
136  std::vector<int> turns;
137  for (int j = 0; j < numEdges; ++j) {
138  int turn;
139  dev >> turn;
140  turns.push_back(turn);
141  }
142 
143  std::vector<std::pair<int, int> > conns;
144  for (int j = 0; j < numEdges; ++j) {
145  int connF, connT;
146  dev >> connF;
147  dev >> connT;
148  conns.push_back(std::pair<int, int>(connF, connT));
149  }
150 
151  std::vector<std::vector<int> > times;
152  for (int j = 0; j < numEdges; ++j) {
153  int t1, t2, t3;
154  dev >> t1;
155  dev >> t2;
156  dev >> t3;
157  std::vector<int> time;
158  time.push_back(t1);
159  time.push_back(t2);
160  time.push_back(t3);
161  times.push_back(time);
162  }
163 
164  Position pos((double)(posX / 1000.), -(double)(posY / 1000.));
166  NBNode* node = new NBNode(toString(id), pos);
167  myNodeCont.insert(node);
168  --noNodes;
169  } while (noNodes != 0);
170 }
171 
172 
173 void
174 NIImporter_RobocupRescue::loadEdges(const std::string& file) {
175  BinaryInputDevice dev(file);
176  int skip;
177  dev >> skip; // the number in 19_s
178  dev >> skip; // x-offset in 19_s
179  dev >> skip; // y-offset in 19_s
180  //
181  int noEdges;
182  dev >> noEdges;
183  std::cout << "Expected edge number: " << noEdges << std::endl;
184  do {
185  std::cout << " left " << (noEdges) << std::endl;
186  int entrySize, id, begNode, endNode, length, roadKind, carsToHead,
187  carsToTail, humansToHead, humansToTail, width, block, repairCost, median,
188  linesToHead, linesToTail, widthForWalkers;
189  dev >> entrySize >> id >> begNode >> endNode >> length >> roadKind >> carsToHead
190  >> carsToTail >> humansToHead >> humansToTail >> width >> block >> repairCost
191  >> median >> linesToHead >> linesToTail >> widthForWalkers;
192  NBNode* fromNode = myNodeCont.retrieve(toString(begNode));
193  NBNode* toNode = myNodeCont.retrieve(toString(endNode));
194  double speed = (double)(50. / 3.6);
195  int priority = -1;
196  LaneSpreadFunction spread = linesToHead > 0 && linesToTail > 0 ? LANESPREAD_RIGHT : LANESPREAD_CENTER;
197  if (linesToHead > 0) {
198  NBEdge* edge = new NBEdge(toString(id), fromNode, toNode, "", speed, linesToHead, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
199  if (!myEdgeCont.insert(edge)) {
200  WRITE_ERROR("Could not insert edge '" + toString(id) + "'");
201  }
202  }
203  if (linesToTail > 0) {
204  NBEdge* edge = new NBEdge("-" + toString(id), toNode, fromNode, "", speed, linesToTail, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
205  if (!myEdgeCont.insert(edge)) {
206  WRITE_ERROR("Could not insert edge '-" + toString(id) + "'");
207  }
208  }
209  --noEdges;
210  } while (noEdges != 0);
211 }
212 
213 
214 /****************************************************************************/
215 
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:106
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:54
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 double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:258
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:255
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:158
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:155
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:202
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:160
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
A storage for options typed value containers)
Definition: OptionsCont.h:99
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:77
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:75
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
#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.