4 #include<hugo/list_graph.h>
5 #include<hugo/smart_graph.h>
6 #include<hugo/dijkstra.h>
7 #include<hugo/time_measure.h>
9 #include<../work/jacint/max_flow.h>
14 ///An experimental typedef factory
15 #define GRAPH_TYPEDEF_FACTORY(Graph) \
16 typedef typename Graph:: Node Node;\
17 typedef typename Graph:: NodeIt NodeIn;\
18 typedef typename Graph:: Edge Edge;\
19 typedef typename Graph:: EdgeIt EdgeIt;\
20 typedef typename Graph:: InEdgeIt InEdgeIt;\
21 typedef typename Graph::OutEdgeIt OutEdgeIt;
23 #define GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph) \
24 typedef Graph:: Node Node;\
25 typedef Graph:: NodeIt NodeIn;\
26 typedef Graph:: Edge Edge;\
27 typedef Graph:: EdgeIt EdgeIt;\
28 typedef Graph:: InEdgeIt InEdgeIt;\
29 typedef Graph::OutEdgeIt OutEdgeIt;
39 for(int i=0;m<primes[i]*primes[i];i++) if(!(m%primes[i])) return false;
47 if(primes.size()==0) {
52 do n+=2; while(!isPrime(n));
60 void addHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
62 GRAPH_TYPEDEF_FACTORY(Graph);
64 vector<int> bits(dim+1);
66 for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
68 for(int i=0;i<bits[dim];i++) {
69 nodes.push_back(G.addNode());
70 for(j=0;j<dim;j++) if(i&bits[j]) G.addEdge(nodes[i-bits[j]],nodes[i]);
75 void addBiDirHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
77 GRAPH_TYPEDEF_FACTORY(Graph);
79 vector<int> bits(dim+1);
81 for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
83 for(int i=0;i<bits[dim];i++) {
84 nodes.push_back(G.addNode());
85 for(int j=0;j<dim;j++) if(i&bits[j]) {
86 G.addEdge(nodes[i-bits[j]],nodes[i]);
87 G.addEdge(nodes[i],nodes[i-bits[j]]);
93 int main(int argc, char *argv[])
95 // typedef ListGraph Graph;
96 typedef SmartGraph Graph;
98 ///\bug GRAPH_TYPEDEF_FACTORY(Graph);
99 GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph);
106 cout << "Usage: " << argv[0] << " dim\n";
110 int dim=atoi(argv[1]);
112 cout << "Creating Hipercube ("<< (1<<dim) << " nodes, "
113 << dim*(1<<dim) << " edges):";
116 addBiDirHiperCube(G,dim,nodes);
118 cout << "\nGenerating the lengths: ";
120 Graph::EdgeMap<int> map(G);
123 for(int i=0;i<dim*(1<<dim);i++) P();
125 // for(EdgeIt e(G);G.valid(e);G.next(e)) map[e]=P();
126 for(int i=0;i<dim*(1<<dim);i++)
127 // map[Edge(((long long int)(i)*2987)%(dim*(1<<dim)))]=P();
128 map[Edge(((long long int)(i)*93505)%(dim*(1<<dim)))]=P();
132 cout << "\nRunning Dijkstra: ";
135 Dijkstra<Graph> Dij(G,map);
139 // cout << "\nRunning MaxFlow: ";
142 // Graph::EdgeMap<int> flow(G);
144 // MaxFlow<Graph,int> MF(G,nodes[0],nodes[1<<dim-1],map,flow);
145 // MF.run(MF.NO_FLOW);