2 #include<hugo/list_graph.h>
3 #include<hugo/time_measure.h>
9 ///An experimental typedef factory
10 #define GRAPH_TYPEDEF_FACTORY(Graph) \
11 typedef typename Graph:: Node Node;\
12 typedef typename Graph:: NodeIt NodeIn;\
13 typedef typename Graph:: Edge Edge;\
14 typedef typename Graph:: EdgeIt EdgeIt;\
15 typedef typename Graph:: InEdgeIt InEdgeIt;\
16 typedef typename Graph::OutEdgeIt OutEdgeIt;
19 ///A primitive primtest
23 for(int k=3;n/k>=k;k+=2)
24 if(!(n%k)) return false;
30 ///Finds the smallest prime not less then \c n.
33 for(n+=!(n%2);!isPrim(n);n+=2) ;
37 ///Makes a full graph by adding and deleting a lot of edges;
39 ///\param n Number of nodes.
40 ///\param rat The funcion will make \f$rat\timesn^2\f$ edge addition and
41 ///\f$(rat-1)\timesn^2\f$ deletion.
42 ///\param p Tuning parameters.
43 ///\warning \c rat, \c p, and \c n must be pairwise relative primes.
44 template <class Graph>
45 void makeFullGraph(int n, int rat, int p)
47 GRAPH_TYPEDEF_FACTORY(Graph);
52 for(int i=0;i<n;i++) nodes[i]=G.addNode();
56 unsigned long long int count;
58 for(count=0;count<rat;count++) {
59 equ[count%rat]=G.addEdge(nodes[(count*p)%n],nodes[(count*p/n)%n]);
61 for(;(count%rat)||((count*p)%n)||((count*p/n)%n);count++) {
62 // if(!(count%1000000)) fprintf(stderr,"%d\r",count);
63 if(count%rat) G.erase(equ[count%rat]);
64 equ[count%rat]=G.addEdge(nodes[(count*p)%n],nodes[(count*p/n)%n]);
66 std::cout << "Added " << count
67 << " ( " << n << "^2 * " << rat << " ) edges\n";
68 // for(int i=0;1;i++) ;
73 std::cout << "START: n=" << nextPrim(1000) << " rat="
74 << nextPrim(300) << " p=" << nextPrim(100) << '\n';
76 makeFullGraph<ListGraph>(nextPrim(1000),nextPrim(300),nextPrim(100));
77 std::cout << T << '\n';
78 std::cout << "START: n=" << nextPrim(1000) << " rat="
79 << nextPrim(300) << " p=" << nextPrim(100) << '\n';
81 makeFullGraph<ListGraph>(nextPrim(100),nextPrim(30000),nextPrim(150));
82 std::cout << T << '\n';