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