Re: [eclipse-clp-users] Propagators with a state

From: Joachim Schimpf <joachim.schimpf_at_...44...>
Date: Mon, 16 Feb 2009 11:17:05 +1100
Wit Jakuczun wrote:
> Hi Kish,
>    the propagator looks like that (this is an example only):
> 
> propagate(Var, OldDom, Susp) :-
>     propagate(Var),
>     ic:get_domain_as_list(Var, NewDom),
>     kill_suspension(Susp),
>     suspend( propagate(Var, NewDom, Susp1),3, Var->ic:hole, Susp1).
> 
> Here the state is a domain of a variable.
> 
> What is the better way to deal with such propagators?

As Kish said, you add a State variable, and use setarg/3 on its arguments.
For your example above this would be

:- demon propagate/3.
propagate(Var, State, Susp) :-
     State = state(OldDom),
     propagate(Var),
     ic:get_domain_as_list(Var, NewDom),
     setarg(1, State, NewDom).

You can find examples of this in the library files ic_constraints.ecl or
generic_global_constraints.ecl

Btw, in 6.1 I intend to add set_suspension_arg/3 for this purpose.

Cheers,
Joachim
Received on Mon Feb 16 2009 - 00:17:09 CET

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST