Re: [eclipse-clp-users] Reified constraint without propia

From: Philipp Marcus <marcus_at_...247...>
Date: Wed, 28 Apr 2010 09:25:44 +0200
Hi,

thanks for your hints. In my case the problem is, that inside the 
mycon(..,Y,1) predicate there exists a ic_sets:in(X,Y,B) predicate (so Y 
is a set variable). When I call mycon(..,Y,1) by my self, the the domain 
of the set is correctly reduced.

But calling mycon_constr(..,Y,1) (which should immediatle 'delegate' to 
the mycon(..,Y,1) predicate, as B is instantiated) does not reduce the 
domain of the set.

mycon_constr(..,Y,B) :-
     mycon(..,Y,B) infers most.

I don't know exactly but I might guess that this has something to do 
with ic_sets and a missing msg predicate. So my question was: Given the 
predicate

mycon(..,Y,1) :-
     ...

and

mycon(..,Y,0) :-
     ...

is there a general pattern to combine the two to a reified constraint 
without using propia? Especially I'd like to know how you would check 
the entailment or disentailment when B is unknown. For the two cases, 
where B is instantiated I'd implement the predicate something like this:

mycon_constr(..,Y,B) :-
     (ground(B)->    mycon(..,Y,B);    suspend( mycon_constr(..,Y,B), 3, 
[B] -> inst)).

But I need to include the entailment/disentailment check. I'd be really 
happy if somebody could give me a suggestion.

Best regards,
Philipp



Am 28.04.2010 02:31, schrieb Joachim Schimpf:
> Philipp Marcus wrote:
>    
>> Hi,
>>
>> I wanted to write a custom reified constraint  and already created the
>> mycon(...,1) and the mycon(...,0) version. Then I wanted to combine them
>> with propia to say mycon_constr(...,B) :-
>>      mycon(...,B) infers most.
>>
>> But now I have the following problem:
>> calling mycon_constr(...,1) gives me less propagation than calling
>> mycon(...,1). But in my opinion it should reduce the variable bounds to
>> the same intervals (I'm using ic).
>>      
> Using infers/2 only makes sense when you apply it to a nondeterministic
> (i.e. more than one solution) predicate.  For example the following
> gives you 3 solutions:
>
> ?- member(X, [1, 2, 3]).
> X = 1
> Yes (0.00s cpu, solution 1, maybe more)
> X = 2
> Yes (0.00s cpu, solution 2, maybe more)
> X = 3
> Yes (0.00s cpu, solution 3)
>
> and by wrapping this in infers/2 you get a single solution which is
> the "convex hull" of the alternative solutions:
>
> ?- member(X, [1, 2, 3]) infers ic.
> X = X{1 .. 3}
> Yes (0.00s cpu)
>
> Only in the latter case do we talk about "propagation".
> If you have the impression that your unannotated predicate gives
> your more "propagation", then you may have overlooked that you get
> alternative solutions that need to be taken into account as well.
>
>
>    
>> Now I thought of doing the reified stuff by my self, instead of using
>> propia in order to circumvent the problem. So I wanted to ask if there
>> is general pattern that fulfills the requirements for the three situations:
>>
>>      * Reified variable is unbound (check if constraint is entailed)
>>      
> You also want to check if the constraint is disentailed (i.e. whether
> you can bind the Boolean to 0).
>
>    
>>      * Reified variable is bound to 0
>>      * Reified variable is bound to 1
>>
>> Especially I'd like to know how to realize the first case best. Would
>> you use suspend to do that? And how would you do that?
>>      
> The implementation of a reified constraint is not really any different
> from any other constraint - you just have an extra argument.
> For example, if your original constraint has the following truth table:
>
> and(0,0,0).
> and(0,1,0).
> and(1,0,0).
> and(1,1,1).
>
> then the reified version has this one
>
> and_reif(0,0,0,1).   % the entailed cases
> and_reif(0,1,0,1).
> and_reif(1,0,0,1).
> and_reif(1,1,1,1).
> and_reif(0,0,1,0).   % the disentailed cases
> and_reif(0,1,1,0).
> and_reif(1,0,1,0).
> and_reif(1,1,0,0).
>
> and you can make either into a constraint by using infers/2, e.g.
>
> ?- and_reif(0, Y, 1, B) infers ic.
> Y = Y{[0, 1]}
> B = 0
> Yes (0.00s cpu)
>
>
> For an example of direct implementation without propia, look at the library
> source file sd.ecl, which implements a reified predicate (&\=)/3.
>
>
> -- Joachim
>
> ------------------------------------------------------------------------------
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>    
Received on Wed Apr 28 2010 - 07:25:51 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST