% ------------------------------------------------------------------------------------------------------
% Test the Prova Rule Engine
%
% In dag(n,k) (directed acyclic graph) a0 is at the root of a k-branching tree
% of depth n in which every literal occurs k times. The test is propositional with 
% goal memoization
%
% dag(n,k) =
% a0 :- a1, a2, ..., ak.
% a1 :- a2, a3, ..., ak+1.
%     ...
% ank :- ank+1, ank+2, ..., ank+k. % rules
%
% ank+1. ank+2. ... ank+k.  % facts
%
% A query a0? will use and memorize every rule and fact.
% ------------------------------------------------------------------------------------------------------

% include basic predicates
:-eval(consult('ContractLog/math.prova')).

% set up cache localy (memorize subgoals for one query)
cacheTimeout(0).

a0() :- cache(a1()),cache(a2()),cache(a3()),cache(a4()).
a1() :- cache(a2()),cache(a3()),cache(a4()),cache(a5()).
a2() :- cache(a3()),cache(a4()),cache(a5()),cache(a6()).
a3() :- cache(a4()),cache(a5()),cache(a6()),cache(a7()).
a4() :- cache(a5()),cache(a6()),cache(a7()),cache(a8()).
a5() :- cache(a6()),cache(a7()),cache(a8()),cache(a9()).
a6() :- cache(a7()),cache(a8()),cache(a9()),cache(a10()).
a7() :- cache(a8()),cache(a9()),cache(a10()),cache(a11()).
a8() :- cache(a9()),cache(a10()),cache(a11()),cache(a12()).
a9() :- cache(a10()),cache(a11()),cache(a12()),cache(a13()).
a10() :- cache(a11()),cache(a12()),cache(a13()),cache(a14()).
a11() :- cache(a12()),cache(a13()),cache(a14()),cache(a15()).
a12() :- cache(a13()),cache(a14()),cache(a15()),cache(a16()).
a13() :- cache(a14()),cache(a15()),cache(a16()),cache(a17()).
a14() :- cache(a15()),cache(a16()),cache(a17()),cache(a18()).
a15() :- cache(a16()),cache(a17()),cache(a18()),cache(a19()).
a16() :- cache(a17()),cache(a18()),cache(a19()),cache(a20()).
a17().
a18().
a19().
a20().






% Tests


testDag() :-
println(["Test propositional DAG 2: depth n = 4  width k = 4 with memoization"]),
println(["----------------------------"]),
C1=rbsla.utils.WebsiteAvailable.getDate(),
T1=C1.getTimeInMillis(),

a0(),

C2=rbsla.utils.WebsiteAvailable.getDate(),
T2=C2.getTimeInMillis(),
math_sub(T2,T1,DIF),
println(["Duration:",DIF]),
println(["-----------------------------"]).

% 6 Experiments in a row - First is only for garbage removal of parsing

:-solve(testDag()).
:-solve(testDag()).
:-solve(testDag()).
:-solve(testDag()).
:-solve(testDag()).
:-solve(testDag()).