author | jacint |
Wed, 05 May 2004 17:24:06 +0000 | |
changeset 535 | bd79aa43f299 |
child 558 | 4cbfb435ec2b |
permissions | -rw-r--r-- |
jacint@534 | 1 |
// -*- c++ -*- |
jacint@534 | 2 |
//randomGraph(i,j) gives a random graph on i nodes and j edges. |
jacint@534 | 3 |
#include <vector> |
jacint@534 | 4 |
#include <cstdlib> |
jacint@534 | 5 |
|
jacint@534 | 6 |
//#include <list_graph.h> |
jacint@534 | 7 |
//#include <time_measure.h> |
jacint@534 | 8 |
//#include <for_each_macros.h> |
jacint@534 | 9 |
//#include <bfs_iterator.h> |
jacint@534 | 10 |
//#include <bipartite_graph_wrapper.h> |
jacint@534 | 11 |
//#include <maps.h> |
jacint@534 | 12 |
//#include <max_flow.h> |
jacint@534 | 13 |
|
jacint@534 | 14 |
namespace hugo { |
jacint@534 | 15 |
|
jacint@534 | 16 |
|
jacint@534 | 17 |
/** |
jacint@534 | 18 |
* Inicializalja a veletlenszamgeneratort. |
jacint@534 | 19 |
* Figyelem, ez nem jo igazi random szamokhoz, |
jacint@534 | 20 |
* erre ne bizzad a titkaidat! |
jacint@534 | 21 |
*/ |
jacint@534 | 22 |
void random_init() |
jacint@534 | 23 |
{ |
jacint@534 | 24 |
unsigned int seed = getpid(); |
jacint@534 | 25 |
seed |= seed << 15; |
jacint@534 | 26 |
seed ^= time(0); |
jacint@534 | 27 |
|
jacint@534 | 28 |
srand(seed); |
jacint@534 | 29 |
} |
jacint@534 | 30 |
|
jacint@534 | 31 |
|
jacint@534 | 32 |
/** |
jacint@534 | 33 |
* Egy veletlen int-et ad vissza 0 es m-1 kozott. |
jacint@534 | 34 |
*/ |
jacint@534 | 35 |
int random(int m) |
jacint@534 | 36 |
{ |
jacint@534 | 37 |
return int( double(m) * rand() / (RAND_MAX + 1.0) ); |
jacint@534 | 38 |
} |
jacint@534 | 39 |
|
jacint@534 | 40 |
|
jacint@534 | 41 |
template<typename Graph> |
jacint@534 | 42 |
void randomGraph (Graph& g, int n, int m) { |
jacint@534 | 43 |
typedef typename Graph::Node Node; |
jacint@534 | 44 |
g.clear(); |
jacint@534 | 45 |
std::vector<Node> nodes; |
jacint@534 | 46 |
for (int i=0; i<n; ++i) |
jacint@534 | 47 |
nodes.push_back(g.addNode()); |
jacint@534 | 48 |
for (int i=0; i<m; ++i) |
jacint@534 | 49 |
g.addEdge(nodes[random(n)], nodes[random(n)]); |
jacint@534 | 50 |
} |
jacint@534 | 51 |
|
jacint@534 | 52 |
} |