|
14 | 14 |
|
15 | 15 | mod all_pairs_all_simple_paths; |
16 | 16 | mod johnson_simple_cycles; |
17 | | -mod minimum_cycle_basis; |
| 17 | +mod min_cycle_basis; |
18 | 18 | mod subgraphs; |
19 | 19 |
|
20 | 20 | use super::{ |
@@ -919,25 +919,54 @@ pub fn stoer_wagner_min_cut( |
919 | 919 | })) |
920 | 920 | } |
921 | 921 |
|
| 922 | +/// Find a minimum cycle basis of an undirected graph. |
| 923 | +/// All weights must be nonnegative. If the input graph does not have |
| 924 | +/// any nodes or edges, this function returns ``None``. |
| 925 | +/// If the input graph does not any weight, this function will find the |
| 926 | +/// minimum cycle basis with the weight of 1.0 for all edges. |
| 927 | +/// |
| 928 | +/// :param PyGraph: The undirected graph to be used |
| 929 | +/// :param Callable edge_cost_fn: An optional callable object (function, lambda, etc) which |
| 930 | +/// will be passed the edge object and expected to return a ``float``. |
| 931 | +/// Edges with ``NaN`` weights will be considered to have 1.0 weight. |
| 932 | +/// If ``edge_cost_fn`` is not specified a default value of ``1.0`` will be used for all edges. |
| 933 | +/// |
| 934 | +/// :returns: A list of cycles, where each cycle is a list of node indices |
| 935 | +/// :rtype: list |
922 | 936 | #[pyfunction] |
923 | 937 | #[pyo3(text_signature = "(graph, edge_cost_fn, /)")] |
924 | 938 | pub fn graph_minimum_cycle_basis( |
925 | 939 | py: Python, |
926 | 940 | graph: &graph::PyGraph, |
927 | 941 | edge_cost_fn: PyObject, |
928 | 942 | ) -> PyResult<Vec<Vec<NodeIndices>>> { |
929 | | - let basis = minimum_cycle_basis::minimum_cycle_basis_map(py, &graph.graph, edge_cost_fn); |
930 | | - Ok(basis |
931 | | - .into_iter() |
932 | | - .map(|cycle| { |
933 | | - cycle |
934 | | - .into_iter() |
935 | | - .map(|node| NodeIndices { |
936 | | - nodes: node.iter().map(|nx| nx.index()).collect(), |
937 | | - }) |
938 | | - .collect() |
939 | | - }) |
940 | | - .collect()) |
| 943 | + min_cycle_basis::minimum_cycle_basis(py, &graph.graph, edge_cost_fn) |
| 944 | +} |
| 945 | + |
| 946 | +/// Find a minimum cycle basis of a directed graph (which is not of interest in the context |
| 947 | +/// of minimum cycle basis). This function will return the minimum cycle basis of the |
| 948 | +/// underlying undirected graph of the input directed graph. |
| 949 | +/// All weights must be nonnegative. If the input graph does not have |
| 950 | +/// any nodes or edges, this function returns ``None``. |
| 951 | +/// If the input graph does not any weight, this function will find the |
| 952 | +/// minimum cycle basis with the weight of 1.0 for all edges. |
| 953 | +/// |
| 954 | +/// :param PyDiGraph: The directed graph to be used |
| 955 | +/// :param Callable edge_cost_fn: An optional callable object (function, lambda, etc) which |
| 956 | +/// will be passed the edge object and expected to return a ``float``. |
| 957 | +/// Edges with ``NaN`` weights will be considered to have 1.0 weight. |
| 958 | +/// If ``edge_cost_fn`` is not specified a default value of ``1.0`` will be used for all edges. |
| 959 | +/// |
| 960 | +/// :returns: A list of cycles, where each cycle is a list of node indices |
| 961 | +/// :rtype: list |
| 962 | +#[pyfunction] |
| 963 | +#[pyo3(text_signature = "(graph, edge_cost_fn, /)")] |
| 964 | +pub fn digraph_minimum_cycle_basis( |
| 965 | + py: Python, |
| 966 | + graph: &digraph::PyDiGraph, |
| 967 | + edge_cost_fn: PyObject, |
| 968 | +) -> PyResult<Vec<Vec<NodeIndices>>> { |
| 969 | + min_cycle_basis::minimum_cycle_basis(py, &graph.graph, edge_cost_fn) |
941 | 970 | } |
942 | 971 |
|
943 | 972 | /// Return the articulation points of an undirected graph. |
|
0 commit comments