lemon/core.h
changeset 1187 4c89e925cfe2
parent 1162 404b98971e1f
child 1188 5ef0ab7b61cd
     1.1 --- a/lemon/core.h	Sun Nov 14 16:35:31 2010 +0100
     1.2 +++ b/lemon/core.h	Sun Nov 14 20:06:23 2010 +0100
     1.3 @@ -148,6 +148,48 @@
     1.4    typedef typename Graph::template EdgeMap<int> IntEdgeMap;             \
     1.5    typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
     1.6  
     1.7 +  ///Create convenience typedefs for the bipartite graph types and iterators
     1.8 +
     1.9 +  ///This \c \#define creates the same convenient type definitions as defined
    1.10 +  ///by \ref GRAPH_TYPEDEFS(BpGraph) and ten more, namely it creates
    1.11 +  ///\c RedNode, \c RedIt, \c BoolRedMap, \c IntRedMap, \c DoubleRedMap,
    1.12 +  ///\c BlueNode, \c BlueIt, \c BoolBlueMap, \c IntBlueMap, \c DoubleBlueMap.
    1.13 +  ///
    1.14 +  ///\note If the graph type is a dependent type, ie. the graph type depend
    1.15 +  ///on a template parameter, then use \c TEMPLATE_BPGRAPH_TYPEDEFS()
    1.16 +  ///macro.
    1.17 +#define BPGRAPH_TYPEDEFS(BpGraph)                                       \
    1.18 +  GRAPH_TYPEDEFS(BpGraph);                                              \
    1.19 +  typedef BpGraph::RedNode RedNode;                                     \
    1.20 +  typedef BpGraph::RedIt RedIt;                                         \
    1.21 +  typedef BpGraph::RedMap<bool> BoolRedMap;                             \
    1.22 +  typedef BpGraph::RedMap<int> IntRedMap;                               \
    1.23 +  typedef BpGraph::RedMap<double> DoubleRedMap                          \
    1.24 +  typedef BpGraph::BlueNode BlueNode;                                   \
    1.25 +  typedef BpGraph::BlueIt BlueIt;                                       \
    1.26 +  typedef BpGraph::BlueMap<bool> BoolBlueMap;                           \
    1.27 +  typedef BpGraph::BlueMap<int> IntBlueMap;                             \
    1.28 +  typedef BpGraph::BlueMap<double> DoubleBlueMap
    1.29 +
    1.30 +  ///Create convenience typedefs for the bipartite graph types and iterators
    1.31 +
    1.32 +  ///\see BPGRAPH_TYPEDEFS
    1.33 +  ///
    1.34 +  ///\note Use this macro, if the graph type is a dependent type,
    1.35 +  ///ie. the graph type depend on a template parameter.
    1.36 +#define TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph)                              \
    1.37 +  TEMPLATE_GRAPH_TYPEDEFS(BpGraph);                                     \
    1.38 +  typedef typename BpGraph::RedNode RedNode;                            \
    1.39 +  typedef typename BpGraph::RedIt RedIt;                                \
    1.40 +  typedef typename BpGraph::template RedMap<bool> BoolRedMap;           \
    1.41 +  typedef typename BpGraph::template RedMap<int> IntRedMap;             \
    1.42 +  typedef typename BpGraph::template RedMap<double> DoubleRedMap;       \
    1.43 +  typedef typename BpGraph::BlueNode BlueNode;                          \
    1.44 +  typedef typename BpGraph::BlueIt BlueIt;                              \
    1.45 +  typedef typename BpGraph::template BlueMap<bool> BoolBlueMap;         \
    1.46 +  typedef typename BpGraph::template BlueMap<int> IntBlueMap;           \
    1.47 +  typedef typename BpGraph::template BlueMap<double> DoubleBlueMap
    1.48 +
    1.49    /// \brief Function to count the items in a graph.
    1.50    ///
    1.51    /// This function counts the items (nodes, arcs etc.) in a graph.
    1.52 @@ -199,6 +241,74 @@
    1.53      return _core_bits::CountNodesSelector<Graph>::count(g);
    1.54    }
    1.55  
    1.56 +  namespace _graph_utils_bits {
    1.57 +    
    1.58 +    template <typename Graph, typename Enable = void>
    1.59 +    struct CountRedNodesSelector {
    1.60 +      static int count(const Graph &g) {
    1.61 +        return countItems<Graph, typename Graph::RedNode>(g);
    1.62 +      }
    1.63 +    };
    1.64 +
    1.65 +    template <typename Graph>
    1.66 +    struct CountRedNodesSelector<
    1.67 +      Graph, typename 
    1.68 +      enable_if<typename Graph::NodeNumTag, void>::type> 
    1.69 +    {
    1.70 +      static int count(const Graph &g) {
    1.71 +        return g.redNum();
    1.72 +      }
    1.73 +    };    
    1.74 +  }
    1.75 +
    1.76 +  /// \brief Function to count the red nodes in the graph.
    1.77 +  ///
    1.78 +  /// This function counts the red nodes in the graph.
    1.79 +  /// The complexity of the function is O(n) but for some
    1.80 +  /// graph structures it is specialized to run in O(1).
    1.81 +  ///
    1.82 +  /// If the graph contains a \e redNum() member function and a 
    1.83 +  /// \e NodeNumTag tag then this function calls directly the member
    1.84 +  /// function to query the cardinality of the node set.
    1.85 +  template <typename Graph>
    1.86 +  inline int countRedNodes(const Graph& g) {
    1.87 +    return _graph_utils_bits::CountRedNodesSelector<Graph>::count(g);
    1.88 +  }
    1.89 +
    1.90 +  namespace _graph_utils_bits {
    1.91 +    
    1.92 +    template <typename Graph, typename Enable = void>
    1.93 +    struct CountBlueNodesSelector {
    1.94 +      static int count(const Graph &g) {
    1.95 +        return countItems<Graph, typename Graph::BlueNode>(g);
    1.96 +      }
    1.97 +    };
    1.98 +
    1.99 +    template <typename Graph>
   1.100 +    struct CountBlueNodesSelector<
   1.101 +      Graph, typename 
   1.102 +      enable_if<typename Graph::NodeNumTag, void>::type> 
   1.103 +    {
   1.104 +      static int count(const Graph &g) {
   1.105 +        return g.blueNum();
   1.106 +      }
   1.107 +    };    
   1.108 +  }
   1.109 +
   1.110 +  /// \brief Function to count the blue nodes in the graph.
   1.111 +  ///
   1.112 +  /// This function counts the blue nodes in the graph.
   1.113 +  /// The complexity of the function is O(n) but for some
   1.114 +  /// graph structures it is specialized to run in O(1).
   1.115 +  ///
   1.116 +  /// If the graph contains a \e blueNum() member function and a 
   1.117 +  /// \e NodeNumTag tag then this function calls directly the member
   1.118 +  /// function to query the cardinality of the node set.
   1.119 +  template <typename Graph>
   1.120 +  inline int countBlueNodes(const Graph& g) {
   1.121 +    return _graph_utils_bits::CountBlueNodesSelector<Graph>::count(g);
   1.122 +  }
   1.123 +
   1.124    // Arc counting:
   1.125  
   1.126    namespace _core_bits {
   1.127 @@ -1257,7 +1367,7 @@
   1.128  
   1.129      /// The Digraph type
   1.130      typedef GR Digraph;
   1.131 -
   1.132 +    
   1.133    protected:
   1.134  
   1.135      class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type