% Path-oriented Random Testing implementation
% Author : Arnaud Gotlieb -- INRIA Rennes Bretagne Atlantique
% Ref: Path-oriented random testing, A.Gotlieb and M. Petit,  Proc. of workshop on Random Testing RT'2006,
%      Constraint reasonning in path-oriented random testing, A. Gotlieb and M. Petit, Proc of COMPSAC'2008
% Date : Feb. 10th, 2010
%

% Requires SICStus Prolog 3 (or higher) but only tested with 4.1.1 on WinXP
% Portability issue : lists:nth1 in Sicstus4, lists:nth in Sicstus3

% Requires Euclide V0 for benchmarks tcas and ardeta
% ['../../EUCLIDE_V0/SRC/lib_c.pl'].

% Two main predicates with the following parameters
%    Seq is a sequence of uniform random vectors for VARS, satisfying C a set of constraints
%    N is the expected length of Seq -
%    K is the division parameter
%
%   rt  : "pure" random testing implementation
%   prt : our path-oriented random implementation

% Warning: constraints are posted to clpfd

% Examples:
%   ?- rt(domain([X,Y],0,100), (Y #> X + 50, X*Y #< 60), [X,Y], 1000, Seq1).
%   ?- prt((domain([X,Y],0,100), Y #> X + 50, X*Y #< 60), [X,Y], 1000, 2, Seq3).


:- ensure_loaded(library(lists)).
:- ensure_loaded(library(ordsets)).
:- ensure_loaded(library(random)).
:- ensure_loaded(library(clpfd)).

prt(C, VARS, N, K, Seq) :-
        call(C),
        divide(VARS,K, DOMS),  % divide the domain of each var in VARS in K subdomains
        build_cartesian_product(DOMS, CP_DOMS),  % complexity = K^#VARS
        reverse(VARS,RVARS),
        inconsistency_check(RVARS, CP_DOMS, TRUE_DOMS, LEN, NB_INCONS),  % remove inconstant domains
        M is 3*N, 
        random_choice_dom(M, LEN, TRUE_DOMS, N_TRUE_DOMS, F), % build a seq of randomly choosed domain
        F = N_TRUE_DOMS,  % N_TRUE_DOMS becomes an endless lists
        iterate_N(N, N_TRUE_DOMS, RVARS, Seq, NB),  % generate Seq
        ((number(LEN),number(NB_INCONS)) -> NB_DOM is LEN + NB_INCONS ; true ),
        write('nb of inconsistant domains: '), write(NB_INCONS), write(' over a total of '), write(NB_DOM), write(' domains'),
        nl,
        write('length of the random sequence generated: '), write(NB),
        nl.

iterate_N(0, _DOMS, _VARS, [], 0):-!.
iterate_N(N, [D|DOMS], VARS, [X|S], NB) :-
        \+( \+( (random_choice_val(D, VARS),reverse(VARS,RVARS), assert(t(RVARS)) ) ) ),  % may fail due to an inconsistant choice
        !,
        retract(t(X)),
        N1 is N-1,
        iterate_N(N1, DOMS, VARS, S, NB1),
        NB is NB1 + 1.
iterate_N(N, [D|DOMS], VARS, S, NB) :-
        iterate_N(N, DOMS, VARS, S, NB1),
        NB is NB1 + 1.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% divide(VARS, K, D)
% D is a list of K domains of the same size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
divide([],_K,[]):-!.
divide([X|S], K, [D|SD]) :-
        fd_min(X, Min),
        fd_max(X, Max),
        Size is Max - Min - 1,
        Rem is Size mod K,
        Pas is (Max - Min + Rem) // K,
        build(K, Pas, Min, _NMax, D),
        divide(S, K, SD).

build(0, Pas, NMax, NMax, []):-!.
build(K, Pas, Min, NMax, [[Min,M]|S]):-
        M is Min+Pas,
        M1 is M+1,
        K1 is K-1,
        build(K1,Pas, M1, NMax, S).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% build_cartesian_product(DOMS, CP_DOMS)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
build_cartesian_product([D], D) :- !.
build_cartesian_product([L1,L2], D) :-
        !,
        list_to_ord_set(L1,D1),   % optional
        list_to_ord_set(L2,D2),   % optional
        ord_setproduct(D1,D2, D).
build_cartesian_product([L1,L2|S], RES) :-
        build_cartesian_product([L1,L2], D),
        build_cartesian_product([D|S], RES).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% inconsistency_check(DOMS_K, TRUE_DOMS, LK)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
inconsistency_check(_VARS, [], [], 0, 0):-!.
inconsistency_check(VARS, [DOM|DOMS], TRUE_DOMS, LEN, NB) :-
        \+( assign_fd(VARS, DOM) ),
        !,
        inconsistency_check(VARS, DOMS, TRUE_DOMS, LEN, NB1),
        NB is NB1+1.
inconsistency_check(VARS, [DOM|DOMS], [DOM|TRUE_DOMS], LEN, NB) :-
        inconsistency_check(VARS, DOMS, TRUE_DOMS, LEN1, NB),
        LEN is LEN1+1.
        

assign_fd([X],[Min,Max]) :-
        X in Min .. Max,
        !.
assign_fd([X|S], DS-[Min,Max]) :-
        X in Min .. Max,
        assign_fd(S,DS).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% random_choice_dom(N, LEN, TRUE_DOMS, N_TRUE_DOMS)
% random_choice_val(D,X)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
random_choice_dom(0, _LEN, _TRUE_DOMS, F,F) :- !.
random_choice_dom(N, LEN, TRUE_DOMS, [TD|N_TRUE_DOMS],F) :-
        N1 is N-1,
        LEN1 is LEN+1,
        random(1,LEN1,R),
%        lists:nth1(R, TRUE_DOMS, TD),  % SICSTUS 4
        lists:nth(R, TRUE_DOMS, TD),    % SICSTUS 3
        random_choice_dom(N1, LEN, TRUE_DOMS, N_TRUE_DOMS,F).

random_choice_val([M,M], [X]) :-
        X = M,
        !.
random_choice_val([Min,Max], [X]) :-
        Max1 is Max+1,
        random(Min, Max1, R),
        X = R,
        !.
random_choice_val(D2-[M,M], [X|S1]) :-
        X = M,
        !,
        random_choice_val(D2,S1).
random_choice_val(D2-[Min,Max], [X|S1]) :-
        Max1 is Max+1,
        random(Min, Max1, R),
        X = R,
        !,
        random_choice_val(D2, S1).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RT without constraint propagation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rt(DOM, C, VARS, N, Seq) :-
        call(DOM),
        random_rt(N,5000000, VARS, C, Seq, NB),
        write('length of the random sequence generated: '), write(NB),
        nl.

random_rt(N,0, _VARS, _C, _Seq, 5000000) :-!.
random_rt(0,_M, _VARS, _C, [], 0) :-!.
%random_rt(N,10000, VARS, C, S, P) :-
%         !,
%         gc,
%        random_rt(N,9999,VARS,C,S,P).
%random_rt(N,5000, VARS, C, S, P) :-
%         !,
%         gc,
%         random_rt(N,4999,VARS,C,S,P).
random_rt(N, M, VARS, C, LISTE, NB) :-
        \+( \+( (rrt_rec(VARS, C, V), assert((f(V)))) ) ),
        !,
        retract(f(V)),    
        N1 is N-1,
        random_rt(N1, M, VARS, C, S, NB1),
        NB is NB1 + 1,
        LISTE = [V|S].
random_rt(N,M, VARS, C, S,NB) :-
        M1 is M-1,
        random_rt(N,M1,VARS, C, S, NB1),
        NB is NB1 + 1.

rrt_rec([], C, []) :-
        call(C),
        !.
rrt_rec([X|Xs], C, [V|Vs]) :-
        fd_min(X, Min),
        fd_max(X, Max),
        Max1 is Max+1,
        random(Min, Max1, V),
        X #= V,
        rrt_rec(Xs, C, Vs).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Experiments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

rt_paths([],D, VARS, N, K, Seq):-
        rt(D, VARS, N, K, Seq).
rt_paths([C|L], D, VARS, N, K, Seq) :-
        \+( \+ (call(C))),
        !,
        rt_paths(L, (C) #\/ D,  VARS, N, K, Seq).
rt_paths([_C|L], D, VARS, N, K, Seq) :-
        rt_paths(L, D,  VARS, N, K, Seq).

% Specifies a path in power, when X and Y are positives, but unknowns - X and Y must be free variables, N must be ground
%ex:
%| ?- power(X,Y, RES, 5), X = 2.       % power(X,Y, RES, 1000), X = 1. 
%
%X = 2,
%Y = 5,
%RES = 32 ? 

power(X,Y, RES, N) :-
        abs(Y) #\= 0,
        iterate_power(X, Y, X, R, 1, N),
        abs(Y) - N #= 0,
        Y #>=0,
        RES #= R.

iterate_power(X, Y, R, R, N, N) :-
        !.
iterate_power(X, Y, R, R2, M, N) :-
        abs(Y)- M #\= 0,
        M1 is M+1,
%        R1 #= X*R,  % exception due to the 26bits limitations of clpfd vars
        R1 #= X*R mod 2,
        iterate_power(X, Y, R1, R2, M1, N).

trityp(I,J,K, L, C):-
        L = [(I#=0#/\ T1 #= 4),(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#=J#/\ T2#=T1+1#/\ I#=K#/\ T3#=T2+2#/\ J#=K#/\ T4#=T3+3#/\ T4#>3#/\ T5#=3),(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#=0#/\ I+J#=< K#/\ T2#=4),(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#=0#/\ I+J #> K#/\ I+K #> J#/\ K+J #> I#/\T2#=1),(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#\=0#/\ T1 #=< 3#/\ T1 #= 1#/\ I+J#>K#/\ T2#=2),(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#\=0#/\ T1 #=< 3#/\ T1 #\= 1#/\ T1 #= 2#/\ I+K#>J#/\ T2#=2),(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#\=0#/\ T1 #=< 3#/\ T1 #\= 1#/\ T1 #\= 2#/\ T1 #= 3#/\ J+K#>I#/\ T2#=2),(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#=J#/\ T2 #= T1 + 1#/\ I#\=K#/\ J#\=K#/\ T2#\=0#/\ T2 #=< 3#/\ T2 #\= 1#/\ T2 #\= 2#/\T2#\=3#/\ T3#=4)],
        C = ((I#=0#/\T1 #= 4)#\/(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#=J#/\ T2#=T1+1#/\ I#=K#/\ T3#=T2+2#/\ J#=K#/\ T4#=T3+3#/\ T4#>3#/\ T5#=3)#\/(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#=0#/\ I+J#=< K#/\ T2#=4)#\/(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#=0#/\ I+J #> K#/\ I+K #> J#/\ K+J #> I#/\T2#=1)#\/(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#\=0#/\ T1 #=< 3#/\ T1 #= 1#/\ I+J#>K#/\ T2#=2)#\/(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#\=0#/\ T1 #=< 3#/\ T1 #\= 1#/\ T1 #= 2#/\ I+K#>J#/\ T2#=2)#\/(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#\=J#/\ I#\=K#/\ J#\=K#/\ T1#\=0#/\ T1 #=< 3#/\ T1 #\= 1#/\ T1 #\= 2#/\ T1 #= 3#/\ J+K#>I#/\ T2#=2)#\/(I#\=0#/\ J#\= 0#/\ K#\=0#/\ T1#=0#/\ I#=J#/\ T2 #= T1 + 1#/\ I#\=K#/\ J#\=K#/\ T2#\=0#/\ T2 #=< 3#/\ T2 #\= 1#/\ T2 #\= 2#/\T2#\=3#/\ T3#=4)).

tcas([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2]) :-
        init_env(ENV,10000,2),
        interface:alt_sep_test([1,0,0,1,0,1,1,0], ([],[K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2],[]), ([],[],[_]), ENV),
        fin_env(ENV).

ardeta([K,L,M,N,O,P,Q,R,S,T,U,V]) :-
        init_env(ENV,10000,2),
        interface:'P_rad_eta'([0,1,1,0,0,1,1,0,0,1,0,1,1,0,_,_,_,_,0,1], ([],[K,L,M,N,O,P,Q,R,S,T,U,V],[]), _, ENV),
        fin_env(ENV).




%%%%% AG 10/02/10 BENCHMARKING for JSS paper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

benchs(foo, LEN) :-
        nl,
        (
          statistics(runtime,[_,_]), rt(domain([X,Y],0,100), (Y #> X + 50, X*Y #< 60), [X,Y], LEN, Seq1),statistics(runtime,[_,TIME_RT]),
          write('RT for foo : '), T1 is TIME_RT / 1000, write(T1), write(' sec'), nl,nl,fail
        ;
          statistics(runtime,[_,_]), prt((domain([X,Y],0,100),Y #> X + 50, X*Y #< 60), [X,Y], LEN, 1, Seq2),statistics(runtime,[_,TIME_RTP]),
          write('PRT for foo : '), T2 is TIME_RTP / 1000, write(T2), write(' sec'), write('       -- div param k = 1'),nl,nl,fail
        ;
          statistics(runtime,[_,_]), prt((domain([X,Y],0,100), Y #> X + 50, X*Y #< 60), [X,Y], LEN, 2, Seq3),statistics(runtime,[_,TIME_PRT2]),
          write('PRT for foo : '), T3 is TIME_PRT2 / 1000, write(T3), write(' sec'), write('       -- div param k = 2'),nl, nl,fail
        ;
          statistics(runtime,[_,_]), prt((domain([X,Y],0,100), Y #> X + 50, X*Y #< 60), [X,Y], LEN, 3, Seq4),statistics(runtime,[_,TIME_PRT3]),
          write('PRT for foo : '), T4 is TIME_PRT3 / 1000, write(T4), write(' sec'), write('       -- div param k = 3'),nl, nl,fail
        ;
          statistics(runtime,[_,_]), prt((domain([X,Y],0,100), Y #> X + 50, X*Y #< 60), [X,Y], LEN, 4, Seq5),statistics(runtime,[_,TIME_PRT4]),
          write('PRT for foo : '), T5 is TIME_PRT4 / 1000, write(T5), write(' sec'), write('       -- div param k = 4'),nl, nl
        ).

benchs(power, LEN) :-
        nl,
        (
          statistics(runtime,[_,_]), prt((domain([X,Y],0,50000),power(X,Y,_RES,10000)), [X,Y], LEN, 1, Seq2),statistics(runtime,[_,TIME_RTP]),
          write('PRT for foo : '), T2 is TIME_RTP / 1000, write(T2), write(' sec'), write('       -- div param k = 1'),nl,nl,fail
        ;
          statistics(runtime,[_,_]), prt((domain([X,Y],0,50000),power(X,Y,_RES,10000)), [X,Y], LEN, 2, Seq3),statistics(runtime,[_,TIME_PRT2]),
          write('PRT for foo : '), T3 is TIME_PRT2 / 1000, write(T3), write(' sec'), write('       -- div param k = 2'),nl, nl,fail
        ;
          statistics(runtime,[_,_]), prt((domain([X,Y],0,50000),power(X,Y,_RES,10000)), [X,Y], LEN, 3, Seq4),statistics(runtime,[_,TIME_PRT3]),
          write('PRT for foo : '), T4 is TIME_PRT3 / 1000, write(T4), write(' sec'), write('       -- div param k = 3'),nl, nl,fail
        ;
          statistics(runtime,[_,_]), prt((domain([X,Y],0,50000), power(X,Y,_RES,10000)), [X,Y], LEN, 4, Seq5),statistics(runtime,[_,TIME_PRT4]),
          write('PRT for foo : '), T5 is TIME_PRT4 / 1000, write(T5), write(' sec'), write('       -- div param k = 4'),nl, nl
        ).

benchs(trityp, LEN) :-
        nl,
        (  statistics(runtime,[_,_]), trityp(I,J,K,_,C), rt(domain([I,J,K], 0,100),C, [I,J,K], LEN, Seq1),statistics(runtime,[_,TIME_RT]),
            write('RT for trityp :'), T1 is TIME_RT / 1000, write(T1), write(' sec'), nl,nl,fail
        ;
            statistics(runtime,[_,_]), trityp(I,J,K,_,C), prt((domain([I,J,K], 0,100),C), [I,J,K], LEN, 1, Seq2),statistics(runtime,[_,TIME_RTP]),
            write('PRT for trityp :'), T2 is TIME_RTP / 1000, write(T2), write(' sec'), write('       -- div param k = 1'),nl,nl, fail
        ;
            statistics(runtime,[_,_]), trityp(I,J,K,_,C), prt((domain([I,J,K], 0,100),C), [I,J,K], LEN, 2, Seq3),statistics(runtime,[_,TIME_PRT2]),
            write('PRT for trityp :'), T3 is TIME_PRT2 / 1000, write(T3), write(' sec'), write('       -- div param k = 2'),nl, nl, fail
        ;
            statistics(runtime,[_,_]), trityp(I,J,K,_,C),prt((domain([I,J,K], 0,100),C), [I,J,K], LEN, 3, Seq4),statistics(runtime,[_,TIME_PRT3]),
            write('PRT for trityp :'), T4 is TIME_PRT3 / 1000, write(T4), write(' sec'), write('       -- div param k = 3'),nl, nl, fail
        ;
            statistics(runtime,[_,_]), trityp(I,J,K,_,C),prt((domain([I,J,K], 0,100),C), [I,J,K], LEN, 4, Seq5),statistics(runtime,[_,TIME_PRT4]),
            write('PRT for trityp :'), T5 is TIME_PRT4 / 1000, write(T5), write(' sec'), write('       -- div param k = 4'),nl, nl
        ).

benchs(tcas, LEN) :-
        compile(['../../EUCLIDE_V0/SRC/lib_c.pl']),
        pl_CREATE_TS('../../EUCLIDE_V0/examples/tcas.cpp', c),
        pl_GET_CLPVARS('../../EUCLIDE_V0/examples/tcas.cpp', 74,alt_sep_test, IN_N, IN_V, OUT_N, OUT_V),
        pl_ASSERT('../../EUCLIDE_V0/examples/tcas.cpp', 74, alt_sep_test),
        nl,
        (  statistics(runtime,[_,_]),
           rt(domain([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2],0,1000),tcas([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2]),[K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2], LEN, Seq1),
           statistics(runtime,[_,TIME_RT]),
           write('RT for tcas :'), T1 is TIME_RT / 1000, write(T1), write(' sec'), nl,nl,fail
        ;
            statistics(runtime,[_,_]),
            prt((domain([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2],0,1000),tcas([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2])),[K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2],LEN,1,Seq2),
            statistics(runtime,[_,TIME_RTP]),
            write('PRT for tcas :'), T2 is TIME_RTP / 1000, write(T2), write(' sec'), write('       -- div param k = 1'), nl,nl, fail
        ;
            statistics(runtime,[_,_]), 
            prt((domain([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2],0,1000),tcas([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2])),[K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2], LEN, 2, Seq3),
            statistics(runtime,[_,TIME_PRT2]),
            write('PRT for tcas :'), T3 is TIME_PRT2 / 1000, write(T3), write(' sec'), write('       -- div param k = 2'),nl, nl
        ),
        pl_CLOSE_TS('../../EUCLIDE_V0/examples/tcas.cpp'),
        retractall(interface:alt_sep_test).

benchs(ardeta, LEN) :-
        compile(['../../EUCLIDE_V0/SRC/lib_c.pl']),
        pl_CREATE_TS('../../EUCLIDE_V0/examples/ardeta03.cpp', c),
        pl_GET_CLPVARS('../../EUCLIDE_V0/examples/ardeta03.cpp', 548, 'P_rad_eta', IN_N, IN_V, OUT_N, OUT_V),
        pl_ASSERT('../../EUCLIDE_V0/examples/ardeta03.cpp', 548, 'P_rad_eta'),
        nl,
        (  statistics(runtime,[_,_]),
           rt(domain([K,L,M,N,O,P,Q,R,S,T,U,V],0,1000),ardeta([K,L,M,N,O,P,Q,R,S,T,U,V]),[K,L,M,N,O,P,Q,R,S,T,U,V], LEN, Seq1),
           statistics(runtime,[_,TIME_RT]),
           write('RT for ardeta :'), T1 is TIME_RT / 1000, write(T1), write(' sec'), nl,nl,fail
        ;
            statistics(runtime,[_,_]),
            prt((domain([K,L,M,N,O,P,Q,R,S,T,U,V],0,1000),ardeta([K,L,M,N,O,P,Q,R,S,T,U,V])),[K,L,M,N,O,P,Q,R,S,T,U,V],LEN,1,Seq2),
            statistics(runtime,[_,TIME_RTP]),
            write('RT for ardeta :'), T2 is TIME_RTP / 1000, write(T2), write(' sec'), write('       -- div param k = 1'), nl,nl, fail
        ;
            statistics(runtime,[_,_]), 
            prt((domain([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2],0,1000),ardeta([K,L,M,N,O,P,Q,R,S,T,U,V])),[K,L,M,N,O,P,Q,R,S,T,U,V], LEN, 2, Seq3),
            statistics(runtime,[_,TIME_PRT2]),
            write('PRT for ardeta :'), T3 is TIME_PRT2 / 1000, write(T3), write(' sec'), write('       -- div param k = 2'),nl, nl
        ),
        pl_CLOSE_TS('../../EUCLIDE_V0/examples/ardeta03.cpp'),
        retractall(interface:'P_rad_eta').

benchs(ardeta, LEN, Min, Max) :-
        compile(['../../EUCLIDE_V0/SRC/lib_c.pl']),
        pl_CREATE_TS('../../EUCLIDE_V0/examples/ardeta03.cpp', c),
        pl_GET_CLPVARS('../../EUCLIDE_V0/examples/ardeta03.cpp', 548, 'P_rad_eta', IN_N, IN_V, OUT_N, OUT_V),
        pl_ASSERT('../../EUCLIDE_V0/examples/ardeta03.cpp', 548, 'P_rad_eta'),
        nl,
        (  statistics(runtime,[_,_]),
           rt(domain([K,L,M,N,O,P,Q,R,S,T,U,V],Min,Max),ardeta([K,L,M,N,O,P,Q,R,S,T,U,V]),[K,L,M,N,O,P,Q,R,S,T,U,V], LEN, Seq1),
           statistics(runtime,[_,TIME_RT]),
           write('RT for ardeta :'), T1 is TIME_RT / 1000, write(T1), write(' sec'), nl,nl,fail
        ;
            statistics(runtime,[_,_]),
            prt((domain([K,L,M,N,O,P,Q,R,S,T,U,V],Min,Max),ardeta([K,L,M,N,O,P,Q,R,S,T,U,V])),[K,L,M,N,O,P,Q,R,S,T,U,V],LEN,1,Seq2),
            statistics(runtime,[_,TIME_RTP]),
            write('RT for ardeta :'), T2 is TIME_RTP / 1000, write(T2), write(' sec'), write('       -- div param k = 1'), nl,nl, fail
        ;
            statistics(runtime,[_,_]), 
            prt((domain([K,L,M,N,O,P,Q,R,S,T,U,V,U1,V1,U2,V2],Min,Max),ardeta([K,L,M,N,O,P,Q,R,S,T,U,V])),[K,L,M,N,O,P,Q,R,S,T,U,V], LEN, 2, Seq3),
            statistics(runtime,[_,TIME_PRT2]),
            write('PRT for ardeta :'), T3 is TIME_PRT2 / 1000, write(T3), write(' sec'), write('       -- div param k = 2'),nl, nl
        ),
        pl_CLOSE_TS('../../EUCLIDE_V0/examples/ardeta03.cpp'),
        retractall(interface:'P_rad_eta').


