[Lemon-commits] [lemon_svn] alpar: r960 - hugo/trunk/src/benchmark
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:42:26 CET 2006
Author: alpar
Date: Mon Jul 19 15:31:47 2004
New Revision: 960
Added:
hugo/trunk/src/benchmark/hcube.cc
Modified:
hugo/trunk/src/benchmark/Makefile.am
hugo/trunk/src/benchmark/graph-bench.cc
Log:
A new benchmark (hcube)
and other minor changes
Modified: hugo/trunk/src/benchmark/Makefile.am
==============================================================================
--- hugo/trunk/src/benchmark/Makefile.am (original)
+++ hugo/trunk/src/benchmark/Makefile.am Mon Jul 19 15:31:47 2004
@@ -1,5 +1,7 @@
-AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/work
+AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/work -I$(top_srcdir)/src/work/marci
-noinst_PROGRAMS = graph-bench
+noinst_PROGRAMS = graph-bench hcube
graph_bench_SOURCES = graph-bench.cc
+
+hcube_SOURCES = hcube.cc
Modified: hugo/trunk/src/benchmark/graph-bench.cc
==============================================================================
--- hugo/trunk/src/benchmark/graph-bench.cc (original)
+++ hugo/trunk/src/benchmark/graph-bench.cc Mon Jul 19 15:31:47 2004
@@ -3,6 +3,7 @@
#include<hugo/time_measure.h>
#include<iostream>
#include<sage_graph.h>
+#include<vector>
using namespace hugo;
@@ -48,10 +49,12 @@
Graph G;
- Node nodes[n];
+ // Node nodes[n];
+ std::vector<Node> nodes(n);
for(int i=0;i<n;i++) nodes[i]=G.addNode();
- Edge equ[rat];
+ //Edge equ[rat];
+ std::vector<Edge> equ(rat);
unsigned long long int count;
Added: hugo/trunk/src/benchmark/hcube.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/benchmark/hcube.cc Mon Jul 19 15:31:47 2004
@@ -0,0 +1,149 @@
+// -*- mode:C++ -*-
+
+#include<math.h>
+#include<hugo/list_graph.h>
+#include<hugo/smart_graph.h>
+#include<hugo/dijkstra.h>
+#include<hugo/time_measure.h>
+#include<iostream>
+#include<../work/jacint/max_flow.h>
+
+using namespace std;
+using namespace hugo;
+
+///An experimental typedef factory
+#define GRAPH_TYPEDEF_FACTORY(Graph) \
+ typedef typename Graph:: Node Node;\
+ typedef typename Graph:: NodeIt NodeIn;\
+ typedef typename Graph:: Edge Edge;\
+ typedef typename Graph:: EdgeIt EdgeIt;\
+ typedef typename Graph:: InEdgeIt InEdgeIt;\
+ typedef typename Graph::OutEdgeIt OutEdgeIt;
+
+#define GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph) \
+ typedef Graph:: Node Node;\
+ typedef Graph:: NodeIt NodeIn;\
+ typedef Graph:: Edge Edge;\
+ typedef Graph:: EdgeIt EdgeIt;\
+ typedef Graph:: InEdgeIt InEdgeIt;\
+ typedef Graph::OutEdgeIt OutEdgeIt;
+
+
+class Primes
+{
+ vector<int> primes;
+ int n;
+
+ bool isPrime(int m)
+ {
+ for(int i=0;m<primes[i]*primes[i];i++) if(!(m%primes[i])) return false;
+ return true;
+ }
+public:
+ Primes() : n(1) {}
+
+ int operator() ()
+ {
+ if(primes.size()==0) {
+ primes.push_back(2);
+ return 2;
+ }
+ else {
+ do n+=2; while(!isPrime(n));
+ primes.push_back(n);
+ return n;
+ }
+ }
+};
+
+template<class Graph>
+void addHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
+{
+ GRAPH_TYPEDEF_FACTORY(Graph);
+
+ vector<int> bits(dim+1);
+ bits[0]=1;
+ for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
+
+ for(int i=0;i<bits[dim];i++) {
+ nodes.push_back(G.addNode());
+ for(j=0;j<dim;j++) if(i&bits[j]) G.addEdge(nodes[i-bits[j]],nodes[i]);
+ }
+}
+
+template<class Graph>
+void addBiDirHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
+{
+ GRAPH_TYPEDEF_FACTORY(Graph);
+
+ vector<int> bits(dim+1);
+ bits[0]=1;
+ for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
+
+ for(int i=0;i<bits[dim];i++) {
+ nodes.push_back(G.addNode());
+ for(int j=0;j<dim;j++) if(i&bits[j]) {
+ G.addEdge(nodes[i-bits[j]],nodes[i]);
+ G.addEdge(nodes[i],nodes[i-bits[j]]);
+ }
+
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ // typedef ListGraph Graph;
+ typedef SmartGraph Graph;
+
+ ///\bug GRAPH_TYPEDEF_FACTORY(Graph);
+ GRAPH_TYPEDEF_FACTORY_NOTYPENAME(Graph);
+
+ Graph G;
+
+ Timer T;
+
+ if(argc!=2) {
+ cout << "Usage: " << argv[0] << " dim\n";
+ return 1;
+ }
+
+ int dim=atoi(argv[1]);
+
+ cout << "Creating Hipercube ("<< (1<<dim) << " nodes, "
+ << dim*(1<<dim) << " edges):";
+
+ vector<Node> nodes;
+ addBiDirHiperCube(G,dim,nodes);
+ cout << T;
+ cout << "\nGenerating the lengths: ";
+ T.reset();
+ Graph::EdgeMap<int> map(G);
+ {
+ Primes P;
+ for(int i=0;i<dim*(1<<dim);i++) P();
+
+ // for(EdgeIt e(G);G.valid(e);G.next(e)) map[e]=P();
+ for(int i=0;i<dim*(1<<dim);i++)
+ // map[Edge(((long long int)(i)*2987)%(dim*(1<<dim)))]=P();
+ map[Edge(((long long int)(i)*93505)%(dim*(1<<dim)))]=P();
+ }
+
+ cout << T;
+ cout << "\nRunning Dijkstra: ";
+ T.reset();
+ {
+ Dijkstra<Graph> Dij(G,map);
+ Dij.run(nodes[0]);
+ }
+ cout << T;
+// cout << "\nRunning MaxFlow: ";
+// T.reset();
+// {
+// Graph::EdgeMap<int> flow(G);
+
+// MaxFlow<Graph,int> MF(G,nodes[0],nodes[1<<dim-1],map,flow);
+// MF.run(MF.NO_FLOW);
+// }
+// cout << T;
+ cout << "\n";
+}
More information about the Lemon-commits
mailing list