Re: [eclipse-clp-users] Copying domain and delayed goals

From: Joachim Schimpf <jschimpf_at_...311...>
Date: Tue, 23 Apr 2013 23:49:43 +0100
On 23/04/2013 22:38, Sergii Dymchenko wrote:
> Hello,
>
> Is it possible to copy domain and delayed goals of some variables to
> another variables?
>
> I tried (after lib(ic).):
>
>> A :: 1..3, B :: 1..3, A #\= B, copy_term([A, B], [AN, BN]).
> A = A{1 .. 3}
> B = B{1 .. 3}
> AN = AN{1 .. 3}
> BN = BN{1 .. 3}
>
> Delayed goals:
>      -(B{1 .. 3}) + A{1 .. 3} #\= 0
> Yes (0.00s cpu)
>
> But I'd also want to have delayed goal -(BN{1 .. 3}) + AN{1 .. 3} #\= 0

The system does not attempt to do this automatically, because in
general that would require to "project" the existing constraints
onto the set of variables that gets copied, and there is no generic
way to compute such a projection for arbitrary constraints.

If you knew which constraints can occur (such as #\=), you could
attempt to write your own copying routine, based on copy_term/3,
copying the delayed goals explicitly, but that approach is probably
too complex and fragile.


> If it's not possible then I'd appreciate any suggestions how I should
> implement the following scenario:
> - Large number of constraints, that takes some time to propagate,
> possibly leaving delayed goals.
> - Many small independed 'queries', each query is an additional small
> number of constraints.
> - Do propagation for the first (large) set of constraints once
> - For every query add additional constraints and label variables.
> Obviously for every new query there should be a 'fresh copy' of the
> large set of constraints - propagated, but not labeled.

That does not sound very different from what is done during search:
in every branch of a search tree node, a different "small additional
constraint" is added and propagated.  Once a branch has been explored,
backtracking takes you back to the computational state *before* the
extra constraint was added, and a different one can be tried.

That way, you don't copy the large constraint setup, you instead
undo the incremental modification.  Your code structure would
be something like this:

main :-
     setup_constraints,
     % propagation happens automatically
     answer_queries.

answer_queries :-
     get_query,
     (
        add_constraints,
        % propagation happens automatically
        labeling,
        report_answer
     ;
        report_no_answer
     ),
     fail.
answer_queries :-
     answer_queries.

On every recursive call of answer_queries you are back to the same
starting point (because you have failed across add_constraints).


-- Joachim
Received on Tue Apr 23 2013 - 22:49:54 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST