COIN-OR::LEMON - Graph Library

Changeset 598:1faa5bec1717 in lemon-0.x for src/work/jacint


Ignore:
Timestamp:
05/10/04 18:32:21 (21 years ago)
Author:
marci
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@778
Message:

complete graphs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/work/jacint/graph_gen.h

    r593 r598  
    6363
    6464  /// Generates a complete graph in the undirected sense
    65   /// with n nodes and m edges.
     65  /// with n nodes.
    6666  /// Before generating the random graph, \c g.clear() is called.
    6767  template<typename Graph>
     
    7575        g.addEdge(nodes[i], nodes[j]);
    7676  }
     77
     78  /// Generates a complete bidirected graph on n nodes.
     79  /// Before generating the random graph, \c g.clear() is called.
     80  template<typename Graph>
     81  void completeBidirectedGraph(Graph& g, int n) {
     82    g.clear();
     83    std::vector<typename Graph::Node> nodes;
     84    for (int i=0; i<n; ++i)
     85      nodes.push_back(g.addNode());
     86    for (int i=0; i<n; ++i)
     87      for (int j=i+1; j<n; ++j) {
     88        g.addEdge(nodes[i], nodes[j]); 
     89        g.addEdge(nodes[j], nodes[i]);
     90      }
     91  }
     92
     93  /// Generates a complete bipartite graph with a and b nodes
     94  /// in the color classes.
     95  /// Before generating the random graph, \c g.clear() is called.
     96  template<typename Graph>
     97  void completeBipartiteGraph(Graph& g, int a, int b) {
     98    g.clear();
     99    std::vector<typename Graph::Node> s_nodes;
     100    std::vector<typename Graph::Node> t_nodes;
     101    for (int i=0; i<a; ++i)
     102      ///\bug g.addNode(g.S_CLASS) would be better.
     103      s_nodes.push_back(g.addNode(false));
     104    for (int i=0; i<b; ++i)
     105      ///\bug g.addNode(g.T_CLASS) would be better.
     106      t_nodes.push_back(g.addNode(true));
     107    for (int i=0; i<a; ++i)
     108      for (int j=0; j<b; ++j)       
     109        g.addEdge(s_nodes[i], t_nodes[j]);
     110  }
    77111 
    78112} //namespace hugo
Note: See TracChangeset for help on using the changeset viewer.