1 :- module(wfs,[main/0, main/1]).
3 :- use_module(library(lists)).
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 % Schrijf het programma waarvan je de wellfounded semantics wil bepalen
8 % hieronder onder de vorm van prog/1 feiten. Let erop dat je een conjunctie
9 % in de body tussen haakjes zet zodat prog/1 geparsed wordt, ipv prog/n.
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 :- constraints true/1, false/1, undefined/1, aclause/2, pos/2, neg/2, nbulit/2, nbplit/2, nbucl/2, phase2/0, true2/1, undefined2/1, aclause2/2, pos2/2, nbplit2/2, phase1/0, witness1/0, witness2/0.
44 true(At), aclause(Cl,At) \ pos(_,Cl) <=> true.
46 true(At), aclause(Cl,At) \ neg(_,Cl) <=> true.
48 false(At), aclause(Cl,At) \ pos(_,Cl) <=> true.
50 false(At), aclause(Cl,At) \ neg(_,Cl) <=> true.
52 true(At) \ nbucl(At,_) <=> true.
54 true(At) \ aclause(Cl,At), nbulit(Cl,_), nbplit(Cl,_) <=> true.
56 false(At) \ nbucl(At,_) <=> true.
58 nbucl(At,0) <=> false(At).
60 aclause(Cl,At), nbulit(Cl,0), nbplit(Cl,0) <=> true(At).
62 true(At) \ pos(At,Cl), nbulit(Cl,NU), nbplit(Cl,NP)
64 NU1 is NU - 1, nbulit(Cl,NU1),
65 NP1 is NP - 1, nbplit(Cl,NP1).
67 false(At) \ neg(At,Cl), nbulit(Cl,NU)
69 NU1 is NU - 1, nbulit(Cl,NU1).
71 true(At) \ neg(At,Cl), aclause(Cl,OAt), nbulit(Cl,_), nbplit(Cl,_), nbucl(OAt,N)
73 N1 is N - 1, nbucl(OAt,N1).
75 false(At) \ pos(At,Cl), aclause(Cl,OAt), nbulit(Cl,_), nbplit(Cl,_), nbucl(OAt,N)
77 N1 is N - 1, nbucl(OAt,N1).
79 witness2 \ witness2 <=> true.
80 phase2, nbucl(At,_) ==> witness2, undefined2(At).
81 phase2, pos(At,Cl) ==> pos2(At,Cl).
82 phase2, aclause(Cl,At) ==> aclause2(Cl,At).
83 phase2, nbplit(Cl,N) ==> nbplit2(Cl,N).
84 phase2, witness2 # ID <=> phase1 pragma passive(ID).
85 phase2 \ nbplit2(_,_) # ID <=> true pragma passive(ID).
86 phase2 \ aclause2(_,_) # ID <=> true pragma passive(ID).
90 true2(At), aclause2(Cl,At) \ pos2(_,Cl) <=> true.
91 true2(At) \ undefined2(At) <=> true.
92 aclause2(Cl,At), nbplit2(Cl,0) <=> true2(At).
93 true2(At) \ pos2(At,Cl), nbplit2(Cl,NP)
95 NP1 is NP - 1, nbplit2(Cl,NP1).
97 witness1 \ witness1 <=> true.
98 phase1, undefined2(At) # ID1 , aclause(Cl,At) # ID2 \ pos(_,Cl) # ID3 <=> true pragma passive(ID1), passive(ID2), passive(ID3).
99 phase1, undefined2(At) # ID1 , aclause(Cl,At) # ID2 \ neg(_,Cl) # ID3 <=> true pragma passive(ID1), passive(ID2), passive(ID3).
100 phase1, undefined2(At) # ID1 \ aclause(Cl,At) # ID2 , nbulit(Cl,_) # ID3, nbplit(Cl,_) # ID4 <=> true pragma passive(ID1), passive(ID2), passive(ID3), passive(ID4).
101 phase1 \ undefined2(At) # ID <=> witness1, false(At) pragma passive(ID).
102 phase1 \ true2(_) # ID <=> true pragma passive(ID).
103 phase1 \ aclause2(_,_) <=> true.
104 phase1 \ pos2(_,_) # ID <=> true pragma passive(ID).
105 phase1 \ nbplit2(_,_) # ID <=> true pragma passive(ID).
106 phase1, witness1 # ID <=> phase2 pragma passive(ID).
107 phase1 \ nbucl(At,_) # ID <=> undefined(At) pragma passive(ID).
108 phase1 \ pos(_,_) # ID <=> true.
109 phase1 \ neg(_,_) # ID <=> true pragma passive(ID).
110 phase1 \ aclause(_,_) # ID <=> true pragma passive(ID).
111 phase1 \ nbulit(_,_) # ID <=> true pragma passive(ID).
112 phase1 \ nbplit(_,_) # ID <=> true pragma passive(ID).
120 nbucl(p,1), % aantal undefined clauses voor p
121 pos(r,cl1), % positief voorkomen van r in clause cl1
122 aclause(cl1,p), % clause cl1 defineert p
123 nbulit(cl1,1), % aantal undefined literals in cl1
124 nbplit(cl1,1), % aantal positieve undefined literals in cl1
200 write(bench(wfs ,N , T,0,hprolog)),write('.'),nl.
206 ( prog, fail ; true),
212 findall(Clause,wfs:prog(Clause),Clauses),
214 setof(At,B^(wfs:prog(At :- B) ; wfs:prog(At), atom(At)),Ats),
222 conj2list(B,Literals,[]),
223 process_literals(Literals,N,NbULit,NbPLit),
243 process_literals([],_,0,0).
244 process_literals([L|R],Cl,U,P) :-
245 process_literals(R,Cl,U1,P1),
257 process_atoms([A|As]) :-
258 findall(A,wfs:prog(A :- _),L),