SlideShare a Scribd company logo
Optimal Implementation of
Watched Literals and More General
Techniques
Ian Gent
University of St Andrews
Scotland
ian.gent@st-andrews.ac.uk
Note: this paper will appear in JAIR, in press
Monday, 16 September 13
A surprising result
• Dangerous to use the word “surprising”
• in fact deleted from final version of paper
• But it surprised me
• And it surprised Pete Nightingale
• And it surprised Christian Bessiere
• And there’s no hint of it in the literature
• So I call it surprising
Monday, 16 September 13
Some conventional
wisdom is wrong
• Searching a linear list for key element
• e.g. watched literals in SAT
• e.g. support lists in CSP
• Don’t have to backtrack pointer (well known)
• And can still retain optimality (result of this paper)
• Was thought to be non-optimal
• work can be repeated many times on a single branch
• But a different partition of tree gives result
Monday, 16 September 13
The Setup
• We are in backtracking search (depth-first like)
• Elements in LIST might be acceptable
• e.g. domain value still valid
• Acceptability is monotonic
• if an element of LIST is unacceptable
• it is unacceptable at all descendant nodes
• When LIST has no acceptable elements
• e.g. no valid values still exist
• Search engine needs to be notified immediately
• typically to perform some propagation
Monday, 16 September 13
The Setup
• We maintain a pointer last
• With the following invariant
• EITHER LIST[last] is acceptable
• OR no element in LIST is acceptable
• When LIST[last] becomes unacceptable
• System notifies us (through some assumed mechanism)
• Look for new value of last
• If we can’t find one...
• then no element in LIST is acceptable
• We can notify search engine this information
Monday, 16 September 13
Three ways to maintain
last
1. We do not store state of last at all
• Search LIST from start every time
• Can check the same element multiple times per branch
2. Restore value of last on backtracking
• Scan list once only per branch
• But requires additional memory
3. Store value of last without backtracking
• continue search from last+1
• but have to cycle round to start of LIST at end
Monday, 16 September 13
Find-New-Element
(FNE)
• FNE: procedure to find new value of last
• Called by our assumed mechanism
• when LIST[last] becomes unacceptable
• Three variants for three approaches
1. last not stored between calls
2. last stored and restored on backtracking
3. last stored but not restored
• call this “circular” because of cycle at end of LIST
Monday, 16 September 13
No State Stored
(unacceptable), so we have to scan for a new watched literal
propagations at the same node can make this new value unsatisfi
This paper compares three implementations of findNewEle
properties of the last one. The differences arise from how las
invocations of findNewElement. The simplest variant is sh
time it is called the previous value of last is discarded and
beginning.
Procedure 1: FNE-NoState(list)
1: last := -1
2: repeat
3: last := last + 1
4: if acceptable(list,last) then return true
5: until last = N
6: return false
Procedure 1 is simple, certainly maintains Invariant 2, and
has a significant disadvantage in that its worst case is to require Θ
at every leaf node, stated here as Proposition 3 and proved in A
omitted from the main text but is available online, see Appendi
Monday, 16 September 13
State restored on
backtracking
The remaining two variants both use FNE-NoState to in
calls thereafter. The second variant is based on state restorat
from the most recent value of last found at the current node
the value of last may be changed by descendent nodes, some
search solver must be exploited to restore the value of last wh
this method is will vary between solvers, and is not critical f
method is shown as Procedure 2.
Procedure 2: FNE-RestoreState(list)
1: repeat
2: last := last + 1
3: if acceptable(list,last) then return true
4: until last = N
5: return false
Since acceptability is monotonic and last is always restored
the invariant is guaranteed. We have the following, for which
Proposition 4. The procedure FNE-RestoreState maint
branch of the search tree from root to leaf node, at most N c
Monday, 16 September 13
Circular: State Stored
but not backtracked
node. To deal with this correctly, we have to allow every elemen
even if some may have already been checked higher on the curren
same node. The focus of this paper is the “circular” method for c
the end of the list we circle around from the end of the list to zer
until we hit the value that last had when the call was made. For
above procedure FNE-NoState. All subsequent calls are to the f
Procedure 3: FNE-Circular(list)
1: last-cache := last
2: repeat
3: last := last + 1
4: if last = N then last := 0
5: if acceptable(list,last) then return true
6: until last = last-cache
7: return false
No claim is made for originality of the circular method: it was
and Miguel (2006b) and probably by earlier authors. Unlike th
invariant does not hold for all search algorithms. Correctness wil
below, in the context of ‘downwards-explored search trees’, as defi
Monday, 16 September 13
Example Search Tree
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Say length of LIST = N = 20
Monday, 16 September 13
Right Hand Branch
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
At Node 0, we set last=14,
total cost = 14
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Stuff happens on left hand subtree
and value of last changes
Right Hand Branch
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Stuff happens on left hand subtree
and value of last changes
Right Hand Branch
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
We loop round to set last=14
(again!) total cost = 17
Right Hand Branch
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Stuff happens on left hand subtree
and value of last changes
Right Hand Branch
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Stuff happens on left hand subtree
and value of last changes
Right Hand Branch
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Right Hand Branch
We loop round to set last=14
(again!) total cost = 18
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Stuff happens on left hand subtree
and value of last changes
Right Hand Branch
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Stuff happens on left hand subtree
and value of last changes
Right Hand Branch
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Right Hand Branch
We loop round to set last=14
(again!) cost = 18
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Right Hand Branch
At the same node we search again
and fail, total cost at node = 38
Monday, 16 September 13
2.1 Worked Example
I present a worked example of Procedure 3, showing how we can amortize the count of calls
to acceptable in a way which will form the basis of the optimality results of this paper.
Figure 1 shows an example search using the circular approach. In the example we assume
node id = 0:last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
0,1,2,4
= 19
0,1,5,6
= 52
0,1,5,7
= 51
0,8,9,10
= 52
0,8,9,11
= 52
0,8,12,13
= 50
0,8,12,14
= 87
Figure 1: A search using the circular approach. See main text for description.
that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation
sets last = 0. The box at a node indicates the node number (italics), the value of last
after any calls to FNE-Circular (bold), and the cost of those calls in total at the node
Right Hand Branch
Total cost down branch =
17+16+15+38 = 87
Monday, 16 September 13
Left Branch Segment
(LBS)Optimal Implementation of Watched Literals
node id = 0: last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
4
= 2
5,6
= 38
7
= 19
8,9,10
= 38
11
= 0
12,13
= 19
14
= 38
Figure 2: The example from Figure 1 with additional annotations. A double line indicates
a left hand branch, while a wavy line the right hand branch. A sequence of double
lines indicates a left branch segment. A solid box around a node indicates the
start of a left branch segment. Finally, the sums of costs are made only over the
Left Branch Segment is sequence of nodes
from solid box down double lines
Monday, 16 September 13
Left Branch Segment
(LBS)Optimal Implementation of Watched Literals
node id = 0: last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
4
= 2
5,6
= 38
7
= 19
8,9,10
= 38
11
= 0
12,13
= 19
14
= 38
Figure 2: The example from Figure 1 with additional annotations. A double line indicates
a left hand branch, while a wavy line the right hand branch. A sequence of double
lines indicates a left branch segment. A solid box around a node indicates the
start of a left branch segment. Finally, the sums of costs are made only over the
Left Branch Segment is sequence of
nodes where we always branch left
Monday, 16 September 13
Left Branch Segment
(LBS)Optimal Implementation of Watched Literals
node id = 0: last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
4
= 2
5,6
= 38
7
= 19
8,9,10
= 38
11
= 0
12,13
= 19
14
= 38
Figure 2: The example from Figure 1 with additional annotations. A double line indicates
a left hand branch, while a wavy line the right hand branch. A sequence of double
lines indicates a left branch segment. A solid box around a node indicates the
start of a left branch segment. Finally, the sums of costs are made only over the
In LBS sequence of nodes is consecutive in
number without backtracking
Monday, 16 September 13
Left Branch Segment
(LBS)Optimal Implementation of Watched Literals
node id = 0: last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
4
= 2
5,6
= 38
7
= 19
8,9,10
= 38
11
= 0
12,13
= 19
14
= 38
Figure 2: The example from Figure 1 with additional annotations. A double line indicates
a left hand branch, while a wavy line the right hand branch. A sequence of double
lines indicates a left branch segment. A solid box around a node indicates the
start of a left branch segment. Finally, the sums of costs are made only over the
Each node is in exactly one LBS
Monday, 16 September 13
Left Branch Segment
(LBS)Optimal Implementation of Watched Literals
node id = 0: last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
4
= 2
5,6
= 38
7
= 19
8,9,10
= 38
11
= 0
12,13
= 19
14
= 38
Figure 2: The example from Figure 1 with additional annotations. A double line indicates
a left hand branch, while a wavy line the right hand branch. A sequence of double
lines indicates a left branch segment. A solid box around a node indicates the
start of a left branch segment. Finally, the sums of costs are made only over the
There are the same number of
LBSs as branches/leaf nodes
Monday, 16 September 13
Left Branch Segment
(LBS)Optimal Implementation of Watched Literals
node id = 0: last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
4
= 2
5,6
= 38
7
= 19
8,9,10
= 38
11
= 0
12,13
= 19
14
= 38
Figure 2: The example from Figure 1 with additional annotations. A double line indicates
a left hand branch, while a wavy line the right hand branch. A sequence of double
lines indicates a left branch segment. A solid box around a node indicates the
start of a left branch segment. Finally, the sums of costs are made only over the
Never make as many as 2N = 40
calls to Acceptable in LBS
Monday, 16 September 13
Left Branch Segment
(LBS)Optimal Implementation of Watched Literals
node id = 0: last=14, cost = 14
last=17
1:14, 0
last=19
8:14, 17
last=16
2:17, 3 5:17, 18
last=18
9:16, 21 × 12:14, 18
last=15
3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 ×
0,1,2,3
= 36
4
= 2
5,6
= 38
7
= 19
8,9,10
= 38
11
= 0
12,13
= 19
14
= 38
Figure 2: The example from Figure 1 with additional annotations. A double line indicates
a left hand branch, while a wavy line the right hand branch. A sequence of double
lines indicates a left branch segment. A solid box around a node indicates the
start of a left branch segment. Finally, the sums of costs are made only over the
All these statements are general.
Last is crux of optimality result.
Monday, 16 September 13
Key Lemma
• Say length of LIST=N
• In any Left Branch Segment
• there are at most N-1 successful calls to
Acceptable()
• Proof is easy:
• if there are N it has checked every element
• after a successful call there is only another call if that
element becomes unacceptable
• if there are N every element has become unacceptable
Monday, 16 September 13
Key Corollary
• In any Left Branch Segment
• there are at most 2N-1 calls to
Acceptable()
• Proof is easy:
• N-1 successful calls
• then N including cycle for the last failed
attempt
Monday, 16 September 13
Optimality Theorem
• In a search tree, FNE-Circular can make no more than
2N calls to Acceptable() per branch of the tree
• Note this applies to every search tree
• no average case or asymptotics
• This is optimal because we must check O(N) per
branch in any method
• Worst case is only 2x worst case of state restoration
• and only worse when failure on branch
Monday, 16 September 13
Application: Constraints
• Typically in GAC algorithm
• (Generalised arc consistency)
• Need support for each variable/value
• Each variable/value has list of support tuples
• acceptable means:
• every assignment in tuple is still valid
• Losing support = element unacceptable
Monday, 16 September 13
From GAC to MGAC
• MGAC = Maintaining GAC in search
• Two approaches can both be improved
• Restore State
• e.g. Bessiere et al implementation of MGAC
• Optimal per branch but uses additional space to store pointer
• Circular
• e.g. Gent et al, various papers
• Used because of simplicity and effectiveness in practice
• With warning in paper that approach is not optimal
• but it was optimal!
Monday, 16 September 13
Application: SAT
• Watched literals in SAT
• Need two acceptable elements
• Generalisation is not hard
• though did not find till the last minute
• Fun Fact:
• if you want w watched elements
• number of calls to Acceptable() does not increase
with w
Monday, 16 September 13
Application: SAT
• I thought that Circular was standard
implementation
• But Reviewer pointed out that was wrong
• Actually most people do FNE-NoState
• e.g. MiniSat, tiniSat
• meaning can be O(N2) calls per branch
• Complete surprise to me
• So is Circular (optimal) better?
Monday, 16 September 13
Is circular better than
no-state in MiniSat?Gent
0.5
0.6
0.8
1
2
3
4
5
6
8
10
0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20
Circular:Stock
0.548x + 0.523
Yes!
Monday, 16 September 13
Is circular better than
no-state in MiniSat?Gent
0.5
0.6
0.8
1
2
3
4
5
6
8
10
0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20
Circular:Stock
0.548x + 0.523
Average of 29% faster propagation
Monday, 16 September 13
Is circular better than
no-state in MiniSat?Gent
0.5
0.6
0.8
1
2
3
4
5
6
8
10
0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20
Circular:Stock
0.548x + 0.523
Circular can propagate almost 10x faster
Monday, 16 September 13
Is circular better than
no-state in MiniSat?Gent
0.5
0.6
0.8
1
2
3
4
5
6
8
10
0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20
Circular:Stock
0.548x + 0.523
Circular is better at finding literals that are not falsified
Monday, 16 September 13
Is circular better than
no-state in MiniSat?
No!
Gent
0.01
0.1
1
10
100
0.01 0.1 1 10 100 1000
Circular ratio
TwoPointer ratio
Monday, 16 September 13
Is circular better than
no-state in MiniSat?
No significant improvement in overall search
Gent
0.01
0.1
1
10
100
0.01 0.1 1 10 100 1000
Circular ratio
TwoPointer ratio
Monday, 16 September 13
Is circular better than
no-state in MiniSat?
Different propagations = different explanations
= different heuristics = different search
Gent
0.01
0.1
1
10
100
0.01 0.1 1 10 100 1000
Circular ratio
TwoPointer ratio
Monday, 16 September 13
Conclusions
• The circular approach is optimal
• and this is surprising
• minimises space and very easy to implement
• Some existing implementations are optimal
• even though their authors said not
• Generalises to finding multiple elements
• e.g. watched literals in SAT
• Circular can improve propagation in MiniSat
• but there’s no evidence it improves overall solving speed
Monday, 16 September 13
And finally...
• JAIR paper gives me particular pleasure...
• I have published papers in JAIR 20 years apart
• Gent &Walsh, September 1993
• Gent, September, 2013
• JAIR was platinum open access from day one
• Original publication by anon ftp and gopher
• web page set up a few months later!
Monday, 16 September 13

More Related Content

PPTX
Roots of polynomials
PPTX
My1 ark presentation1
PPTX
Mediterranean diet
PPTX
sicsa-phd2016
PPTX
Why Computer Science is a Great Choice
PDF
V1 of The Computer Scientist and The Cleaner
PDF
Women in Science 2015: The Computer Scientist and the Cleaner
PPTX
Sicsa phd2015
Roots of polynomials
My1 ark presentation1
Mediterranean diet
sicsa-phd2016
Why Computer Science is a Great Choice
V1 of The Computer Scientist and The Cleaner
Women in Science 2015: The Computer Scientist and the Cleaner
Sicsa phd2015

Viewers also liked (8)

PDF
Computer Scientist And the Cleaner, V6
PDF
The Computer Scientist and the Cleaner v4
PDF
The Computer Scientist and the Cleaner v5
PDF
V2 of The Computer Scientist and the Cleaner
PDF
The Computer Scientist and The Cleaner
PPT
Chapter 8 - Organizing the Body of the Speech
PPT
Chapter 7 - Supporting Your Ideas
Computer Scientist And the Cleaner, V6
The Computer Scientist and the Cleaner v4
The Computer Scientist and the Cleaner v5
V2 of The Computer Scientist and the Cleaner
The Computer Scientist and The Cleaner
Chapter 8 - Organizing the Body of the Speech
Chapter 7 - Supporting Your Ideas
Ad

Similar to Optimal Implementation of Watched Literals and More General Techniques (20)

PPTX
A presentation on Counting Principles.pptx
PPTX
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PDF
Binary Search - Design & Analysis of Algorithms
PDF
advanced searching and sorting.pdf
PPT
PPT
Advanced s and s algorithm.ppt
PPT
PDF
L1803016468
PPTX
Chapter3.pptx
PPT
Chapter 11 - Sorting and Searching
PDF
Data structures arrays
PPT
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
PPT
Ch 1 intriductions
PDF
Chapter-3-Sample-Space-of-Experiment.pdf
PDF
one main advantage of bubble sort as compared to others
PPT
Sorting algorithms
PDF
Sortsearch
PDF
PPT
Sorting algorithms
PPTX
Basic Sorting algorithms csharp
A presentation on Counting Principles.pptx
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Binary Search - Design & Analysis of Algorithms
advanced searching and sorting.pdf
Advanced s and s algorithm.ppt
L1803016468
Chapter3.pptx
Chapter 11 - Sorting and Searching
Data structures arrays
CHAP 3 ALGORITHM for infomatique ingenieure .ppt
Ch 1 intriductions
Chapter-3-Sample-Space-of-Experiment.pdf
one main advantage of bubble sort as compared to others
Sorting algorithms
Sortsearch
Sorting algorithms
Basic Sorting algorithms csharp
Ad

Recently uploaded (20)

PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Architecture types and enterprise applications.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PPTX
The various Industrial Revolutions .pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
PPTX
TLE Review Electricity (Electricity).pptx
PDF
August Patch Tuesday
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Hybrid model detection and classification of lung cancer
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
OMC Textile Division Presentation 2021.pptx
Architecture types and enterprise applications.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
DP Operators-handbook-extract for the Mautical Institute
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
The various Industrial Revolutions .pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
observCloud-Native Containerability and monitoring.pptx
Getting started with AI Agents and Multi-Agent Systems
TLE Review Electricity (Electricity).pptx
August Patch Tuesday
A contest of sentiment analysis: k-nearest neighbor versus neural network
Group 1 Presentation -Planning and Decision Making .pptx
Module 1.ppt Iot fundamentals and Architecture
Hybrid model detection and classification of lung cancer
NewMind AI Weekly Chronicles - August'25-Week II
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...

Optimal Implementation of Watched Literals and More General Techniques

  • 1. Optimal Implementation of Watched Literals and More General Techniques Ian Gent University of St Andrews Scotland ian.gent@st-andrews.ac.uk Note: this paper will appear in JAIR, in press Monday, 16 September 13
  • 2. A surprising result • Dangerous to use the word “surprising” • in fact deleted from final version of paper • But it surprised me • And it surprised Pete Nightingale • And it surprised Christian Bessiere • And there’s no hint of it in the literature • So I call it surprising Monday, 16 September 13
  • 3. Some conventional wisdom is wrong • Searching a linear list for key element • e.g. watched literals in SAT • e.g. support lists in CSP • Don’t have to backtrack pointer (well known) • And can still retain optimality (result of this paper) • Was thought to be non-optimal • work can be repeated many times on a single branch • But a different partition of tree gives result Monday, 16 September 13
  • 4. The Setup • We are in backtracking search (depth-first like) • Elements in LIST might be acceptable • e.g. domain value still valid • Acceptability is monotonic • if an element of LIST is unacceptable • it is unacceptable at all descendant nodes • When LIST has no acceptable elements • e.g. no valid values still exist • Search engine needs to be notified immediately • typically to perform some propagation Monday, 16 September 13
  • 5. The Setup • We maintain a pointer last • With the following invariant • EITHER LIST[last] is acceptable • OR no element in LIST is acceptable • When LIST[last] becomes unacceptable • System notifies us (through some assumed mechanism) • Look for new value of last • If we can’t find one... • then no element in LIST is acceptable • We can notify search engine this information Monday, 16 September 13
  • 6. Three ways to maintain last 1. We do not store state of last at all • Search LIST from start every time • Can check the same element multiple times per branch 2. Restore value of last on backtracking • Scan list once only per branch • But requires additional memory 3. Store value of last without backtracking • continue search from last+1 • but have to cycle round to start of LIST at end Monday, 16 September 13
  • 7. Find-New-Element (FNE) • FNE: procedure to find new value of last • Called by our assumed mechanism • when LIST[last] becomes unacceptable • Three variants for three approaches 1. last not stored between calls 2. last stored and restored on backtracking 3. last stored but not restored • call this “circular” because of cycle at end of LIST Monday, 16 September 13
  • 8. No State Stored (unacceptable), so we have to scan for a new watched literal propagations at the same node can make this new value unsatisfi This paper compares three implementations of findNewEle properties of the last one. The differences arise from how las invocations of findNewElement. The simplest variant is sh time it is called the previous value of last is discarded and beginning. Procedure 1: FNE-NoState(list) 1: last := -1 2: repeat 3: last := last + 1 4: if acceptable(list,last) then return true 5: until last = N 6: return false Procedure 1 is simple, certainly maintains Invariant 2, and has a significant disadvantage in that its worst case is to require Θ at every leaf node, stated here as Proposition 3 and proved in A omitted from the main text but is available online, see Appendi Monday, 16 September 13
  • 9. State restored on backtracking The remaining two variants both use FNE-NoState to in calls thereafter. The second variant is based on state restorat from the most recent value of last found at the current node the value of last may be changed by descendent nodes, some search solver must be exploited to restore the value of last wh this method is will vary between solvers, and is not critical f method is shown as Procedure 2. Procedure 2: FNE-RestoreState(list) 1: repeat 2: last := last + 1 3: if acceptable(list,last) then return true 4: until last = N 5: return false Since acceptability is monotonic and last is always restored the invariant is guaranteed. We have the following, for which Proposition 4. The procedure FNE-RestoreState maint branch of the search tree from root to leaf node, at most N c Monday, 16 September 13
  • 10. Circular: State Stored but not backtracked node. To deal with this correctly, we have to allow every elemen even if some may have already been checked higher on the curren same node. The focus of this paper is the “circular” method for c the end of the list we circle around from the end of the list to zer until we hit the value that last had when the call was made. For above procedure FNE-NoState. All subsequent calls are to the f Procedure 3: FNE-Circular(list) 1: last-cache := last 2: repeat 3: last := last + 1 4: if last = N then last := 0 5: if acceptable(list,last) then return true 6: until last = last-cache 7: return false No claim is made for originality of the circular method: it was and Miguel (2006b) and probably by earlier authors. Unlike th invariant does not hold for all search algorithms. Correctness wil below, in the context of ‘downwards-explored search trees’, as defi Monday, 16 September 13
  • 11. Example Search Tree 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Say length of LIST = N = 20 Monday, 16 September 13
  • 12. Right Hand Branch 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node At Node 0, we set last=14, total cost = 14 Monday, 16 September 13
  • 13. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Stuff happens on left hand subtree and value of last changes Right Hand Branch Monday, 16 September 13
  • 14. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Stuff happens on left hand subtree and value of last changes Right Hand Branch Monday, 16 September 13
  • 15. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node We loop round to set last=14 (again!) total cost = 17 Right Hand Branch Monday, 16 September 13
  • 16. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Stuff happens on left hand subtree and value of last changes Right Hand Branch Monday, 16 September 13
  • 17. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Stuff happens on left hand subtree and value of last changes Right Hand Branch Monday, 16 September 13
  • 18. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Right Hand Branch We loop round to set last=14 (again!) total cost = 18 Monday, 16 September 13
  • 19. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Stuff happens on left hand subtree and value of last changes Right Hand Branch Monday, 16 September 13
  • 20. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Stuff happens on left hand subtree and value of last changes Right Hand Branch Monday, 16 September 13
  • 21. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Right Hand Branch We loop round to set last=14 (again!) cost = 18 Monday, 16 September 13
  • 22. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Right Hand Branch At the same node we search again and fail, total cost at node = 38 Monday, 16 September 13
  • 23. 2.1 Worked Example I present a worked example of Procedure 3, showing how we can amortize the count of calls to acceptable in a way which will form the basis of the optimality results of this paper. Figure 1 shows an example search using the circular approach. In the example we assume node id = 0:last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 0,1,2,4 = 19 0,1,5,6 = 52 0,1,5,7 = 51 0,8,9,10 = 52 0,8,9,11 = 52 0,8,12,13 = 50 0,8,12,14 = 87 Figure 1: A search using the circular approach. See main text for description. that the list being searched has 20 elements, indexed from 0 to 19. and that initialisation sets last = 0. The box at a node indicates the node number (italics), the value of last after any calls to FNE-Circular (bold), and the cost of those calls in total at the node Right Hand Branch Total cost down branch = 17+16+15+38 = 87 Monday, 16 September 13
  • 24. Left Branch Segment (LBS)Optimal Implementation of Watched Literals node id = 0: last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 4 = 2 5,6 = 38 7 = 19 8,9,10 = 38 11 = 0 12,13 = 19 14 = 38 Figure 2: The example from Figure 1 with additional annotations. A double line indicates a left hand branch, while a wavy line the right hand branch. A sequence of double lines indicates a left branch segment. A solid box around a node indicates the start of a left branch segment. Finally, the sums of costs are made only over the Left Branch Segment is sequence of nodes from solid box down double lines Monday, 16 September 13
  • 25. Left Branch Segment (LBS)Optimal Implementation of Watched Literals node id = 0: last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 4 = 2 5,6 = 38 7 = 19 8,9,10 = 38 11 = 0 12,13 = 19 14 = 38 Figure 2: The example from Figure 1 with additional annotations. A double line indicates a left hand branch, while a wavy line the right hand branch. A sequence of double lines indicates a left branch segment. A solid box around a node indicates the start of a left branch segment. Finally, the sums of costs are made only over the Left Branch Segment is sequence of nodes where we always branch left Monday, 16 September 13
  • 26. Left Branch Segment (LBS)Optimal Implementation of Watched Literals node id = 0: last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 4 = 2 5,6 = 38 7 = 19 8,9,10 = 38 11 = 0 12,13 = 19 14 = 38 Figure 2: The example from Figure 1 with additional annotations. A double line indicates a left hand branch, while a wavy line the right hand branch. A sequence of double lines indicates a left branch segment. A solid box around a node indicates the start of a left branch segment. Finally, the sums of costs are made only over the In LBS sequence of nodes is consecutive in number without backtracking Monday, 16 September 13
  • 27. Left Branch Segment (LBS)Optimal Implementation of Watched Literals node id = 0: last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 4 = 2 5,6 = 38 7 = 19 8,9,10 = 38 11 = 0 12,13 = 19 14 = 38 Figure 2: The example from Figure 1 with additional annotations. A double line indicates a left hand branch, while a wavy line the right hand branch. A sequence of double lines indicates a left branch segment. A solid box around a node indicates the start of a left branch segment. Finally, the sums of costs are made only over the Each node is in exactly one LBS Monday, 16 September 13
  • 28. Left Branch Segment (LBS)Optimal Implementation of Watched Literals node id = 0: last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 4 = 2 5,6 = 38 7 = 19 8,9,10 = 38 11 = 0 12,13 = 19 14 = 38 Figure 2: The example from Figure 1 with additional annotations. A double line indicates a left hand branch, while a wavy line the right hand branch. A sequence of double lines indicates a left branch segment. A solid box around a node indicates the start of a left branch segment. Finally, the sums of costs are made only over the There are the same number of LBSs as branches/leaf nodes Monday, 16 September 13
  • 29. Left Branch Segment (LBS)Optimal Implementation of Watched Literals node id = 0: last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 4 = 2 5,6 = 38 7 = 19 8,9,10 = 38 11 = 0 12,13 = 19 14 = 38 Figure 2: The example from Figure 1 with additional annotations. A double line indicates a left hand branch, while a wavy line the right hand branch. A sequence of double lines indicates a left branch segment. A solid box around a node indicates the start of a left branch segment. Finally, the sums of costs are made only over the Never make as many as 2N = 40 calls to Acceptable in LBS Monday, 16 September 13
  • 30. Left Branch Segment (LBS)Optimal Implementation of Watched Literals node id = 0: last=14, cost = 14 last=17 1:14, 0 last=19 8:14, 17 last=16 2:17, 3 5:17, 18 last=18 9:16, 21 × 12:14, 18 last=15 3:17, 19× 4:19, 2 6:18, 20 × 7:17, 19 10:16, 0 11:16, 0 13:15, 1 14:14, 38 × 0,1,2,3 = 36 4 = 2 5,6 = 38 7 = 19 8,9,10 = 38 11 = 0 12,13 = 19 14 = 38 Figure 2: The example from Figure 1 with additional annotations. A double line indicates a left hand branch, while a wavy line the right hand branch. A sequence of double lines indicates a left branch segment. A solid box around a node indicates the start of a left branch segment. Finally, the sums of costs are made only over the All these statements are general. Last is crux of optimality result. Monday, 16 September 13
  • 31. Key Lemma • Say length of LIST=N • In any Left Branch Segment • there are at most N-1 successful calls to Acceptable() • Proof is easy: • if there are N it has checked every element • after a successful call there is only another call if that element becomes unacceptable • if there are N every element has become unacceptable Monday, 16 September 13
  • 32. Key Corollary • In any Left Branch Segment • there are at most 2N-1 calls to Acceptable() • Proof is easy: • N-1 successful calls • then N including cycle for the last failed attempt Monday, 16 September 13
  • 33. Optimality Theorem • In a search tree, FNE-Circular can make no more than 2N calls to Acceptable() per branch of the tree • Note this applies to every search tree • no average case or asymptotics • This is optimal because we must check O(N) per branch in any method • Worst case is only 2x worst case of state restoration • and only worse when failure on branch Monday, 16 September 13
  • 34. Application: Constraints • Typically in GAC algorithm • (Generalised arc consistency) • Need support for each variable/value • Each variable/value has list of support tuples • acceptable means: • every assignment in tuple is still valid • Losing support = element unacceptable Monday, 16 September 13
  • 35. From GAC to MGAC • MGAC = Maintaining GAC in search • Two approaches can both be improved • Restore State • e.g. Bessiere et al implementation of MGAC • Optimal per branch but uses additional space to store pointer • Circular • e.g. Gent et al, various papers • Used because of simplicity and effectiveness in practice • With warning in paper that approach is not optimal • but it was optimal! Monday, 16 September 13
  • 36. Application: SAT • Watched literals in SAT • Need two acceptable elements • Generalisation is not hard • though did not find till the last minute • Fun Fact: • if you want w watched elements • number of calls to Acceptable() does not increase with w Monday, 16 September 13
  • 37. Application: SAT • I thought that Circular was standard implementation • But Reviewer pointed out that was wrong • Actually most people do FNE-NoState • e.g. MiniSat, tiniSat • meaning can be O(N2) calls per branch • Complete surprise to me • So is Circular (optimal) better? Monday, 16 September 13
  • 38. Is circular better than no-state in MiniSat?Gent 0.5 0.6 0.8 1 2 3 4 5 6 8 10 0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20 Circular:Stock 0.548x + 0.523 Yes! Monday, 16 September 13
  • 39. Is circular better than no-state in MiniSat?Gent 0.5 0.6 0.8 1 2 3 4 5 6 8 10 0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20 Circular:Stock 0.548x + 0.523 Average of 29% faster propagation Monday, 16 September 13
  • 40. Is circular better than no-state in MiniSat?Gent 0.5 0.6 0.8 1 2 3 4 5 6 8 10 0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20 Circular:Stock 0.548x + 0.523 Circular can propagate almost 10x faster Monday, 16 September 13
  • 41. Is circular better than no-state in MiniSat?Gent 0.5 0.6 0.8 1 2 3 4 5 6 8 10 0.5 0.6 0.8 1 1.2 2 3 4 5 6 8 10 20 Circular:Stock 0.548x + 0.523 Circular is better at finding literals that are not falsified Monday, 16 September 13
  • 42. Is circular better than no-state in MiniSat? No! Gent 0.01 0.1 1 10 100 0.01 0.1 1 10 100 1000 Circular ratio TwoPointer ratio Monday, 16 September 13
  • 43. Is circular better than no-state in MiniSat? No significant improvement in overall search Gent 0.01 0.1 1 10 100 0.01 0.1 1 10 100 1000 Circular ratio TwoPointer ratio Monday, 16 September 13
  • 44. Is circular better than no-state in MiniSat? Different propagations = different explanations = different heuristics = different search Gent 0.01 0.1 1 10 100 0.01 0.1 1 10 100 1000 Circular ratio TwoPointer ratio Monday, 16 September 13
  • 45. Conclusions • The circular approach is optimal • and this is surprising • minimises space and very easy to implement • Some existing implementations are optimal • even though their authors said not • Generalises to finding multiple elements • e.g. watched literals in SAT • Circular can improve propagation in MiniSat • but there’s no evidence it improves overall solving speed Monday, 16 September 13
  • 46. And finally... • JAIR paper gives me particular pleasure... • I have published papers in JAIR 20 years apart • Gent &Walsh, September 1993 • Gent, September, 2013 • JAIR was platinum open access from day one • Original publication by anon ftp and gopher • web page set up a few months later! Monday, 16 September 13