Q about CHRs

From: Ulrich Scholz <ulrich.scholz_at_eml-d.villa-bosch.de>
Date: Fri 22 Jul 2005 01:43:13 PM GMT
Message-ID: <20050722134313.GA2781@eml-d.villa-bosch.de>
Dear all,

I've started using the ECLiPSe CHR library ech and now have some questions.
Maybe you can help me with them.

1) 

The user manual states: "Every time a user-defined constraint goal is added
or re-activated, it checks itself the applicability of its associated CHRs
by trying each CHR." (The CHR Language, How CHRs Work)

I guess "re-activated" includes the application of notify_constrained/1 to
one of the variables in the head of the CHR.  Is it possible to identify
this variable (these variables) in the guard of a constraint handling rule?

For example, let

r1 ::= c(X,Y) <=> Guard | Body 

be a CHR and X, Y be two ic variables.  Then r1 is tried if either X or Y
get more constrained.  Is it possible to write something like this:

r2 ::= c(X,Y) <=> has_been_constrained(X) | Body

Here, the guard of r2 should be false if notify_constrained(X) has not
been called.


2) 

Is it possible to add a rule to the CHR compiler without initiating the
checking process as a result of this insertion (checking it later is OK, of
course)?

Sometimes you know that a new constraint will not make the guard of any CHR
true because it has just been created that way.


3)

The rationale behind my questions is that some guards are compuationally
expensive and I want to avoid unnecessary tests.  

In particular, I'd like to build a variant of the ic constraint element/3.
This constraint requires to calculate the union of the domains of a list of
ic variables - an expensive calculation.

[Maybe you have a comment/suggestion.  I'd be happy to send my code for
review (3 CHRs)] 


element2(?Index, +List, ?Value) 

?Index
    An variable or an integer. 
+List
    A non-empty list of ic integer variables or integers. 
?Value
    A variable or an integer. 


This constraint relates Var to one of the variables in List.  List is a list
of ic integer variables and the constraint states that its Index'th element
is equal to Value, i.e.

    List_Index #= Value

Let List2 indicate the set of those variables in List whose index is in the
domain of Index.

Every time Index or one of the variables in List2 is updated, this
constraint is activated and the domain of Value is updated to the union of
all domains of variables in List2.

In addition this constraint is activated if Value is updated.  In this case,
the domain of Index is updated to set of indices of those variables in List
that can be equal to Value, i.e., whose domains have a common element with the
domain of value.


Thank you, Uli


-- 
Ulrich Scholz            

Personal Memory Group                   
European Media Laboratory GmbH
Received on Fri Jul 22 14:49:56 2005

This archive was generated by hypermail 2.1.8 : Wed 16 Nov 2005 06:07:38 PM GMT GMT