#include <NGRandomNetBuilder.h>
Definition at line 43 of file NGRandomNetBuilder.h.
Public Member Functions | |
| void | add (int numNeighbours, SUMOReal ratio) throw () |
| adds a neighbour item to list | |
| int | num () throw () |
| Get random number of neighbours. | |
Private Attributes | |
| std::map< int, SUMOReal > | myNeighbours |
| A map from neighbor number to their probabilities. | |
| void TNeighbourDistribution::add | ( | int | numNeighbours, | |
| SUMOReal | ratio | |||
| ) | throw () |
adds a neighbour item to list
If NumNeighbours is already existing, the old ratio is overwritten
| [in] | numNeighbours | The number of neighbors this item shall describe |
| [in] | ratio | The probability of this number of neighbors |
Definition at line 49 of file NGRandomNetBuilder.cpp.
Referenced by buildNetwork().
00049 { 00050 myNeighbours[NumNeighbours] = ratio; 00051 }
| int TNeighbourDistribution::num | ( | ) | throw () |
Get random number of neighbours.
Definition at line 55 of file NGRandomNetBuilder.cpp.
References myNeighbours, RandHelper::rand(), and SUMOReal.
Referenced by NGRandomNetBuilder::createNewNode().
00055 { 00056 SUMOReal sum=0, RandValue; 00057 std::map<int, SUMOReal>::iterator i; 00058 // total sum of ratios 00059 for (i=myNeighbours.begin(); i!=myNeighbours.end(); ++i) { 00060 sum += (*i).second; 00061 } 00062 // RandValue = [0,sum] 00063 RandValue = RandHelper::rand(sum); 00064 // find selected item 00065 i = myNeighbours.begin(); 00066 sum = (*i).second; 00067 while ((i != myNeighbours.end()) && (sum < RandValue)) { 00068 i++; 00069 sum += (*i).second; 00070 } 00071 return (*i).first; 00072 }
std::map<int, SUMOReal> TNeighbourDistribution::myNeighbours [private] |
A map from neighbor number to their probabilities.
Definition at line 66 of file NGRandomNetBuilder.h.
Referenced by num().
1.5.6