smutnyjoe

Untitled

Jan 4th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. std::vector<std::list<int>> P( graph.size() );
  2. std::vector<int> sigma( graph.size() );
  3. std::vector<int> d( graph.size() );
  4. std::vector<int> delta( graph.size() );
  5.  
  6. for ( auto i = a; i < b; ++i ) {
  7.     if ( graph[i].first == -1 ) continue; // omit nonexistent nodes
  8.     int s = graph[i].first;
  9.     std::stack<int> S;
  10.  
  11.     for ( auto j = 0; j < graph.size(); ++j ) {
  12.         int w = graph[j].first;
  13.         if ( w == -1 ) continue; // omit nonexistent nodes
  14.         P[w] = std::list<int>();
  15.         sigma[w] = 0;
  16.         d[w] = -1;
  17.         delta[w] = 0;
  18.     }
  19.  
  20.     sigma[s] = 1;
  21.     d[s] = 0;
  22.     std::queue<int> Q;
  23.     Q.push( s );
  24.  
  25.     while ( !Q.empty() ) {
  26.         int v = Q.front();
  27.         Q.pop();
  28.         S.push( v );
  29.  
  30.         for ( auto w : graph[v].second ) {
  31.             if ( d[w] < 0 ) {
  32.                 Q.push( w );
  33.                 d[w] = d[v] + 1;
  34.             }
  35.             if ( d[w] == d[v] + 1 ) {
  36.                 sigma[w] += sigma[v];
  37.                 P[w].push_back(v);
  38.             }
  39.         }
  40.     }
  41.  
  42.     while ( !S.empty() ) {
  43.         int w = S.top();
  44.         S.pop();
  45.  
  46.         for ( auto v : P[w] ) {
  47.             delta[v] += ( sigma[v] / sigma[w] ) * ( 1 + delta[w] );
  48.         }
  49.  
  50.         if ( w != s ) {
  51.             cout << "bsp [" << a <<", " << b << "): Increasing BC[" << w << "] by delta[" << w << "] = " << delta[w] << endl;
  52.             BC[w].second += delta[w];
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment