78 lines
2.1 KiB
C++
Raw Normal View History

2022-08-30 15:42:35 +08:00
#ifndef _basesolver_hpp_INCLUDED
#define _basesolver_hpp_INCLUDED
#include "../light.hpp"
#include "../utils/vec.hpp"
2022-09-15 10:31:41 +08:00
#include "clause.hpp"
#include <fstream>
#include <iostream>
2023-03-15 14:15:44 +08:00
#include <boost/thread.hpp>
2023-02-28 15:14:04 +08:00
#include <boost/thread/thread.hpp>
#include <boost/lockfree/spsc_queue.hpp>
2023-03-20 21:40:19 +08:00
2022-12-04 23:30:36 +08:00
class sharer;
2022-08-30 15:42:35 +08:00
class basesolver {
public:
2023-02-28 15:14:04 +08:00
virtual void add(int l) = 0;
2022-08-30 15:42:35 +08:00
virtual int solve() = 0;
2023-02-28 15:14:04 +08:00
virtual int val(int l) = 0;
2022-08-30 15:42:35 +08:00
virtual void terminate() = 0;
2023-03-01 22:05:44 +08:00
virtual void configure(const char* name, int id) = 0;
2023-02-28 15:14:04 +08:00
virtual int get_conflicts() = 0;
virtual void parse_from_CNF(char* filename) = 0;
virtual void parse_from_PAR(preprocess* pre) = 0;
virtual void exp_clause(void *cl, int lbd) = 0;
virtual bool imp_clause(clause_store *cls, void *cl) = 0;
2023-03-20 21:40:19 +08:00
void export_clauses_to(vec<clause_store *> &clauses);
void import_clauses_from(vec<clause_store *> &clauses);
void get_model(vec<int> &model);
void select_clauses();
void broaden_export_limit();
void restrict_export_limit();
double get_waiting_time();
int get_period();
void inc_period();
void internal_terminate();
void external_terminate();
double waiting_time = 0;
int good_clause_lbd = 0;
2022-08-30 15:42:35 +08:00
light * controller;
int id;
2022-12-04 23:30:36 +08:00
sharer* in_sharer;
2023-03-15 14:15:44 +08:00
vec<int> model;
2023-03-20 21:40:19 +08:00
int terminate_period = 1e9;
int maxvar, period, margin, terminated = 0;
2023-03-15 14:15:44 +08:00
mutable boost::mutex mtx;
boost::condition_variable cond;
period_queue pq;
vec<clause_store *> cls;
vec<vec<clause_store *>> bucket;
2023-03-20 21:40:19 +08:00
vec<int> unfree;
2022-08-30 15:42:35 +08:00
2023-02-28 15:14:04 +08:00
boost::lockfree::spsc_queue<clause_store*, boost::lockfree::capacity<1024000>> import_clause;
boost::lockfree::spsc_queue<clause_store*, boost::lockfree::capacity<1024000>> export_clause;
2023-03-20 21:40:19 +08:00
basesolver(int sid, light* light) : id(sid), controller(light) {
good_clause_lbd = 2;
period = 0;
margin = 0;
}
2022-08-30 15:42:35 +08:00
~basesolver() {
if (controller) {
controller = NULL;
}
}
2023-03-20 21:40:19 +08:00
friend void cbk_start_new_period(void *);
friend void cbk_free_clauses(void *);
2022-08-30 15:42:35 +08:00
};
2023-03-20 21:40:19 +08:00
void cbk_start_new_period(void *);
void cbk_free_clauses(void *);
2022-08-30 15:42:35 +08:00
#endif