Re: [eclipse-users] ECLiPSe-Users Digest, Vol 16, Issue 3

From: Dimitris Bilidas <grad0903_at_di.uoa.gr>
Date: Wed, 6 Feb 2008 00:41:07 +0200
> Date: Tue, 29 Jan 2008 11:07:47 +0000
> From: "Joachim Schimpf (Independent Contractor)" <jschimpf_at_cisco.com>
> Subject: Re: [eclipse-users] Question about branch and bound
> To: eclipse-users_at_crosscoreop.com
> Message-ID: <479F0903.3010001_at_cisco.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Dimitris Bilidas wrote:
> > Joachim thanks very much for your answer. I've tried what you wrote and it
> > works, but when I'm trying to use a predicate to get the cost, I'm getting
> some
> > strange behavior and I can't understand what's wrong.
> > 
> > What I am trying to do is something like that:
> > 
> > ...,
> >     ( fromto(Board, [Qi|Qs], [Qs], []), foreach(D,Ds) do
> >         D #= Qi
> >     ),
> >     getCost(Ds, Result),
> >     Cost #= Result,
> 
> What you have written here is exactly equivalent to
> 
>       getCost(Board, Cost)
> 
> So we need to see your getCost. The key point is that you have
> to write getCost using only primitives that do something sensible
> (i.e. can propagate information) with uninstantiated variables.
> Such primitives are constraints like #=/3, element/3 etc, or suitable
> user-defined delayed goals.
> 
> 
> >     branch_and_bound:minimize(labeling(Board), Cost).
> > 
> > Any ideas?
> > Thanks in advance (again),
> > Dimitris.
> > 
>

Thanks, that was very helpful, I had some mistakes with uninstantiated
variables. The problem I have now is how to get the last position of an element
with a specific value from a list with uninstantiated variables. What I want to
do is to get the position of the last 1, from a list of which all elements must
be either 0 or 1.

I have tried this:
positionLast(D, [H|B], X):-
positionLast(D, B, Y), X #= Y+1,!.

positionLast(D, [D|C], 1):-notContains(D,C).

But I get a result as if the branch and bound method running repeatedly and
finding no solution (Is something wrong with the cut?)

I've also tried these and I get instantiation errors (for example: instantiation
fault in element(Index, [R{[0, 1]}, R{[0, 1]}, R{[0, 1]}, R{[0, 1]}, R{[0, 1]},
R{[0, 1]}, R{[0, 1]}, R{[0, 1]}, R{[0, 1]}, M{[0, 1]}], 1))

getLastOne1(List, Res):-
M#=length(List),
(foreach(E,List), for(I,1,M), foreach(T,Temp) do
T #= I*E),
Res#=max(Temp).

getLastOne2(List, Res):-
element(Index, List, 1),
Res#=get_max(Index).

Any ideas?
Dimitris.
Received on Tue Feb 05 2008 - 22:41:14 CET

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