ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_rephase.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
9/*------------------------------------------------------------------------*/
10
11// We experimented with resetting and reinitializing the saved phase with
12// many solvers. Actually RSAT had already such a scheme. Our newest
13// version seems to be quite beneficial for satisfiable instances. In an
14// arithmetic increasing interval in the number of conflicts we either use
15// the original phase (set by the option 'phase'), its inverted value, flip
16// the current phase, pick random phases, then pick the best since the last
17// time a best phase was picked and finally also use local search to find
18// phases which minimize the number of falsified clauses. During
19// stabilization (see 'stabilizing' in 'restart.cpp' when 'stable' is true)
20// we execute a different rephasing schedule. The same applies if local
21// search is disabled.
22
23/*------------------------------------------------------------------------*/
24
26 if (!opts.rephase)
27 return false;
28 if (opts.forcephase)
29 return false;
30 return stats.conflicts > lim.rephase;
31}
32
33/*------------------------------------------------------------------------*/
34
35// Pick the original default phase.
36
38 stats.rephased.original++;
39 signed char val = opts.phase ? 1 : -1; // original = initial
40 PHASE ("rephase", stats.rephased.total, "switching to original phase %d",
41 val);
42 for (auto idx : vars)
43 phases.saved[idx] = val;
44 return 'O';
45}
46
47// Pick the inverted original default phase.
48
50 stats.rephased.inverted++;
51 signed char val = opts.phase ? -1 : 1; // original = -initial
52 PHASE ("rephase", stats.rephased.total,
53 "switching to inverted original phase %d", val);
54 for (auto idx : vars)
55 phases.saved[idx] = val;
56 return 'I';
57}
58
59// Flip the current phase.
60
62 stats.rephased.flipped++;
63 PHASE ("rephase", stats.rephased.total,
64 "flipping all phases individually");
65 for (auto idx : vars)
66 phases.saved[idx] *= -1;
67 return 'F';
68}
69
70// Complete random picking of phases.
71
73 stats.rephased.random++;
74 PHASE ("rephase", stats.rephased.total, "resetting all phases randomly");
75 Random random (opts.seed); // global seed
76 random += stats.rephased.random; // different every time
77 for (auto idx : vars)
78 phases.saved[idx] = random.generate_bool () ? -1 : 1;
79 return '#';
80}
81
82// Best phases are those saved at the largest trail height without conflict.
83// See code and comments in 'update_target_and_best' in 'backtrack.cpp'
84
86 stats.rephased.best++;
87 PHASE ("rephase", stats.rephased.total,
88 "overwriting saved phases by best phases");
89 signed char val;
90 for (auto idx : vars)
91 if ((val = phases.best[idx]))
92 phases.saved[idx] = val;
93 return 'B';
94}
95
96// Trigger local search 'walk' in 'walk.cpp'.
97
99 stats.rephased.walk++;
100 PHASE ("rephase", stats.rephased.total,
101 "starting local search to improve current phase");
102 walk ();
103 return 'W';
104}
105
106/*------------------------------------------------------------------------*/
107
109
110 stats.rephased.total++;
111 PHASE ("rephase", stats.rephased.total,
112 "reached rephase limit %" PRId64 " after %" PRId64 " conflicts",
113 lim.rephase, stats.conflicts);
114
115 // Report current 'target' and 'best' and then set 'rephased' below, which
116 // will trigger reporting the new 'target' and 'best' after updating it in
117 // the next 'update_target_and_best' called from the next 'backtrack'.
118 //
119 report ('~', 1);
120
121 backtrack ();
122 clear_phases (phases.target);
123 target_assigned = 0;
124
125 size_t count = lim.rephased[stable]++;
126 bool single;
127 char type;
128
129 if (opts.stabilize && opts.stabilizeonly)
130 single = true;
131 else
132 single = !opts.stabilize;
133
134 if (single && !opts.walk) {
135 // (inverted,best,flipping,best,random,best,original,best)^\omega
136 switch (count % 8) {
137 case 0:
139 break;
140 case 1:
141 type = rephase_best ();
142 break;
143 case 2:
145 break;
146 case 3:
147 type = rephase_best ();
148 break;
149 case 4:
150 type = rephase_random ();
151 break;
152 case 5:
153 type = rephase_best ();
154 break;
155 case 6:
157 break;
158 case 7:
159 type = rephase_best ();
160 break;
161 default:
162 type = 0;
163 break;
164 }
165 } else if (single && opts.walk) {
166 // (inverted,best,walk,
167 // flipping,best,walk,
168 // random,best,walk,
169 // original,best,walk)^\omega
170 switch (count % 12) {
171 case 0:
173 break;
174 case 1:
175 type = rephase_best ();
176 break;
177 case 2:
178 type = rephase_walk ();
179 break;
180 case 3:
182 break;
183 case 4:
184 type = rephase_best ();
185 break;
186 case 5:
187 type = rephase_walk ();
188 break;
189 case 6:
190 type = rephase_random ();
191 break;
192 case 7:
193 type = rephase_best ();
194 break;
195 case 8:
196 type = rephase_walk ();
197 break;
198 case 9:
200 break;
201 case 10:
202 type = rephase_best ();
203 break;
204 case 11:
205 type = rephase_walk ();
206 break;
207 default:
208 type = 0;
209 break;
210 }
211 } else if (stable && !opts.walk) {
212 // original,inverted,(best,original,best,inverted)^\omega
213 if (!count)
215 else if (count == 1)
217 else
218 switch ((count - 2) % 4) {
219 case 0:
220 type = rephase_best ();
221 break;
222 case 1:
224 break;
225 case 2:
226 type = rephase_best ();
227 break;
228 case 3:
230 break;
231 default:
232 type = 0;
233 break;
234 }
235 } else if (stable && opts.walk) {
236 // original,inverted,(best,walk,original,best,walk,inverted)^\omega
237 if (!count)
239 else if (count == 1)
241 else
242 switch ((count - 2) % 6) {
243 case 0:
244 type = rephase_best ();
245 break;
246 case 1:
247 type = rephase_walk ();
248 break;
249 case 2:
251 break;
252 case 3:
253 type = rephase_best ();
254 break;
255 case 4:
256 type = rephase_walk ();
257 break;
258 case 5:
260 break;
261 default:
262 type = 0;
263 break;
264 }
265 } else if (!stable && (!opts.walk || !opts.walknonstable)) {
266 // flipping,(random,best,flipping,best)^\omega
267 if (!count)
269 else
270 switch ((count - 1) % 4) {
271 case 0:
272 type = rephase_random ();
273 break;
274 case 1:
275 type = rephase_best ();
276 break;
277 case 2:
279 break;
280 case 3:
281 type = rephase_best ();
282 break;
283 default:
284 type = 0;
285 break;
286 }
287 } else {
288 CADICAL_assert (!stable && opts.walk && opts.walknonstable);
289 // flipping,(random,best,walk,flipping,best,walk)^\omega
290 if (!count)
292 else
293 switch ((count - 1) % 6) {
294 case 0:
295 type = rephase_random ();
296 break;
297 case 1:
298 type = rephase_best ();
299 break;
300 case 2:
301 type = rephase_walk ();
302 break;
303 case 3:
305 break;
306 case 4:
307 type = rephase_best ();
308 break;
309 case 5:
310 type = rephase_walk ();
311 break;
312 default:
313 type = 0;
314 break;
315 }
316 }
318
319 int64_t delta = opts.rephaseint * (stats.rephased.total + 1);
320 lim.rephase = stats.conflicts + delta;
321
322 PHASE ("rephase", stats.rephased.total,
323 "new rephase limit %" PRId64 " after %" PRId64 " conflicts",
324 lim.rephase, delta);
325
326 // This will trigger to report the effect of this new set of phases at the
327 // 'backtrack' (actually 'update_target_and_best') after the next
328 // conflict, as well as resetting 'best_assigned' then to allow to compute
329 // a new "best" assignment at that point.
330 //
331 last.rephase.conflicts = stats.conflicts;
332 rephased = type;
333
334 if (stable)
336 else
337 shuffle_queue ();
338}
339
340} // namespace CaDiCaL
341
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
Definition global.h:14
type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
#define PHASE(...)
Definition message.hpp:52
void report(char type, int verbose_level=0)
void clear_phases(vector< signed char > &)
signed char val(int lit) const
void backtrack(int target_level=0)
const Range vars
Definition internal.hpp:324
long random()