Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Specy opened this issue Nov 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Specy
Copy link
Owner

Specy commented Nov 5, 2024

        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
Copy link
Owner Author

Specy commented Nov 5, 2024

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

@Specy Specy changed the title Using large values like i64::MAX or f64::MAX causes non optimal values Using large values like i64::MAX or f64::MAX causes non optimal solutions Nov 5, 2024
@lovasoa
Copy link
Collaborator

lovasoa commented Nov 5, 2024

i think so, yes

@Specy
Copy link
Owner Author

Specy commented Nov 5, 2024

@Specy Specy added the bug Something isn't working label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants