Re: [eclipse-clp-users] rewritten the default indomain(X, max).?

From: Kish Shen <kisshen_at_cisco.com>
Date: Tue, 31 Aug 2010 21:09:48 +0100
On 31/08/2010 19:31, mauricio montecinos wrote:


>
> indomain() can be rewritten as:
>
>
>
> choose_val_indomain(Var,Val):-
>
>              get_domain_as_list(Var,Domain),
>
>              mem(Val,Domain).
>
>
>
> mem(X,[X|_]).
>
> mem(X,[_|Xs]):- mem(X,Xs).
>

The actual implementation of indomain/1 in lib(ic) uses low-level 
primitives instead of get_domain_as_list/2 to get the domain, but
what you have should be equivalent.


> I have rewritten indomain(X, max) as:
>
>
>
> choose_val_indomainmax(Var,Val):-
>
>              get_domain_as_list(Var,Domain),
>
>              mem2(Val,Domain).
>
>
>
> mem2(X,[]):-!,fail.
>
> mem2(X,Lista):- maxlist(Lista,X).
>
> mem2(X,Lista):- maxlist(Lista,Y), elimina_elemento(Y,Lista,RLista),
> mem2(X,RLista).
>
>
>
> elimina_elemento(_,[],[]):-fail.
>
> elimina_elemento(X,[X|T],T).
>
> elimina_elemento(X,[H|T],[H|T1]):-elimina_elemento(X,T,T1).
>

Are you trying to remove the selected value from the domain with 
elimina_elemento? The List that elimina_elemento is operating on is not 
the domain itself, so your predicate will not eliminate the value from 
the domain. To eliminate a value from a variable's domain, you need to 
post a constraint. The most general method is to use #\=/2, so you can 
write the equivalent to indomain(X, max) as:

my_indomain_max(X) :-
	get_max(X, V),
	( X = V
	;
	  X #\= V,
	  my_indomain_max(X)
         ).



Cheers,

Kish

-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Tue Aug 31 2010 - 20:09:59 CEST

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