% ------------------------------------------------------------------------------------------------------
%  Copyright (C) 1999-2007 <a href="mailto:adrian.paschke@gmx.de">Adrian Paschke</a>
% 
% The Contractlog library is part of the Rule Based Service Level Agreement (RBSLA)
%  project, available at 
% <a href="https://sourceforge.net/projects/rbsla">SourceForge RBSLA</a>
% 
% More information <a href="http://ibis.in.tum.de/staff/paschke/rbsla/index.htm">RBSLA Project Site</a>
%
% This library is free software; you can redistribute it and/or
% modify it under the terms of the GNU Lesser General Public
% License as published by the Free Software Foundation; either
%  version 2 of the License, or (at your option) any later version.
% 
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this library; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
%
% ------------------------------------------------------------------------------------------------------

% ------------------------------------------------------------------------------------------------------
% Defeasible Deontic Implementation
% 
%
% Conflict handling for deontic conflicts/paradoxes using time based conflict handling and defeasible
% logic.
%
 % @author <A HREF="mailto:adrian.paschke@gmx.de">Adrian Paschke</A>
 % @version 0.2 <1 Nov 2006>
 % @since 0.1
 % @dependencies defeasible.prova
% ------------------------------------------------------------------------------------------------------

moduleOID("./ContractLog/defeasible_deontic.prova").


% ----------------------------------------------------------
% Violations to primary norms
% ----------------------------------------------------------

% Note: dependencies with utils.prova neg(neg(X)) --> X

% A violation event happens if there is an obligaton on A and neg A happens and the obligation is time-based
happens(violation(oblige(S,O,A)),T) :-
	happens(neg(A),T),
	holdsAt(oblige(S,O,A),T),
	not(initially(oblige(S,O,A))).

% A violation event terminates the primary obligation.
% A contrary-to-duty obligation can now safely initiated
terminates(violation(oblige(S,O,A),oblige(S,O,A),T).

%TODO: forbidden violation

% ----------------------------------------------------------
% Exceptions to primary norms
% ----------------------------------------------------------

% an exception to a obligation terminates the obligation
% now a secondary norm can be initiated by the exception event
terminates(exception(oblige(S,O,A)),oblige(S,O,A),T).

%TODO: forbidden exception





% ----------------------------------------------------------
% Defeasible deontic logic
%
% by default all strict norms are also defeasible
%
% @dependencies: defeasible.prova
% ----------------------------------------------------------

% by default all strict norms are also defeasible
% a defeasible norm is not blocked if it strictly holds
neg(blocked(defeasible(holdsAt([Norm,S,O,A],T)))):- bound(Norm), holdsAt([Norm,S,O,A],T).

% ------------------
%priority rules for defeasible deontic norms
% 

% oblige neg A overrides oblige A
overrides(holdsAt(oblige(S,O,neg(A)),T), holdsAt(oblige(S,O,A),T)).
% oblige A overrides oblige neg A
% overrides(holdsAt(oblige(S,O,A),T), holdsAt(oblige(S,O,neg(A)),T)).

% oblige A overrides forbid A
overrides(holdsAt(oblige(S,O,A),T), holdsAt(forbid(S,O,A),T)).
% overrides(holdsAt(forbid(S,O,A),T), holdsAt(oblige(S,O,A),T)).

% forbid A overrides permit A
 overrides(holdsAt(forbid(S,O,A),T), holdsAt(permit(S,O,A),T)).
% overrides(holdsAt(permit(S,O,A),T), holdsAt(forbid(S,O,A),T)).