COIN-OR::LEMON - Graph Library

Changeset 1187:4c89e925cfe2 in lemon for lemon/core.h


Ignore:
Timestamp:
11/14/10 20:06:23 (13 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

SmartBpGraph? implementation (#69)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/core.h

    r1162 r1187  
    149149  typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
    150150
     151  ///Create convenience typedefs for the bipartite graph types and iterators
     152
     153  ///This \c \#define creates the same convenient type definitions as defined
     154  ///by \ref GRAPH_TYPEDEFS(BpGraph) and ten more, namely it creates
     155  ///\c RedNode, \c RedIt, \c BoolRedMap, \c IntRedMap, \c DoubleRedMap,
     156  ///\c BlueNode, \c BlueIt, \c BoolBlueMap, \c IntBlueMap, \c DoubleBlueMap.
     157  ///
     158  ///\note If the graph type is a dependent type, ie. the graph type depend
     159  ///on a template parameter, then use \c TEMPLATE_BPGRAPH_TYPEDEFS()
     160  ///macro.
     161#define BPGRAPH_TYPEDEFS(BpGraph)                                       \
     162  GRAPH_TYPEDEFS(BpGraph);                                              \
     163  typedef BpGraph::RedNode RedNode;                                     \
     164  typedef BpGraph::RedIt RedIt;                                         \
     165  typedef BpGraph::RedMap<bool> BoolRedMap;                             \
     166  typedef BpGraph::RedMap<int> IntRedMap;                               \
     167  typedef BpGraph::RedMap<double> DoubleRedMap                          \
     168  typedef BpGraph::BlueNode BlueNode;                                   \
     169  typedef BpGraph::BlueIt BlueIt;                                       \
     170  typedef BpGraph::BlueMap<bool> BoolBlueMap;                           \
     171  typedef BpGraph::BlueMap<int> IntBlueMap;                             \
     172  typedef BpGraph::BlueMap<double> DoubleBlueMap
     173
     174  ///Create convenience typedefs for the bipartite graph types and iterators
     175
     176  ///\see BPGRAPH_TYPEDEFS
     177  ///
     178  ///\note Use this macro, if the graph type is a dependent type,
     179  ///ie. the graph type depend on a template parameter.
     180#define TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph)                              \
     181  TEMPLATE_GRAPH_TYPEDEFS(BpGraph);                                     \
     182  typedef typename BpGraph::RedNode RedNode;                            \
     183  typedef typename BpGraph::RedIt RedIt;                                \
     184  typedef typename BpGraph::template RedMap<bool> BoolRedMap;           \
     185  typedef typename BpGraph::template RedMap<int> IntRedMap;             \
     186  typedef typename BpGraph::template RedMap<double> DoubleRedMap;       \
     187  typedef typename BpGraph::BlueNode BlueNode;                          \
     188  typedef typename BpGraph::BlueIt BlueIt;                              \
     189  typedef typename BpGraph::template BlueMap<bool> BoolBlueMap;         \
     190  typedef typename BpGraph::template BlueMap<int> IntBlueMap;           \
     191  typedef typename BpGraph::template BlueMap<double> DoubleBlueMap
     192
    151193  /// \brief Function to count the items in a graph.
    152194  ///
     
    198240  inline int countNodes(const Graph& g) {
    199241    return _core_bits::CountNodesSelector<Graph>::count(g);
     242  }
     243
     244  namespace _graph_utils_bits {
     245   
     246    template <typename Graph, typename Enable = void>
     247    struct CountRedNodesSelector {
     248      static int count(const Graph &g) {
     249        return countItems<Graph, typename Graph::RedNode>(g);
     250      }
     251    };
     252
     253    template <typename Graph>
     254    struct CountRedNodesSelector<
     255      Graph, typename
     256      enable_if<typename Graph::NodeNumTag, void>::type>
     257    {
     258      static int count(const Graph &g) {
     259        return g.redNum();
     260      }
     261    };   
     262  }
     263
     264  /// \brief Function to count the red nodes in the graph.
     265  ///
     266  /// This function counts the red nodes in the graph.
     267  /// The complexity of the function is O(n) but for some
     268  /// graph structures it is specialized to run in O(1).
     269  ///
     270  /// If the graph contains a \e redNum() member function and a
     271  /// \e NodeNumTag tag then this function calls directly the member
     272  /// function to query the cardinality of the node set.
     273  template <typename Graph>
     274  inline int countRedNodes(const Graph& g) {
     275    return _graph_utils_bits::CountRedNodesSelector<Graph>::count(g);
     276  }
     277
     278  namespace _graph_utils_bits {
     279   
     280    template <typename Graph, typename Enable = void>
     281    struct CountBlueNodesSelector {
     282      static int count(const Graph &g) {
     283        return countItems<Graph, typename Graph::BlueNode>(g);
     284      }
     285    };
     286
     287    template <typename Graph>
     288    struct CountBlueNodesSelector<
     289      Graph, typename
     290      enable_if<typename Graph::NodeNumTag, void>::type>
     291    {
     292      static int count(const Graph &g) {
     293        return g.blueNum();
     294      }
     295    };   
     296  }
     297
     298  /// \brief Function to count the blue nodes in the graph.
     299  ///
     300  /// This function counts the blue nodes in the graph.
     301  /// The complexity of the function is O(n) but for some
     302  /// graph structures it is specialized to run in O(1).
     303  ///
     304  /// If the graph contains a \e blueNum() member function and a
     305  /// \e NodeNumTag tag then this function calls directly the member
     306  /// function to query the cardinality of the node set.
     307  template <typename Graph>
     308  inline int countBlueNodes(const Graph& g) {
     309    return _graph_utils_bits::CountBlueNodesSelector<Graph>::count(g);
    200310  }
    201311
     
    12581368    /// The Digraph type
    12591369    typedef GR Digraph;
    1260 
     1370   
    12611371  protected:
    12621372
Note: See TracChangeset for help on using the changeset viewer.