lemon/topology.h
changeset 1773 ea5927cef15c
parent 1763 49045f2d28d4
child 1793 d8130458dd86
equal deleted inserted replaced
5:cb3ea2c504c1 6:97c001c082d3
   694   template <typename UndirGraph>
   694   template <typename UndirGraph>
   695   int countNodeBiconnectedComponents(const UndirGraph& graph);
   695   int countNodeBiconnectedComponents(const UndirGraph& graph);
   696 
   696 
   697   /// \ingroup topology
   697   /// \ingroup topology
   698   ///
   698   ///
   699   /// \brief Checks the graph is node biconnected.
   699   /// \brief Checks the graph is bi-node-connected.
   700   ///
   700   ///
   701   /// This function checks that the undirected graph is node biconnected  
   701   /// This function checks that the undirected graph is bi-node-connected  
   702   /// graph. The graph is node biconnected if any two undirected edge is 
   702   /// graph. The graph is bi-node-connected if any two undirected edge is 
   703   /// on same circle.
   703   /// on same circle.
   704   ///
   704   ///
   705   /// \param graph The graph.
   705   /// \param graph The graph.
   706   /// \return %True when the graph node biconnected.
   706   /// \return %True when the graph bi-node-connected.
   707   /// \todo Make it faster.
   707   /// \todo Make it faster.
   708   template <typename UndirGraph>
   708   template <typename UndirGraph>
   709   bool nodeBiconnected(const UndirGraph& graph) {
   709   bool biNodeConnected(const UndirGraph& graph) {
   710     return countNodeBiconnectedComponents(graph) == 1;
   710     return countNodeBiconnectedComponents(graph) == 1;
   711   }
   711   }
   712 
   712 
   713   /// \ingroup topology
   713   /// \ingroup topology
   714   ///
   714   ///
   715   /// \brief Count the biconnected components.
   715   /// \brief Count the biconnected components.
   716   ///
   716   ///
   717   /// This function finds the node biconnected components in an undirected 
   717   /// This function finds the bi-node-connected components in an undirected 
   718   /// graph. The biconnected components are the classes of an equivalence 
   718   /// graph. The biconnected components are the classes of an equivalence 
   719   /// relation on the undirected edges. Two undirected edge is in relationship
   719   /// relation on the undirected edges. Two undirected edge is in relationship
   720   /// when they are on same circle.
   720   /// when they are on same circle.
   721   ///
   721   ///
   722   /// \param graph The graph.
   722   /// \param graph The graph.
   745     return compNum;
   745     return compNum;
   746   }
   746   }
   747 
   747 
   748   /// \ingroup topology
   748   /// \ingroup topology
   749   ///
   749   ///
   750   /// \brief Find the node biconnected components.
   750   /// \brief Find the bi-node-connected components.
   751   ///
   751   ///
   752   /// This function finds the node biconnected components in an undirected 
   752   /// This function finds the bi-node-connected components in an undirected 
   753   /// graph. The node biconnected components are the classes of an equivalence
   753   /// graph. The bi-node-connected components are the classes of an equivalence
   754   /// relation on the undirected edges. Two undirected edge are in relationship
   754   /// relation on the undirected edges. Two undirected edge are in relationship
   755   /// when they are on same circle.
   755   /// when they are on same circle.
   756   ///
   756   ///
   757   /// \image html node_biconnected_components.png
   757   /// \image html node_biconnected_components.png
   758   /// \image latex node_biconnected_components.eps "Node biconnected components" width=\textwidth
   758   /// \image latex node_biconnected_components.eps "bi-node-connected components" width=\textwidth
   759   ///
   759   ///
   760   /// \param graph The graph.
   760   /// \param graph The graph.
   761   /// \retval comp A writable undir edge map. The values will be set from 0 to
   761   /// \retval comp A writable undir edge map. The values will be set from 0 to
   762   /// the number of the biconnected components minus one. Each values 
   762   /// the number of the biconnected components minus one. Each values 
   763   /// of the map will be set exactly once, the values of a certain component 
   763   /// of the map will be set exactly once, the values of a certain component 
   764   /// will be set continuously.
   764   /// will be set continuously.
   765   /// \return The number of components.
   765   /// \return The number of components.
   766   ///
   766   ///
   767   template <typename UndirGraph, typename UndirEdgeMap>
   767   template <typename UndirGraph, typename UndirEdgeMap>
   768   int nodeBiconnectedComponents(const UndirGraph& graph, 
   768   int biNodeConnectedComponents(const UndirGraph& graph, 
   769 				UndirEdgeMap& compMap) {
   769 				UndirEdgeMap& compMap) {
   770     checkConcept<concept::UndirGraph, UndirGraph>();
   770     checkConcept<concept::UndirGraph, UndirGraph>();
   771     typedef typename UndirGraph::NodeIt NodeIt;
   771     typedef typename UndirGraph::NodeIt NodeIt;
   772     typedef typename UndirGraph::UndirEdge UndirEdge;
   772     typedef typename UndirGraph::UndirEdge UndirEdge;
   773     checkConcept<concept::WriteMap<UndirEdge, int>, UndirEdgeMap>();
   773     checkConcept<concept::WriteMap<UndirEdge, int>, UndirEdgeMap>();
   791     return compNum;
   791     return compNum;
   792   }
   792   }
   793 
   793 
   794   /// \ingroup topology
   794   /// \ingroup topology
   795   ///
   795   ///
   796   /// \brief Find the node biconnected cut nodes.
   796   /// \brief Find the bi-node-connected cut nodes.
   797   ///
   797   ///
   798   /// This function finds the node biconnected cut nodes in an undirected 
   798   /// This function finds the bi-node-connected cut nodes in an undirected 
   799   /// graph. The node biconnected components are the classes of an equivalence
   799   /// graph. The bi-node-connected components are the classes of an equivalence
   800   /// relation on the undirected edges. Two undirected edges are in 
   800   /// relation on the undirected edges. Two undirected edges are in 
   801   /// relationship when they are on same circle. The biconnected components 
   801   /// relationship when they are on same circle. The biconnected components 
   802   /// are separted by nodes which are the cut nodes of the components.
   802   /// are separted by nodes which are the cut nodes of the components.
   803   ///
   803   ///
   804   /// \param graph The graph.
   804   /// \param graph The graph.
   805   /// \retval comp A writable edge map. The values will be set true when
   805   /// \retval comp A writable edge map. The values will be set true when
   806   /// the node separate two or more components.
   806   /// the node separate two or more components.
   807   /// \return The number of the cut nodes.
   807   /// \return The number of the cut nodes.
   808   template <typename UndirGraph, typename NodeMap>
   808   template <typename UndirGraph, typename NodeMap>
   809   int nodeBiconnectedCutNodes(const UndirGraph& graph, NodeMap& cutMap) {
   809   int biNodeConnectedCutNodes(const UndirGraph& graph, NodeMap& cutMap) {
   810     checkConcept<concept::UndirGraph, UndirGraph>();
   810     checkConcept<concept::UndirGraph, UndirGraph>();
   811     typedef typename UndirGraph::Node Node;
   811     typedef typename UndirGraph::Node Node;
   812     typedef typename UndirGraph::NodeIt NodeIt;
   812     typedef typename UndirGraph::NodeIt NodeIt;
   813     checkConcept<concept::WriteMap<Node, bool>, NodeMap>();
   813     checkConcept<concept::WriteMap<Node, bool>, NodeMap>();
   814 
   814 
  1021   template <typename UndirGraph>
  1021   template <typename UndirGraph>
  1022   int countEdgeBiconnectedComponents(const UndirGraph& graph);
  1022   int countEdgeBiconnectedComponents(const UndirGraph& graph);
  1023 
  1023 
  1024   /// \ingroup topology
  1024   /// \ingroup topology
  1025   ///
  1025   ///
  1026   /// \brief Checks that the graph is edge biconnected.
  1026   /// \brief Checks that the graph is bi-edge-connected.
  1027   ///
  1027   ///
  1028   /// This function checks that the graph is edge biconnected. The undirected
  1028   /// This function checks that the graph is bi-edge-connected. The undirected
  1029   /// graph is edge biconnected when any two nodes are connected with two
  1029   /// graph is bi-edge-connected when any two nodes are connected with two
  1030   /// edge-disjoint paths.
  1030   /// edge-disjoint paths.
  1031   ///
  1031   ///
  1032   /// \param graph The undirected graph.
  1032   /// \param graph The undirected graph.
  1033   /// \return The number of components.
  1033   /// \return The number of components.
  1034   /// \todo Make it faster.
  1034   /// \todo Make it faster.
  1035   template <typename UndirGraph>
  1035   template <typename UndirGraph>
  1036   bool edgeBiconnected(const UndirGraph& graph) { 
  1036   bool biEdgeConnected(const UndirGraph& graph) { 
  1037     return countEdgeBiconnectedComponents(graph) == 1;
  1037     return countEdgeBiconnectedComponents(graph) == 1;
  1038   }
  1038   }
  1039 
  1039 
  1040   /// \ingroup topology
  1040   /// \ingroup topology
  1041   ///
  1041   ///
  1042   /// \brief Count the edge biconnected components.
  1042   /// \brief Count the bi-edge-connected components.
  1043   ///
  1043   ///
  1044   /// This function count the edge biconnected components in an undirected 
  1044   /// This function count the bi-edge-connected components in an undirected 
  1045   /// graph. The edge biconnected components are the classes of an equivalence
  1045   /// graph. The bi-edge-connected components are the classes of an equivalence
  1046   /// relation on the nodes. Two nodes are in relationship when they are  
  1046   /// relation on the nodes. Two nodes are in relationship when they are  
  1047   /// connected with at least two edge-disjoint paths.
  1047   /// connected with at least two edge-disjoint paths.
  1048   ///
  1048   ///
  1049   /// \param graph The undirected graph.
  1049   /// \param graph The undirected graph.
  1050   /// \return The number of components.
  1050   /// \return The number of components.
  1072     return compNum;
  1072     return compNum;
  1073   }
  1073   }
  1074 
  1074 
  1075   /// \ingroup topology
  1075   /// \ingroup topology
  1076   ///
  1076   ///
  1077   /// \brief Find the edge biconnected components.
  1077   /// \brief Find the bi-edge-connected components.
  1078   ///
  1078   ///
  1079   /// This function finds the edge biconnected components in an undirected 
  1079   /// This function finds the bi-edge-connected components in an undirected 
  1080   /// graph. The edge biconnected components are the classes of an equivalence
  1080   /// graph. The bi-edge-connected components are the classes of an equivalence
  1081   /// relation on the nodes. Two nodes are in relationship when they are  
  1081   /// relation on the nodes. Two nodes are in relationship when they are  
  1082   /// connected at least two edge-disjoint paths.
  1082   /// connected at least two edge-disjoint paths.
  1083   ///
  1083   ///
  1084   /// \image html edge_biconnected_components.png
  1084   /// \image html edge_biconnected_components.png
  1085   /// \image latex edge_biconnected_components.eps "Edge biconnected components" width=\textwidth
  1085   /// \image latex edge_biconnected_components.eps "bi-edge-connected components" width=\textwidth
  1086   ///
  1086   ///
  1087   /// \param graph The graph.
  1087   /// \param graph The graph.
  1088   /// \retval comp A writable node map. The values will be set from 0 to
  1088   /// \retval comp A writable node map. The values will be set from 0 to
  1089   /// the number of the biconnected components minus one. Each values 
  1089   /// the number of the biconnected components minus one. Each values 
  1090   /// of the map will be set exactly once, the values of a certain component 
  1090   /// of the map will be set exactly once, the values of a certain component 
  1091   /// will be set continuously.
  1091   /// will be set continuously.
  1092   /// \return The number of components.
  1092   /// \return The number of components.
  1093   ///
  1093   ///
  1094   template <typename UndirGraph, typename NodeMap>
  1094   template <typename UndirGraph, typename NodeMap>
  1095   int edgeBiconnectedComponents(const UndirGraph& graph, NodeMap& compMap) { 
  1095   int biEdgeConnectedComponents(const UndirGraph& graph, NodeMap& compMap) { 
  1096     checkConcept<concept::UndirGraph, UndirGraph>();
  1096     checkConcept<concept::UndirGraph, UndirGraph>();
  1097     typedef typename UndirGraph::NodeIt NodeIt;
  1097     typedef typename UndirGraph::NodeIt NodeIt;
  1098     typedef typename UndirGraph::Node Node;
  1098     typedef typename UndirGraph::Node Node;
  1099     checkConcept<concept::WriteMap<Node, int>, NodeMap>();
  1099     checkConcept<concept::WriteMap<Node, int>, NodeMap>();
  1100 
  1100 
  1117     return compNum;
  1117     return compNum;
  1118   }
  1118   }
  1119 
  1119 
  1120   /// \ingroup topology
  1120   /// \ingroup topology
  1121   ///
  1121   ///
  1122   /// \brief Find the edge biconnected cut edges.
  1122   /// \brief Find the bi-edge-connected cut edges.
  1123   ///
  1123   ///
  1124   /// This function finds the edge biconnected components in an undirected 
  1124   /// This function finds the bi-edge-connected components in an undirected 
  1125   /// graph. The edge biconnected components are the classes of an equivalence
  1125   /// graph. The bi-edge-connected components are the classes of an equivalence
  1126   /// relation on the nodes. Two nodes are in relationship when they are 
  1126   /// relation on the nodes. Two nodes are in relationship when they are 
  1127   /// connected with at least two edge-disjoint paths. The edge biconnected 
  1127   /// connected with at least two edge-disjoint paths. The bi-edge-connected 
  1128   /// components are separted by edges which are the cut edges of the 
  1128   /// components are separted by edges which are the cut edges of the 
  1129   /// components.
  1129   /// components.
  1130   ///
  1130   ///
  1131   /// \param graph The graph.
  1131   /// \param graph The graph.
  1132   /// \retval comp A writable node map. The values will be set true when the
  1132   /// \retval comp A writable node map. The values will be set true when the
  1133   /// edge is a cut edge.
  1133   /// edge is a cut edge.
  1134   /// \return The number of cut edges.
  1134   /// \return The number of cut edges.
  1135   template <typename UndirGraph, typename UndirEdgeMap>
  1135   template <typename UndirGraph, typename UndirEdgeMap>
  1136   int edgeBiconnectedCutEdges(const UndirGraph& graph, UndirEdgeMap& cutMap) { 
  1136   int biEdgeConnectedCutEdges(const UndirGraph& graph, UndirEdgeMap& cutMap) { 
  1137     checkConcept<concept::UndirGraph, UndirGraph>();
  1137     checkConcept<concept::UndirGraph, UndirGraph>();
  1138     typedef typename UndirGraph::NodeIt NodeIt;
  1138     typedef typename UndirGraph::NodeIt NodeIt;
  1139     typedef typename UndirGraph::UndirEdge UndirEdge;
  1139     typedef typename UndirGraph::UndirEdge UndirEdge;
  1140     checkConcept<concept::WriteMap<UndirEdge, bool>, UndirEdgeMap>();
  1140     checkConcept<concept::WriteMap<UndirEdge, bool>, UndirEdgeMap>();
  1141 
  1141