File: encoding.lp

package info (click to toggle)
gringo 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,128 kB
  • sloc: cpp: 210,867; ansic: 37,507; python: 11,271; yacc: 825; javascript: 627; sh: 368; xml: 364; makefile: 102
file content (71 lines) | stat: -rw-r--r-- 2,969 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "../common/meta.lp".
#include "../common/metaD.lp".

cxopt(card).  cxopt(incl).  cxopt(pref).

criteria(J,W,Q,A) :- output(_criteria(J,W,Q),A).
criteria(J,W,A) :- criteria(J,W,Q,A).

cxopt(J,W,O)    :- criteria(J,W,_,_), cxopt(O), optimize(J,W,O).
cxopt(J,W,card) :- criteria(J,W,_,_), #false : optimize(J,W,O).

%%%%%%%%%% verify dominance

equal(J) :- cxopt(J,_,_), equal(J,W,O) : cxopt(J,W,O).

chain(J1,J2) :- cxopt(J1,_,_), cxopt(J2,_,_), J2 < J1,
                #false : cxopt(J3,W,O), J2 < J3, J3 < J1.

check(J2) :- cxopt(J2,_,_), #false : chain(J1,J2).
check(J2) :- chain(J1,J2), check(J1), equal(J1).

bot :- #false : cxopt(J,W,O).
bot :- check(J1), worse(J1).
bot :- check(J1), equal(J1), #false : chain(J1,J2).

% require non-existence of dominating answer set

:- not bot.

%%%%%%%%%% check cardinality criteria

equal(J,W,card) :- cxopt(J,W,card), #sum { -1,Q : not not conjunction(A),  criteria(J,W,Q,A) ;
                                            1,Q :         true(normal(A)), criteria(J,W,Q,A) } >= 0.
worse(J)        :- cxopt(J,W,card), #sum { -1,Q : not not conjunction(A),  criteria(J,W,Q,A) ;
                                            1,Q :         true(normal(A)), criteria(J,W,Q,A) } >= 1.
%%%%%%%%%% check inclusion criteria

ndiff(A) :- cxopt(J,W,incl), criteria(J,W,A), true(normal(A)).
ndiff(A) :- cxopt(J,W,incl), criteria(J,W,A), not conjunction(A).

equal(J,W,incl) :- cxopt(J,W,incl), ndiff(A) : criteria(J,W,A).
worse(J)        :- cxopt(J,W,incl), criteria(J,W,A), true(normal(A)), not conjunction(A).

%%%%%%%%%% check preference criteria (relative to user predicate prefer/2)

cando(A) :- cxopt(J,W,pref), criteria(J,W,A), fail(normal(A)),     conjunction(A).
nocan(A) :- cxopt(J,W,pref), criteria(J,W,A), true(normal(A)).
nocan(A) :- cxopt(J,W,pref), criteria(J,W,A), not conjunction(A).

condo(A) :- cxopt(J,W,pref), criteria(J,W,A), true(normal(A)), not conjunction(A).
nocon(A) :- cxopt(J,W,pref), criteria(J,W,A), fail(normal(A)).
nocon(A) :- cxopt(J,W,pref), criteria(J,W,A),     conjunction(A).

cando(J,W,A)    :- cxopt(J,W,pref), criteria(J,W,A), criteria(J,W,A'), prefer(A,A'), A != A', cando(A), condo(A').

nocon(J,W,A)    :- cxopt(J,W,pref), criteria(J,W,A), nocon(A).
nocon(J,W,A)    :- cxopt(J,W,pref), criteria(J,W,A), nocan(A') : criteria(J,W,A'), A != A', prefer(A,A').
nocon(J,W,A)    :- cxopt(J,W,pref), criteria(J,W,A), criteria(J,W,A'), prefer(A',A), not prefer(A,A'), cando(A').

equal(J,W,pref) :- cxopt(J,W,pref), criteria(J,W,A), cando(J,W,A), nocon(A') : criteria(J,W,A'), prefer(A',A), not prefer(A,A').

worse(J)        :- cxopt(J,W,pref), nocon(J,W,A) : criteria(J,W,A).

%%%%%%%%%% handling fo queries and optimization statements

optimize(J,W,Q) :- output(_optimize(J,W,Q),B), conjunction(B).
 :- output(_query,B), not conjunction(B).

hide(_criteria(J,W,Q)) :- output(_criteria(J,W,Q),_).
hide(_query)           :- output(_query,_).
hide(_optimize(J,W,Q)) :- output(_optimize(J,W,Q),_).