Watched Literals in SAT and CP T opics in this Series Why SAT - - PowerPoint PPT Presentation

watched literals in sat and cp t opics in this series
SMART_READER_LITE
LIVE PREVIEW

Watched Literals in SAT and CP T opics in this Series Why SAT - - PowerPoint PPT Presentation

Watched Literals in SAT and CP T opics in this Series Why SAT & Constraints? SAT basics Constraints basics Encodings between SAT and Constraints Watched Literals in SAT and Constraints Learning in SAT and Constraints


slide-1
SLIDE 1

Watched Literals in SAT and CP

slide-2
SLIDE 2

T

  • pics in this Series
  • Why SAT & Constraints?
  • SAT basics
  • Constraints basics
  • Encodings between SAT and Constraints
  • Watched Literals in SAT and Constraints
  • Learning in SAT and Constraints
  • Lazy Clause Generation + SAT Modulo

Theories

slide-3
SLIDE 3

Legal Warning

  • Watched literals may be patented
  • it’s not so clear to a non-lawyer like me
  • US Patent 7,418,369, August 26, 2008:
  • “Method and System for Efficient

Implementation of Boolean Satisfiability”

  • Covers Chaff, Watched Literals, VSIDS
slide-4
SLIDE 4

Legal Warning

  • May not be an everyday problem
  • http://tinyurl.com/satpatent
  • Sharad Malik says ok for noncommercial use:
  • “The chaff software and related intellectual property have been

freely available for research purposes and will continue to be available for free use by the research community for non- commercial purposes. This includes the development of other SAT solvers with this technology as well as their research use.”

  • But I don’t know if that stands up in court
  • Or what happens if you put it open source code
  • which then is used commercially
slide-5
SLIDE 5

Patent in Constraints?

  • As far as I know, WL patent doesn’t cover

Watched Literals in Constraints to be covered later

  • And I know for certain that we have not

applied for a patent for our work on it

slide-6
SLIDE 6

Patents

  • Software patents arouse great passions
  • I’m somewhere in the middle
  • But I’m shocked they had a patent

pending for years and never told anyone

  • Please don’t do this!
slide-7
SLIDE 7

Watched Literals

  • Key technique in the SAT propagation algorithm
  • i.e. unit propagation
  • Introduced with the SAT solver Chaff
  • Chaff: Engineering an Efficient SAT Solver by Moskewicz,

Madigan, Zhao, Zhang, Malik, DAC 2001.

  • though with precursors (of course)
  • Especially Head-Tail lists by Stickel/Zhang
  • Carried over to Constraint Propagation in Minion
  • Watched Literals for Constraint Propagation in Minion, by Gent,

Jefferson, Miguel, CP 2006.

slide-8
SLIDE 8

First key idea

  • There is no work on backtracking
  • Example of not restoring state on backtracking
  • ensuring that when we return ...
  • ... state is equivalent in vital ways but not

identical

  • This is super cute but ...
  • oversold as the key idea of WLs
  • in my opinion anyway
slide-9
SLIDE 9

Second key idea

  • There can be no work in propagation
  • If a value is deleted, we may do nothing at all
  • Even though the value is in the constraint
  • This is super cute and ...
  • undersold as the key idea of WLs
  • in my opinion anyway
  • A big difference between 0 and O(1)
slide-10
SLIDE 10

Watched Literal Propagation in SAT

  • Remember: Unit propagation fires when all

but one literal is assigned false

  • Idea: If two variables are either unassigned
  • r assigned true, no need to do anything.
  • So just find two variables which satisfy this

condition.

  • If can’t find two, may have to propagate or
slide-11
SLIDE 11

‘Watched Literals’

  • Different from normal triggers (in

Constraints):

  • Able to move around.
  • Not restored on backtrack.
slide-12
SLIDE 12

Propagation Example

  • a ∨ b ∨ c ∨ d

0/1 0/1 0/1 0/1 a b c d

Triggers:

slide-13
SLIDE 13

Propagation Example

  • a assigned false.
  • Update pointer.

0/1 0/1 0/1 a b c d

Triggers:

slide-14
SLIDE 14

Propagation Example

  • a assigned false.
  • Update pointer.

0/1 0/1 0/1 a b c d

Triggers:

slide-15
SLIDE 15

Propagation Example

  • Backtrack. a unassigned.
  • Pointers do not move back

0/1 0/1 0/1 0/1 a b c d

Triggers:

slide-16
SLIDE 16

Propagation Example

  • If b is assigned true,

pointer doesn’t move.

0/1 1 0/1 0/1 a b c d

Triggers:

slide-17
SLIDE 17

Propagation Example

  • If other variables assigned, nothing happens!
  • Can’t emphasise enough ....

0/1 0/1 a b c d

Triggers:

slide-18
SLIDE 18

Propagation Example

  • NOTHING HAPPENS
  • Zero work takes place

0/1 0/1 a b c d

Triggers:

slide-19
SLIDE 19

Propagation Example

  • The unwatched literals a/d cause no work
  • Not even checking there is nothing to do
  • because that would be O(1)

0/1 0/1 a b c d

Triggers:

slide-20
SLIDE 20

Propagation Example

  • The unwatched literals a/d cause no work
  • Because there is no trigger attached to them

0/1 0/1 a b c d

Triggers:

slide-21
SLIDE 21

Propagation Example

  • If we cannot find something new & unassigned

to watch...

  • 0/1

a b c d

Triggers:

slide-22
SLIDE 22

Propagation Example

  • We can set the remaining literal
  • i.e. do unit propagation since this clause is unit

1 a b c d

Triggers:

slide-23
SLIDE 23

Propagation Example

  • Leave triggers where they are!

1 a b c d

Triggers:

slide-24
SLIDE 24

Propagation Example

  • Triggers in the right place to continue after

backtracking.

0/1 0/1 a b c d

Triggers:

slide-25
SLIDE 25

Advantages of WL

  • ZERO cost if a literal not watched.
  • ZERO cost on backtrack.
slide-26
SLIDE 26

Watched Literals in SAT

  • Really come into their own on large clauses
  • probably not worthwhile on 3-SAT, for example
  • E.g. if I have 100 variables in clause
  • I still only need to watch 2
  • and 98% of the time I will do no work
  • As if my problem was 98% smaller!
  • We can handle problems with many large clauses
  • Which links with explanations & learning
  • since those clauses are often big
slide-27
SLIDE 27

Watched Literals in SAT

  • A key technique in modern SAT solvers
  • Sadly, under analysed
  • Everyone uses them
  • Everyone thinks why they work well
  • But few to no experiments showing really

why

slide-28
SLIDE 28

Porting to Constraints

  • Nothing too deep
  • Have trigger on literals instead of variables (or bounds)
  • trigger = event that causes propagator to be called
  • literal = variable/value pair, e.g. x=7
  • Allow triggers to move during search
  • can lead to horrible bugs without huge caution
  • Care in coming up with correct sets of watches
  • for each constraint we want to use
slide-29
SLIDE 29
  • What do we need

to watch?

  • Enough to support

every value

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

slide-30
SLIDE 30

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need

to watch?

  • Enough to support

every value

  • Start with Index
  • M[1] = 1
slide-31
SLIDE 31

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need

to watch?

  • Enough to support

every value

  • Start with Index
  • M[2] = 2
slide-32
SLIDE 32

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need

to watch?

  • Enough to support

every value

  • Start with Index
  • M[3] = 3
slide-33
SLIDE 33

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need

to watch?

  • Enough to support

every value

  • We’ve supported

every value of Index

  • And 1,2,3 of Result
  • And some of M
slide-34
SLIDE 34

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need

to watch?

  • Enough to support

every value

  • We’ve supported

many values

  • Are we done?
  • Almost ...
slide-35
SLIDE 35

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need

to watch?

  • Enough to support

every value

  • Must support ...
  • Result = 4
slide-36
SLIDE 36

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need

to watch?

  • Enough to support

every value

  • Must support ...
  • Result = 4
  • M[2] = 4
slide-37
SLIDE 37

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need to

watch?

  • Enough to support

every value

  • We’ve supported every

value of Index

  • And Result
  • And some of M
slide-38
SLIDE 38

Element Example

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • What do we need to

watch?

  • Enough to support

every value

  • We’ve supported every

value of Index

  • And Result
  • And ALL of M
slide-39
SLIDE 39

All of M?

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

  • How have we

supported all of M?

  • Many values are

unwatched

  • M[Index] = Result
  • While there’s two

values of Index ...

  • All values of M are

possible

slide-40
SLIDE 40

Watching literals...

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

  • What happens

when literals get deleted?

slide-41
SLIDE 41

Watching literals...

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

  • What happens when

literals get deleted?

  • Nothing ...
  • ... for supports where all

watched literals still there

  • even though domain of

every variable involved has changed

slide-42
SLIDE 42

Watching literals...

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

  • What happens when

literals get deleted?

  • Nothing ...
  • ... if the literals were

not watched

  • Huge difference

between Nothing and O(1)

slide-43
SLIDE 43

Watching literals...

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

  • What happens

when literals get deleted?

slide-44
SLIDE 44

Watching literals...

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

  • What happens when

literals get deleted?

  • Very little ...
  • if values being supported

have been deleted

  • We don’t even move

watches

  • when we backtrack they

will come back to life

slide-45
SLIDE 45

Watching literals...

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

  • What happens when

literals get deleted?

  • Real work ...
  • ... If deleted literal was

watching active support

  • ... we must find new

support (watches)

  • r we will remove values
slide-46
SLIDE 46
  • Result = 2?

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

slide-47
SLIDE 47
  • Result = 2?
  • None of three

possible ways work ...

  • ... i.e. provide new

watches

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

slide-48
SLIDE 48
  • Result = 2?
  • None of three

possible ways work

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

slide-49
SLIDE 49
  • Result = 2?
  • None of three

possible ways work

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

slide-50
SLIDE 50
  • Result = 2?
  • None of three

possible ways work

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

slide-51
SLIDE 51
  • Result = 2?
  • None of three

possible ways work

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

2 4

slide-52
SLIDE 52
  • Remove 2 from

domain of Result

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

4

slide-53
SLIDE 53

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

4

  • Remove 2 from

domain of Result

slide-54
SLIDE 54

Watching literals...

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

4

  • Index = 1?
slide-55
SLIDE 55

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

4

  • Index = 1?
  • No.
  • No value of M[1] is

the same as a value

  • f Result.
slide-56
SLIDE 56

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

4

  • Index = 1?
  • No.
  • No value of M[1] is

the same as a value

  • f Result.
slide-57
SLIDE 57

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

4

  • Index = 1?
  • No.
  • No value of M[1] is

the same as a value

  • f Result.
slide-58
SLIDE 58

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

1 2

Result

4

  • Index = 1?
  • No.
  • Remove 1 from

domain of Index

slide-59
SLIDE 59

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

2

Result

4

  • Index = 1?
  • No.
  • Remove 1 from

domain of Index

slide-60
SLIDE 60

Element Example

M1 M2 M3

1 3 1 3 4 1 2 3 4

Index

2

Result

4

  • Index = 1?
  • No.
  • Remove 1 from

domain of Index

slide-61
SLIDE 61

Key advantage

  • If M is vector of size m
  • so Index domain is size m
  • And M[i], Result have domain size n
  • Then we need to watch O(m+n) literals
  • one for each value of Index, Result
  • But there are O(mn) literals in M
  • so we often do nothing
  • Best way to propagate GAC for element

M1 M2 M3

1 2 3 4 1 2 3 4 1 2 3 4

Index

1 2 3

Result

1 2 3 4

slide-62
SLIDE 62

Key disadvantage

  • Fairly heavyweight infrastructure
  • for operations right in the inner loop of

the solver

  • Only worthwhile if we win big
  • So not if we end up watching most literals
  • Can be faster not to do GAC for element
slide-63
SLIDE 63

Another advantage

  • We can win on space in search
  • which can be critical if search is big
  • and data structures are big
  • Because we don’t have to backtrack triggers
  • the constraint need put nothing on the backtrack stack
  • memory required for current state of triggers
  • also covers all previous states on this branch
  • i.e. space used by moved triggers reclaimable immediately
  • This can be a bigger issue than it sounds
slide-64
SLIDE 64

Another Disadvantage

  • Constraints get less state, because search

may be deeper or higher than when last called.

  • Often leads to theoretically worse

behaviour.

  • Though in practice this doesn’t often

matter much

slide-65
SLIDE 65

Looping Example

  • If triggers backtrack, there is no need to ever

loop around from d back to a, as one pass is enough.

0/1 0/1 0/1 0/1 a b c d

Triggers:

slide-66
SLIDE 66

My story about Tom Kelsey

0 0 2 2 2 2 2 7 7 7 0 0 2 2 2 2 3 7 7 7 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 2 2 2 2 2 2 2 2 5 5 2 2 2 2 2 3 3 3 5 5 2 2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 5 5 2 2 2 2 3 3 2 3 4 4 2 2 2 4 4 2 4 2

  • An example of a semigroup
  • mathematicians study these
  • various algebraic

constraints

  • Enumerated by Minion
  • Distler/Kelsey/Kotthoff
  • 72.9 CPU years
  • 50,000 found per CPU

second

slide-67
SLIDE 67

Not a panacea

  • I find WL’s in CP super cool and fun
  • and sometimes much faster
  • But they are not a universal cure
  • Typically use in constraint which is
  • not too tight (lots of allowed tuples)
  • lots of cases where not all vars in support
  • Part of a mixed system of triggers