cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
satcheck_lingeling.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Michael Tautschnig, michael.tautschnig@cs.ox.ac.uk
6
7
\*******************************************************************/
8
9
#include "
satcheck_lingeling.h
"
10
11
#include <algorithm>
12
13
#include <
util/invariant.h
>
14
#include <
util/threeval.h
>
15
16
extern
"C"
17
{
18
#include <lglib.h>
19
}
20
21
#ifndef HAVE_LINGELING
22
#error "Expected HAVE_LINGELING"
23
#endif
24
25
tvt
satcheck_lingelingt::l_get
(
literalt
a)
const
26
{
27
if
(a.
is_constant
())
28
return
tvt
(a.
sign
());
29
30
tvt
result;
31
32
if
(a.
var_no
()>lglmaxvar(
solver
))
33
return
tvt
(
tvt::tv_enumt::TV_UNKNOWN
);
34
35
const
int
val=lglderef(
solver
, a.
dimacs
());
36
if
(val>0)
37
result=
tvt
(
true
);
38
else
if
(val<0)
39
result=
tvt
(
false
);
40
else
41
return
tvt
(
tvt::tv_enumt::TV_UNKNOWN
);
42
43
return
result;
44
}
45
46
std::string
satcheck_lingelingt::solver_text
()
const
47
{
48
return
"Lingeling"
;
49
}
50
51
void
satcheck_lingelingt::lcnf
(
const
bvt
&bv)
52
{
53
bvt
new_bv;
54
55
if
(
process_clause
(bv, new_bv))
56
return
;
57
58
for
(
const
auto
&literal : new_bv)
59
lgladd(
solver
, literal.dimacs());
60
61
lgladd(
solver
, 0);
62
63
clause_counter
++;
64
}
65
66
propt::resultt
satcheck_lingelingt::do_prop_solve
(
const
bvt
&assumptions)
67
{
68
PRECONDITION
(
status
!=
ERROR
);
69
70
// We start counting at 1, thus there is one variable fewer.
71
{
72
std::string msg=
73
std::to_string(
no_variables
()-1)+
" variables, "
+
74
std::to_string(
clause_counter
)+
" clauses"
;
75
log
.statistics() << msg <<
messaget::eom
;
76
}
77
78
std::string msg;
79
80
for
(
const
auto
&literal : assumptions)
81
if
(!literal.is_true())
82
lglassume(
solver
, literal.dimacs());
83
84
const
int
res=lglsat(
solver
);
85
CHECK_RETURN
(res == 10 || res == 20);
86
87
if
(res==10)
88
{
89
msg=
"SAT checker: instance is SATISFIABLE"
;
90
log
.status() << msg <<
messaget::eom
;
91
status
=
SAT
;
92
return
P_SATISFIABLE
;
93
}
94
else
95
{
96
INVARIANT
(res == 20,
"result value is either 10 or 20"
);
97
msg=
"SAT checker: instance is UNSATISFIABLE"
;
98
log
.status() << msg <<
messaget::eom
;
99
}
100
101
status
=
UNSAT
;
102
return
P_UNSATISFIABLE
;
103
}
104
105
void
satcheck_lingelingt::set_assignment
(
literalt
a,
bool
value)
106
{
107
UNREACHABLE
;
108
}
109
110
satcheck_lingelingt::satcheck_lingelingt
() :
111
solver
(lglinit())
112
{
113
}
114
115
satcheck_lingelingt::~satcheck_lingelingt
()
116
{
117
lglrelease(
solver
);
118
solver
=0;
119
}
120
121
void
satcheck_lingelingt::set_frozen
(
literalt
a)
122
{
123
if
(!a.
is_constant
())
124
lglfreeze(
solver
, a.
dimacs
());
125
}
126
131
bool
satcheck_lingelingt::is_in_conflict
(
literalt
a)
const
132
{
133
PRECONDITION
(!a.
is_constant
());
134
return
lglfailed(
solver
, a.
dimacs
())!=0;
135
}
cnf_solvert::status
statust status
Definition
cnf.h:87
cnf_solvert::statust::UNSAT
@ UNSAT
Definition
cnf.h:86
cnf_solvert::statust::SAT
@ SAT
Definition
cnf.h:86
cnf_solvert::statust::ERROR
@ ERROR
Definition
cnf.h:86
cnf_solvert::clause_counter
size_t clause_counter
Definition
cnf.h:88
cnft::process_clause
bool process_clause(const bvt &bv, bvt &dest) const
filter 'true' from clause, eliminate duplicates, recognise trivially satisfied clauses
Definition
cnf.cpp:424
cnft::no_variables
virtual size_t no_variables() const override
Definition
cnf.h:42
literalt
Definition
literal.h:26
literalt::sign
bool sign() const
Definition
literal.h:88
literalt::is_constant
bool is_constant() const
Definition
literal.h:166
literalt::dimacs
int dimacs() const
Definition
literal.h:117
literalt::var_no
var_not var_no() const
Definition
literal.h:83
messaget::eom
static eomt eom
Definition
message.h:289
propt::resultt
resultt
Definition
prop.h:101
propt::resultt::P_UNSATISFIABLE
@ P_UNSATISFIABLE
Definition
prop.h:101
propt::resultt::P_SATISFIABLE
@ P_SATISFIABLE
Definition
prop.h:101
propt::log
messaget log
Definition
prop.h:134
satcheck_lingelingt::lcnf
void lcnf(const bvt &bv) override
Definition
satcheck_lingeling.cpp:51
satcheck_lingelingt::l_get
tvt l_get(literalt a) const override
Definition
satcheck_lingeling.cpp:25
satcheck_lingelingt::do_prop_solve
resultt do_prop_solve(const bvt &assumptions) override
Definition
satcheck_lingeling.cpp:66
satcheck_lingelingt::~satcheck_lingelingt
virtual ~satcheck_lingelingt()
Definition
satcheck_lingeling.cpp:115
satcheck_lingelingt::set_assignment
void set_assignment(literalt a, bool value) override
Definition
satcheck_lingeling.cpp:105
satcheck_lingelingt::solver_text
std::string solver_text() const override
Definition
satcheck_lingeling.cpp:46
satcheck_lingelingt::set_frozen
void set_frozen(literalt a) override
Definition
satcheck_lingeling.cpp:121
satcheck_lingelingt::is_in_conflict
bool is_in_conflict(literalt a) const override
Returns true if an assumed literal is in conflict if the formula is UNSAT.
Definition
satcheck_lingeling.cpp:131
satcheck_lingelingt::solver
struct LGL * solver
Definition
satcheck_lingeling.h:45
satcheck_lingelingt::satcheck_lingelingt
satcheck_lingelingt()
Definition
satcheck_lingeling.cpp:110
tvt
Definition
threeval.h:20
tvt::tv_enumt::TV_UNKNOWN
@ TV_UNKNOWN
Definition
threeval.h:23
bvt
std::vector< literalt > bvt
Definition
literal.h:201
satcheck_lingeling.h
invariant.h
CHECK_RETURN
#define CHECK_RETURN(CONDITION)
Definition
invariant.h:495
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition
invariant.h:525
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition
invariant.h:423
threeval.h
solvers
sat
satcheck_lingeling.cpp
Generated by
1.17.0