Expand description
NETGEN, a classic min-cost flow / assignment / max-flow generator.
Produces DIMACS-formatted flow problem instances (assignment, max flow, or min-cost flow) matching the original NETGEN (Klingman, Napier, Stutz, 1974) implementation, including the BCJL overflow fixes.
This crate is a pure-Rust rewrite of the reference C implementation shipped with the DIMACS network flow challenge.
§Usage
§Quick start
use netgen_rs::{generate, NetgenParams};
let params = NetgenParams {
nodes: 512,
sources: 10,
sinks: 10,
density: 2000,
mincost: 5,
maxcost: 500,
supply: 1000,
tsources: 3,
tsinks: 3,
hicost_pct: 20,
capacitated_pct: 80,
mincap: 50,
maxcap: 2000,
};
let result = generate(13502460, ¶ms).unwrap();
println!("Generated {} arcs", result.arcs.len());§Writing DIMACS output
Use write_dimacs to stream into any io::Write, or
to_dimacs_string to collect into a string.
use netgen_rs::{generate, write_dimacs, NetgenParams};
let params = NetgenParams::from_slice(&[
512, 10, 10, 2000, 5, 500, 1000, 3, 3, 20, 80, 50, 2000,
])?;
let dimacs = netgen_rs::to_dimacs_string(13502460, 1, ¶ms)?;
println!("{}", dimacs.lines().next().unwrap());
let result = generate(13502460, ¶ms)?;
let stdout = std::io::stdout();
write_dimacs(&mut stdout.lock(), 13502460, 1, ¶ms, &result)?;The 13 integers mirror the original parms[] array (see
NetgenParams).
Structs§
- Arc
- A single arc in the generated network.
- Netgen
Params - Parameters for network generation.
- Netgen
Result - Result of network generation.
Enums§
- Netgen
Error - Errors that may occur while running the generator.
- Param
Error - Specific parameter validation errors.
- Problem
Type - Problem type detected from parameters.
Functions§
- generate
- Generate a network flow problem.
- to_
dimacs_ string - Generate and format as DIMACS string.
- write_
dimacs - Write complete DIMACS output (header + network).
- write_
dimacs_ header - Write the DIMACS-format header comments.
- write_
dimacs_ network - Write the DIMACS-format network data (problem line, node lines, arc lines).