Re: [eclipse-clp-users] basic problem

From: Marcin Krol <mrkafk_at_gmail.com>
Date: Mon, 16 Feb 2009 17:11:20 +0100
Marco Gavanelli wrote:
> I agree with Wit.
> The last problem I see in your code is that bb_min requires as argument 
> a predicate that generates a search tree, such as labeling.

Right... I read the docs example:

?- bb_min(member(X,[9,6,8,4,7,2,4,7]), X, O).
Found a solution with cost 9
Found a solution with cost 6
Found a solution with cost 4
Found a solution with cost 2
Found no solution with cost -1.0Inf .. 1
X = 2
O = bb_options(continue, -1.0Inf, 1.0Inf, 1, 1, 0, 0, _, _)
yes.

..and I was under impression that I could use any predicate as bb_min's 
Goal? How do I tell which predicate generates a search tree and which 
does not?

http://eclipse.crosscoreoptimization.com/doc/bips/lib/lists/member-2.html

I fail to see how member/2 is different from sum/2 in this regard.. At 
least the docs do not say so..

> 
> So, your predicate should end like the following:
> 
>     ...
>     S #= sum(X),
>     bb_min(labeling(X),S).

1st problem:

Thanks to everyone for answers and explanations, but the above generates:

calling an undefined procedure _730 #= sum([_431, _449, _467, _485, 
_503, _521]) in module eclipse


This does work, though:

:- lib(ic).
:- lib(branch_and_bound).
:- lib(ic_global).

minsum(X, Range) :-
     X = [A,B,C,D,E,F],
     X :: 1 .. Range,
     integers(X),
     alldifferent(X),
     sumlist(X,S),
     bb_min(labeling(X),S,bb_options{strategy:continue}).


Found a solution with cost 21
Found no solution with cost 6.0 .. 20.0


Though I'm not really sure why - why does it not work with a normal 
constraint like S #= sum(X) ?

2nd problem: I see that eclipse generated the first solution and then 
stopped, unlike typical predicate solving where a user can click "More" 
if there's another solution. Is there some way to make it look for more 
solutions? A different strategy, perhaps? The docs say:

restart
     after finding a solution, restart the whole search with the newly 
found bound imposed on Cost

But that doesn't seem to generate more solutions. Does it work like it 
can only search for another solution if another constraint in form of S 
< 21 is fulfilled, and since no such solution exists, it stops 
searching? The docs suggest that:

A solution of the goal Goal is found that minimizes the value of Cost.

Sorry for all those newbie questions, but I'm *totally* new to Prolog 
and declarative programming in general..

Regards,
mk
Received on Mon Feb 16 2009 - 16:13:47 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET