For Programmers: Free Programming Magazines  


Home > Archive > Prolog > February 2005 > Global constraints in SICStus CLPFD









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Global constraints in SICStus CLPFD
Nick Lacey

2005-02-07, 9:00 pm

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





Bart Demoen

2005-02-08, 9:00 am

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/c...GlobalCons2.pdf

I hope they help you.

Cheers

Bart Demoen
A.L.

2005-02-08, 3:59 pm

On Tue, 08 Feb 2005 11:03:31 +0100, Bart Demoen
<bmd@cs.kuleuven.ac.be> wrote:

>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/c...GlobalCons2.pdf


This link is dead. Beldiceeanu is now with SICS, link to this
tutorial is as follows:

ftp://ftp.sics.se/pub/isl/papers/globalctr.pdf

More publications are here

http://www.sics.se/isl/cps/

A.L.
Nick Lacey

2005-02-08, 8:59 pm

A.L. <alewando_tego_nie@oddpost_tego_tez_nie.com> writes:

> On Tue, 08 Feb 2005 11:03:31 +0100, Bart Demoen
> <bmd@cs.kuleuven.ac.be> wrote:
>
>
> This link is dead. Beldiceeanu is now with SICS, link to this
> tutorial is as follows:
>
> ftp://ftp.sics.se/pub/isl/papers/globalctr.pdf


Many thanks to you both - this is very helpful.

Regards,

Nick
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com