Specy / microlp

A pure Rust linear programming solver
Apache License 2.0
1 stars 0 forks source link

Using large values like i64::MAX or f64::MAX causes non optimal solutions #3

Open Specy opened 6 hours ago

Specy commented 6 hours ago
        let mut problem = Problem::new(OptimizationDirection::Maximize);

        let x = problem.add_var(50.0, (2.0, f64::INFINITY));
        let y = problem.add_var(40.0, (0.0, 7.0)); 

        let z = problem.add_var(45.0, (0.0, f64::MAX)); //<----- here

        problem.add_constraint(&[(x, 3.0), (y, 2.0), (z, 1.0)], ComparisonOp::Le, 20.0);
        problem.add_constraint(&[(x, 2.0), (y, 1.0), (z, 3.0)], ComparisonOp::Le, 15.0);

        let sol = problem.solve().unwrap();

For example this gives solution [2.0, 0.0, 0.0] while using f64::INFINITY gives [2.0, 6.2, 1.6] and f32::MAX gives [2.0, 7.0, 0.0]

the correct value is [2.0, 6.2, 1.6]

Specy commented 5 hours ago

@lovasoa should the f64::INFINITY vs f64::MAX difference be considered a bug?

lovasoa commented 5 hours ago

i think so, yes

Specy commented 5 hours ago

Worth to look at this old PR: https://github.com/ztlpn/minilp/pull/4/files#diff-cbd16a2b1fdb7e2f39b676831dfaee5250000b403a9f1fcfcbfede424d7cbf73