Skip to main content

Crate gridgraph_rs

Crate gridgraph_rs 

Source
Expand description

GRIDGRAPH, a min-cost flow grid graph generator

Produces a min-cost flow problem instance in DIMACS .min format, laid out on a directed grid graph. Originally by Mauricio G.C. Resende (1991), AT&T Bell Laboratories.

This is a Rust rewrite of the original Fortran program ggraph1.f.

§Usage

§Quick start

use gridgraph_rs::{generate_instance, GridGraphParams};

let params = GridGraphParams::new(3, 3, 100, 10, 12345).unwrap();
let instance = generate_instance(params);
println!("{}", instance.to_dimacs_string());

§Writing to a file

Use DimacsInstance::write_dimacs_io to stream into any io::Write or the convenience DimacsInstance::write_to_file helper for buffered file output.

use gridgraph_rs::{generate_instance, GridGraphParams};
use std::error::Error;
use std::fs::File;
use std::io::{BufWriter, Write};

fn main() -> Result<(), Box<dyn Error>> {
    let params = GridGraphParams::new(3, 3, 100, 10, 12345)?;
    let instance = generate_instance(params);
    let path = std::env::temp_dir().join("gridgraph_doc_example.min");

    // Write to any `io::Write` implementor
    {
        let file = File::create(&path)?;
        let mut buf = BufWriter::new(file);
        instance.write_dimacs_io(&mut buf)?;
        buf.flush()?;
    }

    // Or let the helper create the buffered file for you
    instance.write_to_file(&path)?;
    std::fs::remove_file(path)?;
    Ok(())
}

The five integers correspond to grid dimensions, capacity/cost bounds and RNG seed. See GridGraphParams for details.

Structs§

DimacsInstance
Complete DIMACS min-cost flow instance for a GRIDGRAPH.
GridArc
Directed arc within the generated grid graph.
GridGraphParams
Parameters that fully describe a GRIDGRAPH instance.

Enums§

GridGraphError
Errors returned when the supplied parameters are invalid.

Functions§

generate_dimacs
Generate a DIMACS .min string for the supplied parameters.
generate_instance
Generate a grid graph instance along with all derived metadata.