Re: Multiple calls of ECLiPSe from C

From: Warwick Harvey <wh_at_icparc.ic.ac.uk>
Date: Fri 20 Apr 2001 05:16:49 PM GMT
Message-ID: <3AE06F01.330EEE3C@icparc.ic.ac.uk>
Hi Tallys,

Tallys Hoover Yunes wrote:
>    I'm writing an application in C that is going to call
>    ECLiPSe to solve some FD constraints. I have 2 main
>    questions:
> 
>    1) I'll have to call ECLiPSe many times, but the contexts of
>       the calls will be independent (different variables, different
>       domains, different constraints, etc.). Do I need to call ec_init()
>       and ec_cleanup() at the beginning and at the end of each
>       interaction with ECLiPSe? Or is there another way of doing
>       a kind of "cleanup" that does not shut the engine down?
> 
>       My concern here is to free all memory used by ECLiPSe during
>       a round of constraint solving before going to the next round.

I'll leave that one to somebody who knows more about it than I do, but
should be quite possible without doing an init/cleanup each time.

>    2) Now suppose that I have a set of variables with their
>       respective default initial domains. Also, suppose that these
>       variables have to satisfy some constraints.
> 
>       I'll need to call ECLiPSe many times (let's call them rounds)
>       and, at each time, the domains of the variables will be
>       further restricted *in a different way* before constraint
>       propagation takes place.
[etc.]

This seems to be covered in the "Control flow and search" section of the
embedding manual.  E.g. "By posting a goal that fails, the ECLiPSe
execution will fail back into the previous set of goals and these will
succeed with a different solution."  So taking your example, you could,
for instance do the following:

>         Let's call S0 the state of the system after the following
>         constraints have been posted:
> 
>            [X,Y]::[1..5], X #>= Y.

Post these constraints.  Also post the goal "repeat".  Call ec_resume().

>         Then, at round 1 I need the following:
> 
>            Starting from S0 and adding X #<= 4, what are the
>            final domains of X, Y after propagation?

Post these constraints.  Call ec_resume().  Get the information you
want.  Post the goal "fail".  Call ec_resume().  Assuming the
constraints just posted do not create choice points, ECLiPSe will
backtrack to the "repeat" goal, undoing the constraints you just added
and returning you to the state just after "repeat" was posted.

>         At round 2 I need:
> 
>            Starting from S0 and adding Y #>= 3, what are the
>            final domains of X, Y after propagation?

Again, post these constraints, resume, get the info you want, and fail.

... etc.


Of course, if the constraints you post at each point may create choice
points, you'll need to do cuts, etc., and things get more complicated. 
You can get the choice point you need to cut back to by giving an
argument to ec_resume().  As well as the control flow section of the
manual mentioned earlier, I recommend having a look at eg_c_fail_loop.c
in doc/examples, as it does exactly this.


Note that all of the above control is very easy and natural to do in
ECLiPSe, which begs the question: why do you want to do all this
management from C?

Cheers,
Warwick
Received on Fri Apr 20 18:17:05 2001

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