#include <NGNet.h>
An instance of this class stores both the edges and the nodes build during the generation of a network (using any type of generation algorithm). These instances are later transformed into netbuild-structures using toNB().
Definition at line 53 of file NGNet.h.
Public Member Functions | |
| void | add (NGEdge *edge) throw () |
| Adds the given edge to the network. | |
| void | add (NGNode *node) throw () |
| Adds the given node to the network. | |
| void | createChequerBoard (int numX, int numY, SUMOReal spaceX, SUMOReal spaceY, SUMOReal attachLength) throw () |
| Creates a grid network. | |
| void | createSpiderWeb (int numRadDiv, int numCircles, SUMOReal spaceRad, bool hasCenter) throw () |
| Creates a spider network. | |
| NGNode * | findNode (int xPos, int yPos) throw () |
| Returns the node at the given position. | |
| std::string | getNextFreeID () throw () |
| Returns the next free id. | |
| NGNet (NBNetBuilder &nb) throw () | |
| Constructor. | |
| size_t | nodeNo () const throw () |
| Returns the number of stored nodes. | |
| SUMOReal | radialToX (SUMOReal radius, SUMOReal phi) throw () |
| Returns the x-position resulting from the given radius and angle. | |
| SUMOReal | radialToY (SUMOReal radius, SUMOReal phi) throw () |
| Returns the y-position resulting from the given radius and angle. | |
| void | toNB () const throw (ProcessError) |
| Converts the stored network into its netbuilder-representation. | |
| ~NGNet () throw () | |
| Destructor. | |
Private Member Functions | |
| void | connect (NGNode *node1, NGNode *node2) throw () |
| Connects both nodes with two edges, one for each direction. | |
| NGNet (const NGNet &) | |
| Invalidated copy constructor. | |
| NGNet & | operator= (const NGNet &) |
| Invalidated assignment operator. | |
Private Attributes | |
| NGEdgeList | myEdgeList |
| The list of links. | |
| int | myLastID |
| The last ID given to node or link. | |
| NBNetBuilder & | myNetBuilder |
| The builder used to build NB*-structures. | |
| NGNodeList | myNodeList |
| The list of nodes. | |
| NGNet::NGNet | ( | NBNetBuilder & | nb | ) | throw () |
Constructor.
Definition at line 53 of file NGNet.cpp.
00054 : myNetBuilder(nb) { 00055 myLastID = 0; 00056 }
| NGNet::~NGNet | ( | ) | throw () |
Destructor.
Definition at line 59 of file NGNet.cpp.
References myEdgeList, and myNodeList.
00059 { 00060 for (NGEdgeList::iterator ni=myEdgeList.begin(); ni!=myEdgeList.end(); ++ni) { 00061 delete *ni; 00062 } 00063 for (NGNodeList::iterator ni=myNodeList.begin(); ni!=myNodeList.end(); ++ni) { 00064 delete *ni; 00065 } 00066 }
| NGNet::NGNet | ( | const NGNet & | ) | [private] |
Invalidated copy constructor.
| void NGNet::add | ( | NGEdge * | edge | ) | throw () |
Adds the given edge to the network.
The edge is added to myEdgeList.
| [in] | edge | The edge to add |
Definition at line 240 of file NGNet.cpp.
References myEdgeList.
00240 { 00241 myEdgeList.push_back(edge); 00242 }
| void NGNet::add | ( | NGNode * | node | ) | throw () |
Adds the given node to the network.
The node is added to myNodeList.
| [in] | node | The node to add |
Definition at line 234 of file NGNet.cpp.
References myNodeList.
Referenced by NGRandomNetBuilder::createNet(), and NGRandomNetBuilder::createNewNode().
00234 { 00235 myNodeList.push_back(node); 00236 }
Connects both nodes with two edges, one for each direction.
Builds one link for each direction and appends the links to myEdgeList. The name of a link is as following: <FROM_NODE_ID>to<TO_NODE_ID>.
| [in] | node1 | The first node to connect |
| [in] | node2 | The second node to connect |
Definition at line 193 of file NGNet.cpp.
References myEdgeList.
Referenced by createChequerBoard(), and createSpiderWeb().
00193 { 00194 std::string id1 = node1->getID() + "to" + node2->getID(); 00195 std::string id2 = node2->getID() + "to" + node1->getID(); 00196 NGEdge *link1 = new NGEdge(id1, node1, node2); 00197 NGEdge *link2 = new NGEdge(id2, node2, node1); 00198 myEdgeList.push_back(link1); 00199 myEdgeList.push_back(link2); 00200 }
| void NGNet::createChequerBoard | ( | int | numX, | |
| int | numY, | |||
| SUMOReal | spaceX, | |||
| SUMOReal | spaceY, | |||
| SUMOReal | attachLength | |||
| ) | throw () |
Creates a grid network.
Performs a souble-loop over numX, then numY. Builds NGNodes at the according positions and connects them using NGNet::connect. Stores both the nodes and the edges within the internal container.
The nodes get an id using <RUNNING_X>/<RUNNING_Y>. The ids of the links are set in NGNet::connect.
| [in] | numX | The number of nodes in x-direction |
| [in] | numY | The number of nodes in y-direction |
| [in] | spaceX | The space between nodes in x-direction |
| [in] | spaceY | The space between nodes in y-direction |
| [in] | attachLength | The length of streets attached at the border |
Definition at line 87 of file NGNet.cpp.
References connect(), findNode(), myNodeList, NGNode::setX(), and NGNode::setY().
Referenced by buildNetwork().
00087 { 00088 for (int ix=0; ix<numX; ix++) { 00089 for (int iy=0; iy<numY; iy++) { 00090 // create Node 00091 std::string nodeID = toString<int>(ix) + "/" + toString<int>(iy); 00092 NGNode *node = new NGNode(nodeID, ix, iy); 00093 node->setX(ix * spaceX + attachLength); 00094 node->setY(iy * spaceY + attachLength); 00095 myNodeList.push_back(node); 00096 // create Links 00097 if (ix > 0) { 00098 connect(node, findNode(ix-1, iy)); 00099 } 00100 if (iy > 0) { 00101 connect(node, findNode(ix, iy-1)); 00102 } 00103 } 00104 } 00105 if (attachLength > 0.0) { 00106 for (int ix=0; ix<numX; ix++) { 00107 // create nodes 00108 NGNode *topNode = new NGNode("top" + toString<int>(ix), ix, numY); 00109 NGNode *bottomNode = new NGNode("bottom" + toString<int>(ix), ix, numY+1); 00110 topNode->setX(ix * spaceX + attachLength); 00111 bottomNode->setX(ix * spaceX + attachLength); 00112 topNode->setY((numY-1) * spaceY + 2 * attachLength); 00113 bottomNode->setY(0); 00114 myNodeList.push_back(topNode); 00115 myNodeList.push_back(bottomNode); 00116 // create links 00117 connect(topNode, findNode(ix, numY-1)); 00118 connect(bottomNode, findNode(ix, 0)); 00119 } 00120 for (int iy=0; iy<numY; iy++) { 00121 // create nodes 00122 NGNode *leftNode = new NGNode("left" + toString<int>(iy), numX, iy); 00123 NGNode *rightNode = new NGNode("right" + toString<int>(iy), numX+1, iy); 00124 leftNode->setX(0); 00125 rightNode->setX((numX-1) * spaceX + 2 * attachLength); 00126 leftNode->setY(iy * spaceY + attachLength); 00127 rightNode->setY(iy * spaceY + attachLength); 00128 myNodeList.push_back(leftNode); 00129 myNodeList.push_back(rightNode); 00130 // create links 00131 connect(leftNode, findNode(0, iy)); 00132 connect(rightNode, findNode(numX-1, iy)); 00133 } 00134 } 00135 }
| void NGNet::createSpiderWeb | ( | int | numRadDiv, | |
| int | numCircles, | |||
| SUMOReal | spaceRad, | |||
| bool | hasCenter | |||
| ) | throw () |
Creates a spider network.
Creates a spider web by going through all arms and then all circles in a loop. Builds the NGNodes at the positions obtained using radialToX and radialToY and connects them using NGNet::connect. Builds optionally a center node, and connects it, too.
The nodes get an id using <RUNNING_ARM_NUMBER>/<RUNNING_CIRCLE_NUMBER>. The ids of the links are set in NGNet::connect.
| [in] | numRadDiv | The number of arms to build |
| [in] | numCircles | The number of circles to build |
| [in] | spaceRad | The distance between the circles |
| [in] | hasCenter | Information whether a center node shall be built |
Definition at line 151 of file NGNet.cpp.
References connect(), findNode(), getNextFreeID(), myNodeList, PI, radialToX(), radialToY(), NGNode::setX(), NGNode::setY(), and SUMOReal.
Referenced by buildNetwork().
00151 { 00152 if (numRadDiv < 3) numRadDiv = 3; 00153 if (numCircles < 1) numCircles = 1; 00154 00155 int ir, ic; 00156 SUMOReal angle = (SUMOReal)(2*PI/numRadDiv); // angle between radial divisions 00157 NGNode *Node; 00158 for (ir=1; ir<numRadDiv+1; ir++) { 00159 for (ic=1; ic<numCircles+1; ic++) { 00160 // create Node 00161 Node = new NGNode( 00162 toString<int>(ir) + "/" + toString<int>(ic), ir, ic); 00163 Node->setX(radialToX((ic) * spaceRad, (ir-1) * angle)); 00164 Node->setY(radialToY((ic) * spaceRad, (ir-1) * angle)); 00165 myNodeList.push_back(Node); 00166 // create Links 00167 if (ir > 1) { 00168 connect(Node, findNode(ir-1, ic)); 00169 } 00170 if (ic > 1) { 00171 connect(Node, findNode(ir, ic-1)); 00172 } 00173 if (ir == numRadDiv) { 00174 connect(Node, findNode(1, ic)); 00175 } 00176 } 00177 } 00178 if (hasCenter) { 00179 // node 00180 Node = new NGNode(getNextFreeID(), 0, 0, true); 00181 Node->setX(0); 00182 Node->setY(0); 00183 myNodeList.push_back(Node); 00184 // links 00185 for (ir=1; ir<numRadDiv+1; ir++) { 00186 connect(Node, findNode(ir, 1)); 00187 } 00188 } 00189 }
| NGNode * NGNet::findNode | ( | int | xPos, | |
| int | yPos | |||
| ) | throw () |
Returns the node at the given position.
Searches for a node with the given position within myNodeList. Returns the matching node, if one exists, or 0 otherwise.
| [in] | xPos | The x-position of the searched node |
| [in] | yPos | The y-position of the searched node |
Definition at line 76 of file NGNet.cpp.
References myNodeList.
Referenced by createChequerBoard(), and createSpiderWeb().
00076 { 00077 for (NGNodeList::iterator ni = myNodeList.begin(); ni!= myNodeList.end(); ++ni) { 00078 if ((*ni)->samePos(xID, yID)) { 00079 return *ni; 00080 } 00081 } 00082 return 0; 00083 }
| std::string NGNet::getNextFreeID | ( | ) | throw () |
Returns the next free id.
Uses the value of myLastID to return a new (numeric) id. Increases myLastID.
Definition at line 70 of file NGNet.cpp.
References myLastID.
Referenced by NGRandomNetBuilder::createNet(), NGRandomNetBuilder::createNewNode(), and createSpiderWeb().
00070 { 00071 return toString<int>(++myLastID); 00072 }
| size_t NGNet::nodeNo | ( | ) | const throw () |
Returns the number of stored nodes.
Definition at line 246 of file NGNet.cpp.
References myNodeList.
Referenced by NGRandomNetBuilder::createNet().
00246 { 00247 return myNodeList.size(); 00248 }
| SUMOReal NGNet::radialToX | ( | SUMOReal | radius, | |
| SUMOReal | phi | |||
| ) | throw () |
Returns the x-position resulting from the given radius and angle.
| [in] | radius | The radius of the circle |
| [in] | phi | The angle the position is located at |
Definition at line 139 of file NGNet.cpp.
Referenced by createSpiderWeb().
| SUMOReal NGNet::radialToY | ( | SUMOReal | radius, | |
| SUMOReal | phi | |||
| ) | throw () |
Returns the y-position resulting from the given radius and angle.
| [in] | radius | The radius of the circle |
| [in] | phi | The angle the position is located at |
Definition at line 145 of file NGNet.cpp.
Referenced by createSpiderWeb().
| void NGNet::toNB | ( | ) | const throw (ProcessError) |
Converts the stored network into its netbuilder-representation.
Goes through all stored nodes, first, converts them into their netbuilder representations using NGNode::buildNBNode, and stores the built NBNodes into the net builder myNetBuilder.
Then, the method goes through all edges, converts them into their netbuilder representations using NGEdge::buildNBEdge, and stores the built NBEdges into the net builder myNetBuilder.
If one of the nodes is controlled by a tls and the built logic could not be added to net builder's storage, a ProcessError is thrown. This in fact may only happen when two same ids occur, what is not possible.
| ProcessError | If a built tls logic could not be added (should never happen) |
Definition at line 204 of file NGNet.cpp.
References NBNode::getConnectionTo(), NBTypeCont::getDefaultNoLanes(), NBTypeCont::getDefaultPriority(), NBTypeCont::getDefaultSpeed(), NBNetBuilder::getEdgeCont(), OptionsCont::getFloat(), NBNode::getIncomingEdges(), NBNetBuilder::getNodeCont(), OptionsCont::getOptions(), NBNetBuilder::getTypeCont(), NBEdgeCont::insert(), NBNodeCont::insert(), myEdgeList, myNetBuilder, myNodeList, RandHelper::rand(), and SUMOReal.
Referenced by main().
00204 { 00205 std::vector<NBNode*> nodes; 00206 for (NGNodeList::const_iterator i1=myNodeList.begin(); i1!=myNodeList.end(); i1++) { 00207 NBNode *node = (*i1)->buildNBNode(myNetBuilder); 00208 nodes.push_back(node); 00209 myNetBuilder.getNodeCont().insert(node); 00210 } 00211 for (NGEdgeList::const_iterator i2=myEdgeList.begin(); i2!=myEdgeList.end(); i2++) { 00212 NBEdge *edge = (*i2)->buildNBEdge(myNetBuilder); 00213 myNetBuilder.getEdgeCont().insert(edge); 00214 } 00215 // now, let's append the reverse directions... 00216 SUMOReal bidiProb = OptionsCont::getOptions().getFloat("rand-bidi-probability"); 00217 for (std::vector<NBNode*>::const_iterator i=nodes.begin(); i!=nodes.end(); ++i) { 00218 NBNode *node = *i; 00219 EdgeVector incoming = node->getIncomingEdges(); 00220 for (EdgeVector::const_iterator j=incoming.begin(); j!=incoming.end(); ++j) { 00221 if (node->getConnectionTo((*j)->getFromNode())==0 && RandHelper::rand()<=bidiProb) { 00222 NBEdge *back = new NBEdge("-" + (*j)->getID(), node, (*j)->getFromNode(), 00223 "netgen-default", myNetBuilder.getTypeCont().getDefaultSpeed(), 00224 myNetBuilder.getTypeCont().getDefaultNoLanes(), 00225 myNetBuilder.getTypeCont().getDefaultPriority()); 00226 myNetBuilder.getEdgeCont().insert(back); 00227 } 00228 } 00229 } 00230 }
NGEdgeList NGNet::myEdgeList [private] |
int NGNet::myLastID [private] |
The last ID given to node or link.
Definition at line 201 of file NGNet.h.
Referenced by getNextFreeID().
NBNetBuilder& NGNet::myNetBuilder [private] |
NGNodeList NGNet::myNodeList [private] |
The list of nodes.
Definition at line 207 of file NGNet.h.
Referenced by add(), createChequerBoard(), createSpiderWeb(), findNode(), nodeNo(), toNB(), and ~NGNet().
1.5.6