| [708] | 1 | // -*- mode:C++ -*- | 
|---|
 | 2 |  | 
|---|
 | 3 | #include<math.h> | 
|---|
| [921] | 4 | #include<lemon/list_graph.h> | 
|---|
 | 5 | #include<lemon/smart_graph.h> | 
|---|
 | 6 | #include<lemon/dijkstra.h> | 
|---|
 | 7 | #include<lemon/preflow.h> | 
|---|
| [729] | 8 |  | 
|---|
| [711] | 9 | #include"bench_tools.h" | 
|---|
| [708] | 10 |  | 
|---|
 | 11 | using namespace std; | 
|---|
| [921] | 12 | using namespace lemon; | 
|---|
| [708] | 13 |  | 
|---|
| [718] | 14 | inline int numOfOnes(int n,int dim) | 
|---|
 | 15 | { | 
|---|
 | 16 |   int s=0; | 
|---|
 | 17 |   for(int i=0;i<dim;i++) { | 
|---|
 | 18 |     s+=n%2; | 
|---|
 | 19 |     n>>=1; | 
|---|
 | 20 |   } | 
|---|
 | 21 |   return s; | 
|---|
 | 22 | } | 
|---|
 | 23 |  | 
|---|
 | 24 | inline int numOfZeros(int n,int dim) | 
|---|
 | 25 | { | 
|---|
 | 26 |   int s=dim; | 
|---|
 | 27 |   for(int i=0;i<dim;i++) { | 
|---|
 | 28 |     s-=n&1; | 
|---|
 | 29 |     n>>=1; | 
|---|
 | 30 |   } | 
|---|
 | 31 |   return s; | 
|---|
 | 32 | } | 
|---|
 | 33 |  | 
|---|
| [708] | 34 | int main(int argc, char *argv[]) | 
|---|
 | 35 | { | 
|---|
 | 36 |   //  typedef ListGraph Graph; | 
|---|
 | 37 |   typedef SmartGraph Graph; | 
|---|
 | 38 |  | 
|---|
 | 39 |   ///\bug GRAPH_TYPEDEF_FACTORY(Graph); | 
|---|
 | 40 |   GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph); | 
|---|
 | 41 |  | 
|---|
 | 42 |   Graph G; | 
|---|
 | 43 |    | 
|---|
 | 44 |   Timer T; | 
|---|
 | 45 |    | 
|---|
 | 46 |   if(argc!=2) { | 
|---|
 | 47 |     cout << "Usage: " << argv[0] << " dim\n"; | 
|---|
 | 48 |     return 1; | 
|---|
 | 49 |   } | 
|---|
 | 50 |    | 
|---|
 | 51 |   int dim=atoi(argv[1]); | 
|---|
 | 52 |    | 
|---|
| [718] | 53 | //   cout << "Creating Hipercube ("<< (1<<dim) << " nodes, " | 
|---|
 | 54 | //        << dim*(1<<dim) << " edges):"; | 
|---|
| [708] | 55 |  | 
|---|
| [718] | 56 |   T.reset(); | 
|---|
| [708] | 57 |   vector<Node> nodes; | 
|---|
 | 58 |   addBiDirHiperCube(G,dim,nodes); | 
|---|
| [718] | 59 |  | 
|---|
 | 60 |   PrintTime("GENGRAPH",T); | 
|---|
 | 61 |  | 
|---|
| [708] | 62 |   T.reset(); | 
|---|
 | 63 |   Graph::EdgeMap<int> map(G); | 
|---|
| [729] | 64 |   for(int i=0;i<5;i++) { | 
|---|
| [708] | 65 |     Primes P; | 
|---|
 | 66 |     for(int i=0;i<dim*(1<<dim);i++) P(); | 
|---|
 | 67 |      | 
|---|
 | 68 |     //  for(EdgeIt e(G);G.valid(e);G.next(e)) map[e]=P(); | 
|---|
| [946] | 69 |  | 
|---|
 | 70 |     ///\todo It must have been commented out because of | 
|---|
 | 71 |     ///setToId | 
|---|
 | 72 | //     Edge te; | 
|---|
 | 73 | //     for(int i=0;i<dim*(1<<dim);i++) { | 
|---|
 | 74 | //       te.setToId(((long long int)(i)*93505)%(dim*(1<<dim))); | 
|---|
 | 75 | //       //    map[Edge(((long long int)(i)*2987)%(dim*(1<<dim)))]=P(); | 
|---|
 | 76 | //       map[te]=P(); | 
|---|
 | 77 | //     } | 
|---|
| [905] | 78 |      | 
|---|
| [718] | 79 | //     for(int i=0;i<(1<<dim);i++) { | 
|---|
 | 80 | //       int mul= (1<<(numOfZeros(i,dim)/4)); | 
|---|
 | 81 | //       for(OutEdgeIt e(G,nodes[i]);G.valid(e);G.next(e)) | 
|---|
 | 82 | //      map[e]*=mul; | 
|---|
 | 83 | //     } | 
|---|
| [708] | 84 |   } | 
|---|
 | 85 |    | 
|---|
| [718] | 86 |   PrintTime("GENLENGTHS",T); | 
|---|
 | 87 |  | 
|---|
| [708] | 88 |   T.reset(); | 
|---|
 | 89 |   { | 
|---|
 | 90 |     Dijkstra<Graph> Dij(G,map); | 
|---|
| [729] | 91 |     for(int i=0;i<10;i++) | 
|---|
 | 92 |       Dij.run(nodes[0]); | 
|---|
| [708] | 93 |   } | 
|---|
| [718] | 94 |   PrintTime("DIJKSTRA",T); | 
|---|
 | 95 |  | 
|---|
 | 96 |   T.reset(); | 
|---|
 | 97 |   { | 
|---|
 | 98 |    Graph::EdgeMap<int> flow(G); | 
|---|
| [708] | 99 |     | 
|---|
| [840] | 100 |     Preflow<Graph,int> MF(G,nodes[0],nodes[1<<dim-1],map,flow); | 
|---|
| [729] | 101 |     for(int i=0;i<10;i++) | 
|---|
 | 102 |       MF.run(MF.NO_FLOW); | 
|---|
| [718] | 103 |   } | 
|---|
 | 104 |   PrintTime("PREFLOW",T); | 
|---|
 | 105 |  | 
|---|
| [708] | 106 | } | 
|---|