CBMC
satcheck_zchaff.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "satcheck_zchaff.h"
10 
11 #include <util/invariant.h>
12 
13 #include <zchaff_solver.h>
14 
16 {
17  status=INIT;
18  solver->set_randomness(0);
19  solver->set_variable_number(0);
20 }
21 
23 {
24 }
25 
27 {
29 
30  if(a.is_true())
31  return tvt(true);
32  else if(a.is_false())
33  return tvt(false);
34 
35  tvt result;
36 
37  INVARIANT(
38  a.var_no() < solver->variables().size(),
39  "variable number shall be within bounds");
40 
41  switch(solver->variable(a.var_no()).value())
42  {
43  case 0: result=tvt(false); break;
44  case 1: result=tvt(true); break;
45  default: result=tvt(tvt::tv_enumt::TV_UNKNOWN); break;
46  }
47 
48  if(a.sign())
49  result=!result;
50 
51  return result;
52 }
53 
55 {
56  return solver->version();
57 }
58 
60 {
62 
63  // this can only be called once
64  solver->set_variable_number(no_variables());
65 
66  for(clausest::const_iterator it=clauses.begin();
67  it!=clauses.end();
68  it++)
69  solver->add_orig_clause(
70  reinterpret_cast<int*>(&((*it)[0])), it->size());
71 }
72 
74 {
75  // this is *not* incremental
76  PRECONDITION(assumptions.empty());
78 
79  copy_cnf();
80 
81  {
82  std::string msg=
83  std::to_string(solver->num_variables())+" variables, "+
84  std::to_string(solver->clauses().size())+" clauses";
85  log.statistics() << msg << messaget::eom;
86  }
87 
88  SAT_StatusT result=(SAT_StatusT)solver->solve();
89 
90  {
91  std::string msg;
92 
93  switch(result)
94  {
95  case UNSATISFIABLE:
96  msg="SAT checker: instance is UNSATISFIABLE";
97  break;
98 
99  case SATISFIABLE:
100  msg="SAT checker: instance is SATISFIABLE";
101  break;
102 
103  case UNDETERMINED:
104  msg="SAT checker failed: UNDETERMINED";
105  break;
106 
107  case TIME_OUT:
108  msg="SAT checker failed: Time out";
109  break;
110 
111  case MEM_OUT:
112  msg="SAT checker failed: Out of memory";
113  break;
114 
115  case ABORTED:
116  msg="SAT checker failed: ABORTED";
117  break;
118 
119  default:
120  msg="SAT checker failed: unknown result";
121  break;
122  }
123 
124  log.status() << msg << messaget::eom;
125  }
126 
127  if(result==SATISFIABLE)
128  {
129  // see if it is complete
130  for(unsigned i=1; i<solver->variables().size(); i++)
131  INVARIANT(
132  solver->variables()[i].value() == 0 ||
133  solver->variables()[i].value() == 1,
134  "all variables shall have been assigned");
135  }
136 
137  #ifdef DEBUG
138  if(result==SATISFIABLE)
139  {
140  for(unsigned i=2; i<(_no_variables*2); i+=2)
141  cout << "DEBUG L" << i << ":" << get(i) << '\n';
142  }
143  #endif
144 
145  if(result==UNSATISFIABLE)
146  {
147  status=UNSAT;
148  return P_UNSATISFIABLE;
149  }
150 
151  if(result==SATISFIABLE)
152  {
153  status=SAT;
154  return P_SATISFIABLE;
155  }
156 
157  status=ERROR;
158 
159  return P_ERROR;
160 }
161 
163 {
164  unsigned v=a.var_no();
165  bool sign=a.sign();
166  value^=sign;
167  solver->variables()[v].set_value(value);
168 }
169 
171  satcheck_zchaff_baset(new CSolver)
172 {
173 }
174 
176 {
177  delete solver;
178 }
virtual size_t no_variables() const override
Definition: cnf.h:42
size_t _no_variables
Definition: cnf.h:57
bool is_true() const
Definition: literal.h:156
bool sign() const
Definition: literal.h:88
var_not var_no() const
Definition: literal.h:83
bool is_false() const
Definition: literal.h:161
mstreamt & statistics() const
Definition: message.h:419
mstreamt & status() const
Definition: message.h:414
static eomt eom
Definition: message.h:297
resultt
Definition: prop.h:101
messaget log
Definition: prop.h:134
resultt do_prop_solve(const bvt &assumptions) override
std::string solver_text() const override
void set_assignment(literalt a, bool value) override
satcheck_zchaff_baset(CSolver *_solver)
tvt l_get(literalt a) const override
virtual ~satcheck_zchafft()
Definition: threeval.h:20
std::vector< literalt > bvt
Definition: literal.h:201
void solver(std::vector< framet > &frames, const std::unordered_set< symbol_exprt, irep_hash > &address_taken, const solver_optionst &solver_options, const namespacet &ns, std::vector< propertyt > &properties, std::size_t property_index)
Definition: solver.cpp:44
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.