# Re: [eclipse-clp-users] negate constraints

From: Oliver Shycle <oliver.shycle_at_...1...>
Date: Wed, 31 Mar 2010 15:18:40 +0200
```Your example, Marco, is very clear and simple. Unfortunately it cannot be
transformed to a solution for my general problem. Using reified constraints
as proposed by Thorsten look interesting. I hope I can use them to construct
my complex constraints somehow.

Generally, I am sure there is a possible solution for every problem, as
given by your examples. However, I wonder if ther isn't a more "intuitive"
way of expressing constraints. As described in my first mail of this thread,
why cant I have a constraint like "greater_eight/1", formulated as a prolog
clause, and use it along with other "standard cosntraints" like #>, #\ etc.?
As described in the first email, if ECLiPSe comes along such a constraint it
evaluates to true without even having instantiated the variable to any
value.
Maybe I haven't understood something about constraints right!?

Another example for behavior I dont understand is the following:
X #< 8 => greater_eight(Y)

This raises the error "calling an undefined procedure greater_eight" even if
it is defined. I gues that is because greater_eight/1 is not recognized as a
constraint. The operator "=>" however expects a constraint?

Thanks for you help and forgive me that is is hard to express what my
problem is :-)

On 31 March 2010 14:47, Thorsten Winterer <thorsten_winterer_at_...126...> wrote:

>  Hello,
>
> you can use reified constraints to express "if any variable has a value
> greater than eight, there must be at least one variable with a value smaller
> than eight.":
>
> :- lib(ic).
> :- lib(ic_global).
>
> test(L) :-
>     L = [X,Y,Z],
>     L #:: 1..10,
>     ( foreach(V,L),foreach(BG,BGs), foreach(BS,BSs) do
>         #>(V,8,BG),
>         #<(V,8,BS)
>     ),
>     sumlist(BGs,EG),
>     sumlist(BSs,ES),
>     (EG #>= 1) => (ES #>= 1),
>     X #= 9,
>     Y #= 9,
>     get_max(Z,Z).
>
>
> For each variable V, BG is set to 1 if V > 8, else 0. BS is set to 1 if V <
> 8, else 0.
> If the sum of the BG values is at least 1, then the sum of the BS values
> must also be at least 1.
>
> Now, if X and Y are instantiated to 9, the maximum value in Z's domain is
> 7.
>
> Cheers,
> Thorsten
>
>
> Am 31.03.2010 14:27, schrieb Oliver Shycle:
>
> Hello,
>
> well I think the negation axample was not really good to express what i
> want. Let me formulate the problem like this:
> We stick to the variables and their domains as before. I need constraints
> that express the following: "if any variable has a value greater than eight,
> there must be at least one variable with a value smaller than eight."
> -------------------------------
>  example :-
>     OutputModel = [A, B, C, D],
>     A #:: 1..100,
>     B #:: 1..100,
>     C #:: 1..100,
>     D #:: 1..100,
>
>  % constraints
>
>      labeling(OutputModel),
>     writeln(OutputModel).
> ---------------------------------
>
> I dont know how to express such kind of constraints.
>
> Oliver.
>
> On 31 March 2010 11:02, Alexandre Saidi <Alexandre.Saidi_at_...37...>wrote:
>
>> Hi Olivier,
>> I’m not sur i understand what you want to do with the negation.
>>
>>  Tell me what if :
>>  example :-
>>
>>      OutputModel = [A, B, C, D],
>>     A #:: 1..100,
>>     B #:: 1..100,
>>     C #:: 1..100,
>>     D #:: 1..100,
>>
>>  #\+ (A #> 8 #\/ B#> 8 #\/  C #> 8 #\/ D#> 8),
>>
>>     labeling(OutputModel),
>>     writeln(OutputModel).
>>
>>  In both cases,  constraint propagation will restrict variable domaine.
>> It’s better not to use Disjunction (like member).
>>
>>  Alex
>>
>>  Le 30 mars 2010 à 09:57, Oliver Shycle a écrit :
>>
>>  Hi all,
>>
>> I have a problem to express negated constraints in ECLiPSe. In my
>> programm, I want to express what value certain interval constraints may NOT
>> have. Consider the following problem description: the program shall find
>> values for four variables such that the values are NOT greater than 8.
>>
>> Here's the code:
>> ------------------------------------------------------
>> :- lib(ic).
>>
>> example :-
>>
>>     OutputModel = [A, B, C, D],
>>     A #:: 1..100,
>>     B #:: 1..100,
>>     C #:: 1..100,
>>     D #:: 1..100,
>>
>>     not(wrong_value(OutputModel)),
>>     labeling(OutputModel),
>>     writeln(OutputModel).
>>
>> wrong_value(Vars) :-
>>     member(Var, Vars),
>>     greater_eight(Var).
>>
>> greater_eight(X) :-
>>     X #> 8.
>> ------------------------------------------------------
>>
>> I know that I rather could limit the variable's domains to a maximum of 8,
>> but I want to demonstrate my problem with this snippet. When ECLiPSe comes
>> along the constraint "X #> 8" with the first variable of the list, the term
>> evaluates to true. Therefore wrong_value evaluates to true without even
>> setting up constraints for the other variables. The negation
>> not(wrong_value(OutputModel)) thus becomes false and ECLiPSe sais it can't
>> find a solution. If I test the code with a set of integers instead of
>> variables everything works as expected.
>> How can I tell ECLiPSe not to evaluate X #> 8 instantly, but keeping the
>> constraint in mind for later instantiation during labeling/1?
>>
>> Many thanks for your help.
>>
>> Oliver.
>>
>>
>> ------------------------------------------------------------------------------
>> Try the new software tools for yourself. Speed compiling, find bugs
>> proactively, and fine-tune applications for parallel performance.
>> See why Intel Parallel Studio got high marks during beta.
>>
>> http://p.sf.net/sfu/intel-sw-dev_______________________________________________
>> ECLiPSe-CLP-Users mailing list
>> ECLiPSe-CLP-Users_at_lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>>
>>
>>     -------------------------------
>> Alexandre Saidi
>> Maitre de Conférences
>> Ecole Centrale de Lyon-Dép. MI
>> LIRIS-CNRS UMR 5205
>> Tél : 0472186530, Fax : 0472186443
>>
>>
>>
>>
>>
>>
>>
>
> ------------------------------------------------------------------------------
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.http://p.sf.net/sfu/intel-sw-dev
>
>
> _______________________________________________
> ECLiPSe-CLP-Users mailing listECLiPSe-CLP-Users_at_...242...://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>
>
>
> --
> Dr. Thorsten Winterer
> A: Salzäckerstraße 178
>    70567 Stuttgart, Germany
> T: +49 (0)711 6935080
> M: +49 (0)162 3240054
> E: thorsten_winterer_at_...126...
>
>
>
> ------------------------------------------------------------------------------
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>
>
```
Received on Wed Mar 31 2010 - 13:18:47 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 21 2019 - 09:13:32 CEST