CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
satcheck_zchaff.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: 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{
18 solver->set_randomness(0);
19 solver->set_variable_number(0);
20}
21
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
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";
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 {
148 return P_UNSATISFIABLE;
149 }
150
151 if(result==SATISFIABLE)
152 {
153 status=SAT;
154 return P_SATISFIABLE;
155 }
156
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
174
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
virtual size_t no_variables() const override
Definition cnf.h:42
size_t _no_variables
Definition cnf.h:57
mstreamt & statistics() const
Definition message.h:411
static eomt eom
Definition message.h:289
mstreamt & status() const
Definition message.h:406
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
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
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423