1.1 --- a/src/work/jacint/graph_gen.h Sun Apr 17 18:57:22 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,120 +0,0 @@
1.4 -// -*- c++ -*-
1.5 -#include <vector>
1.6 -#include <cstdlib>
1.7 -
1.8 -// ///\ingroup gwrappers
1.9 -///\file
1.10 -///\brief Graph generator functions.
1.11 -///
1.12 -///This file contains several graph generator functions.
1.13 -///
1.14 -// ///\author Marton Makai
1.15 -
1.16 -namespace lemon {
1.17 -
1.18 -
1.19 - /**
1.20 - * Inicializalja a veletlenszamgeneratort.
1.21 - * Figyelem, ez nem jo igazi random szamokhoz,
1.22 - * erre ne bizzad a titkaidat!
1.23 - */
1.24 - void random_init()
1.25 - {
1.26 - unsigned int seed = getpid();
1.27 - seed |= seed << 15;
1.28 - seed ^= time(0);
1.29 -
1.30 - srand(seed);
1.31 - }
1.32 -
1.33 -
1.34 - /**
1.35 - * Egy veletlen int-et ad vissza 0 es m-1 kozott.
1.36 - */
1.37 - int random(int m)
1.38 - {
1.39 - return int( double(m) * rand() / (RAND_MAX + 1.0) );
1.40 - }
1.41 -
1.42 -
1.43 - /// Generates a random graph with n nodes and m edges.
1.44 - /// Before generating the random graph, \c g.clear() is called.
1.45 - template<typename Graph>
1.46 - void randomGraph(Graph& g, int n, int m) {
1.47 - g.clear();
1.48 - std::vector<typename Graph::Node> nodes;
1.49 - for (int i=0; i<n; ++i)
1.50 - nodes.push_back(g.addNode());
1.51 - for (int i=0; i<m; ++i)
1.52 - g.addEdge(nodes[random(n)], nodes[random(n)]);
1.53 - }
1.54 -
1.55 - /// Generates a random bipartite graph with a and b nodes
1.56 - /// in the color classes and m edges.
1.57 - /// According to the bipartite graph concept, the resulting
1.58 - /// graph is directed from the first class to the second one.
1.59 - /// Before generating the random graph, \c g.clear() is called.
1.60 - template<typename Graph>
1.61 - void randomBipartiteGraph(Graph& g, int a, int b, int m) {
1.62 - g.clear();
1.63 - std::vector<typename Graph::Node> s_nodes;
1.64 - std::vector<typename Graph::Node> t_nodes;
1.65 - for (int i=0; i<a; ++i)
1.66 - ///\bug g.addNode(g.S_CLASS) would be better.
1.67 - s_nodes.push_back(g.addNode(false));
1.68 - for (int i=0; i<b; ++i)
1.69 - ///\bug g.addNode(g.T_CLASS) would be better.
1.70 - t_nodes.push_back(g.addNode(true));
1.71 - for (int i=0; i<m; ++i)
1.72 - g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
1.73 - }
1.74 -
1.75 - /// Generates a complete graph in the undirected sense
1.76 - /// with n nodes.
1.77 - /// Before generating the random graph, \c g.clear() is called.
1.78 - template<typename Graph>
1.79 - void completeGraph(Graph& g, int n) {
1.80 - g.clear();
1.81 - std::vector<typename Graph::Node> nodes;
1.82 - for (int i=0; i<n; ++i)
1.83 - nodes.push_back(g.addNode());
1.84 - for (int i=0; i<n; ++i)
1.85 - for (int j=i+1; j<n; ++j)
1.86 - g.addEdge(nodes[i], nodes[j]);
1.87 - }
1.88 -
1.89 - /// Generates a complete bidirected graph on n nodes.
1.90 - /// Before generating the random graph, \c g.clear() is called.
1.91 - template<typename Graph>
1.92 - void completeBidirectedGraph(Graph& g, int n) {
1.93 - g.clear();
1.94 - std::vector<typename Graph::Node> nodes;
1.95 - for (int i=0; i<n; ++i)
1.96 - nodes.push_back(g.addNode());
1.97 - for (int i=0; i<n; ++i)
1.98 - for (int j=i+1; j<n; ++j) {
1.99 - g.addEdge(nodes[i], nodes[j]);
1.100 - g.addEdge(nodes[j], nodes[i]);
1.101 - }
1.102 - }
1.103 -
1.104 - /// Generates a complete bipartite graph with a and b nodes
1.105 - /// in the color classes.
1.106 - /// Before generating the random graph, \c g.clear() is called.
1.107 - template<typename Graph>
1.108 - void completeBipartiteGraph(Graph& g, int a, int b) {
1.109 - g.clear();
1.110 - std::vector<typename Graph::Node> s_nodes;
1.111 - std::vector<typename Graph::Node> t_nodes;
1.112 - for (int i=0; i<a; ++i)
1.113 - ///\bug g.addNode(g.S_CLASS) would be better.
1.114 - s_nodes.push_back(g.addNode(false));
1.115 - for (int i=0; i<b; ++i)
1.116 - ///\bug g.addNode(g.T_CLASS) would be better.
1.117 - t_nodes.push_back(g.addNode(true));
1.118 - for (int i=0; i<a; ++i)
1.119 - for (int j=0; j<b; ++j)
1.120 - g.addEdge(s_nodes[i], t_nodes[j]);
1.121 - }
1.122 -
1.123 -} //namespace lemon