[1956] | 1 | /* -*- C++ -*- |
---|
| 2 | * |
---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 2003-2006 |
---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
| 8 | * |
---|
| 9 | * Permission to use, modify and distribute this software is granted |
---|
| 10 | * provided that this copyright notice appears in all copies. For |
---|
| 11 | * precise terms see the accompanying LICENSE file. |
---|
| 12 | * |
---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
| 14 | * express or implied, and with no claim as to its suitability for any |
---|
| 15 | * purpose. |
---|
| 16 | * |
---|
| 17 | */ |
---|
[708] | 18 | |
---|
[1632] | 19 | #include<cmath> |
---|
[921] | 20 | #include<lemon/list_graph.h> |
---|
| 21 | #include<lemon/smart_graph.h> |
---|
| 22 | #include<lemon/dijkstra.h> |
---|
| 23 | #include<lemon/preflow.h> |
---|
[729] | 24 | |
---|
[711] | 25 | #include"bench_tools.h" |
---|
[708] | 26 | |
---|
| 27 | using namespace std; |
---|
[921] | 28 | using namespace lemon; |
---|
[708] | 29 | |
---|
[718] | 30 | inline int numOfOnes(int n,int dim) |
---|
| 31 | { |
---|
| 32 | int s=0; |
---|
| 33 | for(int i=0;i<dim;i++) { |
---|
| 34 | s+=n%2; |
---|
| 35 | n>>=1; |
---|
| 36 | } |
---|
| 37 | return s; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | inline int numOfZeros(int n,int dim) |
---|
| 41 | { |
---|
| 42 | int s=dim; |
---|
| 43 | for(int i=0;i<dim;i++) { |
---|
| 44 | s-=n&1; |
---|
| 45 | n>>=1; |
---|
| 46 | } |
---|
| 47 | return s; |
---|
| 48 | } |
---|
| 49 | |
---|
[708] | 50 | int main(int argc, char *argv[]) |
---|
| 51 | { |
---|
| 52 | // typedef ListGraph Graph; |
---|
| 53 | typedef SmartGraph Graph; |
---|
| 54 | |
---|
[1756] | 55 | GRAPH_TYPEDEFS(Graph); |
---|
[708] | 56 | |
---|
| 57 | Graph G; |
---|
| 58 | |
---|
| 59 | Timer T; |
---|
| 60 | |
---|
| 61 | if(argc!=2) { |
---|
| 62 | cout << "Usage: " << argv[0] << " dim\n"; |
---|
| 63 | return 1; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | int dim=atoi(argv[1]); |
---|
| 67 | |
---|
[718] | 68 | // cout << "Creating Hipercube ("<< (1<<dim) << " nodes, " |
---|
| 69 | // << dim*(1<<dim) << " edges):"; |
---|
[708] | 70 | |
---|
[1847] | 71 | T.restart(); |
---|
[708] | 72 | vector<Node> nodes; |
---|
[1689] | 73 | addBiDirHyperCube(G,dim,nodes); |
---|
[718] | 74 | |
---|
| 75 | PrintTime("GENGRAPH",T); |
---|
| 76 | |
---|
[1847] | 77 | T.restart(); |
---|
[708] | 78 | Graph::EdgeMap<int> map(G); |
---|
[729] | 79 | for(int i=0;i<5;i++) { |
---|
[708] | 80 | Primes P; |
---|
| 81 | for(int i=0;i<dim*(1<<dim);i++) P(); |
---|
| 82 | |
---|
| 83 | // for(EdgeIt e(G);G.valid(e);G.next(e)) map[e]=P(); |
---|
[946] | 84 | |
---|
| 85 | ///\todo It must have been commented out because of |
---|
| 86 | ///setToId |
---|
| 87 | // Edge te; |
---|
| 88 | // for(int i=0;i<dim*(1<<dim);i++) { |
---|
| 89 | // te.setToId(((long long int)(i)*93505)%(dim*(1<<dim))); |
---|
| 90 | // // map[Edge(((long long int)(i)*2987)%(dim*(1<<dim)))]=P(); |
---|
| 91 | // map[te]=P(); |
---|
| 92 | // } |
---|
[905] | 93 | |
---|
[718] | 94 | // for(int i=0;i<(1<<dim);i++) { |
---|
| 95 | // int mul= (1<<(numOfZeros(i,dim)/4)); |
---|
| 96 | // for(OutEdgeIt e(G,nodes[i]);G.valid(e);G.next(e)) |
---|
| 97 | // map[e]*=mul; |
---|
| 98 | // } |
---|
[708] | 99 | } |
---|
| 100 | |
---|
[718] | 101 | PrintTime("GENLENGTHS",T); |
---|
| 102 | |
---|
[1847] | 103 | T.restart(); |
---|
[708] | 104 | { |
---|
| 105 | Dijkstra<Graph> Dij(G,map); |
---|
[729] | 106 | for(int i=0;i<10;i++) |
---|
| 107 | Dij.run(nodes[0]); |
---|
[708] | 108 | } |
---|
[718] | 109 | PrintTime("DIJKSTRA",T); |
---|
| 110 | |
---|
[1847] | 111 | T.restart(); |
---|
[718] | 112 | { |
---|
| 113 | Graph::EdgeMap<int> flow(G); |
---|
[708] | 114 | |
---|
[840] | 115 | Preflow<Graph,int> MF(G,nodes[0],nodes[1<<dim-1],map,flow); |
---|
[729] | 116 | for(int i=0;i<10;i++) |
---|
| 117 | MF.run(MF.NO_FLOW); |
---|
[718] | 118 | } |
---|
| 119 | PrintTime("PREFLOW",T); |
---|
| 120 | |
---|
[708] | 121 | } |
---|