2022-08-30 15:42:35 +08:00
|
|
|
#include "basekissat.hpp"
|
2022-12-04 23:30:36 +08:00
|
|
|
#include "sharer.hpp"
|
|
|
|
#include <thread>
|
|
|
|
#include <condition_variable>
|
2022-08-30 15:42:35 +08:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "src/application.h"
|
|
|
|
#include "src/parse.h"
|
|
|
|
#include "src/internal.h"
|
|
|
|
#include "src/witness.h"
|
|
|
|
#include "src/import.h"
|
|
|
|
}
|
|
|
|
|
2023-02-28 15:14:04 +08:00
|
|
|
void basekissat::add(int l) {
|
|
|
|
kissat_add(solver, l);
|
|
|
|
}
|
|
|
|
|
2023-03-20 21:40:19 +08:00
|
|
|
void basekissat::configure(const char* name, int val) {
|
|
|
|
printf("c %d set %s to %d\n", id, name, val);
|
|
|
|
kissat_set_option(solver, name, val);
|
2023-02-28 15:14:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int basekissat::solve() {
|
|
|
|
return kissat_solve(solver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void basekissat::terminate() {
|
|
|
|
kissat_terminate(solver);
|
|
|
|
}
|
|
|
|
|
|
|
|
int basekissat::val(int l) {
|
|
|
|
int v = abs(l);
|
|
|
|
int tmp = kissat_value(solver, v);
|
|
|
|
if (!tmp) tmp = v;
|
|
|
|
if (l < 0) tmp = -tmp;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void basekissat::exp_clause(void* cl, int lbd) {
|
|
|
|
cvec *c = (cvec *) cl;
|
2022-09-08 13:54:29 +08:00
|
|
|
clause_store* cls = new clause_store(c->sz);
|
|
|
|
for (int i = 0; i < c->sz; i++) {
|
|
|
|
int v = cvec_data(c, i);
|
2023-02-28 15:14:04 +08:00
|
|
|
int eidx = PEEK_STACK(solver->exportk, (v >> 1));
|
2022-09-08 13:54:29 +08:00
|
|
|
cls->data[i] = v & 1 ? -eidx : eidx;
|
|
|
|
}
|
2023-02-28 15:14:04 +08:00
|
|
|
// ++S->x2;
|
2022-09-15 10:31:41 +08:00
|
|
|
// if (S->id == 0) puts("");
|
2022-09-08 13:54:29 +08:00
|
|
|
cls->lbd = lbd;
|
2023-02-28 15:14:04 +08:00
|
|
|
export_clause.push(cls);
|
2022-09-08 13:54:29 +08:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:14:04 +08:00
|
|
|
|
|
|
|
void call_back_out(void *solver, int lbd, cvec *c) {
|
2022-09-08 13:54:29 +08:00
|
|
|
basekissat* S = (basekissat *) solver;
|
2023-02-28 15:14:04 +08:00
|
|
|
if (lbd <= S->good_clause_lbd) {
|
|
|
|
S->exp_clause(c, lbd);
|
|
|
|
}
|
|
|
|
}
|
2022-09-08 13:54:29 +08:00
|
|
|
|
2023-02-28 15:14:04 +08:00
|
|
|
bool basekissat::imp_clause(clause_store *cls, void *cl) {
|
|
|
|
cvec *c = (cvec *) cl;
|
2022-09-08 13:54:29 +08:00
|
|
|
for (int i = 0; i < cls->size; i++) {
|
2022-09-15 10:31:41 +08:00
|
|
|
// S->outimport << cls->data[i] << std::endl;
|
2022-09-08 13:54:29 +08:00
|
|
|
int eidx = abs(cls->data[i]);
|
2023-03-15 14:15:44 +08:00
|
|
|
if (eidx >= SIZE_STACK(solver->import)) printf("c wrong %d\n", eidx);
|
2023-02-28 15:14:04 +08:00
|
|
|
import *import = &PEEK_STACK (solver->import, eidx);
|
|
|
|
if (import->eliminated) return false;
|
2022-09-08 13:54:29 +08:00
|
|
|
else {
|
|
|
|
int ilit = import->lit;
|
|
|
|
if (cls->data[i] < 0) ilit = ilit ^ 1;
|
|
|
|
cvec_push(c, ilit);
|
|
|
|
}
|
|
|
|
}
|
2023-02-28 15:14:04 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int call_back_in(void *solver, int *lbd, cvec *c) {
|
|
|
|
basekissat* S = (basekissat *) solver;
|
|
|
|
clause_store* cls = NULL;
|
|
|
|
if (S->import_clause.pop(cls) == false) return -1;
|
2022-09-08 13:54:29 +08:00
|
|
|
*lbd = cls->lbd;
|
2023-02-28 15:14:04 +08:00
|
|
|
bool res = S->imp_clause(cls, c);
|
2023-03-20 21:40:19 +08:00
|
|
|
if (!S->solver->dps) {
|
2023-03-15 14:15:44 +08:00
|
|
|
cls->free_clause();
|
|
|
|
}
|
2023-02-28 15:14:04 +08:00
|
|
|
if (!res) return -10;
|
2022-09-08 13:54:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-09-15 10:31:41 +08:00
|
|
|
basekissat::basekissat(int id, light* light) : basesolver(id, light) {
|
|
|
|
solver = kissat_init();
|
|
|
|
solver -> issuer = this;
|
2022-12-04 23:30:36 +08:00
|
|
|
solver -> cbkImportClause = NULL;
|
|
|
|
solver -> cbkExportClause = NULL;
|
2023-03-20 21:40:19 +08:00
|
|
|
solver -> cbk_start_new_period = NULL;
|
2022-12-04 23:30:36 +08:00
|
|
|
if (light->opt->share) {
|
2023-03-20 21:40:19 +08:00
|
|
|
solver -> cbkImportClause = call_back_in;
|
|
|
|
solver -> cbkExportClause = call_back_out;
|
|
|
|
solver -> cbk_start_new_period = cbk_start_new_period;
|
|
|
|
solver -> cbk_free_clauses = cbk_free_clauses;
|
|
|
|
solver -> dps = light->opt->DPS;
|
|
|
|
solver -> dps_period = light->opt->DPS_period;
|
2022-12-04 23:30:36 +08:00
|
|
|
}
|
2022-09-15 10:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
basekissat::~basekissat(){
|
|
|
|
delete solver;
|
|
|
|
}
|
|
|
|
|
2023-02-28 15:14:04 +08:00
|
|
|
void basekissat::parse_from_CNF(char* filename) {
|
2023-03-20 21:40:19 +08:00
|
|
|
int vars, clauses;
|
|
|
|
vec<vec<int>> clause;
|
|
|
|
readfile(filename, &vars, &clauses, clause);
|
|
|
|
maxvar = vars;
|
|
|
|
kissat_reserve(solver, vars);
|
|
|
|
for (int i = 1; i <= clauses; i++) {
|
|
|
|
int l = clause[i].size();
|
|
|
|
for (int j = 0; j < l; j++)
|
|
|
|
add(clause[i][j]);
|
|
|
|
add(0);
|
|
|
|
}
|
2022-08-30 15:42:35 +08:00
|
|
|
}
|
|
|
|
|
2023-02-28 15:14:04 +08:00
|
|
|
void basekissat::parse_from_PAR(preprocess* pre) {
|
2023-03-20 21:40:19 +08:00
|
|
|
maxvar = pre->vars;
|
2022-08-30 15:42:35 +08:00
|
|
|
kissat_reserve(solver, pre->vars);
|
|
|
|
for (int i = 1; i <= pre->clauses; i++) {
|
|
|
|
int l = pre->clause[i].size();
|
|
|
|
for (int j = 0; j < l; j++)
|
2023-02-28 15:14:04 +08:00
|
|
|
add(pre->clause[i][j]);
|
|
|
|
add(0);
|
2022-08-30 15:42:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 15:14:04 +08:00
|
|
|
int basekissat::get_conflicts() {
|
|
|
|
return solver->nconflict;
|
|
|
|
}
|
|
|
|
|