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 /****************************************************************************/
16 // Importer for networks stored in robocup rescue league format
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 #include <string>
28 #include <utils/common/ToString.h>
30 #include <netbuild/NBEdge.h>
31 #include <netbuild/NBEdgeCont.h>
32 #include <netbuild/NBNode.h>
33 #include <netbuild/NBNodeCont.h>
34 #include <netbuild/NBNetBuilder.h>
40 #include <utils/xml/XMLSubSys.h>
42 #include "NILoader.h"
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 // ---------------------------------------------------------------------------
50 // static methods (interface in this case)
51 // ---------------------------------------------------------------------------
52 void
54  // check whether the option is set (properly)
55  if (!oc.isSet("robocup-dir")) {
56  return;
57  }
58  // build the handler
60  // parse file(s)
61  std::vector<std::string> files = oc.getStringVector("robocup-dir");
62  for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
63  // nodes
64  std::string nodesName = (*file) + "/node.bin";
65  if (!FileHelpers::isReadable(nodesName)) {
66  WRITE_ERROR("Could not open robocup-node-file '" + nodesName + "'.");
67  return;
68  }
69  PROGRESS_BEGIN_MESSAGE("Parsing robocup-nodes from '" + nodesName + "'");
70  handler.loadNodes(nodesName);
72  // edges
73  std::string edgesName = (*file) + "/road.bin";
74  if (!FileHelpers::isReadable(edgesName)) {
75  WRITE_ERROR("Could not open robocup-road-file '" + edgesName + "'.");
76  return;
77  }
78  PROGRESS_BEGIN_MESSAGE("Parsing robocup-roads from '" + edgesName + "'");
79  handler.loadEdges(edgesName);
81  }
82 }
83 
84 
85 
86 // ---------------------------------------------------------------------------
87 // loader methods
88 // ---------------------------------------------------------------------------
90  : myNodeCont(nc), myEdgeCont(ec) {}
91 
92 
94 }
95 
96 
97 void
98 NIImporter_RobocupRescue::loadNodes(const std::string& file) {
99  BinaryInputDevice dev(file);
100  int skip;
101  dev >> skip; // the number in 19_s
102  dev >> skip; // x-offset in 19_s
103  dev >> skip; // y-offset in 19_s
104  //
105  int noNodes;
106  dev >> noNodes;
107  WRITE_MESSAGE("Expected node number: " + toString(noNodes));
108  do {
109  //cout << " left " << (noNodes) << endl;
110  int entrySize, id, posX, posY, numEdges;
111  dev >> entrySize;
112  entrySize /= 4;
113  dev >> id;
114  dev >> posX;
115  dev >> posY;
116  dev >> numEdges;
117 
118  std::vector<int> edges;
119  for (int j = 0; j < numEdges; ++j) {
120  int edge;
121  dev >> edge;
122  edges.push_back(edge);
123  }
124 
125  int signal;
126  dev >> signal;
127 
128  std::vector<int> turns;
129  for (int j = 0; j < numEdges; ++j) {
130  int turn;
131  dev >> turn;
132  turns.push_back(turn);
133  }
134 
135  std::vector<std::pair<int, int> > conns;
136  for (int j = 0; j < numEdges; ++j) {
137  int connF, connT;
138  dev >> connF;
139  dev >> connT;
140  conns.push_back(std::pair<int, int>(connF, connT));
141  }
142 
143  std::vector<std::vector<int> > times;
144  for (int j = 0; j < numEdges; ++j) {
145  int t1, t2, t3;
146  dev >> t1;
147  dev >> t2;
148  dev >> t3;
149  std::vector<int> time;
150  time.push_back(t1);
151  time.push_back(t2);
152  time.push_back(t3);
153  times.push_back(time);
154  }
155 
156  Position pos((double)(posX / 1000.), -(double)(posY / 1000.));
158  NBNode* node = new NBNode(toString(id), pos);
159  myNodeCont.insert(node);
160  --noNodes;
161  } while (noNodes != 0);
162 }
163 
164 
165 void
166 NIImporter_RobocupRescue::loadEdges(const std::string& file) {
167  BinaryInputDevice dev(file);
168  int skip;
169  dev >> skip; // the number in 19_s
170  dev >> skip; // x-offset in 19_s
171  dev >> skip; // y-offset in 19_s
172  //
173  int noEdges;
174  dev >> noEdges;
175  std::cout << "Expected edge number: " << noEdges << std::endl;
176  do {
177  std::cout << " left " << (noEdges) << std::endl;
178  int entrySize, id, begNode, endNode, length, roadKind, carsToHead,
179  carsToTail, humansToHead, humansToTail, width, block, repairCost, median,
180  linesToHead, linesToTail, widthForWalkers;
181  dev >> entrySize >> id >> begNode >> endNode >> length >> roadKind >> carsToHead
182  >> carsToTail >> humansToHead >> humansToTail >> width >> block >> repairCost
183  >> median >> linesToHead >> linesToTail >> widthForWalkers;
184  NBNode* fromNode = myNodeCont.retrieve(toString(begNode));
185  NBNode* toNode = myNodeCont.retrieve(toString(endNode));
186  double speed = (double)(50. / 3.6);
187  int priority = -1;
188  LaneSpreadFunction spread = linesToHead > 0 && linesToTail > 0 ? LANESPREAD_RIGHT : LANESPREAD_CENTER;
189  if (linesToHead > 0) {
190  NBEdge* edge = new NBEdge(toString(id), fromNode, toNode, "", speed, linesToHead, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
191  if (!myEdgeCont.insert(edge)) {
192  WRITE_ERROR("Could not insert edge '" + toString(id) + "'");
193  }
194  }
195  if (linesToTail > 0) {
196  NBEdge* edge = new NBEdge("-" + toString(id), toNode, fromNode, "", speed, linesToTail, priority, NBEdge::UNSPECIFIED_WIDTH, NBEdge::UNSPECIFIED_OFFSET, "", spread);
197  if (!myEdgeCont.insert(edge)) {
198  WRITE_ERROR("Could not insert edge '-" + toString(id) + "'");
199  }
200  }
201  --noEdges;
202  } while (noEdges != 0);
203 }
204 
205 
206 /****************************************************************************/
207 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
NBEdge::UNSPECIFIED_OFFSET
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:318
ToString.h
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
GeomConvHelper.h
OptionsCont.h
LANESPREAD_RIGHT
Definition: SUMOXMLDefinitions.h:1098
MsgHandler.h
NBNodeCont::insert
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:78
SUMOSAXHandler.h
FileHelpers.h
NBEdgeCont.h
GeoConvHelper.h
NIImporter_RobocupRescue::myEdgeCont
NBEdgeCont & myEdgeCont
The edge container to fill.
Definition: NIImporter_RobocupRescue.h:91
NBNetBuilder::transformCoordinate
static bool transformCoordinate(Position &from, bool includeInBoundary=true, GeoConvHelper *from_srs=0)
transforms loaded coordinates handles projections, offsets (using GeoConvHelper) and import of height...
Definition: NBNetBuilder.cpp:633
NBEdgeCont::insert
bool insert(NBEdge *edge, bool ignorePrunning=false)
Adds an edge to the dictionary.
Definition: NBEdgeCont.cpp:153
LANESPREAD_CENTER
Definition: SUMOXMLDefinitions.h:1099
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:59
NBNetBuilder::getEdgeCont
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:150
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
OptionsCont::getStringVector
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
Definition: OptionsCont.cpp:235
BinaryInputDevice.h
NIImporter_RobocupRescue::loadNodes
void loadNodes(const std::string &file)
Loads nodes from the given file.
Definition: NIImporter_RobocupRescue.cpp:98
NIImporter_RobocupRescue.h
NIImporter_RobocupRescue::loadNetwork
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given RoboCup Rescue League files.
Definition: NIImporter_RobocupRescue.cpp:53
NBNetBuilder.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
UtilExceptions.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NIImporter_RobocupRescue::~NIImporter_RobocupRescue
~NIImporter_RobocupRescue()
Destructor.
Definition: NIImporter_RobocupRescue.cpp:93
NIImporter_RobocupRescue::myNodeCont
NBNodeCont & myNodeCont
The node container to fill.
Definition: NIImporter_RobocupRescue.h:88
NIImporter_RobocupRescue::NIImporter_RobocupRescue
NIImporter_RobocupRescue(NBNodeCont &nc, NBEdgeCont &ec)
Constructor.
Definition: NIImporter_RobocupRescue.cpp:89
NBNodeCont::retrieve
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:107
NBNodeCont.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
NILoader.h
PROGRESS_BEGIN_MESSAGE
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:278
PROGRESS_DONE_MESSAGE
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:279
NBEdge::UNSPECIFIED_WIDTH
static const double UNSPECIFIED_WIDTH
unspecified lane width
Definition: NBEdge.h:315
LaneSpreadFunction
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
Definition: SUMOXMLDefinitions.h:1097
FileHelpers::isReadable
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:49
config.h
NIImporter_RobocupRescue::loadEdges
void loadEdges(const std::string &file)
Loads edges from the given file.
Definition: NIImporter_RobocupRescue.cpp:166
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBNetBuilder::getNodeCont
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:155
NBNode.h
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
NIImporter_RobocupRescue
Importer for networks stored in robocup rescue league format.
Definition: NIImporter_RobocupRescue.h:47
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:277
SUMOXMLDefinitions.h
NBEdge.h
BinaryInputDevice
Encapsulates binary reading operations on a file.
Definition: BinaryInputDevice.h:57
XMLSubSys.h