% ------------------------------------------------------------------------------------------------------
%
% Shows a simple priority solution - for more sophisticated formalizations use defeasible logic
% ------------------------------------------------------------------------------------------------------

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

% ------------------------------------------------------------------------ 
% ifNotAvailInform(personA, PersonB)
%
% set a priority chain for informing admin etc.

person(kurt, role(firstStandByAdmin, companyA), "kurt@company.de", "+49 89 453454554").

person(felix, role(secondStandByAdmin, companyA),"felix@company.de", "+49 89 9892723").

person(michael, role(chiefAdmin, companyA), "michael@company.de","+49 89 27879783").

person(petra, role(firstAmanuensisOfChiefAdmin, companyA),"petra@company.de", "+49 89 2722343").

person(sabine, role(secondAmanuensisOfChiefAdmin, companyA),"sabine@company.de", "+49 89 272123").

ifNotAvailInform(firstStandByAdmin, secondStandByAdmin).
ifNotAvailInform(secondStandByAdmin, firstAmanuensisOfChiefAdmin).
ifNotAvailInform(secondStandByAdmin, chiefAdmin).
ifNotAvailInform(firstAmanuensisOfChiefAdmin, secondAmanuensisOfChiefAdmin).
ifNotAvailInform(endElement,firstStandByAdmin).


% ------------------------------------------------------------------------ 
% morePriority(X, Y)
%
% define this priority chain in terms of the priority framework

morePriority(X, endElement):-
	ifNotAvailInform(endElement, XX),
	equ(X, informPrio(XX)).

morePriority(X, Y):-
	ifNotAvailInform(YY, XX),
	equ(X, informPrio(XX)),
	equ(Y, informPrio(YY)).

causeExists(informPrio(X)) :-	
	personNotAvailable(Person),
	person(Person, role(X,_), _, _).


% ------------------------------------------------------------------------ 
% personNotAvailable(X)
%
% Depends on some fluents.

personNotAvailable(X) :-	
	holdsAt(personNotAvailable(X), datetime(2006,1,2,0,0,0)).

holdsAt(personNotAvailable(X), T) :-
	holdsAt(personIll(X), T).
holdsAt(personNotAvailable(X), T) :-
	holdsAt(personHoliday(X), T).

initiates(takenIll(X), personIll(X), T).
terminates(gotWell(X), personIll(X), T).

initiates(goHoliday(X), personHoliday(X), T).
terminates(leaveHoliday(X), personHoliday(X), T).
terminates(takenIll(X), personHoliday(X), T).


% ------------------------------------------------------------------------ 
% happens()
%
% some examples, what can happen to all the admins

% kurt get ill for 3 days, because he have drunken too much at new year
happens(takenIll(kurt), datetime(2006,1,1,0,0,0)).
happens(gotWell(kurt), datetime(2006,1,3,0,0,0)).

% felix is on a realy long holidy trip
happens(goHoliday(felix), datetime(2005,12,20,0,0,0)).
happens(leaveHoliday(felix), datetime(2006,1,20,0,0,0)).

% petra decided for a holiday, and than get ill
happens(goHoliday(petra), datetime(2005,12,23,0,0,0)).
happens(takenIll(petra), datetime(2005,12,30,0,0,0)).
