Re: Global constraints in SICStus CLPFD

From: Bart Demoen (bmd_at_cs.kuleuven.ac.be)
Date: 02/08/05

  • Next message: A.L.: "Re: Global constraints in SICStus CLPFD"
    Date: Tue, 08 Feb 2005 11:03:31 +0100
    
    

    Nick Lacey wrote:
    > Hello,
    >
    > I think I have a question about global constraints in CLP/FD in
    > SICStus. I say 'I think', as if there was a solution without using
    > global constraints, that would be just as good.
    >
    > Basically, what I want to do is be able to assert and retract
    > constraints between an arbitrary number of different facts in the
    > database. For example:
    >
    > fact_1(A):-
    > A #< 9.
    >
    > fact_2(B):-
    > B #= 8.
    >
    > fact_3(A):-
    > A #= B.
    >
    > [I know there is no difference between A and B in this context - this
    > is for illustration only]
    >
    > .. so A = 8. If fact_2 were changed so that B #=7, the value of A
    > would change dynamically, and so on.
    >
    > This is very easy if we have local constraints, like:
    >
    > all_facts:-
    > A #< 9,
    > B #=8,
    > A #= B.
    > ---------------------------------
    > | ?- all_facts(A,B).
    >
    > A = 8,
    > B = 8 ? ;
    >
    > no
    > | ?-
    > ---------------------------------
    >
    > ... as we'd expect.
    >
    > But as the number of constraints will be arbitrary, I need to be able
    > to assert and retract them at runtime, so I can't hard code them into
    > one clause and make them all local constraints.
    >
    > I tried using FD sets, but found I had to do a lot of manipulation and
    > consistency checking myself.
    >
    > I have a feeling I'm missing something obvious ... ? Do I need to use
    > global constraints? I had a look through the SICStus manual, but I'm
    > afraid I didn't find the entries concerning global constraints to be
    > very helpful to me. (This is a failing of myself, not of the SICStus
    > manual).
    >
    > If someone could give me a simple example and/or point me in the right
    > direction, that would be wonderful.
    >
    > Many thanks,
    >
    > Nick
    >
    >
    >
    >
    >

    Maybe you expect the wrong thing about global constraints: you still need
    the variables involved in them in order to impose new constraints - it's not
    as if you pluck them out of nowhere.

    Some time ago, I found a set of slides by Nicolas Beldiceanu
    on global constraints - I liked them a lot:
    http://www.user.it.uu.se/~pierref/courses/CT/Slides/GlobalCons2.pdf

    I hope they help you.

    Cheers

    Bart Demoen


  • Next message: A.L.: "Re: Global constraints in SICStus CLPFD"

    Relevant Pages

    • Re: CLP(FD): what is necessary?
      ... possibilities to write their own global constraints ... but also good manual (SWI lacks such manual). ... is SICStus. ... yet produced the ultimate language for such extensions. ...
      (comp.lang.prolog)
    • Global constraints in SICStus CLPFD
      ... global constraints, that would be just as good. ... what I want to do is be able to assert and retract ... This is very easy if we have local constraints, ... I had a look through the SICStus manual, ...
      (comp.lang.prolog)