src/work/jacint/graph_gen.h
changeset 558 4cbfb435ec2b
parent 534 22ce98f7d0f1
child 593 b83b36ee7f10
     1.1 --- a/src/work/jacint/graph_gen.h	Thu May 06 17:01:31 2004 +0000
     1.2 +++ b/src/work/jacint/graph_gen.h	Thu May 06 17:22:11 2004 +0000
     1.3 @@ -1,16 +1,7 @@
     1.4  // -*- c++ -*-
     1.5 -//randomGraph(i,j) gives a random graph on i nodes and j edges.
     1.6  #include <vector>
     1.7  #include <cstdlib>
     1.8  
     1.9 -//#include <list_graph.h>
    1.10 -//#include <time_measure.h>
    1.11 -//#include <for_each_macros.h>
    1.12 -//#include <bfs_iterator.h>
    1.13 -//#include <bipartite_graph_wrapper.h>
    1.14 -//#include <maps.h>
    1.15 -//#include <max_flow.h>
    1.16 -
    1.17  namespace hugo {
    1.18  
    1.19  
    1.20 @@ -38,15 +29,36 @@
    1.21    }
    1.22  
    1.23  
    1.24 +  /// Generates a random graph with n nodes and m edges.
    1.25 +  /// Before generating the random graph, \c g.clear() is called.
    1.26    template<typename Graph>
    1.27 -  void randomGraph (Graph& g, int n, int m) {
    1.28 -    typedef typename Graph::Node Node;
    1.29 +  void randomGraph(Graph& g, int n, int m) {
    1.30      g.clear();
    1.31 -    std::vector<Node> nodes;
    1.32 +    std::vector<typename Graph::Node> nodes;
    1.33      for (int i=0; i<n; ++i)
    1.34        nodes.push_back(g.addNode());
    1.35      for (int i=0; i<m; ++i) 
    1.36        g.addEdge(nodes[random(n)], nodes[random(n)]);
    1.37    }
    1.38  
    1.39 -}
    1.40 +  /// Generates a random bipartite graph with a and b nodes 
    1.41 +  /// in the color classes and m edges.
    1.42 +  /// According to the bipartite graph concept, the resulting 
    1.43 +  /// graph is directed from the first class to the second one.
    1.44 +  /// Before generating the random graph, \c g.clear() is called.
    1.45 +  template<typename Graph>
    1.46 +  void randomBipartiteGraph(Graph& g, int a, int b, int m) {
    1.47 +    g.clear();
    1.48 +    std::vector<typename Graph::Node> s_nodes;
    1.49 +    std::vector<typename Graph::Node> t_nodes;
    1.50 +    for (int i=0; i<a; ++i)
    1.51 +      ///\bug g.addNode(g.S_CLASS) would be better.
    1.52 +      s_nodes.push_back(g.addNode(false));
    1.53 +    for (int i=0; i<b; ++i)
    1.54 +      ///\bug g.addNode(g.T_CLASS) would be better.
    1.55 +      t_nodes.push_back(g.addNode(true));
    1.56 +    for (int i=0; i<m; ++i) 
    1.57 +      g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
    1.58 +  }
    1.59 +
    1.60 +} //namespace hugo