NIImporter_RobocupRescue Class Reference

#include <NIImporter_RobocupRescue.h>


Detailed Description

Importer for networks stored in robocup rescue league format.

Definition at line 53 of file NIImporter_RobocupRescue.h.


Static Public Member Functions

static void loadNetwork (const OptionsCont &oc, NBNetBuilder &nb)
 Loads content of the optionally given RoboCup Rescue League files.

Protected Member Functions

void loadEdges (const std::string &file)
 Loads edges from the given file.
void loadNodes (const std::string &file)
 Loads nodes from the given file.
 NIImporter_RobocupRescue (NBNodeCont &nc, NBEdgeCont &ec)
 Constructor.
 ~NIImporter_RobocupRescue () throw ()
 Destructor.

Protected Attributes

NBEdgeContmyEdgeCont
 The edge container to fill.
NBNodeContmyNodeCont
 The node container to fill.

Constructor & Destructor Documentation

NIImporter_RobocupRescue::NIImporter_RobocupRescue ( NBNodeCont nc,
NBEdgeCont ec 
) [protected]

Constructor.

Parameters:
[in] nc The node control to fill
[in] ec The edge control to fill

Definition at line 98 of file NIImporter_RobocupRescue.cpp.

00099         : myNodeCont(nc), myEdgeCont(ec) {}

NIImporter_RobocupRescue::~NIImporter_RobocupRescue (  )  throw () [protected]

Destructor.

Definition at line 102 of file NIImporter_RobocupRescue.cpp.

00102                                                             {
00103 }


Member Function Documentation

void NIImporter_RobocupRescue::loadEdges ( const std::string &  file  )  [protected]

Loads edges from the given file.

Parameters:
[in] file The file to read edges from

Definition at line 175 of file NIImporter_RobocupRescue.cpp.

References MsgHandler::getErrorInstance(), MsgHandler::inform(), NBEdgeCont::insert(), NBEdge::LANESPREAD_CENTER, NBEdge::LANESPREAD_RIGHT, myEdgeCont, myNodeCont, NBNodeCont::retrieve(), SUMOReal, and toString().

00175                                                          {
00176     BinaryInputDevice dev(file);
00177     unsigned int skip;
00178     dev >> skip; // the number in 19_s
00179     dev >> skip; // x-offset in 19_s
00180     dev >> skip; // y-offset in 19_s
00181     //
00182     unsigned int noEdges;
00183     dev >> noEdges;
00184     std::cout << "Expected edge number: " << noEdges << std::endl;
00185     do {
00186         std::cout << "  left " << (noEdges) << std::endl;
00187         unsigned int entrySize, id, begNode, endNode, length, roadKind, carsToHead,
00188         carsToTail, humansToHead, humansToTail, width, block, repairCost, median,
00189         linesToHead, linesToTail, widthForWalkers;
00190         dev >> entrySize >> id >> begNode >> endNode >> length >> roadKind >> carsToHead
00191         >> carsToTail >> humansToHead >> humansToTail >> width >> block >> repairCost
00192         >> median >> linesToHead >> linesToTail >> widthForWalkers;
00193         NBNode *fromNode = myNodeCont.retrieve(toString(begNode));
00194         NBNode *toNode = myNodeCont.retrieve(toString(endNode));
00195         SUMOReal speed = (SUMOReal)(50. / 3.6);
00196         int priority = -1;
00197         NBEdge::LaneSpreadFunction spread = linesToHead>0&&linesToTail>0 ? NBEdge::LANESPREAD_RIGHT : NBEdge::LANESPREAD_CENTER;
00198         if (linesToHead>0) {
00199             NBEdge *edge = new NBEdge(toString(id), fromNode, toNode, "",
00200                                       speed, linesToHead, priority, spread);
00201             if (!myEdgeCont.insert(edge)) {
00202                 MsgHandler::getErrorInstance()->inform("Could not insert edge '" + toString(id) + "'");
00203             }
00204         }
00205         if (linesToTail>0) {
00206             NBEdge *edge = new NBEdge("-" + toString(id), toNode, fromNode, "",
00207                                       speed, linesToTail, priority, spread);
00208             if (!myEdgeCont.insert(edge)) {
00209                 MsgHandler::getErrorInstance()->inform("Could not insert edge '-" + toString(id) + "'");
00210             }
00211         }
00212         --noEdges;
00213     } while (noEdges!=0);
00214 }

void NIImporter_RobocupRescue::loadNetwork ( const OptionsCont oc,
NBNetBuilder nb 
) [static]

Loads content of the optionally given RoboCup Rescue League files.

If the option "robocup-net" is set, the file stored therein is read and the network definition stored therein is stored within the given network builder.

If the option "robocup-net" is not set, this method simply returns.

Parameters:
[in] oc The options to use
[in] nb The network builder to fill

Definition at line 61 of file NIImporter_RobocupRescue.cpp.

References MsgHandler::beginProcessMsg(), MsgHandler::endProcessMsg(), FileHelpers::exists(), NBNetBuilder::getEdgeCont(), MsgHandler::getErrorInstance(), MsgHandler::getMessageInstance(), NBNetBuilder::getNodeCont(), OptionsCont::getStringVector(), MsgHandler::inform(), and OptionsCont::isSet().

Referenced by NILoader::load().

00061                                                                              {
00062     // check whether the option is set (properly)
00063     if (!oc.isSet("robocup-net")) {
00064         return;
00065     }
00066     // build the handler
00067     NIImporter_RobocupRescue handler(nb.getNodeCont(), nb.getEdgeCont());
00068     // parse file(s)
00069     std::vector<std::string> files = oc.getStringVector("robocup-net");
00070     for (std::vector<std::string>::const_iterator file=files.begin(); file!=files.end(); ++file) {
00071         // nodes
00072         std::string nodesName = (*file) + "/node.bin";
00073         if (!FileHelpers::exists(nodesName)) {
00074             MsgHandler::getErrorInstance()->inform("Could not open robocup-node-file '" + nodesName + "'.");
00075             return;
00076         }
00077         MsgHandler::getMessageInstance()->beginProcessMsg("Parsing robocup-nodes from '" + nodesName + "'...");
00078         handler.loadNodes(nodesName);
00079         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00080         // edges
00081         std::string edgesName = (*file) + "/road.bin";
00082         if (!FileHelpers::exists(edgesName)) {
00083             MsgHandler::getErrorInstance()->inform("Could not open robocup-road-file '" + edgesName + "'.");
00084             return;
00085         }
00086         MsgHandler::getMessageInstance()->beginProcessMsg("Parsing robocup-roads from '" + edgesName + "'...");
00087         handler.loadEdges(edgesName);
00088         MsgHandler::getMessageInstance()->endProcessMsg("done.");
00089     }
00090     // build edges
00091 }

void NIImporter_RobocupRescue::loadNodes ( const std::string &  file  )  [protected]

Loads nodes from the given file.

Parameters:
[in] file The file to read nodes from

Definition at line 107 of file NIImporter_RobocupRescue.cpp.

References MsgHandler::getMessageInstance(), MsgHandler::inform(), NBNodeCont::insert(), myNodeCont, SUMOReal, toString(), and GeoConvHelper::x2cartesian().

00107                                                          {
00108     BinaryInputDevice dev(file);
00109     unsigned int skip;
00110     dev >> skip; // the number in 19_s
00111     dev >> skip; // x-offset in 19_s
00112     dev >> skip; // y-offset in 19_s
00113     //
00114     unsigned int noNodes;
00115     dev >> noNodes;
00116     MsgHandler::getMessageInstance()->inform("Expected node number: " + toString(noNodes));
00117     do {
00118         //cout << "  left " << (noNodes) << endl;
00119         unsigned int entrySize, id, posX, posY, numEdges;
00120         dev >> entrySize;
00121         entrySize /= 4;
00122         dev >> id;
00123         dev >> posX;
00124         dev >> posY;
00125         dev >> numEdges;
00126 
00127         std::vector<int> edges;
00128         for (unsigned int j=0; j<numEdges; ++j) {
00129             unsigned int edge;
00130             dev >> edge;
00131             edges.push_back(edge);
00132         }
00133 
00134         unsigned int signal;
00135         dev >> signal;
00136 
00137         std::vector<int> turns;
00138         for (unsigned int j=0; j<numEdges; ++j) {
00139             unsigned int turn;
00140             dev >> turn;
00141             turns.push_back(turn);
00142         }
00143 
00144         std::vector<std::pair<int, int> > conns;
00145         for (unsigned int j=0; j<numEdges; ++j) {
00146             unsigned int connF, connT;
00147             dev >> connF;
00148             dev >> connT;
00149             conns.push_back(std::pair<int, int>(connF, connT));
00150         }
00151 
00152         std::vector<std::vector<int> > times;
00153         for (unsigned int j=0; j<numEdges; ++j) {
00154             unsigned int t1, t2, t3;
00155             dev >> t1;
00156             dev >> t2;
00157             dev >> t3;
00158             std::vector<int> time;
00159             time.push_back(t1);
00160             time.push_back(t2);
00161             time.push_back(t3);
00162             times.push_back(time);
00163         }
00164 
00165         Position2D pos((SUMOReal)(posX / 1000.), -(SUMOReal)(posY / 1000.));
00166         GeoConvHelper::x2cartesian(pos);
00167         NBNode *node = new NBNode(toString(id), pos);
00168         myNodeCont.insert(node);
00169         --noNodes;
00170     } while (noNodes!=0);
00171 }


Field Documentation

The edge container to fill.

Definition at line 99 of file NIImporter_RobocupRescue.h.

Referenced by loadEdges().

The node container to fill.

Definition at line 96 of file NIImporter_RobocupRescue.h.

Referenced by loadEdges(), and loadNodes().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:52 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6