broccoli
broccoli

Reputation: 4836

SWI Prolog maximize function appears to not work

I'm new to prolog and I'm using swi-prolog on ubuntu to learn. I'm using the clpfd module to solve a worker/product allocation problem. The problem is stated in this paper on page 7. Here is what I have so far from that paper.

solver(Sol) :- 
   Sol = [A,B,C,D],
   [A,B,C,D] ins 1..4,
   all_distinct(Sol),
   element(A,[7,1,3,4],A1),
   element(B,[8,2,5,1],B1),
   element(C,[4,3,7,2],C1),
   element(D,[3,1,6,3],D1),
   A1 + B1 + C1 + D1 #= E,
   maximize(E,Sol),
   label(Sol).

I'm unable to get maximize to work. It throws an error

ERROR: solver/1: Undefined procedure: maximize/2
ERROR:   However, there are definitions for:
ERROR:         maximize/3

Could someone point out why the maximize function isn't working as expected or how I should be framing it? Thanks in advance.

Upvotes: 3

Views: 399

Answers (1)

mat
mat

Reputation: 40768

In SWI-Prolog, maximization is available as a labeling/2 option. Replace the maximize/2 and label/1 goals by:

labeling([max(E)], Sol]

On backtracking, you get solutions in decreasing order of E.

Upvotes: 4

Related Questions