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

Bug CLP(B) and CLP(FD) dont work together #14

Open
ghost opened this issue Mar 4, 2021 · 2 comments
Open

Bug CLP(B) and CLP(FD) dont work together #14

ghost opened this issue Mar 4, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 4, 2021

I am not assuming that CLP(B) from SWI-Prolog uses branch and bound
for weighted_maximum/2. But theoreticall CLP(B) branch and bound should
work for any constraints, given as freeze/2, when/2, CLP(FD) etc..

I tried this theoretical claim. In my system I get:

/* Jekejeke Prolog 1.5.0 */
?- List = [Alice, Bob, Carla, David], weighted_maximum([5,-3,7,-9], List, Max).
List = [1, 0, 1, 0],
Max = 12 ;
No

?- List = [Alice, Bob, Carla, David], Alice*5-Bob*3+Carla*7-David*9 #<10, 
   weighted_maximum([5,-3,7,-9], List, Max).
List = [1, 1, 1, 0],
Max = 9 ;
No

But in SWI-Prolog I get:

/* SWI-Prolog 8.3.20 */
?- List = [Alice, Bob, Carla, David], weighted_maximum([5,-3,7,-9], List, Max).
List = [1, 0, 1, 0],
Max = 12.

?- List = [Alice, Bob, Carla, David], Alice*5-Bob*3+Carla*7-David*9 #<10, 
   weighted_maximum([5,-3,7,-9], List, Max).
false.

Is this unavoidable in SWI-Prolog? Does CLP(Z) fare better?

@triska
Copy link
Owner

triska commented Mar 4, 2021

In Scryer Prolog, I currently also get:

?- List = [Alice, Bob, Carla, David], Alice*5-Bob*3+Carla*7-David*9 #<10,
   weighted_maximum([5,-3,7,-9], List, Max).
false.

Definitely a wrong result.

@ghost
Copy link
Author

ghost commented Mar 5, 2021

The problem carries over to sat_count/2:

/* SWI-Prolog 8.3.20 */
?- List = [Alice, Bob, Carla, David], Alice*5-Bob*3+Carla*7-David*9 #<10, sat_count(+[1|List], Count).
List = [Alice, Bob, Carla, David],
Count = 16,
5*Alice+7*Carla#=<3*Bob+9*David+9.

?- List = [Alice, Bob, Carla, David], Alice*5-Bob*3+Carla*7-David*9 #<10, aggregate_all(count, labeling(List), Count).
List = [Alice, Bob, Carla, David],
Count = 15,
5*Alice+7*Carla#=<3*Bob+9*David+9.

Seems ok on my side:

/* Jekejeke Prolog 1.5.0 */
?- List = [Alice, Bob, Carla, David], Alice*5-Bob*3+Carla*7-David*9 #<10, sat_count(+[1|List], Count).
List = [Alice, Bob, Carla, David],
Count = 15,
9*David #> 5*Alice-3*Bob+7*Carla-10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant