@@ -65,8 +65,18 @@ template<typename T>
65
65
void satcheck_glucose_baset<T>::set_polarity(literalt a, bool value)
66
66
{
67
67
assert (!a.is_constant ());
68
- add_variables ();
69
- solver->setPolarity (a.var_no (), value);
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,26 +99,35 @@ 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
+ assert (it->var_no () < (unsigned )solver->nVars ());
112
+ }
113
+
114
+ Glucose::vec<Glucose::Lit> c;
103
115
104
- convert (bv, c);
116
+ convert (bv, c);
105
117
106
- // Note the underscore.
107
- // Add a clause to the solver without making superflous internal copy.
118
+ // Note the underscore.
119
+ // Add a clause to the solver without making superflous internal copy.
108
120
109
- solver->addClause_ (c);
121
+ solver->addClause_ (c);
110
122
111
- clause_counter++;
123
+ clause_counter++;
124
+ }
125
+ catch (Glucose::OutOfMemoryException)
126
+ {
127
+ messaget::error () << " SAT checker ran out of memory" << eom;
128
+ status = statust::ERROR;
129
+ throw std::bad_alloc ();
130
+ }
112
131
}
113
132
114
133
template <typename T>
@@ -123,63 +142,79 @@ propt::resultt satcheck_glucose_baset<T>::prop_solve()
123
142
solver->nClauses () << " clauses" << eom;
124
143
}
125
144
126
- add_variables ();
127
-
128
- if (!solver->okay ())
145
+ try
129
146
{
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 ;
147
+ add_variables ();
141
148
142
- if (has_false )
149
+ if (!solver-> okay () )
143
150
{
144
- messaget::status () <<
145
- " got FALSE as assumption : instance is UNSATISFIABLE" << eom;
151
+ messaget::status ()
152
+ << " SAT checker inconsistent : instance is UNSATISFIABLE" << eom;
146
153
}
147
154
else
148
155
{
149
- Glucose::vec<Glucose::Lit> solver_assumptions;
150
- convert (assumptions, solver_assumptions);
156
+ // if assumptions contains false, we need this to be UNSAT
157
+ bool has_false = false ;
158
+
159
+ forall_literals (it, assumptions)
160
+ if (it->is_false ())
161
+ has_false = true ;
151
162
152
- if (solver-> solve (solver_assumptions) )
163
+ if (has_false )
153
164
{
154
- messaget::status () <<
155
- " SAT checker: instance is SATISFIABLE" << eom;
156
- status=statust::SAT;
157
- return resultt::P_SATISFIABLE;
165
+ messaget::status ()
166
+ << " got FALSE as assumption: instance is UNSATISFIABLE" << eom;
158
167
}
159
168
else
160
169
{
161
- messaget::status () <<
162
- " SAT checker: instance is UNSATISFIABLE" << eom;
170
+ Glucose::vec<Glucose::Lit> solver_assumptions;
171
+ convert (assumptions, solver_assumptions);
172
+
173
+ if (solver->solve (solver_assumptions))
174
+ {
175
+ messaget::status () << " SAT checker: instance is SATISFIABLE" << eom;
176
+ status = statust::SAT;
177
+ return resultt::P_SATISFIABLE;
178
+ }
179
+ else
180
+ {
181
+ messaget::status () << " SAT checker: instance is UNSATISFIABLE" << eom;
182
+ }
163
183
}
164
184
}
165
- }
166
185
167
- status=statust::UNSAT;
168
- return resultt::P_UNSATISFIABLE;
186
+ status = statust::UNSAT;
187
+ return resultt::P_UNSATISFIABLE;
188
+ }
189
+ catch (Glucose::OutOfMemoryException)
190
+ {
191
+ messaget::error () << " SAT checker ran out of memory" << eom;
192
+ status = statust::ERROR;
193
+ throw std::bad_alloc ();
194
+ }
169
195
}
170
196
171
197
template <typename T>
172
198
void satcheck_glucose_baset<T>::set_assignment(literalt a, bool value)
173
199
{
174
200
assert (!a.is_constant ());
175
201
176
- unsigned v=a.var_no ();
177
- bool sign=a.sign ();
202
+ try
203
+ {
204
+ unsigned v = a.var_no ();
205
+ bool sign = a.sign ();
178
206
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);
207
+ // MiniSat2 kills the model in case of UNSAT
208
+ solver->model .growTo (v + 1 );
209
+ value ^= sign;
210
+ solver->model [v] = Glucose::lbool (value);
211
+ }
212
+ catch (Glucose::OutOfMemoryException)
213
+ {
214
+ messaget::error () << " SAT checker ran out of memory" << eom;
215
+ status = statust::ERROR;
216
+ throw std::bad_alloc ();
217
+ }
183
218
}
184
219
185
220
template <typename T>
@@ -233,10 +268,19 @@ satcheck_glucose_simplifiert::satcheck_glucose_simplifiert():
233
268
234
269
void satcheck_glucose_simplifiert::set_frozen (literalt a)
235
270
{
236
- if (!a. is_constant ())
271
+ try
237
272
{
238
- add_variables ();
239
- solver->setFrozen (a.var_no (), true );
273
+ if (!a.is_constant ())
274
+ {
275
+ add_variables ();
276
+ solver->setFrozen (a.var_no (), true );
277
+ }
278
+ }
279
+ catch (Glucose::OutOfMemoryException)
280
+ {
281
+ messaget::error () << " SAT checker ran out of memory" << eom;
282
+ status = statust::ERROR;
283
+ throw std::bad_alloc ();
240
284
}
241
285
}
242
286
0 commit comments