Re: [eclipse-clp-users] negate constraints

From: Thorsten Winterer <thorsten_winterer_at_web.de>
Date: Wed, 31 Mar 2010 14:47:32 +0200
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.
> Thanks for your help.
>
> Oliver.
>
> On 31 March 2010 11:02, Alexandre Saidi <Alexandre.Saidi_at_ec-lyon.fr
> <mailto:Alexandre.Saidi_at_ec-lyon.fr>> 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.
>>
>>     ------------------------------------------------------------------------------
>>     Download Intel&#174; Parallel Studio Eval
>>     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
>>     <mailto: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
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> 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
>   


-- 
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_web.de
Received on Wed Mar 31 2010 - 12:47:49 CEST

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