Re: clpfd constraints not taking effect

James Hogan <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAAG0J98-XbU4OrJT7_mAARxWLZnD4zaFAfE3fCmJbhgdsN=cow@mail.gmail.com>
On 19 August 2013 20:24, Markus Triska <[email protected]> wrote:
> Hi James,
>
> James Hogan <[email protected]> writes:
>
>> Thanks for the patch. I gave it a spin, and tested before and after
>> your change, but it appears that although it fixes the simple case, it
>> makes my big case (with over 2000 constraints) go much slower (gets
>> slower as it goes through the constraints, keeps stopping momentarily
>> on a constraint), and then about half way it says:
>>
>> ERROR: Out of global stack
>
> Please send me your test case, I will try to get the change working in
> such situations. I have for now reverted it. Meanwhile, you can enable
> full propagation by setting the flag clpfd_propagation to 'full':

Hi Markus,

So setting clpfd_propagation to full seems to fix it without running
out of global stack, but as you say, that can make it non-terminating.

So in the hopes of it being helpful, here's how to reproduce:

1) clone chron

$ git clone https://github.com/amalon/chron.git
(for reference. current commit=07db992)
$ git clone https://github.com/amalon/chron-bible.git
(for reference, current commit=8c36540)

2) apply minor patches

$ cd chron-bible
apply the following patch:

diff --git a/genesis/genesis.pl b/genesis/genesis.pl
index b2a6fa5..d165eef 100644
--- a/genesis/genesis.pl
+++ b/genesis/genesis.pl
@@ -40,6 +40,7 @@ event(fall(X)) :-
 :- include('9').
 :- include('10').
 :- include('11').
+/*
 :- include('12').
 :- include('13').
 :- include('14').
@@ -57,3 +58,4 @@ event(fall(X)) :-
 :- include('27').
 :- include('28').
 :- include('29').
+*/

$ cd ../chron
Apply the following patch

diff --git a/src/chron.pl b/src/chron.pl
index a349144..8229773 100644
--- a/src/chron.pl
+++ b/src/chron.pl
@@ -25,7 +25,7 @@
  */

 % Uncomment to enable printing of constraints as the're applied
-%debug_printing.
+debug_printing.

 debug_printing :- fail.
 dbg_print(X) :-
diff --git a/src/wrapper.pl b/src/wrapper.pl
index 857d549..09a37ea 100644
--- a/src/wrapper.pl
+++ b/src/wrapper.pl
@@ -22,7 +22,7 @@
 :- include(prechron).

 % include your data file here
-%:- include('../../bible/bible').
+:- include('../../bible/bible').

 % All the chron clauses
 :- include(calendar).


3) run it through prolog
(working directory is chron/)
$ swipl -q -s src/wrapper.pl

?- process_db(creation, Events), !, member(B, Events), B =
event(begin(lifetime(philistim)), _), print_db_events([B]), !, fail.
after lots of output, the final line is:
event   birth(philistim)        1528 year 312 day .. sup

?- process_db(creation, Events), process_db(creation, Events), !,
member(B, Events), B = event(begin(lifetime(philistim)), _),
print_db_events([B]), !, fail.
applying constraints a second time, the final line is now correct:
event   birth(philistim)        1658 year 151 day .. sup

With the commit prior to your revert, the debug output slows down and
eventually it runs out of global stack. I'm not that experienced with
prolog, so it's possible I'm doing it inefficiently somehow. The main
apply_constraints_inner loop is tail recursive, with each recursion
applying a constraint from a list, so the stack depth presmably gets
pretty large (although still only around 1000 frames when it runs
out).

Thanks for your help
-- 
James Hogan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.