lemon/topology.h
changeset 2514 57143c09dc20
parent 2421 160ebfb944a9
child 2529 93de38566e6c
equal deleted inserted replaced
22:3075a677478b 23:dcb3f5b1dcef
    33 #include <lemon/bucket_heap.h>
    33 #include <lemon/bucket_heap.h>
    34 
    34 
    35 #include <stack>
    35 #include <stack>
    36 #include <functional>
    36 #include <functional>
    37 
    37 
    38 /// \ingroup topology
    38 /// \ingroup graph_prop
    39 /// \file
    39 /// \file
    40 /// \brief Topology related algorithms
    40 /// \brief Topology related algorithms
    41 ///
    41 ///
    42 /// Topology related algorithms
    42 /// Topology related algorithms
    43 
    43 
    44 namespace lemon {
    44 namespace lemon {
    45 
    45 
    46   /// \ingroup topology
    46   /// \ingroup graph_prop
    47   ///
    47   ///
    48   /// \brief Check that the given undirected graph is connected.
    48   /// \brief Check that the given undirected graph is connected.
    49   ///
    49   ///
    50   /// Check that the given undirected graph connected.
    50   /// Check that the given undirected graph connected.
    51   /// \param graph The undirected graph.
    51   /// \param graph The undirected graph.
    64       }
    64       }
    65     }
    65     }
    66     return true;
    66     return true;
    67   }
    67   }
    68 
    68 
    69   /// \ingroup topology
    69   /// \ingroup graph_prop
    70   ///
    70   ///
    71   /// \brief Count the number of connected components of an undirected graph
    71   /// \brief Count the number of connected components of an undirected graph
    72   ///
    72   ///
    73   /// Count the number of connected components of an undirected graph
    73   /// Count the number of connected components of an undirected graph
    74   ///
    74   ///
   106       }
   106       }
   107     }
   107     }
   108     return compNum;
   108     return compNum;
   109   }
   109   }
   110 
   110 
   111   /// \ingroup topology
   111   /// \ingroup graph_prop
   112   ///
   112   ///
   113   /// \brief Find the connected components of an undirected graph
   113   /// \brief Find the connected components of an undirected graph
   114   ///
   114   ///
   115   /// Find the connected components of an undirected graph.
   115   /// Find the connected components of an undirected graph.
   116   ///
   116   ///
   229     };
   229     };
   230 
   230 
   231   }
   231   }
   232 
   232 
   233 
   233 
   234   /// \ingroup topology
   234   /// \ingroup graph_prop
   235   ///
   235   ///
   236   /// \brief Check that the given directed graph is strongly connected.
   236   /// \brief Check that the given directed graph is strongly connected.
   237   ///
   237   ///
   238   /// Check that the given directed graph is strongly connected. The
   238   /// Check that the given directed graph is strongly connected. The
   239   /// graph is strongly connected when any two nodes of the graph are
   239   /// graph is strongly connected when any two nodes of the graph are
   285     }
   285     }
   286 
   286 
   287     return true;
   287     return true;
   288   }
   288   }
   289 
   289 
   290   /// \ingroup topology
   290   /// \ingroup graph_prop
   291   ///
   291   ///
   292   /// \brief Count the strongly connected components of a directed graph
   292   /// \brief Count the strongly connected components of a directed graph
   293   ///
   293   ///
   294   /// Count the strongly connected components of a directed graph.
   294   /// Count the strongly connected components of a directed graph.
   295   /// The strongly connected components are the classes of an
   295   /// The strongly connected components are the classes of an
   349       }
   349       }
   350     }
   350     }
   351     return compNum;
   351     return compNum;
   352   }
   352   }
   353 
   353 
   354   /// \ingroup topology
   354   /// \ingroup graph_prop
   355   ///
   355   ///
   356   /// \brief Find the strongly connected components of a directed graph
   356   /// \brief Find the strongly connected components of a directed graph
   357   ///
   357   ///
   358   /// Find the strongly connected components of a directed graph.  The
   358   /// Find the strongly connected components of a directed graph.  The
   359   /// strongly connected components are the classes of an equivalence
   359   /// strongly connected components are the classes of an equivalence
   419       }
   419       }
   420     }
   420     }
   421     return compNum;
   421     return compNum;
   422   }
   422   }
   423 
   423 
   424   /// \ingroup topology
   424   /// \ingroup graph_prop
   425   ///
   425   ///
   426   /// \brief Find the cut edges of the strongly connected components.
   426   /// \brief Find the cut edges of the strongly connected components.
   427   ///
   427   ///
   428   /// Find the cut edges of the strongly connected components.
   428   /// Find the cut edges of the strongly connected components.
   429   /// The strongly connected components are the classes of an equivalence
   429   /// The strongly connected components are the classes of an equivalence
   703   }
   703   }
   704 
   704 
   705   template <typename UGraph>
   705   template <typename UGraph>
   706   int countBiNodeConnectedComponents(const UGraph& graph);
   706   int countBiNodeConnectedComponents(const UGraph& graph);
   707 
   707 
   708   /// \ingroup topology
   708   /// \ingroup graph_prop
   709   ///
   709   ///
   710   /// \brief Checks the graph is bi-node-connected.
   710   /// \brief Checks the graph is bi-node-connected.
   711   ///
   711   ///
   712   /// This function checks that the undirected graph is bi-node-connected  
   712   /// This function checks that the undirected graph is bi-node-connected  
   713   /// graph. The graph is bi-node-connected if any two undirected edge is 
   713   /// graph. The graph is bi-node-connected if any two undirected edge is 
   719   template <typename UGraph>
   719   template <typename UGraph>
   720   bool biNodeConnected(const UGraph& graph) {
   720   bool biNodeConnected(const UGraph& graph) {
   721     return countBiNodeConnectedComponents(graph) == 1;
   721     return countBiNodeConnectedComponents(graph) == 1;
   722   }
   722   }
   723 
   723 
   724   /// \ingroup topology
   724   /// \ingroup graph_prop
   725   ///
   725   ///
   726   /// \brief Count the biconnected components.
   726   /// \brief Count the biconnected components.
   727   ///
   727   ///
   728   /// This function finds the bi-node-connected components in an undirected 
   728   /// This function finds the bi-node-connected components in an undirected 
   729   /// graph. The biconnected components are the classes of an equivalence 
   729   /// graph. The biconnected components are the classes of an equivalence 
   754       }
   754       }
   755     }
   755     }
   756     return compNum;
   756     return compNum;
   757   }
   757   }
   758 
   758 
   759   /// \ingroup topology
   759   /// \ingroup graph_prop
   760   ///
   760   ///
   761   /// \brief Find the bi-node-connected components.
   761   /// \brief Find the bi-node-connected components.
   762   ///
   762   ///
   763   /// This function finds the bi-node-connected components in an undirected 
   763   /// This function finds the bi-node-connected components in an undirected 
   764   /// graph. The bi-node-connected components are the classes of an equivalence
   764   /// graph. The bi-node-connected components are the classes of an equivalence
   800       }
   800       }
   801     }
   801     }
   802     return compNum;
   802     return compNum;
   803   }
   803   }
   804 
   804 
   805   /// \ingroup topology
   805   /// \ingroup graph_prop
   806   ///
   806   ///
   807   /// \brief Find the bi-node-connected cut nodes.
   807   /// \brief Find the bi-node-connected cut nodes.
   808   ///
   808   ///
   809   /// This function finds the bi-node-connected cut nodes in an undirected 
   809   /// This function finds the bi-node-connected cut nodes in an undirected 
   810   /// graph. The bi-node-connected components are the classes of an equivalence
   810   /// graph. The bi-node-connected components are the classes of an equivalence
  1030   }
  1030   }
  1031 
  1031 
  1032   template <typename UGraph>
  1032   template <typename UGraph>
  1033   int countBiEdgeConnectedComponents(const UGraph& graph);
  1033   int countBiEdgeConnectedComponents(const UGraph& graph);
  1034 
  1034 
  1035   /// \ingroup topology
  1035   /// \ingroup graph_prop
  1036   ///
  1036   ///
  1037   /// \brief Checks that the graph is bi-edge-connected.
  1037   /// \brief Checks that the graph is bi-edge-connected.
  1038   ///
  1038   ///
  1039   /// This function checks that the graph is bi-edge-connected. The undirected
  1039   /// This function checks that the graph is bi-edge-connected. The undirected
  1040   /// graph is bi-edge-connected when any two nodes are connected with two
  1040   /// graph is bi-edge-connected when any two nodes are connected with two
  1046   template <typename UGraph>
  1046   template <typename UGraph>
  1047   bool biEdgeConnected(const UGraph& graph) { 
  1047   bool biEdgeConnected(const UGraph& graph) { 
  1048     return countBiEdgeConnectedComponents(graph) == 1;
  1048     return countBiEdgeConnectedComponents(graph) == 1;
  1049   }
  1049   }
  1050 
  1050 
  1051   /// \ingroup topology
  1051   /// \ingroup graph_prop
  1052   ///
  1052   ///
  1053   /// \brief Count the bi-edge-connected components.
  1053   /// \brief Count the bi-edge-connected components.
  1054   ///
  1054   ///
  1055   /// This function count the bi-edge-connected components in an undirected 
  1055   /// This function count the bi-edge-connected components in an undirected 
  1056   /// graph. The bi-edge-connected components are the classes of an equivalence
  1056   /// graph. The bi-edge-connected components are the classes of an equivalence
  1081       }
  1081       }
  1082     }
  1082     }
  1083     return compNum;
  1083     return compNum;
  1084   }
  1084   }
  1085 
  1085 
  1086   /// \ingroup topology
  1086   /// \ingroup graph_prop
  1087   ///
  1087   ///
  1088   /// \brief Find the bi-edge-connected components.
  1088   /// \brief Find the bi-edge-connected components.
  1089   ///
  1089   ///
  1090   /// This function finds the bi-edge-connected components in an undirected 
  1090   /// This function finds the bi-edge-connected components in an undirected 
  1091   /// graph. The bi-edge-connected components are the classes of an equivalence
  1091   /// graph. The bi-edge-connected components are the classes of an equivalence
  1126       }
  1126       }
  1127     }
  1127     }
  1128     return compNum;
  1128     return compNum;
  1129   }
  1129   }
  1130 
  1130 
  1131   /// \ingroup topology
  1131   /// \ingroup graph_prop
  1132   ///
  1132   ///
  1133   /// \brief Find the bi-edge-connected cut edges.
  1133   /// \brief Find the bi-edge-connected cut edges.
  1134   ///
  1134   ///
  1135   /// This function finds the bi-edge-connected components in an undirected 
  1135   /// This function finds the bi-edge-connected components in an undirected 
  1136   /// graph. The bi-edge-connected components are the classes of an equivalence
  1136   /// graph. The bi-edge-connected components are the classes of an equivalence
  1190       int _num;
  1190       int _num;
  1191     };
  1191     };
  1192     
  1192     
  1193   }
  1193   }
  1194 
  1194 
  1195   /// \ingroup topology
  1195   /// \ingroup graph_prop
  1196   ///
  1196   ///
  1197   /// \brief Sort the nodes of a DAG into topolgical order.
  1197   /// \brief Sort the nodes of a DAG into topolgical order.
  1198   ///
  1198   ///
  1199   /// Sort the nodes of a DAG into topolgical order.
  1199   /// Sort the nodes of a DAG into topolgical order.
  1200   ///
  1200   ///
  1229 	dfs.start();
  1229 	dfs.start();
  1230       }
  1230       }
  1231     }    
  1231     }    
  1232   }
  1232   }
  1233 
  1233 
  1234   /// \ingroup topology
  1234   /// \ingroup graph_prop
  1235   ///
  1235   ///
  1236   /// \brief Sort the nodes of a DAG into topolgical order.
  1236   /// \brief Sort the nodes of a DAG into topolgical order.
  1237   ///
  1237   ///
  1238   /// Sort the nodes of a DAG into topolgical order. It also checks
  1238   /// Sort the nodes of a DAG into topolgical order. It also checks
  1239   /// that the given graph is DAG.
  1239   /// that the given graph is DAG.
  1281       }
  1281       }
  1282     }
  1282     }
  1283     return true;
  1283     return true;
  1284   }
  1284   }
  1285 
  1285 
  1286   /// \ingroup topology
  1286   /// \ingroup graph_prop
  1287   ///
  1287   ///
  1288   /// \brief Check that the given directed graph is a DAG.
  1288   /// \brief Check that the given directed graph is a DAG.
  1289   ///
  1289   ///
  1290   /// Check that the given directed graph is a DAG. The DAG is
  1290   /// Check that the given directed graph is a DAG. The DAG is
  1291   /// an Directed Acyclic Graph.
  1291   /// an Directed Acyclic Graph.
  1323       }
  1323       }
  1324     }    
  1324     }    
  1325     return true;
  1325     return true;
  1326   }
  1326   }
  1327 
  1327 
  1328   /// \ingroup topology
  1328   /// \ingroup graph_prop
  1329   ///
  1329   ///
  1330   /// \brief Check that the given undirected graph is acyclic.
  1330   /// \brief Check that the given undirected graph is acyclic.
  1331   ///
  1331   ///
  1332   /// Check that the given undirected graph acyclic.
  1332   /// Check that the given undirected graph acyclic.
  1333   /// \param graph The undirected graph.
  1333   /// \param graph The undirected graph.
  1357       }
  1357       }
  1358     }
  1358     }
  1359     return true;
  1359     return true;
  1360   }
  1360   }
  1361 
  1361 
  1362   /// \ingroup topology
  1362   /// \ingroup graph_prop
  1363   ///
  1363   ///
  1364   /// \brief Check that the given undirected graph is tree.
  1364   /// \brief Check that the given undirected graph is tree.
  1365   ///
  1365   ///
  1366   /// Check that the given undirected graph is tree.
  1366   /// Check that the given undirected graph is tree.
  1367   /// \param graph The undirected graph.
  1367   /// \param graph The undirected graph.
  1449       PartMap& _part;
  1449       PartMap& _part;
  1450       bool& _bipartite;
  1450       bool& _bipartite;
  1451     };
  1451     };
  1452   }
  1452   }
  1453 
  1453 
  1454   /// \ingroup topology
  1454   /// \ingroup graph_prop
  1455   ///
  1455   ///
  1456   /// \brief Check if the given undirected graph is bipartite or not
  1456   /// \brief Check if the given undirected graph is bipartite or not
  1457   ///
  1457   ///
  1458   /// The function checks if the given undirected \c graph graph is bipartite 
  1458   /// The function checks if the given undirected \c graph graph is bipartite 
  1459   /// or not. The \ref Bfs algorithm is used to calculate the result.
  1459   /// or not. The \ref Bfs algorithm is used to calculate the result.
  1488       }
  1488       }
  1489     }
  1489     }
  1490     return true;
  1490     return true;
  1491   }
  1491   }
  1492   
  1492   
  1493   /// \ingroup topology
  1493   /// \ingroup graph_prop
  1494   ///
  1494   ///
  1495   /// \brief Check if the given undirected graph is bipartite or not
  1495   /// \brief Check if the given undirected graph is bipartite or not
  1496   ///
  1496   ///
  1497   /// The function checks if the given undirected graph is bipartite 
  1497   /// The function checks if the given undirected graph is bipartite 
  1498   /// or not. The  \ref  Bfs  algorithm  is   used  to  calculate the result. 
  1498   /// or not. The  \ref  Bfs  algorithm  is   used  to  calculate the result.