rust-or / good_lp

Linear Programming for Rust, with a user-friendly API. This crate allows modeling LP problems, and lets you solve them with various solvers.
https://crates.io/crates/good_lp
MIT License
216 stars 35 forks source link

`mul` with a float doesn't seem to to the right thing for binary variables #16

Closed urli closed 2 years ago

urli commented 2 years ago

I'm trying to build a sum based on binary variables and coefficients, but the resulting expression doesn't seem to be correct.

let weights = vec![1.1, 1.2, 1.0, 0.9];
let mut vars = variables!();

let xs = vars.add_vector(variable().binary(), weights.len());

let objective = Expression::sum((0..weights.len()).iter().map(|i| xs[i].mul(weights[i])));

I would expect the xs variables to interpreted as ones or zeroes in the sum, i.e., the objective being the sum of the weights of the variables set to 1. However, it appears that the objective is capped at a value smaller than the sum of the weights.

urli commented 2 years ago

I need to research this better before I say anything more.