#linear-programming #bin-packing #problem #binpack

bin+lib binpack

solve binpacking problems using Linear Programming

1 unstable release

Uses new Rust 2024

new 0.1.0 May 14, 2025

#705 in Math

MIT/Apache

22KB
373 lines

Binpack

A rust crate for solving binpacking problems using Linear Programming.

Usage

use binpack::Problem;

const PROBLEM: &str = r#"
bins:
  b1: 100
  b2: 40
  b3: 10

items:
  i1:
    quantity: 30
    affinity:
      soft:
        - weight: 1
          bins: [b1]
    antiAffinity:
      hard:
        bins: [b3]
  i2:
    quantity: 110
    affinity:
      soft:
        - weight: 2
          bins: [b1]
  i3:
    quantity: 10
"#;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let problem: Problem = serde_yaml::from_str(PROBLEM)?;
    let solution = problem.solve()?;

    println!("{}", serde_yaml::to_string(&solution)?);
    assert_eq!(serde_yaml::to_string(&solution)?.trim(), SOLUTION.trim());
    Ok(())
}

const SOLUTION: &str = r#"
solution:
  i1:
    b2: 30
  i2:
    b1: 100
    b3: 10
  i3:
    b2: 10
"#;

License

binpack is dual-licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2–2.8MB
~60K SLoC