Skip to main content

min_st_cut

Function min_st_cut 

Source
pub fn min_st_cut(
    graph: &SqliteGraph,
    source: i64,
    sink: i64,
) -> Result<MinCutResult, SqliteGraphError>
Expand description

Compute minimum s-t edge cut using max-flow min-cut theorem.

Returns the smallest set of edges whose removal disconnects source from sink. Uses Edmonds-Karp algorithm for max-flow computation with unit capacities.

§Arguments

  • graph - The graph to analyze
  • source - The source node ID
  • sink - The sink (target) node ID

§Returns

MinCutResult containing source_side, sink_side, cut_edges, and cut_size.

§Errors

  • Returns SqliteGraphError::NotFound if source or sink doesn’t exist
  • Returns error if graph traversal fails

§Complexity

  • Time: O(|V| * |E|²) for Edmonds-Karp where V = vertices, E = edges
  • Space: O(|V| + |E|) for residual graph and BFS queue

§Edge Cases

  • Source == Sink: Returns empty cut (trivially connected)
  • Disconnected nodes: Returns empty cut (no path = zero cut capacity)
  • Single edge graph: Returns cut containing that single edge

§Example

use sqlitegraph::{SqliteGraph, algo::min_st_cut};

let graph = SqliteGraph::open_in_memory()?;
// ... build graph: 1 -> 2 -> 3 -> 4 -> 5 ...

let result = min_st_cut(&graph, 1, 5)?;
println!("Min cut size: {}", result.cut_size);
println!("Cut edges: {:?}", result.cut_edges);