lemon/core.h
changeset 1019 4c89e925cfe2
parent 1000 404b98971e1f
child 1020 5ef0ab7b61cd
equal deleted inserted replaced
29:618f295a31e6 30:8dbe4aa2090e
   146   typedef typename Graph::IncEdgeIt IncEdgeIt;                          \
   146   typedef typename Graph::IncEdgeIt IncEdgeIt;                          \
   147   typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;           \
   147   typedef typename Graph::template EdgeMap<bool> BoolEdgeMap;           \
   148   typedef typename Graph::template EdgeMap<int> IntEdgeMap;             \
   148   typedef typename Graph::template EdgeMap<int> IntEdgeMap;             \
   149   typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
   149   typedef typename Graph::template EdgeMap<double> DoubleEdgeMap
   150 
   150 
       
   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 
   151   /// \brief Function to count the items in a graph.
   193   /// \brief Function to count the items in a graph.
   152   ///
   194   ///
   153   /// This function counts the items (nodes, arcs etc.) in a graph.
   195   /// This function counts the items (nodes, arcs etc.) in a graph.
   154   /// The complexity of the function is linear because
   196   /// The complexity of the function is linear because
   155   /// it iterates on all of the items.
   197   /// it iterates on all of the items.
   195   /// \c NodeNumTag tag then this function calls directly the member
   237   /// \c NodeNumTag tag then this function calls directly the member
   196   /// function to query the cardinality of the node set.
   238   /// function to query the cardinality of the node set.
   197   template <typename Graph>
   239   template <typename Graph>
   198   inline int countNodes(const Graph& g) {
   240   inline int countNodes(const Graph& g) {
   199     return _core_bits::CountNodesSelector<Graph>::count(g);
   241     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);
   200   }
   310   }
   201 
   311 
   202   // Arc counting:
   312   // Arc counting:
   203 
   313 
   204   namespace _core_bits {
   314   namespace _core_bits {
  1255 
  1365 
  1256   public:
  1366   public:
  1257 
  1367 
  1258     /// The Digraph type
  1368     /// The Digraph type
  1259     typedef GR Digraph;
  1369     typedef GR Digraph;
  1260 
  1370     
  1261   protected:
  1371   protected:
  1262 
  1372 
  1263     class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type
  1373     class AutoNodeMap : public ItemSetTraits<GR, Node>::template Map<Arc>::Type
  1264     {
  1374     {
  1265       typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent;
  1375       typedef typename ItemSetTraits<GR, Node>::template Map<Arc>::Type Parent;