ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_backtrack.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
9// The global assignment stack can only be (partially) reset through
10// 'backtrack' which is the only function using 'unassign' (inlined and thus
11// local to this file). It turns out that 'unassign' does not need a
12// specialization for 'probe' nor 'vivify' and thus it is shared.
13
14inline void Internal::unassign (int lit) {
15 CADICAL_assert (val (lit) > 0);
16 set_val (lit, 0);
17
18 int idx = vidx (lit);
19 LOG ("unassign %d @ %d", lit, var (idx).level);
21
22 // In the standard EVSIDS variable decision heuristic of MiniSAT, we need
23 // to push variables which become unassigned back to the heap.
24 //
25 if (!scores.contains (idx))
26 scores.push_back (idx);
27
28 // For VMTF we need to update the 'queue.unassigned' pointer in case this
29 // variable sits after the variable to which 'queue.unassigned' currently
30 // points. See our SAT'15 paper for more details on this aspect.
31 //
32 if (queue.bumped < btab[idx])
34}
35
36/*------------------------------------------------------------------------*/
37
38// Update the current target maximum assignment and also the very best
39// assignment. Whether a trail produces a conflict is determined during
40// propagation. Thus that all functions in the 'search' loop after
41// propagation can assume that 'no_conflict_until' is valid. If a conflict
42// is found then the trail before the last decision is used (see the end of
43// 'propagate'). During backtracking we can then save this largest
44// propagation conflict free assignment. It is saved as both 'target'
45// assignment for picking decisions in 'stable' mode and if it is the
46// largest ever such assignment also as 'best' assignment. This 'best'
47// assignment can then be used in future stable decisions after the next
48// 'rephase_best' overwrites saved phases with it.
49
51
52 bool reset = (rephased && stats.conflicts > last.rephase.conflicts);
53
54 if (reset) {
56 if (rephased == 'B')
57 best_assigned = 0; // update it again
58 }
59
61 copy_phases (phases.target);
63 LOG ("new target trail level %zu", target_assigned);
64 }
65
67 copy_phases (phases.best);
69 LOG ("new best trail level %zu", best_assigned);
70 }
71
72 if (reset) {
74 rephased = 0;
75 }
76}
77
78/*------------------------------------------------------------------------*/
79
80void Internal::backtrack (int new_level) {
81 CADICAL_assert (new_level <= level);
82 if (new_level == level)
83 return;
84
87}
88
90
91 CADICAL_assert (new_level <= level);
92 if (new_level == level)
93 return;
94
95 stats.backtracks++;
96
98
99 const size_t assigned = control[new_level + 1].trail;
100
101 LOG ("backtracking to decision level %d with decision %d and trail %zd",
102 new_level, control[new_level].decision, assigned);
103
104 const size_t end_of_trail = trail.size ();
105 size_t i = assigned, j = i;
106
107#ifdef LOGGING
108 int unassigned = 0;
109#endif
110 int reassigned = 0;
111
112 notify_backtrack (new_level);
114 notified > assigned) {
115 LOG ("external propagator is notified about some unassignments (trail: "
116 "%zd, notified: %zd).",
117 trail.size (), notified);
119 }
120
121 while (i < end_of_trail) {
122 int lit = trail[i++];
123 Var &v = var (lit);
124 if (v.level > new_level) {
125 unassign (lit);
126#ifdef LOGGING
127 unassigned++;
128#endif
129 } else {
130 // This is the essence of the SAT'18 paper on chronological
131 // backtracking. It is possible to just keep out-of-order assigned
132 // literals on the trail without breaking the solver (after some
133 // modifications to 'analyze' - see 'opts.chrono' guarded code there).
135#ifdef LOGGING
136 if (!v.level)
137 LOG ("reassign %d @ 0 unit clause %d", lit, lit);
138 else
139 LOG (v.reason, "reassign %d @ %d", lit, v.level);
140#endif
141 trail[j] = lit;
142 v.trail = j++;
143 reassigned++;
144 }
145 }
146 trail.resize (j);
147 LOG ("unassigned %d literals %.0f%%", unassigned,
148 percent (unassigned, unassigned + reassigned));
149 LOG ("reassigned %d literals %.0f%%", reassigned,
150 percent (reassigned, unassigned + reassigned));
151
152 if (propagated > assigned)
154 if (propagated2 > assigned)
158
159 propergated = 0; // Always go back to root-level.
160
161 CADICAL_assert (notified <= assigned + reassigned);
162 if (reassigned) {
164 }
165
166 control.resize (new_level + 1);
167 level = new_level;
168 if (tainted_literal) {
169 CADICAL_assert (opts.ilb);
170 if (!val (tainted_literal)) {
171 tainted_literal = 0;
172 }
173 }
174 CADICAL_assert (num_assigned == trail.size ());
175}
176
177} // namespace CaDiCaL
178
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
Definition global.h:14
#define LOG(...)
double percent(double a, double b)
Definition util.hpp:21
int lit
Definition satVec.h:130
void update_queue_unassigned(int idx)
Definition internal.hpp:652
Var & var(int lit)
Definition internal.hpp:452
int vidx(int lit) const
Definition internal.hpp:395
void report(char type, int verbose_level=0)
vector< int > trail
Definition internal.hpp:259
signed char val(int lit) const
void set_val(int lit, signed char val)
size_t no_conflict_until
Definition internal.hpp:258
void backtrack_without_updating_phases(int target_level=0)
void backtrack(int target_level=0)
vector< int64_t > btab
Definition internal.hpp:234
void copy_phases(vector< signed char > &)
vector< Level > control
Definition internal.hpp:282
ScoreSchedule scores
Definition internal.hpp:229
void notify_backtrack(size_t new_level)
int level
Definition var.hpp:19
int trail
Definition var.hpp:20
Clause * reason
Definition var.hpp:21