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

From: mauricio montecinos <mauricio.montecinos_at_...6...>
Date: Tue, 31 Aug 2010 17:35:11 -0400
Thank you very much for your help.



get_domain_as_list/2 generates in the second argument the ordered list of
the values of the current domain.



Now I can get the behavior of indomain(X, max) write:



choose_val_indomainmax(Var,Val):-

            get_domain_as_list(Var,Domain),

            mem3(Val,Domain).



mem3(X,[_|Xs]):- mem3(X,Xs).

mem3(X,[X|_]).



On Tue, Aug 31, 2010 at 4:09 PM, Kish Shen <kisshen_at_...5...> wrote:

> 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 - 21:35:37 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST