/
mainsolver.h
136 lines (102 loc) · 3.36 KB
/
mainsolver.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Copyright (C) 2018, Jianwen Li (lijwen2748@gmail.com), Iowa State University
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
Author: Jianwen Li
Update Date: October 6, 2017
Main Solver in CAR
*/
#ifndef MAIN_SOLVER_H
#define MAIN_SOLVER_H
#include "carsolver.h"
#include "data_structure.h"
#include "model.h"
#include "statistics.h"
#include <vector>
#include <assert.h>
#include <iostream>
namespace car{
class MainSolver : public CARSolver
{
public:
MainSolver (Model*, Statistics* stats, const bool verbose = false);
~MainSolver (){}
//public funcitons
void set_assumption (const Assignment&, const int frame_level, const bool forward);
void set_assumption (const Assignment&, const int);
void set_assumption (const Assignment& st){
assumption_.clear ();
for (auto it = st.begin(); it != st.end(); ++it)
assumption_push (*it);
}
inline bool solve_with_assumption (const Assignment& st, const int p)
{
set_assumption (st, p);
if (verbose_)
std::cout << "MainSolver::";
return solve_assumption ();
}
inline bool solve_with_assumption (const Assignment& st)
{
set_assumption (st);
if (verbose_)
std::cout << "MainSolver::";
return solve_assumption ();
}
inline bool solve_with_assumption ()
{
if (verbose_)
std::cout << "MainSolver::";
return solve_assumption ();
}
Assignment get_state (const bool forward = true, const bool partial = false);
//this version is used for bad check only
Cube get_conflict (const int bad);
Cube get_conflict (const bool forward, const bool minimal, bool& constraint);
void add_new_frame (const Frame& frame, const int frame_level, const bool forward);
//overload
void add_clause_from_cube (const Cube& cu, const int frame_level, const bool forward_);
bool solve_with_assumption_for_temporary (Cube& s, int frame_level, bool forward, Cube& tmp_block);
inline void update_constraint (Cube& cu)
{
CARSolver::add_clause_from_cube (cu);
}
inline void clear_frame_flags () {frame_flags_.clear ();}
inline int new_flag (){
return max_flag_++;
}
inline int init_flag () {return init_flag_;}
inline int dead_flag () {return dead_flag_;}
private:
//members
int max_flag_;
std::vector<int> frame_flags_;
int init_flag_, dead_flag_;
Model* model_;
Statistics* stats_;
//bool verbose_;
//functions
inline int flag_of (const unsigned frame_level)
{
assert (frame_level >= 0);
while (frame_level >= frame_flags_.size ())
{
frame_flags_.push_back (max_flag_++);
}
return frame_flags_[frame_level];
}
void shrink_model (Assignment& model, const bool forward, const bool partial);
void try_reduce (Cube& cu);
};
}
#endif