Skip to content

Commit ac05b97

Browse files
committed
Correcting the CaDiCaL interface when it is called with limits
1 parent 79aac1f commit ac05b97

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

CadicalWrap.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
2626
#include "core/SolverTypes.h"
2727

2828
extern int opt_cpu_lim;
29+
extern void set_interrupted(bool cpu_interrupted);
2930

3031
namespace COMinisatPS {
3132

@@ -38,8 +39,8 @@ class SimpSolver {
3839
volatile static bool timesup;
3940

4041
// Handler interface.
41-
void catch_signal (int ) { }
42-
void catch_alarm () { timesup = true; }
42+
void catch_signal (int ) { set_interrupted(false); }
43+
void catch_alarm () { timesup = true; set_interrupted(true); }
4344
// Terminator interface.
4445
bool terminate() { return timesup; }
4546
} alarm_term;
@@ -84,7 +85,7 @@ class SimpSolver {
8485
CaDiCaL::Signal::alarm(time_limit);
8586
CaDiCaL::Signal::set(&alarm_term);
8687
solver->connect_terminator(&alarm_term);
87-
}
88+
} else CaDiCaL::Signal::alarm(0);
8889
#else
8990
(void)time_limit;
9091
#endif
@@ -145,7 +146,7 @@ class SimpSolver {
145146
void interrupt() { solver->terminate(); }
146147
void clearInterrupt() { }
147148

148-
void setConfBudget(int x) { solver->limit("conflicts", x); }
149+
void setConfBudget(int64_t x) { solver->limit("conflicts", x); }
149150
void budgetOff() { solver->limit("conflicts", -1); }
150151

151152
lbool solveLimited() {

MsSolver.cc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ void SIGINT_interrupt(int signum) {
6464
#endif
6565
}
6666

67+
void set_interrupted(bool cpu_interrupted) {
68+
pb_solver->asynch_interrupt = true;
69+
if (cpu_interrupted) pb_solver->cpu_interrupt = true;
70+
}
71+
6772
extern int verbosity;
6873

6974
static void clear_assumptions(Minisat::vec<Lit>& assump_ps, vec<Int>& assump_Cs)
@@ -115,6 +120,7 @@ static
115120
void core_minimization(SimpSolver &sat_solver, Minisat::vec<Lit> &mus)
116121
{
117122
int last_size = mus.size();
123+
uint64_t totalConflicts = sat_solver.conflicts + 5000;
118124

119125
int verb = sat_solver.verbosity; sat_solver.verbosity = 0;
120126
for (int i = 0; last_size > 1 && i < last_size; ) {
@@ -127,6 +133,7 @@ void core_minimization(SimpSolver &sat_solver, Minisat::vec<Lit> &mus)
127133
for (int j = last_size - 1; j > i; j--) mus[j] = mus[j-1];
128134
mus[i] = p; i++;
129135
} else last_size--;
136+
if (sat_solver.conflicts > totalConflicts) break;
130137
}
131138
sat_solver.budgetOff(); sat_solver.verbosity = verb;
132139

@@ -481,6 +488,7 @@ void MsSolver::maxsat_solve(solve_Command cmd)
481488
if (goal_gcd != 1) {
482489
if (LB_goalvalue != Int_MIN) LB_goalvalue /= Int(goal_gcd);
483490
if (UB_goalvalue != Int_MAX) UB_goalvalue /= Int(goal_gcd);
491+
if (best_goalvalue != Int_MAX) best_goalvalue /= Int(goal_gcd);
484492
}
485493

486494
opt_sort_thres *= opt_goal_bias;
@@ -705,8 +713,8 @@ void MsSolver::maxsat_solve(solve_Command cmd)
705713
sat_conflicts.clear();
706714
if (use_base_assump) for (int i = 0; i < base_assump.size(); i++) assump_ps.push(base_assump[i]);
707715
if (opt_minimization == 1 && opt_to_bin_search && opt_unsat_conflicts >= 100000 &&
708-
sat_solver.conflicts < opt_unsat_conflicts - 500)
709-
sat_solver.setConfBudget(opt_unsat_conflicts - sat_solver.conflicts);
716+
sat_solver.conflicts < opt_unsat_conflicts)
717+
sat_solver.setConfBudget(max(opt_unsat_conflicts - sat_solver.conflicts, uint64_t(500)));
710718
else sat_solver.budgetOff();
711719
status =
712720
base_assump.size() == 1 && base_assump[0] == assump_lit ? l_True :
@@ -729,10 +737,11 @@ void MsSolver::maxsat_solve(solve_Command cmd)
729737
if (ipamir_used && termCallback != nullptr && 0 != termCallback(termCallbackState)) {
730738
asynch_interrupt = true; break;
731739
}
732-
if (!ipamir_used && asynch_interrupt && !cpu_interrupt) {
733-
reportf("*** Interrupted ***\n");
734-
break;
735-
}
740+
if (!ipamir_used && asynch_interrupt)
741+
if (!cpu_interrupt) {
742+
reportf("*** Interrupted ***\n");
743+
break;
744+
} else if (cpuTime() > opt_cpu_lim) break;
736745
#ifdef USE_SCIP
737746
if (scip_solver.must_be_started) {
738747
if (asynch_interrupt && cpu_interrupt) {
@@ -1173,6 +1182,7 @@ void MsSolver::maxsat_solve(solve_Command cmd)
11731182
cpuTime(), sat_solver.conflicts, goal_ps.size(), assump_ps.size());
11741183
}
11751184
opt_minimization = 2;
1185+
opt_core_minimization = false;
11761186
if (assump_ps.size() == 0) opt_reuse_sorters = false;
11771187
if (opt_convert_goal != ct_Undef) opt_convert = opt_convert_goal;
11781188
if (assump_ps.size() == 0 && gbmo_splitting_weights.size() > 0 &&

0 commit comments

Comments
 (0)