[ojAlgo-user] Integer Linear Programming: ojAlgo calculates invalid solution
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Uli S. <Uli...@In...> - 2015-01-27 09:10:11
|
Hi everyone, the attached Java program solves a relatively simple ILP with ojAlgo. However, the solution calculates is invalid. Can somehow shed some light into why this is? Hopefully the program explains itself, but here is some more text: The function getCoefficients() returns the coefficients for 202 inequalities of the form coef[0]*x + coef[1]*y < 0. The main function creates an ExpressionsBasedModel from this, transformimg the "< 0" into "<= -1" (which is valid since this is about integer values). It prints the solution calculated and then checks if all the inequalities really are satisfied. However, this fails since the solution calculated doesn't solve all inequalities: x = 19.999999999999993 ~ 20 y = -0.9950000000000006 ~ -1 Exception in thread "main" java.lang.Exception: -10*x + -200*y = 0 must be negative (exact: -0.9999999999998100) at Solve.main(Solve.java:60) The program also prints the exact solutions calculated from the BigDecimals that ojAlgo produced. This is the "exact" value you see in the error message above and, as you see, this value (almost) satisfies the condition "<= -1". Valid solutions to this inequality systems would be x=21, y=-1 or x=201, y=-10. Obviously, this seems to be a rounding issue. Is there anything that can be done about it? Cheers, Uli -- - Buck, when, exactly, did you lose your mind? - Three months ago. I woke up one morning married to a pineapple. An ugly pineapple... But I loved her. |