Skip to content

Commit 5e85701

Browse files
Catch Minisat::OutOfMemoryException
1 parent 5bd5962 commit 5e85701

File tree

1 file changed

+62
-25
lines changed

1 file changed

+62
-25
lines changed

src/solvers/sat/satcheck_minisat2.cpp

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,18 @@ template<typename T>
6969
void satcheck_minisat2_baset<T>::set_polarity(literalt a, bool value)
7070
{
7171
assert(!a.is_constant());
72-
add_variables();
73-
solver->setPolarity(a.var_no(), value);
72+
73+
try
74+
{
75+
add_variables();
76+
solver->setPolarity(a.var_no(), value);
77+
}
78+
catch(Minisat::OutOfMemoryException)
79+
{
80+
messaget::error() << "SAT checker ran out of memory" << eom;
81+
status = statust::ERROR;
82+
throw std::bad_alloc();
83+
}
7484
}
7585

7686
const std::string satcheck_minisat_no_simplifiert::solver_text()
@@ -93,26 +103,35 @@ void satcheck_minisat2_baset<T>::add_variables()
93103
template<typename T>
94104
void satcheck_minisat2_baset<T>::lcnf(const bvt &bv)
95105
{
96-
add_variables();
97-
98-
forall_literals(it, bv)
106+
try
99107
{
100-
if(it->is_true())
101-
return;
102-
else if(!it->is_false())
103-
assert(it->var_no()<(unsigned)solver->nVars());
104-
}
108+
add_variables();
109+
110+
forall_literals(it, bv)
111+
{
112+
if(it->is_true())
113+
return;
114+
else if(!it->is_false())
115+
assert(it->var_no() < (unsigned)solver->nVars());
116+
}
105117

106-
Minisat::vec<Minisat::Lit> c;
118+
Minisat::vec<Minisat::Lit> c;
107119

108-
convert(bv, c);
120+
convert(bv, c);
109121

110-
// Note the underscore.
111-
// Add a clause to the solver without making superflous internal copy.
122+
// Note the underscore.
123+
// Add a clause to the solver without making superflous internal copy.
112124

113-
solver->addClause_(c);
125+
solver->addClause_(c);
114126

115-
clause_counter++;
127+
clause_counter++;
128+
}
129+
catch(Minisat::OutOfMemoryException)
130+
{
131+
messaget::error() << "SAT checker ran out of memory" << eom;
132+
status = statust::ERROR;
133+
throw std::bad_alloc();
134+
}
116135
}
117136

118137
#ifndef _WIN32
@@ -243,13 +262,22 @@ void satcheck_minisat2_baset<T>::set_assignment(literalt a, bool value)
243262
{
244263
assert(!a.is_constant());
245264

246-
unsigned v=a.var_no();
247-
bool sign=a.sign();
265+
try
266+
{
267+
unsigned v = a.var_no();
268+
bool sign = a.sign();
248269

249-
// MiniSat2 kills the model in case of UNSAT
250-
solver->model.growTo(v+1);
251-
value^=sign;
252-
solver->model[v]=Minisat::lbool(value);
270+
// MiniSat2 kills the model in case of UNSAT
271+
solver->model.growTo(v + 1);
272+
value ^= sign;
273+
solver->model[v] = Minisat::lbool(value);
274+
}
275+
catch(Minisat::OutOfMemoryException)
276+
{
277+
messaget::error() << "SAT checker ran out of memory" << eom;
278+
status = statust::ERROR;
279+
throw std::bad_alloc();
280+
}
253281
}
254282

255283
template<typename T>
@@ -307,10 +335,19 @@ satcheck_minisat_simplifiert::satcheck_minisat_simplifiert():
307335

308336
void satcheck_minisat_simplifiert::set_frozen(literalt a)
309337
{
310-
if(!a.is_constant())
338+
try
311339
{
312-
add_variables();
313-
solver->setFrozen(a.var_no(), true);
340+
if(!a.is_constant())
341+
{
342+
add_variables();
343+
solver->setFrozen(a.var_no(), true);
344+
}
345+
}
346+
catch(Minisat::OutOfMemoryException)
347+
{
348+
messaget::error() << "SAT checker ran out of memory" << eom;
349+
status = statust::ERROR;
350+
throw std::bad_alloc();
314351
}
315352
}
316353

0 commit comments

Comments
 (0)