:-eval(consult('ContractLog/list.prova')).	
:-eval(consult('ContractLog/utils.prova')).
:-eval(consult('ContractLog/integrity.prova')).
:-eval(consult('ContractLog/defeasible.prova')).

%------------------------------------------------------
% Test the defeasible logic with integrity constraints
%
% Example: 
%
% Module 1
%
% module("module1").
%	
% Facts
%
% status("Adrian",gold).
% status("Adrian",silver).
%
% Defeasible rules
%
% discount5: discount(X,5):= defeasible(status(X,silver)).
% discount10: discount(X,10):= defeasible(status(X,gold)).
%
% Integrity constraints
%
% integrity(xor(discount(X,5),discount(X,10))).
%
% Priorities
%
% overrides("discount10","discount5").
%
%
%
% Module 2
%
% module("module2").
%
% neg(payed("Adrian")).

% overrides("module 2","module 1").

% integrity(xor(discount(X,_),neg(discount(X))).
%
% nodiscount: neg(discount(X)):= defeasible(neg(payed("Adrian")).
%
%----------------------------------------------------------------------

%module("module1"). 
%module("module2").

status("Adrian","gold"). % strict fact
status("Adrian","silver"). % strict fact
neg(payed("Adrian")). % strict fact

% neg(discount("Adrian")). %striclty negated opposer


integrity(xor(discount(X,_),neg(discount(X)))).
integrity(xor(discount(X,5),discount(X,10))).
%integrity(not(discount(X,10))).
%integrity(not(discount(X,Y))).
%integrity(and(discount(X,5),discount(X,10))).

%integrity(xor(Oppo1,Oppo2)):-
%	overrides(R1,R2),
%	oid(R1,Oppo1),
%	oid(R2,Oppo2).


%overrides("nodiscount","discount10").
overrides("discount10","nodiscount").
overrides("discount10","discount5").
%overrides(neg(discount(X)),discount(X,Y)).
%overrides(discount(X,Y),neg(discount(X))).
% module 2 overrides module 1
%overrides("module2","module1").


oid(discount5)::defeasible(discount(X,5)):-
	testIntegrity(discount(X,5)),
	defeasible(status(X,"silver")),	
	not(defeated("discount5",discount(X,5))).
neg(blocked(defeasible(discount(X,5)))):- testIntegrity(discount(X,5)), defeasible(status(X,"silver")).	
body(defeasible(discount(X,5))):- defeasible(status(X,"silver")).


oid(discount10)::defeasible(discount(X,10)):-
	testIntegrity(discount(X,10)),
	defeasible(status(X,"gold")),
	not(defeated("discount10",discount(X,10))).
neg(blocked(defeasible(discount(X,10)))):- testIntegrity(discount(X,10)), defeasible(status(X,"gold")).	
body(defeasible(discount(X,10))) :-	defeasible(status(X,"gold")).


oid(nodiscount)::defeasible(neg(discount(X))):-
	testIntegrity(neg(discount(X))),
	defeasible(neg(payed(X))),
	not(defeated("nodiscount",neg(discount(X)))).	
neg(blocked(defeasible(neg(discount(X))))):-  testIntegrity(neg(discount(X))), defeasible(neg(payed(X))).	
body(defeasible(neg(discount(X)))) :- defeasible(neg(payed(X))).


:-solve(defeasible(discount(X,Y))).
	