-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmax-sat.lp
More file actions
38 lines (31 loc) · 1017 Bytes
/
max-sat.lp
File metadata and controls
38 lines (31 loc) · 1017 Bytes
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
% File: max-sat.lp
% Author: Michael Huelsman
% Created On: 25 May 2026
% Purpose:
% A CNF Max-SAT solver written in ASP.
%
% Usage:
% clingo max-sat.lp instance.lp
%
% Instance Setup:
% Each instance contains the following predicates:
% clause(I,L)
% which reads that clause I contains literal L.
% Literals values are only integers.
% Negative integer values means a particular literal is negated in
% the clause. Thus, clause(0, -1) is read as clause 0 contains NOT x1.
% Clauses may have any number of literals, but are assumed to be in CNF form.
% Simplification predicates
literal(L) :- L = |X|, clause(_,X).
clause(C) :- clause(C,_).
% Assign true/false values to literals
1 {true(L); false(L)} 1 :- literal(L).
% Clause satisfiability
sat_clause(C) :- clause(C,L), true(L), L > 0.
sat_clause(C) :- clause(C,L), false(|L|), L < 0.
:- true(L), false(L).
% Max-SAT optimization statement.
#maximize {1,sat_clause(C):sat_clause(C)}.
#show true/1.
#show false/1.
#show sat_clause/1.