-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcominisatps.patch
347 lines (312 loc) · 14.8 KB
/
cominisatps.patch
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
Tylko w cominisatps/core: depend.mk
diff -urB -x '.*' -x '*~' -x '*.a' -x '*config.mk' -x '*minisat' cominisatps-SAT2016/core/Solver.cc cominisatps/core/Solver.cc
--- cominisatps-SAT2016/core/Solver.cc 2016-05-02 03:22:00.000000000 +0200
+++ cominisatps/core/Solver.cc 2019-08-29 13:59:50.587248722 +0200
@@ -150,6 +150,7 @@
trail .capacity(v+1);
setDecisionVar(v, dvar);
+ assump.push(false);
// Additional space needed for stamping.
// TODO: allocate exact memory.
seen .push(0);
@@ -550,16 +551,20 @@
| Specialized analysis procedure to express the final conflict in terms of assumptions.
| Calculates the (possibly empty) set of assumptions that led to the assignment of 'p', and
| stores the result in 'out_conflict'.
+|
+| void Solver::analyzeFinal(Lit p, vec<Lit>& out_conflict)
|________________________________________________________________________________________________@*/
-void Solver::analyzeFinal(Lit p, vec<Lit>& out_conflict)
+void Solver::analyzeFinal(CRef confl, vec<Lit>& out_conflict)
{
out_conflict.clear();
- out_conflict.push(p);
if (decisionLevel() == 0)
return;
- seen[var(p)] = 1;
+ Clause& cl = ca[confl];
+ for (int j = 0; j < cl.size(); j++)
+ if (level(var(cl[j])) > 0)
+ seen[var(cl[j])] = 1;
for (int i = trail.size()-1; i >= trail_lim[0]; i--){
Var x = var(trail[i]);
@@ -577,7 +582,9 @@
}
}
- seen[var(p)] = 0;
+ for (int j = cl.size() == 2 ? 0 : 1; j < cl.size(); j++)
+ if (level(var(cl[j])) > 0)
+ seen[var(cl[j])] = 0;
}
@@ -589,6 +596,55 @@
trail.push_(p);
}
+//=================================================================================================
+// Propagate and check:
+bool Solver::prop_check(const vec<Lit>& assumps, vec<Lit>& prop, int psaving)
+{
+ prop.clear();
+
+ if (!ok)
+ return false;
+
+ bool st = true;
+ int level = decisionLevel();
+ CRef confl = CRef_Undef;
+
+ // dealing with phase saving
+ int psaving_copy = phase_saving;
+ phase_saving = psaving;
+
+ // propagate each assumption at a new decision level
+ for (int i = 0; st && confl == CRef_Undef && i < assumps.size(); ++i) {
+ Lit p = assumps[i];
+
+ if (value(p) == l_False)
+ st = false;
+ else if (value(p) != l_True) {
+ newDecisionLevel ();
+ uncheckedEnqueue(p);
+ confl = propagate();
+ }
+ }
+
+ // copying the result
+ if (decisionLevel() > level) {
+ for (int c = trail_lim[level]; c < trail.size(); ++c)
+ prop.push(trail[c]);
+
+ // if there is a conflict, pushing
+ // the conflicting literal as well
+ if (confl != CRef_Undef)
+ prop.push(ca[confl][0]);
+
+ // backtracking
+ cancelUntil(level);
+ }
+
+ // restoring phase saving
+ phase_saving = psaving_copy;
+
+ return st && confl == CRef_Undef;
+}
/*_________________________________________________________________________________________________
|
@@ -650,12 +706,22 @@
*j++ = w; continue; }
// Look for new watch:
+ int choosenPos = -1;
for (int k = 2; k < c.size(); k++)
if (value(c[k]) != l_False){
- c[1] = c[k]; c[k] = false_lit;
- watches[~c[1]].push(w);
- goto NextClause; }
-
+ choosenPos = k;
+ if(decisionLevel()>assumptions.size() || value(c[k])==l_True || !assump[var(c[k])])
+ break; }
+ if(choosenPos!=-1) {
+ c[1] = c[choosenPos]; c[choosenPos] = false_lit;
+ watches[~c[1]].push(w);
+ goto NextClause; }
+ /* for (int k = 2; k < c.size(); k++)
+ if (value(c[k]) != l_False){
+ c[1] = c[k]; c[k] = false_lit;
+ watches[~c[1]].push(w);
+ goto NextClause; }
+*/
// Did not find watch -- clause is unit under assignment:
*j++ = w;
if (value(first) == l_False){
@@ -789,7 +854,8 @@
ok = stampAll(true);
checkGarbage();
- rebuildOrderHeap();
+ if ((int)dec_vars - nAssigns() < (glucose_restart ? order_heap_glue_r : order_heap_no_r).size() / 2) // M. Piotrow 20.07.2017
+ rebuildOrderHeap();
simpDB_assigns = nAssigns();
simpDB_props = clauses_literals + learnts_literals; // (shouldn't depend on stats really, but it will do for now)
@@ -933,6 +999,7 @@
conflicts++; nof_conflicts--;
if (conflicts == 100000 && learnts_core.size() < 100) core_lbd_cut = 5;
if (decisionLevel() == 0) return l_False;
+ if (decisionLevel() == 1) { analyzeFinal(confl, conflict); return l_False; }
learnt_clause.clear();
analyze(confl, learnt_clause, backtrack_level, lbd);
@@ -998,7 +1065,7 @@
restart = lbd_queue.full() && (lbd_queue.avg() * K > global_lbd_sum / conflicts_glue);
cached = true;
}
- if (restart /*|| !withinBudget()*/){
+ if (restart || !withinBudget()){
lbd_queue.clear();
// Reached bound on number of conflicts:
progress_estimate = progressEstimate();
@@ -1017,22 +1084,18 @@
reduceDB(); }
Lit next = lit_Undef;
- /*while (decisionLevel() < assumptions.size()){
- // Perform user provided assumption:
- Lit p = assumptions[decisionLevel()];
- if (value(p) == l_True){
- // Dummy decision level:
- newDecisionLevel();
- }else if (value(p) == l_False){
- analyzeFinal(~p, conflict);
- return l_False;
- }else{
- next = p;
- break;
+
+ if (decisionLevel() == 0) {
+ newDecisionLevel();
+ for (int i = 0; i < assumptions.size(); i++) {
+ Lit p = assumptions[i];
+ if (value(p) == l_False) { conflict.push(~p); return l_False; }
+ else if (value(p) != l_True) uncheckedEnqueue(p);
}
+ continue;
}
- if (next == lit_Undef)*/{
+ if (next == lit_Undef){
// New variable decision:
decisions++;
next = pickBranchLit();
@@ -1101,25 +1164,23 @@
solves++;
+ for (int i = 0; i <assumptions.size(); i++)
+ assump[var(assumptions[i])] = true;
+
max_learnts = nClauses() * learntsize_factor;
learntsize_adjust_confl = learntsize_adjust_start_confl;
learntsize_adjust_cnt = (int)learntsize_adjust_confl;
lbool status = l_Undef;
- if (verbosity >= 1){
- printf("c ============================[ Search Statistics ]==============================\n");
- printf("c | Conflicts | ORIGINAL | LEARNT | Progress |\n");
- printf("c | | Vars Clauses Literals | Limit Clauses Lit/Cl | |\n");
- printf("c ===============================================================================\n");
- }
+ if (verbosity >= 1)
+ printf("c ======================[ COMiniSatPS search starting ]========================\n");
add_tmp.clear();
-
glucose_restart = true;
int init = 10000;
- while (status == l_Undef && init > 0 /*&& withinBudget()*/)
+ while (status == l_Undef && init > 0 && withinBudget())
status = search(init);
- glucose_restart = false;
+ if (status == l_Undef && withinBudget()) glucose_restart = false;
// Search:
int phase_allotment = 100;
@@ -1127,9 +1188,9 @@
int weighted = glucose_restart ? phase_allotment * 2 : phase_allotment;
fflush(stdout);
- while (status == l_Undef && weighted > 0 /*&& withinBudget()*/)
+ while (status == l_Undef && weighted > 0 && withinBudget())
status = search(weighted);
- if (status != l_Undef /*|| !withinBudget()*/)
+ if (status != l_Undef || !withinBudget())
break; // Should break here for correctness in incremental SAT solving.
glucose_restart = !glucose_restart;
@@ -1137,9 +1198,6 @@
phase_allotment += phase_allotment / 10;
}
- if (verbosity >= 1)
- printf("c ===============================================================================\n");
-
#ifdef BIN_DRUP
if (drup_file && status == l_False) binDRUP_flush(drup_file);
#endif
diff -urB -x '.*' -x '*~' -x '*.a' -x '*config.mk' -x '*minisat' cominisatps-SAT2016/core/Solver.h cominisatps/core/Solver.h
--- cominisatps-SAT2016/core/Solver.h 2016-05-02 03:22:00.000000000 +0200
+++ cominisatps/core/Solver.h 2019-08-29 13:54:42.703051832 +0200
@@ -108,6 +108,7 @@
bool solve (Lit p, Lit q); // Search for a model that respects two assumptions.
bool solve (Lit p, Lit q, Lit r); // Search for a model that respects three assumptions.
bool okay () const; // FALSE means solver is in a conflicting state
+ bool prop_check (const vec<Lit>& assumps, vec<Lit>& prop, int psaving = 0); // compute a list of propagated literals given a set of assumptions
void toDimacs (FILE* f, const vec<Lit>& assumps); // Write CNF to file in DIMACS-format.
void toDimacs (const char *file, const vec<Lit>& assumps);
@@ -228,6 +229,7 @@
OccLists<Lit, vec<Watcher>, WatcherDeleted>
watches_bin, // Watches for binary clauses only.
watches; // 'watches[lit]' is a list of constraints watching 'lit' (will go there if literal becomes true).
+ vec<bool> assump; // Declares if a variable is an assumption variable or not.
vec<lbool> assigns; // The current assignments.
vec<char> polarity; // The preferred polarity of each variable.
vec<char> decision; // Declares if a variable is eligible for selection in the decision heuristic.
@@ -284,7 +286,7 @@
CRef propagate (); // Perform unit propagation. Returns possibly conflicting clause.
void cancelUntil (int level); // Backtrack until a certain level.
void analyze (CRef confl, vec<Lit>& out_learnt, int& out_btlevel, int& out_lbd); // (bt = backtrack)
- void analyzeFinal (Lit p, vec<Lit>& out_conflict); // COULD THIS BE IMPLEMENTED BY THE ORDINARIY "analyze" BY SOME REASONABLE GENERALIZATION?
+ void analyzeFinal(CRef confl, vec<Lit>& out_conflict);
bool litRedundant (Lit p, uint32_t abstract_levels); // (helper method for 'analyze()')
lbool search (int& nof_conflicts); // Search for a given number of conflicts.
lbool solve_ (); // Main solve method (assumptions given in 'assumptions').
diff -urB -x '.*' -x '*~' -x '*.a' -x '*config.mk' -x '*minisat' cominisatps-SAT2016/mtl/template.mk cominisatps/mtl/template.mk
--- cominisatps-SAT2016/mtl/template.mk 2016-05-02 03:22:00.000000000 +0200
+++ cominisatps/mtl/template.mk 2019-05-16 08:14:06.794323553 +0200
@@ -44,7 +44,7 @@
%.o: CFLAGS +=$(COPTIMIZE) -g -D DEBUG
%.op: CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG
%.od: CFLAGS +=-O0 -g -D DEBUG
-%.or: CFLAGS +=$(COPTIMIZE) -g -D NDEBUG
+%.or: CFLAGS +=$(COPTIMIZE) -D NDEBUG
## Link options
$(EXEC): LFLAGS += -g
Tylko w cominisatps/simp: depend.mk
diff -urB -x '.*' -x '*~' -x '*.a' -x '*config.mk' -x '*minisat' cominisatps-SAT2016/simp/SimpSolver.cc cominisatps/simp/SimpSolver.cc
--- cominisatps-SAT2016/simp/SimpSolver.cc 2016-05-02 03:22:00.000000000 +0200
+++ cominisatps/simp/SimpSolver.cc 2019-08-22 15:35:41.645730910 +0200
@@ -636,6 +636,7 @@
int iter = 0;
int n_cls, n_cls_init, n_vars;
+ printf("c Using COMiniSatPS SAT solver by Chanseok Oh (2016)\n");
if (nVars() == 0) goto cleanup; // User disabling preprocessing.
// Get an initial number of clauses (more accurately).
@@ -648,10 +649,10 @@
n_cls = nClauses();
n_vars = nFreeVars();
- printf("c Reduced to %d vars, %d cls (grow=%d)\n", n_vars, n_cls, grow);
+ if (verbosity >= 1) printf("c COMiniSatPS: Reduced to %d vars, %d cls (grow=%d)\n", n_vars, n_cls, grow);
if ((double)n_cls / n_vars >= 10 || n_vars < 10000){
- printf("c No iterative elimination performed. (vars=%d, c/v ratio=%.1f)\n", n_vars, (double)n_cls / n_vars);
+ if (verbosity >= 1) printf("c COMiniSatPS: No iterative elimination performed. (vars=%d, c/v ratio=%.1f)\n", n_vars, (double)n_cls / n_vars);
goto cleanup; }
grow = grow ? grow * 2 : 8;
@@ -678,12 +679,12 @@
double cl_inc_rate = (double)n_cls_now / n_cls_last;
double var_dec_rate = (double)n_vars_last / n_vars_now;
- printf("c Reduced to %d vars, %d cls (grow=%d)\n", n_vars_now, n_cls_now, grow);
- printf("c cl_inc_rate=%.3f, var_dec_rate=%.3f\n", cl_inc_rate, var_dec_rate);
+ if (verbosity >= 1) printf("c COMiniSatPS: Reduced to %d vars, %d cls (grow=%d)\n", n_vars_now, n_cls_now, grow);
+ if (verbosity >= 1) printf("c COMiniSatPS: cl_inc_rate=%.3f, var_dec_rate=%.3f\n", cl_inc_rate, var_dec_rate);
if (n_cls_now > n_cls_init || cl_inc_rate > var_dec_rate) break;
}
- printf("c No. effective iterative eliminations: %d\n", iter);
+ if (verbosity >= 1) printf("c COMiniSatPS: No. effective iterative eliminations: %d\n", iter);
cleanup:
touched .clear(true);
diff -urB -x '.*' -x '*~' -x '*.a' -x '*config.mk' -x '*minisat' cominisatps-SAT2016/utils/Options.h cominisatps/utils/Options.h
--- cominisatps-SAT2016/utils/Options.h 2016-05-02 03:22:00.000000000 +0200
+++ cominisatps/utils/Options.h 2019-01-14 16:42:05.047516560 +0100
@@ -282,15 +282,15 @@
if (range.begin == INT64_MIN)
fprintf(stderr, "imin");
else
- fprintf(stderr, "%4"PRIi64, range.begin);
+ fprintf(stderr, "%4" PRIi64, range.begin);
fprintf(stderr, " .. ");
if (range.end == INT64_MAX)
fprintf(stderr, "imax");
else
- fprintf(stderr, "%4"PRIi64, range.end);
+ fprintf(stderr, "%4" PRIi64, range.end);
- fprintf(stderr, "] (default: %"PRIi64")\n", value);
+ fprintf(stderr, "] (default: %" PRIi64")\n", value);
if (verbose){
fprintf(stderr, "\n %s\n", description);
fprintf(stderr, "\n");