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

Gecode CANNOT solve official "Real Number Solving" example #817

Open
littleQiu22 opened this issue Jun 4, 2024 · 0 comments
Open

Gecode CANNOT solve official "Real Number Solving" example #817

littleQiu22 opened this issue Jun 4, 2024 · 0 comments
Labels
documentation Issue is related to documentation/tutorial

Comments

@littleQiu22
Copy link

  • Minizinc IDE Version: 2.8.5

  • OS: Windows11

  • Expectation

Official example "Real Number Solving" should be solved by gecode, just like other MIP solvers do.

  • Reality

When I execute command minizinc.exe --solver gecode loan.mzn loan1.dzn, it shows =====UNSATISFIABLE=====.

But when I switch to MIP solver by minizinc.exe --solver cbc loan.mzn loan1.dzn, it correctly shows result Borrowing 1000.00 at 4.0% interest, and repaying 260.00 per quarter for 1 year leaves 65.78 owing ---------- .

  • Model & Data

loan.mzn

% variables
var float: R;        % quarterly repayment
var float: P;        % principal initially borrowed
var 0.0 .. 10.0: I;  % interest rate (per quarter)

% intermediate variables
var float: B1; % balance after one quarter
var float: B2; % balance after two quarters
var float: B3; % balance after three quarters
var float: B4; % balance owing at end

constraint B1 = P * (1.0 + I) - R;
constraint B2 = B1 * (1.0 + I) - R;
constraint B3 = B2 * (1.0 + I) - R; 
constraint B4 = B3 * (1.0 + I) - R;

solve satisfy;

output [
 "Borrowing ", show_float(0, 2, P), " at ", show(I*100.0), 
 "% interest, and repaying ", show_float(0, 2, R), 
  "\nper quarter for 1 year leaves ", show_float(0, 2, B4), " owing\n"
];

% inputs to allow us to enter values from playground/IDE
opt float: R_IN;     % quarterly repayment
opt float: P_IN;     % principal initially borrowed
opt float: I_IN;     % interest rate (per quarter)
opt float: B4_IN;    % balance owing at end

constraint R ~= R_IN;
constraint P ~= P_IN;
constraint I ~= I_IN;
constraint B4 ~= B4_IN;

loan1.dzn

I = 0.04;
P = 1000.0;
R = 260.0;
  • My analysis

Compiled fzn file is

array [1..2] of float: X_INTRODUCED_4_ = [1.0,-1.04];
constraint float_lin_eq(X_INTRODUCED_4_,[551.2,780.0],-260.0);
constraint float_lin_eq(X_INTRODUCED_4_,[313.248,551.2],-260.0);
constraint float_lin_eq(X_INTRODUCED_4_,[65.77792000000005,313.248],-260.0);
solve  satisfy;

, which are doing following calculations:

1.0 * 551.2                     - 1.04 * 780.0      == -260
1.0 * 313.248                   - 1.04 * 551.2      == -260
1.0 * 65.77792000000005         - 1.04 * 313.248    == -260

Do these calculations and left-hand-side terms are:

-260.0
-260.0
-259.99999999999995

Even though precision of floating-point numbers after compilation seems acceptable, but gecode doesn't think it's feasible.

Maybe precision of floating-point numbers in gecode differ from precision of floating-point numbers in MiniZinc compiler?

@cyderize cyderize added the documentation Issue is related to documentation/tutorial label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issue is related to documentation/tutorial
Projects
None yet
Development

No branches or pull requests

2 participants