cloud-sat/workers/basesolver.hpp

61 lines
1.9 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>
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;
2023-03-15 14:15:44 +08:00
virtual void dps_terminate() = 0;
2023-02-28 15:14:04 +08:00
virtual void parse_from_CNF(char* filename) = 0;
virtual void parse_from_PAR(preprocess* pre) = 0;
2022-08-30 15:42:35 +08:00
virtual void get_model(vec<int> &model) = 0;
2023-02-28 15:14:04 +08:00
virtual void exp_clause(void *cl, int lbd) = 0;
virtual bool imp_clause(clause_store *cls, void *cl) = 0;
2022-09-08 13:54:29 +08:00
virtual void export_clauses_to(vec<clause_store *> &clauses) = 0;
virtual void import_clauses_from(vec<clause_store *> &clauses) = 0;
2022-09-15 10:31:41 +08:00
virtual void broaden_export_limit() = 0;
virtual void restrict_export_limit() = 0;
2023-03-01 22:05:44 +08:00
virtual double get_waiting_time() = 0;
2023-03-15 14:15:44 +08:00
virtual void select_clauses() = 0;
virtual int get_period() = 0;
virtual void inc_period() = 0;
virtual void set_winner_period() = 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;
int winner_period = 1e9;
int period, margin, terminated = 0;
mutable boost::mutex mtx;
boost::condition_variable cond;
period_queue pq;
vec<clause_store *> cls;
vec<vec<clause_store *>> bucket;
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;
2022-08-30 15:42:35 +08:00
basesolver(int sid, light* light) : id(sid), controller(light) {}
~basesolver() {
if (controller) {
controller = NULL;
}
}
};
#endif