src/work/jacint/graph_gen.h
changeset 598 1faa5bec1717
parent 593 b83b36ee7f10
child 605 b3c57602c516
     1.1 --- a/src/work/jacint/graph_gen.h	Mon May 10 16:31:48 2004 +0000
     1.2 +++ b/src/work/jacint/graph_gen.h	Mon May 10 16:32:21 2004 +0000
     1.3 @@ -62,7 +62,7 @@
     1.4    }
     1.5  
     1.6    /// Generates a complete graph in the undirected sense 
     1.7 -  /// with n nodes and m edges.
     1.8 +  /// with n nodes.
     1.9    /// Before generating the random graph, \c g.clear() is called.
    1.10    template<typename Graph>
    1.11    void completeGraph(Graph& g, int n) {
    1.12 @@ -74,5 +74,39 @@
    1.13        for (int j=i+1; j<n; ++j)
    1.14  	g.addEdge(nodes[i], nodes[j]);
    1.15    }
    1.16 +
    1.17 +  /// Generates a complete bidirected graph on n nodes.
    1.18 +  /// Before generating the random graph, \c g.clear() is called.
    1.19 +  template<typename Graph>
    1.20 +  void completeBidirectedGraph(Graph& g, int n) {
    1.21 +    g.clear();
    1.22 +    std::vector<typename Graph::Node> nodes;
    1.23 +    for (int i=0; i<n; ++i)
    1.24 +      nodes.push_back(g.addNode());
    1.25 +    for (int i=0; i<n; ++i) 
    1.26 +      for (int j=i+1; j<n; ++j) {
    1.27 +	g.addEdge(nodes[i], nodes[j]);	
    1.28 +	g.addEdge(nodes[j], nodes[i]);
    1.29 +      }
    1.30 +  }
    1.31 +
    1.32 +  /// Generates a complete bipartite graph with a and b nodes 
    1.33 +  /// in the color classes.
    1.34 +  /// Before generating the random graph, \c g.clear() is called.
    1.35 +  template<typename Graph>
    1.36 +  void completeBipartiteGraph(Graph& g, int a, int b) {
    1.37 +    g.clear();
    1.38 +    std::vector<typename Graph::Node> s_nodes;
    1.39 +    std::vector<typename Graph::Node> t_nodes;
    1.40 +    for (int i=0; i<a; ++i)
    1.41 +      ///\bug g.addNode(g.S_CLASS) would be better.
    1.42 +      s_nodes.push_back(g.addNode(false));
    1.43 +    for (int i=0; i<b; ++i)
    1.44 +      ///\bug g.addNode(g.T_CLASS) would be better.
    1.45 +      t_nodes.push_back(g.addNode(true));
    1.46 +    for (int i=0; i<a; ++i) 
    1.47 +      for (int j=0; j<b; ++j)       
    1.48 +	g.addEdge(s_nodes[i], t_nodes[j]);
    1.49 +  }
    1.50    
    1.51  } //namespace hugo