Global constraints in SICStus CLPFD

From: Nick Lacey (nick.lacey_at_pobox.com)
Date: 02/08/05

  • Next message: Yereth Jansen: "Re: Another try"
    Date: 07 Feb 2005 23:41:17 +0000
    
    

    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


  • Next message: Yereth Jansen: "Re: Another try"

    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)
    • Re: Global constraints in SICStus CLPFD
      ... Nick Lacey wrote: ... > global constraints, that would be just as good. ... > one clause and make them all local constraints. ... I had a look through the SICStus manual, ...
      (comp.lang.prolog)