-
Notifications
You must be signed in to change notification settings - Fork 0
/
DPLL.h
87 lines (74 loc) · 2.12 KB
/
DPLL.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// DPLL algorithm.
//
#ifndef DPLL_DPLL_H
#define DPLL_DPLL_H
#include "common.h"
#include <stack>
#include <set>
#include <random>
#include <algorithm>
#define DECIDE 0
#define BACKTRACK 1
#define PROPAGATE 2
#define SAT 0
#define CONFLICT 1
#define OTHERS 2
struct choice
{
literal variable;
int category;
choice(literal v, int cat) :variable(v), category(cat) {
}
};
class DPLL {
public:
/**
* Constructor.
*
* @param phi the formula to be checked
* @note Please DON'T CHANGE this signature because the grading script will directly call this function!
*/
DPLL(const formula &phi) : phi(phi), cur_time(0),
remaining_var(phi.num_variable),
roots(phi.num_variable + 1, std::set<int>()),
time_stamp(phi.num_variable + 1, 0),
mp(phi.num_variable + 1, 0),
visited(phi.num_variable + 1, 0)
{
}
/**
* Check if the formula is satisfiable.
*
* @return true if satisfiable, and false if unsatisfiable
* @note Please DON'T CHANGE this signature because the grading script will directly call this function!
*/
bool check_sat();
/**
* Get a satisfying model (interpretation) of the formula, the model must be *complete*, that is,
* it must assign every variable a truth value.
* This function will be called if and only if `check_sat()` returns true.
*
* @return an arbitrary (if there exist many) satisfying model
* @note Please DON'T CHANGE this signature because the grading script will directly call this function!
*/
model get_model();
bool check_sat_noncdcl();
literal propagate();
literal propagate_noncdcl();
bool try_backtrack();
bool try_backjump();
void make_decision(std::default_random_engine& random, std::bernoulli_distribution& d);
void make_decision_noncdcl(std::default_random_engine& random, std::bernoulli_distribution& d);
void traverse_clauses();
private:
formula phi;
int remaining_var;
std::stack<choice> st;
std::stack<int> decision_st;
std::vector<int> mp, visited;
std::vector<std::set<int>> roots;
unsigned long long cur_time;
std::vector<unsigned long long> time_stamp;
};
#endif //DPLL_DPLL_H