Skip to main content

Crate netgen_rs

Crate netgen_rs 

Source
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, &params).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, &params)?;
println!("{}", dimacs.lines().next().unwrap());

let result = generate(13502460, &params)?;
let stdout = std::io::stdout();
write_dimacs(&mut stdout.lock(), 13502460, 1, &params, &result)?;

The 13 integers mirror the original parms[] array (see NetgenParams).

Structs§

Arc
A single arc in the generated network.
NetgenParams
Parameters for network generation.
NetgenResult
Result of network generation.

Enums§

NetgenError
Errors that may occur while running the generator.
ParamError
Specific parameter validation errors.
ProblemType
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).