VSIDS: variable activities for the CDCL solver #
MiniSat's branching heuristic, variable state independent decaying sum. Every variable has an
activity. After each conflict, the variables of the clauses met by the conflict analysis are
bumped: the current increment is added to their activity. These are all the variables of the
conflict clause and of the reasons resolved on, including variables assigned at decision level
0. MiniSat bumps a variable only when it is assigned above level 0 (level(var(q)) > 0 in
analyze), so this rule is a variant of MiniSat's. The increment then becomes inc + inc / 19,
with integer division: at most the factor 1 / 0.95 (MiniSat's var_decay = 0.95), so older bumps
weigh exponentially less. The solver decides an unassigned variable of greatest activity.
Activities and the increment are natural numbers, so the kernel can run the solver. The decay
step sets the increment to inc + inc / 19, with integer division, in place of MiniSat's
floating-point inc / 0.95. As in MiniSat, when an activity reaches a limit (here 2 ^ 60, tested
by a shift so that no large literal is built at run time) all activities and the increment are
scaled down (here by 2 ^ 20, with truncation). The increment starts at 2 ^ 40. An activity is
then below the limit plus the increment, and the increment at most 20 / 19 times the limit, so
every value stays below 2 ^ 62: compiled code keeps them as
unboxed machine integers, with no arbitrary-precision arithmetic. The truncations can make the
increment grow less than by 1 / 0.95 and turn different activities into ties (an activity more
than about 2 ^ 60 times smaller than the increment becomes 0), so decisions can differ from
those of floating-point activities.
The same structure, indexed by clause number and decaying by 1 / 0.999, holds MiniSat's clause
activities.
The variable order (VarOrder, MiniSat's order_heap) finds the decision variable without
scanning the variables for the greatest activity: a binary max-heap of variables, ordered by
activity and then by variable (Activity.keyOrd), with the position of each variable in it
(MiniSat's indices). As in MiniSat, bumping a variable in the heap moves it up
(VarOrder.increase), a variable undone by a backjump is inserted unless it is in the heap
(VarOrder.addAll, MiniSat's insertVarOrder), and popping removes assigned variables from the
top until it finds an unassigned one (VarOrder.pop, MiniSat's pickBranchLit). The sifting
functions compute Batteries' heapifyUp and heapifyDown (VarOrder.siftUp_fst,
VarOrder.siftDown_fst), updating the positions as they swap, so that Batteries' proofs apply.
Scaling the activities down can turn different activities into ties, which the order breaks by
variable, so the heap is then rebuilt (VarOrder.rebuild); scaling is rare, once every few hundred
conflicts.
The invariant (VarOrder.Inv) asks that the heap be well formed in the order of the current
activities, that the positions be consistent with it (VarOrder.PosOK), that every variable have
room in the position array, and that every unassigned variable admitted by the solver be in the
heap. Bumping a variable raises its activity alone, so moving it up restores the heap
(Batteries.BinaryHeap.topDown_heapifyUp_of_isGE). Under the invariant, the variable popped has the
greatest activity among the unassigned variables (VarOrder.pop_spec), and among ties the greatest
variable.
The choice of variable does not affect correctness: the solver only needs an unassigned variable
of the database, or the fact that there is none. Activity.pick scans for one of greatest
activity (Activity.pick_some, Activity.pick_none, Activity.pick_max); the solver uses it,
with every activity 0, when VSIDS is off. With VSIDS, the order runs out only when every
admitted variable is assigned (VarOrder.pop_none).
Main definitions #
Cslib.Algorithms.Lean.CDCL.Activity: activities and the increment.Cslib.Algorithms.Lean.CDCL.Activity.bump: bumping the variables met by an analysis, then decaying.Cslib.Algorithms.Lean.CDCL.Activity.grow: making room for more indices.Cslib.Algorithms.Lean.CDCL.Activity.pick: an unassigned variable of greatest activity.Cslib.Algorithms.Lean.CDCL.VarOrder,Cslib.Algorithms.Lean.CDCL.VarOrder.Inv: the variable order and its invariant.Cslib.Algorithms.Lean.CDCL.VarOrder.insert,Cslib.Algorithms.Lean.CDCL.VarOrder.addAll: inserting variables not in the heap.Cslib.Algorithms.Lean.CDCL.VarOrder.bump: bumping the variables met by an analysis, in the activities and in the heap.Cslib.Algorithms.Lean.CDCL.VarOrder.pop: popping the decision variable.
Main results #
Cslib.Algorithms.Lean.CDCL.Activity.pick_some,Cslib.Algorithms.Lean.CDCL.Activity.pick_none,Cslib.Algorithms.Lean.CDCL.Activity.pick_max: whatpickreturns.Cslib.Algorithms.Lean.CDCL.Activity.get_bump_le: bumping does not raise the other activities.Cslib.Algorithms.Lean.CDCL.VarOrder.bump_fst: bumping in the order bumps the activities asActivity.bumpdoes.Cslib.Algorithms.Lean.CDCL.VarOrder.bump_spec,Cslib.Algorithms.Lean.CDCL.VarOrder.addAll_spec: bumping and inserting keep the heap well formed and the positions consistent.Cslib.Algorithms.Lean.CDCL.VarOrder.pop_spec: the variable popped has the greatest activity among the unassigned variables, and the order keeps its invariant.Cslib.Algorithms.Lean.CDCL.VarOrder.pop_none: with enough fuel, popping finds no variable only by emptying the heap.
The initial activities of the variables below n: all 0, with increment 2 ^ 40.
The activity of the variable v.
Bumping v: its activity grows by the increment; if it reaches 2 ^ 60, every activity
and the increment are divided by 2 ^ 20. The activities are an array indexed by variable: for
v beyond its end, Array.modify leaves it unchanged, so bumping v does nothing and its
activity stays 0. The solver's variables are all within the array (WExec.init sizes it by the
largest variable of the formula).
After a conflict: bump each variable met by the analysis once, then set the increment to
inc + inc / decay, with integer division (by default decay = 19): at most the factor
1 + 1 / decay (1 / 0.95 by default), and less by the truncation.
Bumping each index of is, which has no repetitions, then growing the increment as
Activity.bump does. For the activities of clauses, whose numbers grow with the run: removing
repetitions in linear time would cost as much as the greatest number.
The activities with room for the indices below n, the new ones 0.
The variable order #
Entries compare by activity, then by variable: the lexicographic order on toPair, written
out so that comparing builds no pairs at run time.
The order of the variables by the activities A: by activity, then by variable, the order
of their entries OrderKey.mk (A.get v) v. A total order, so that the variable of the variable
order with the greatest activity, the greatest variable among ties, is well defined.
Whether a comes before b in the order of the activities A: a lower activity, or the same
and a smaller variable.
Positions #
Positions consistent with a heap array a (MiniSat's indices): p holds at each
element of a its index plus one, and 0 at every other variable.
Empty positions for the empty heap.
Sifting, with positions #
The heap #
The variable order, MiniSat's order_heap: a binary max-heap of variables in the order of
their activities (Activity.keyOrd), with the position of each variable in it. A variable's
position is its index plus one, 0 when it is not in the heap (MiniSat's indices). Bumping a
variable in the heap moves it up (VarOrder.increase, MiniSat's decrease).
The variables, as a binary heap.
The position of each variable in
heap, plus one;0for variables not in it.
The empty order, with room for the variables below n.
The heap is well formed in the order of the activities A: as a Batteries heap, every
variable is at least its children.
Rebuilding the heap with the activities A, after they were scaled down: scaling can turn
different activities into ties, which the order breaks by variable.
What the operations keep #
What moving v up keeps, after its activity alone grew from A to A': the heap stays
well formed, the positions consistent, the room and the variables the same.
What inserting the variables vs keeps: a well-formed heap stays well formed, the
positions consistent and the room the same; the variables of vs with room are added.
Bumping #
Bumping v in the activities A and the order H: Activity.bumpVar, and the variable is
moved up in the heap, or the heap is rebuilt if the activities were scaled down.
What an operation on the order keeps, with the activities A' after it: a well-formed heap,
consistent positions, the room and the variables of the order H before.
- wf : H'.WF A'
Bumping each variable of vs in turn (VarOrder.bumpVar).
Bumping variables listed once each: VarOrder.bump without removing repetitions, which
costs an array as large as the greatest variable. The solver bumps the variables met by an
analysis, which lists each once (Cslib.Algorithms.Lean.CDCL.Learned.seen_nodup).
The invariant and popping #
The invariant of the variable order over the variables V, with the activities A, the
trail M and the variables occ admits: a well-formed heap with consistent positions, room for
every variable of V, and every variable of V admitted and not on the trail in the heap.
- wf : H.WF A
Popping the decision variable, as MiniSat's pickBranchLit: the top of the heap is
removed until it is an unassigned variable admitted by occ. none if the heap runs out, or the
fuel does; with more fuel than variables in the heap, the heap runs out (VarOrder.pop_none).
What popping finds: the order stays well formed, with consistent positions and the same
room; a variable found is unassigned, admitted, and of greatest activity among the unassigned
admitted variables of V; and every other unassigned admitted variable of V stays in the
heap.