Re: [eclipse-clp-users] Correct use of minimize to find a globally minimal solution

From: Kish Shen <>
Date: Thu, 28 Feb 2013 17:53:50 +0000
On 28/02/2013 12:50, Misha Aizatulin wrote:
> hi Kish,
>> Can you show how you are calling minimize/2, and any surrounding code?
>    I attach the code once more.
>    I did look at the documentation.
> Best,
>    Misha

Hi Misha,

Sorry, I missed the attachment the first time -- for such a short 
program, it is probably easier to show it inline, rather than as an 

The problem seem to be that you are not doing any search in minimize:

find(Allocation) :-
   % schedule(Allocation),
   length(Allocation, NCouples),
     for(I, 1, NCouples),
     foreach(Lesson, Allocation),
     fromto(0, In, Out, Cost)
     request(I, Lesson),
     cost(I, Lesson, C),
     Out is In + C

   minimize(schedule(Allocation), Cost).

By the time you call minimize, all variables in Allocation and Cost is 
already instantiated -- by the do loop just before -- the search is done 
in this code, along with trying different lengths for Allocation
(I think you mean to try only lengths of 2 -- NCouples should be 2, but 
it is uninstantiated in your code).

In the loop, you are also calculating Cost from instantiated value. For 
Cost to act as a bound, it should be set up as a constraint, rather than 
calculated after you have instantiated the variables. You

I am also not sure why you are using ic_sets: the only place you seem to 
use it is in request/2, in goals like

X in [0,2,3]

this simply set X to the normal finite domain (not set domain) [0,2,3],
which you can do directly with ::/2 from ic:

X :: [0,2,3]

You also don't seem to be really using ic, because as soon as you set up 
the domain variables with request, you simply explicitly assign the 
variable to a value with the call to cost/3.


Received on Thu Feb 28 2013 - 19:03:43 CET

This archive was generated by hypermail 2.2.0 : Fri Mar 01 2013 - 18:13:35 CET