Skip to main content

write_dimacs_flow

Function write_dimacs_flow 

Source
pub fn write_dimacs_flow<W: Write>(
    graph: &Graph,
    source: u32,
    target: u32,
    capacity: &[f64],
    writer: &mut W,
) -> IgraphResult<()>
Expand description

Write a graph in DIMACS max-flow format.

Writes the problem line, source/target node lines, and arc lines with capacity values.

ยงExamples

use rust_igraph::{Graph, write_dimacs_flow};

let mut g = Graph::new(4, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();

let capacity = vec![10.0, 5.0, 8.0];
let mut buf = Vec::new();
write_dimacs_flow(&g, 0, 3, &capacity, &mut buf).unwrap();
let s = String::from_utf8(buf).unwrap();
assert!(s.contains("p max 4 3"));
assert!(s.contains("n 1 s"));
assert!(s.contains("n 4 t"));