:- expects_dialect(lps). /* Original: (The insured is the Holder, the insurer is the Counterparty) insureGoods(goodsPremium, principal, penalty, t1, t2, goodsInsured) = counterpartySecurity = pledge(allGoods(Counterparty)) with to Counterparty getTitle(goodsPremium) insurancePayment(goodsInsured, principal, t1, t2) with when breachedPerformance(insurancePayment) to Holder foreclose(counterpartySecurity, penalty) insurancePayment(goodsInsured, principal, t1, t2) = when safeArrival(goodsInsured) terminate % buggy, IMHO: should check dates when withinPeriod(t1,t2) when choiceOf(Holder) to Holder principal */ :- include(system('date_utils.pl')). % Rather then run live, we'll simulate real time by mapping its time points to simulation cycles: simulatedRealTimeBeginning('2018-05-01'). simulatedRealTimePerCycle(RTPC) :- RTPC is 3600*12. % just 2 LPS cycles per calendar day maxRealTime(M) :- M is 24*3600*120. % 120 days max lifetime of the contract events to(_Agent,_Right), pledge(_Goods,_Security), safeArrival(_GoodsInsured), choiceOf(_Party), foreclose(_Security,_Amount). insureGoods(GoodsPremium, Principal, Penalty, T1-T2, GoodsInsured) from ContractSigned if pledge(allGoods(counterparty),CounterpartySecurity) from ContractSigned, to(counterParty,getTitle(GoodsPremium)) from ContractSigned, T1 @> ContractSigned, ( if insurancePayment(GoodsInsured,Principal) from T, T@>=T1, T@