src/benchmark/graph-bench.cc
author marci
Fri, 01 Oct 2004 10:08:43 +0000
changeset 932 ade3cdb9b45d
parent 718 75d36edc6bc4
child 1403 c479984e459d
permissions -rw-r--r--
New EdgeSubGraphWrapper class specializing SubGraphWrapper in the way that only the edge-set can be filtered.
alpar@699
     1
#include<math.h>
alpar@921
     2
#include<lemon/list_graph.h>
alpar@711
     3
alpar@711
     4
#include"bench_tools.h"
alpar@699
     5
alpar@921
     6
using namespace lemon;
alpar@699
     7
alpar@699
     8
///Makes a full graph by adding and deleting a lot of edges;
alpar@699
     9
alpar@699
    10
///\param n Number of nodes.
alpar@699
    11
///\param rat The funcion will make \f$rat\timesn^2\f$ edge addition and
alpar@699
    12
///\f$(rat-1)\timesn^2\f$ deletion.
alpar@699
    13
///\param p Tuning parameters.
alpar@699
    14
///\warning \c rat, \c p, and \c n must be pairwise relative primes. 
alpar@699
    15
template <class Graph>
alpar@699
    16
void makeFullGraph(int n, int rat, int p)
alpar@699
    17
{
alpar@699
    18
  GRAPH_TYPEDEF_FACTORY(Graph);
alpar@699
    19
alpar@699
    20
  Graph G;
alpar@699
    21
  
alpar@708
    22
  //  Node nodes[n];
alpar@708
    23
  std::vector<Node> nodes(n);
alpar@699
    24
  for(int i=0;i<n;i++) nodes[i]=G.addNode();
alpar@699
    25
  
alpar@708
    26
  //Edge equ[rat];
alpar@708
    27
  std::vector<Edge> equ(rat);
alpar@699
    28
  
alpar@718
    29
  long long int count;
alpar@699
    30
  
alpar@699
    31
  for(count=0;count<rat;count++) {
alpar@699
    32
    equ[count%rat]=G.addEdge(nodes[(count*p)%n],nodes[(count*p/n)%n]);
alpar@699
    33
  }
alpar@699
    34
  for(;(count%rat)||((count*p)%n)||((count*p/n)%n);count++) {
alpar@699
    35
    //    if(!(count%1000000)) fprintf(stderr,"%d\r",count);
alpar@699
    36
    if(count%rat) G.erase(equ[count%rat]);
alpar@699
    37
    equ[count%rat]=G.addEdge(nodes[(count*p)%n],nodes[(count*p/n)%n]);
alpar@699
    38
  }
alpar@718
    39
//   std::cout << "Added " << count
alpar@718
    40
// 	    << " ( " << n << "^2 * " << rat << " ) edges\n";
alpar@718
    41
alpar@718
    42
alpar@699
    43
  //  for(int i=0;1;i++) ;
alpar@699
    44
}
alpar@699
    45
alpar@699
    46
int main()
alpar@699
    47
{
alpar@921
    48
  lemon::Timer T;
alpar@699
    49
  makeFullGraph<ListGraph>(nextPrim(1000),nextPrim(300),nextPrim(100));
alpar@718
    50
  
alpar@718
    51
  PrintTime("BIG",T);
alpar@699
    52
  T.reset();
alpar@699
    53
  makeFullGraph<ListGraph>(nextPrim(100),nextPrim(30000),nextPrim(150));
alpar@718
    54
alpar@718
    55
  PrintTime("SMALL",T);
alpar@699
    56
}