ridgeworks / clpBNR

CLP(BNR) module for SWI-Prolog
MIT License
38 stars 5 forks source link

Not getting expected solution with global_minimum/2 #6

Closed JeanChristopheRohner closed 3 years ago

JeanChristopheRohner commented 3 years ago

Hi!

Not sure if this is a bug or limitation...

Running test:

:-use_module(library(clpBNR)).

x1(X1):- X1::real(0.1, 0.9).
x2(X2):- X2::real(0.1, 0.9).
x3(X3):- X3::real(0.1, 0.9).

z(Z, OUT):- 
    x1(X1),
    x2(X2),
    x3(X3),
    {Z == 1 - (abs(X1 - 1) + abs(X2 - 1) + abs(X3 + 1)) / 3},
    OUT = [X1, X2, X3].

test:- z(Z, OUT), global_minimum(Z, _), maplist(writeln, OUT).

Yields:

_50{real(0.09999999999999999,0.10000228881835882)}
_92{real(0.09999999999999999,0.10000228881835882)}
_134{real(0.09999999999999999,0.9000000000000001)}

But shouldn't the last one be 0.9?

Kind regards, JCR

ridgeworks commented 3 years ago

Definitely a bug in the abs primitive. With a fix:

?- test.
_66{real(0.09999999999999999,0.10000228881835704)}
_108{real(0.09999999999999999,0.10000228881835704)}
_150{real(0.8999977111816431,0.9000000000000001)}
true.

I plan to push a new version (v0.9.3alpha), including this fix, in the next week or so, but if you're willing to edit your current version I can provide a fairly simple patch.

Thanks for testing, RW

JeanChristopheRohner commented 3 years ago

Thanks! I can wait until the new version :-)

ridgeworks commented 3 years ago

OK. I'll reply here when it's available. Nothing major, but it'll include a first cut at a reference section for the User Guide.

ridgeworks commented 3 years ago

abs fix included in version 0.9.3alpha now available on GitHub. (SWI package list may take a few days to update.)