
% the evaluation loop

:-[main].

e:- [eval].

cd:- cd('..').
% name, method/2 (filename,extension), extension (for results),
%                       directory, file filter (in directory)

problem(test,ttSATo,'.test','./TEST/','*').

problem(ttSATo,ttSATo,'.ttsato','./QBFcnfSSS/','*.*').
problem(ttLADo,ttSATo,'.ttlado','./QBFLadn/','*.*').
problem(ttCNFo,ttSATo,'.ttcnfo','./QBFCNF/','*.*').
problem(ttLWBo,ttLWBo,'.ttlwbo','./K-LWB-PL/','k_d*.*').
problem(ttREFo,ttSATo,'.ttrefo','./Reference-TANCS-ModalQBF/','*.*').

problem(ttSATz,ttSATz,'.ttsatz','./QBFcnfSSS/','*.*').
problem(ttLADz,ttSATz,'.ttladz','./QBFLadn/','*.*').
problem(ttCNFz,ttSATz,'.ttcnfz','./QBFCNF/','*.*').
problem(ttLWBz,ttLWBz,'.ttlwbz','./K-LWB-PL/','*.*').
problem(ttREFz,ttSATz,'.ttrefz','./Reference-TANCS-ModalQBF/','*.*').


eval(P):-
    problem(P,METHOD,EXT,DIR,FILTER),
    cd(DIR),
    getFileList(FILTER,L),
    repEval(L,METHOD,EXT),
    cd('..'),
    copyResults(DIR,METHOD,EXT).

repEval([],_,_):-!.
repEval([I|J],M,E):-
    ME =.. [M,I,E],
    %nl,write(ME),
    call(ME),!,
    repEval(J,M,E),!.


getFileList(F,L):-
    concat_list(['ls ',F,' > files'],Cmd),
    shell(Cmd),
    readin_alc(files,L),
    shell('rm files'),!.

copyResults(D,M,E):- % create directory= method name; move .ext files
    concat('mkdir ./EVAL/',M,Cmd0),
    shell(Cmd0),!,
    concat_list(['mv ',D,'*',E,' ./EVAL/',M,'/.'],Cmd),
    shell(Cmd),!.
    
copyResults(D,M,E):-  %  directory= method name already exists; rm files, then copy
    concat_list(['rm ./EVAL/',M,'/*',E],Cmd),
    shell(Cmd),!,
    concat_list(['mv ',D,'*',E,' ./EVAL/',M,'/.'],Cmd1),
    shell(Cmd1),!.
    
    
copyResults(D,M,E):-  %  directory= method name already exists; no files, then copy
    concat_list(['mv ',D,'*',E,' ./EVAL/',M,'/.'],Cmd1),
    shell(Cmd1),!.
    
    
