I am following Ivan Bratkos 'Prolog programming for Artificial Intelligence fourth edition', and I'm currently reading about constraint logic programming.
In the book theres a small optimization example for task scheduling that goes like this:
{Ta >= 0,
Ta + 2 =< Tb,
Ta + 2 =< Tc,
Tb + 3 =< Td,
Tc + 5 =< Tf,
Td + 4 =< Tf},
minimize(Tf).
which in swi-prolog results in
Ta = 0,
Tb = 2,
Td = 5,
Tf = 9,
{_G371>=0, _G377=2-_G371, _G371=<2, Tc=4-_G371}.
The result is fine (even though it would have been prettier if it had just written {Tc =< 4} {Tc >= 2} like in the book), but I don't understand why it adds the '_G377=2-_G371' part, -it seems very unnecessary...
why is this extra variable (_G377) added to the result?
in case someone else is reading the book: I have changed the 'Ta =< 0' to 'Ta >= 0', as I believe the 'Ta =< 0' is an error in the book.
The answer you show suggests that you are using library(clpq)
and not library(clpr)
. In the original implementation of this library in SICStus Prolog, I get:
| ?- {Ta >= 0,
Ta + 2 =< Tb,
Ta + 2 =< Tc,
Tb + 3 =< Td,
Tc + 5 =< Tf,
Td + 4 =< Tf},
minimize(Tf).
Ta = 0,
Tb = 2,
Td = 5,
Tf = 9,
{Tc=<4},
{Tc>=2} ?
yes
So this seems to be a bug in SWI. Probably some variables have not been projected away.