21 Link(
const string & d,
const T & m) : dst(d), metric(m) {}
38 map<string, vector<Link<T> > >
links;
47 links[n].push_back(l);
50 map<string, nhLMetric<T> >
getNextHops (
const string & root,
const T & infMetric) {
51 computeMinG(infMetric, root);
53 map<string, nhLMetric<T> > ret;
55 for(
TNode * n : nodes[root].childs){
56 ret[n->name].metric = n->metric;
57 ret[n->name].nh.insert(n->name);
58 recursiveLook(ret, n->name, n->name);
64 void print(
const string & root,
const T & infMetric) {
66 map<string, nhLMetric<T> > res = getNextHops (root, infMetric);
68 EV <<
"Print tree : " << endl;
69 EV <<
"" << root <<
" (0) " << endl;
71 for(
TNode * n : nodes[root].childs){
72 printRecursive(n->name, 0);
76 EV <<
"Print nextHops : "<< endl;
78 EV << n.first <<
" (" << n.second.metric <<
") ::";
79 for (
string d : n.second.nh) {
80 EV <<
" <" << d <<
">";
91 for(
const auto & vl : links) {
92 nodes[vl.first].name = vl.first;
93 nodes[vl.first].metric = infMetric;
94 nodes[vl.first].known =
true;
95 for(
const Link<T> & l : vl.second) {
97 nodes[l.
dst].metric = infMetric;
101 set<TNode *> waiting;
103 nodes[root].metric = 0;
104 waiting.insert(&nodes[root]);
106 while(!waiting.empty()) {
107 T minCost = USHRT_MAX;
110 for(
TNode * n : waiting) {
111 if(n->metric < minCost) {
115 if(n->metric == minCost){
119 for(
TNode * n : minSet) {
127 for(
const Link<T> & l : links[n->name]) {
128 TNode * d = &nodes[l.dst];
129 T tCost = minCost + l.
metric;
145 for(
TNode * n : nodes[node].childs){
146 ret[n->name].metric = n->metric;
147 ret[n->name].nh.insert(src);
148 recursiveLook(ret, n->name, src);
153 for(
int i = 0; i< index; i++) { EV <<
" "; }
155 EV <<
"|-" << node <<
" ("<< nodes[node].metric <<
") " << endl;
157 for(
TNode * n : nodes[node].childs){
158 printRecursive(n->name, index + 1);
map< string, nhLMetric< T > > getNextHops(const string &root, const T &infMetric)
map< string, TNode > nodes
Link(const string &d, const T &m)
void printRecursive(const string &node, const int &index)
void print(const string &root, const T &infMetric)
void computeMinG(const T &infMetric, const string &root)
void addLink(const string &n, const Link< T > &l)
map< string, vector< Link< T > > > links
void addNode(const string &n, const vector< Link< T > > &ls)
void recursiveLook(map< string, nhLMetric< T > > &ret, const string &node, const string &src)