diff -r 2e959a5a0c2d -r 4c89e925cfe2 lemon/core.h --- a/lemon/core.h Sun Nov 14 16:35:31 2010 +0100 +++ b/lemon/core.h Sun Nov 14 20:06:23 2010 +0100 @@ -148,6 +148,48 @@ typedef typename Graph::template EdgeMap IntEdgeMap; \ typedef typename Graph::template EdgeMap DoubleEdgeMap + ///Create convenience typedefs for the bipartite graph types and iterators + + ///This \c \#define creates the same convenient type definitions as defined + ///by \ref GRAPH_TYPEDEFS(BpGraph) and ten more, namely it creates + ///\c RedNode, \c RedIt, \c BoolRedMap, \c IntRedMap, \c DoubleRedMap, + ///\c BlueNode, \c BlueIt, \c BoolBlueMap, \c IntBlueMap, \c DoubleBlueMap. + /// + ///\note If the graph type is a dependent type, ie. the graph type depend + ///on a template parameter, then use \c TEMPLATE_BPGRAPH_TYPEDEFS() + ///macro. +#define BPGRAPH_TYPEDEFS(BpGraph) \ + GRAPH_TYPEDEFS(BpGraph); \ + typedef BpGraph::RedNode RedNode; \ + typedef BpGraph::RedIt RedIt; \ + typedef BpGraph::RedMap BoolRedMap; \ + typedef BpGraph::RedMap IntRedMap; \ + typedef BpGraph::RedMap DoubleRedMap \ + typedef BpGraph::BlueNode BlueNode; \ + typedef BpGraph::BlueIt BlueIt; \ + typedef BpGraph::BlueMap BoolBlueMap; \ + typedef BpGraph::BlueMap IntBlueMap; \ + typedef BpGraph::BlueMap DoubleBlueMap + + ///Create convenience typedefs for the bipartite graph types and iterators + + ///\see BPGRAPH_TYPEDEFS + /// + ///\note Use this macro, if the graph type is a dependent type, + ///ie. the graph type depend on a template parameter. +#define TEMPLATE_BPGRAPH_TYPEDEFS(BpGraph) \ + TEMPLATE_GRAPH_TYPEDEFS(BpGraph); \ + typedef typename BpGraph::RedNode RedNode; \ + typedef typename BpGraph::RedIt RedIt; \ + typedef typename BpGraph::template RedMap BoolRedMap; \ + typedef typename BpGraph::template RedMap IntRedMap; \ + typedef typename BpGraph::template RedMap DoubleRedMap; \ + typedef typename BpGraph::BlueNode BlueNode; \ + typedef typename BpGraph::BlueIt BlueIt; \ + typedef typename BpGraph::template BlueMap BoolBlueMap; \ + typedef typename BpGraph::template BlueMap IntBlueMap; \ + typedef typename BpGraph::template BlueMap DoubleBlueMap + /// \brief Function to count the items in a graph. /// /// This function counts the items (nodes, arcs etc.) in a graph. @@ -199,6 +241,74 @@ return _core_bits::CountNodesSelector::count(g); } + namespace _graph_utils_bits { + + template + struct CountRedNodesSelector { + static int count(const Graph &g) { + return countItems(g); + } + }; + + template + struct CountRedNodesSelector< + Graph, typename + enable_if::type> + { + static int count(const Graph &g) { + return g.redNum(); + } + }; + } + + /// \brief Function to count the red nodes in the graph. + /// + /// This function counts the red nodes in the graph. + /// The complexity of the function is O(n) but for some + /// graph structures it is specialized to run in O(1). + /// + /// If the graph contains a \e redNum() member function and a + /// \e NodeNumTag tag then this function calls directly the member + /// function to query the cardinality of the node set. + template + inline int countRedNodes(const Graph& g) { + return _graph_utils_bits::CountRedNodesSelector::count(g); + } + + namespace _graph_utils_bits { + + template + struct CountBlueNodesSelector { + static int count(const Graph &g) { + return countItems(g); + } + }; + + template + struct CountBlueNodesSelector< + Graph, typename + enable_if::type> + { + static int count(const Graph &g) { + return g.blueNum(); + } + }; + } + + /// \brief Function to count the blue nodes in the graph. + /// + /// This function counts the blue nodes in the graph. + /// The complexity of the function is O(n) but for some + /// graph structures it is specialized to run in O(1). + /// + /// If the graph contains a \e blueNum() member function and a + /// \e NodeNumTag tag then this function calls directly the member + /// function to query the cardinality of the node set. + template + inline int countBlueNodes(const Graph& g) { + return _graph_utils_bits::CountBlueNodesSelector::count(g); + } + // Arc counting: namespace _core_bits { @@ -1257,7 +1367,7 @@ /// The Digraph type typedef GR Digraph; - + protected: class AutoNodeMap : public ItemSetTraits::template Map::Type