CBMC
satcheck_picosat.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_picosat.h"
10 
11 #include <algorithm>
12 
13 #include <util/invariant.h>
14 #include <util/threeval.h>
15 
16 extern "C"
17 {
18 #include <picosat.h>
19 }
20 
21 #ifndef HAVE_PICOSAT
22 #error "Expected HAVE_PICOSAT"
23 #endif
24 
26 {
27  if(a.is_constant())
28  return tvt(a.sign());
29 
30  tvt result;
31 
32  if(static_cast<int>(a.var_no())>picosat_variables(picosat))
34 
35  const int val=picosat_deref(picosat, a.dimacs());
36  if(val>0)
37  result=tvt(true);
38  else if(val<0)
39  result=tvt(false);
40  else
42 
43  return result;
44 }
45 
46 std::string satcheck_picosatt::solver_text() const
47 {
48  return "PicoSAT";
49 }
50 
52 {
53  bvt new_bv;
54 
55  if(process_clause(bv, new_bv))
56  return;
57 
58  picosat_adjust(picosat, _no_variables);
59 
60  for(const auto &literal : new_bv)
61  picosat_add(picosat, literal.dimacs());
62 
63  picosat_add(picosat, 0);
64 
66 }
67 
69 {
71 
72  {
73  std::string msg=
74  std::to_string(_no_variables-1)+" variables, "+
75  std::to_string(picosat_added_original_clauses(picosat))+" clauses";
76  log.statistics() << msg << messaget::eom;
77  }
78 
79  std::string msg;
80 
81  for(const auto &literal : assumptions)
82  if(!literal.is_true())
83  picosat_assume(picosat, literal.dimacs());
84 
85  const int res=picosat_sat(picosat, -1);
86  if(res==PICOSAT_SATISFIABLE)
87  {
88  msg="SAT checker: instance is SATISFIABLE";
89  log.status() << msg << messaget::eom;
90  status=SAT;
91  return P_SATISFIABLE;
92  }
93  else
94  {
95  INVARIANT(
96  res == PICOSAT_UNSATISFIABLE,
97  "picosat result should report either sat or unsat");
98  msg="SAT checker: instance is UNSATISFIABLE";
99  log.status() << msg << messaget::eom;
100  }
101 
102  status=UNSAT;
103  return P_UNSATISFIABLE;
104 }
105 
107 {
108  UNREACHABLE;
109 }
110 
112 {
113  picosat = picosat_init();
114 }
115 
117 {
118  picosat_reset(picosat);
119 }
120 
122 {
124 
125  return picosat_failed_assumption(picosat, a.dimacs())!=0;
126 }
statust status
Definition: cnf.h:87
size_t clause_counter
Definition: cnf.h:88
bool process_clause(const bvt &bv, bvt &dest) const
filter 'true' from clause, eliminate duplicates, recognise trivially satisfied clauses
Definition: cnf.cpp:424
size_t _no_variables
Definition: cnf.h:57
bool sign() const
Definition: literal.h:88
bool is_constant() const
Definition: literal.h:166
int dimacs() const
Definition: literal.h:117
var_not var_no() const
Definition: literal.h:83
mstreamt & statistics() const
Definition: message.h:411
mstreamt & status() const
Definition: message.h:406
static eomt eom
Definition: message.h:289
resultt
Definition: prop.h:101
messaget log
Definition: prop.h:134
tvt l_get(literalt a) const override
void set_assignment(literalt a, bool value) override
std::string solver_text() const override
bool is_in_conflict(literalt a) const override
Returns true if an assumption is in the final conflict.
resultt do_prop_solve(const bvt &assumptions) override
void lcnf(const bvt &bv) override
Definition: threeval.h:20
std::vector< literalt > bvt
Definition: literal.h:201
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.