12
12
#include < inttypes.h>
13
13
#endif
14
14
15
- #include < cassert>
16
15
#include < stack>
17
16
17
+ #include < util/invariant.h>
18
18
#include < util/threeval.h>
19
19
20
20
#include < core/Solver.h>
@@ -64,9 +64,19 @@ tvt satcheck_glucose_baset<T>::l_get(literalt a) const
64
64
template <typename T>
65
65
void satcheck_glucose_baset<T>::set_polarity(literalt a, bool value)
66
66
{
67
- assert (!a.is_constant ());
68
- add_variables ();
69
- solver->setPolarity (a.var_no (), value);
67
+ PRECONDITION (!a.is_constant ());
68
+
69
+ try
70
+ {
71
+ add_variables ();
72
+ solver->setPolarity (a.var_no (), value);
73
+ }
74
+ catch (Glucose::OutOfMemoryException)
75
+ {
76
+ messaget::error () << " SAT checker ran out of memory" << eom;
77
+ status = statust::ERROR;
78
+ throw std::bad_alloc ();
79
+ }
70
80
}
71
81
72
82
const std::string satcheck_glucose_no_simplifiert::solver_text ()
@@ -89,32 +99,42 @@ void satcheck_glucose_baset<T>::add_variables()
89
99
template <typename T>
90
100
void satcheck_glucose_baset<T>::lcnf(const bvt &bv)
91
101
{
92
- add_variables ();
93
-
94
- forall_literals (it, bv)
102
+ try
95
103
{
96
- if (it->is_true ())
97
- return ;
98
- else if (!it->is_false ())
99
- assert (it->var_no ()<(unsigned )solver->nVars ());
100
- }
104
+ add_variables ();
101
105
102
- Glucose::vec<Glucose::Lit> c;
106
+ forall_literals (it, bv)
107
+ {
108
+ if (it->is_true ())
109
+ return ;
110
+ else if (!it->is_false ())
111
+ INVARIANT (
112
+ it->var_no () < (unsigned )solver->nVars (), " variable not added yet" );
113
+ }
114
+
115
+ Glucose::vec<Glucose::Lit> c;
103
116
104
- convert (bv, c);
117
+ convert (bv, c);
105
118
106
- // Note the underscore.
107
- // Add a clause to the solver without making superflous internal copy.
119
+ // Note the underscore.
120
+ // Add a clause to the solver without making superflous internal copy.
108
121
109
- solver->addClause_ (c);
122
+ solver->addClause_ (c);
110
123
111
- clause_counter++;
124
+ clause_counter++;
125
+ }
126
+ catch (Glucose::OutOfMemoryException)
127
+ {
128
+ messaget::error () << " SAT checker ran out of memory" << eom;
129
+ status = statust::ERROR;
130
+ throw std::bad_alloc ();
131
+ }
112
132
}
113
133
114
134
template <typename T>
115
135
propt::resultt satcheck_glucose_baset<T>::prop_solve()
116
136
{
117
- assert (status!= statust::ERROR);
137
+ PRECONDITION (status != statust::ERROR);
118
138
119
139
// We start counting at 1, thus there is one variable fewer.
120
140
{
@@ -123,63 +143,79 @@ propt::resultt satcheck_glucose_baset<T>::prop_solve()
123
143
solver->nClauses () << " clauses" << eom;
124
144
}
125
145
126
- add_variables ();
127
-
128
- if (!solver->okay ())
146
+ try
129
147
{
130
- messaget::status () <<
131
- " SAT checker inconsistent: instance is UNSATISFIABLE" << eom;
132
- }
133
- else
134
- {
135
- // if assumptions contains false, we need this to be UNSAT
136
- bool has_false=false ;
137
-
138
- forall_literals (it, assumptions)
139
- if (it->is_false ())
140
- has_false=true ;
148
+ add_variables ();
141
149
142
- if (has_false )
150
+ if (!solver-> okay () )
143
151
{
144
- messaget::status () <<
145
- " got FALSE as assumption : instance is UNSATISFIABLE" << eom;
152
+ messaget::status ()
153
+ << " SAT checker inconsistent : instance is UNSATISFIABLE" << eom;
146
154
}
147
155
else
148
156
{
149
- Glucose::vec<Glucose::Lit> solver_assumptions;
150
- convert (assumptions, solver_assumptions);
157
+ // if assumptions contains false, we need this to be UNSAT
158
+ bool has_false = false ;
159
+
160
+ forall_literals (it, assumptions)
161
+ if (it->is_false ())
162
+ has_false = true ;
151
163
152
- if (solver-> solve (solver_assumptions) )
164
+ if (has_false )
153
165
{
154
- messaget::status () <<
155
- " SAT checker: instance is SATISFIABLE" << eom;
156
- status=statust::SAT;
157
- return resultt::P_SATISFIABLE;
166
+ messaget::status ()
167
+ << " got FALSE as assumption: instance is UNSATISFIABLE" << eom;
158
168
}
159
169
else
160
170
{
161
- messaget::status () <<
162
- " SAT checker: instance is UNSATISFIABLE" << eom;
171
+ Glucose::vec<Glucose::Lit> solver_assumptions;
172
+ convert (assumptions, solver_assumptions);
173
+
174
+ if (solver->solve (solver_assumptions))
175
+ {
176
+ messaget::status () << " SAT checker: instance is SATISFIABLE" << eom;
177
+ status = statust::SAT;
178
+ return resultt::P_SATISFIABLE;
179
+ }
180
+ else
181
+ {
182
+ messaget::status () << " SAT checker: instance is UNSATISFIABLE" << eom;
183
+ }
163
184
}
164
185
}
165
- }
166
186
167
- status=statust::UNSAT;
168
- return resultt::P_UNSATISFIABLE;
187
+ status = statust::UNSAT;
188
+ return resultt::P_UNSATISFIABLE;
189
+ }
190
+ catch (Glucose::OutOfMemoryException)
191
+ {
192
+ messaget::error () << " SAT checker ran out of memory" << eom;
193
+ status = statust::ERROR;
194
+ throw std::bad_alloc ();
195
+ }
169
196
}
170
197
171
198
template <typename T>
172
199
void satcheck_glucose_baset<T>::set_assignment(literalt a, bool value)
173
200
{
174
- assert (!a.is_constant ());
201
+ PRECONDITION (!a.is_constant ());
175
202
176
- unsigned v=a.var_no ();
177
- bool sign=a.sign ();
203
+ try
204
+ {
205
+ unsigned v = a.var_no ();
206
+ bool sign = a.sign ();
178
207
179
- // MiniSat2 kills the model in case of UNSAT
180
- solver->model .growTo (v+1 );
181
- value^=sign;
182
- solver->model [v]=Glucose::lbool (value);
208
+ // MiniSat2 kills the model in case of UNSAT
209
+ solver->model .growTo (v + 1 );
210
+ value ^= sign;
211
+ solver->model [v] = Glucose::lbool (value);
212
+ }
213
+ catch (Glucose::OutOfMemoryException)
214
+ {
215
+ messaget::error () << " SAT checker ran out of memory" << eom;
216
+ status = statust::ERROR;
217
+ throw std::bad_alloc ();
218
+ }
183
219
}
184
220
185
221
template <typename T>
@@ -218,7 +254,7 @@ void satcheck_glucose_baset<T>::set_assumptions(const bvt &bv)
218
254
assumptions=bv;
219
255
220
256
forall_literals (it, assumptions)
221
- assert (!it->is_constant ());
257
+ INVARIANT (!it->is_constant (), " assumption literals must not be constant " );
222
258
}
223
259
224
260
satcheck_glucose_no_simplifiert::satcheck_glucose_no_simplifiert ():
@@ -233,16 +269,25 @@ satcheck_glucose_simplifiert::satcheck_glucose_simplifiert():
233
269
234
270
void satcheck_glucose_simplifiert::set_frozen (literalt a)
235
271
{
236
- if (!a. is_constant ())
272
+ try
237
273
{
238
- add_variables ();
239
- solver->setFrozen (a.var_no (), true );
274
+ if (!a.is_constant ())
275
+ {
276
+ add_variables ();
277
+ solver->setFrozen (a.var_no (), true );
278
+ }
279
+ }
280
+ catch (Glucose::OutOfMemoryException)
281
+ {
282
+ messaget::error () << " SAT checker ran out of memory" << eom;
283
+ status = statust::ERROR;
284
+ throw std::bad_alloc ();
240
285
}
241
286
}
242
287
243
288
bool satcheck_glucose_simplifiert::is_eliminated (literalt a) const
244
289
{
245
- assert (!a.is_constant ());
290
+ PRECONDITION (!a.is_constant ());
246
291
247
292
return solver->isEliminated (a.var_no ());
248
293
}
0 commit comments