Half Reification and Flattening Thibaut Feydy Peter Stuckey Zoltan - - PowerPoint PPT Presentation

half reification and flattening
SMART_READER_LITE
LIVE PREVIEW

Half Reification and Flattening Thibaut Feydy Peter Stuckey Zoltan - - PowerPoint PPT Presentation

Half Reification and Flattening Thibaut Feydy Peter Stuckey Zoltan Somogyi NICTA Members NICTA Partners www.nicta.com.au From imagination to impact Flattening 1 Implementing half reification 2 Results 3 Conclusions 4 2/25 Motivation


slide-1
SLIDE 1

Half Reification and Flattening

Thibaut Feydy Peter Stuckey Zoltan Somogyi

NICTA Members NICTA Partners

www.nicta.com.au From imagination to impact

slide-2
SLIDE 2

1

Flattening

2

Implementing half reification

3

Results

4

Conclusions

2/25

slide-3
SLIDE 3

Motivation

Complex integer and Booleans expressions arise in CP models, CP Solvers handle primitive relations (propagators) Reification and Flattening are the techniques used in CP solvers to handle complex expressions But reification is often overkill ! Reification is not available for many constraints

3/25

slide-4
SLIDE 4

1

Flattening

2

Implementing half reification

3

Results

4

Conclusions

4/25

slide-5
SLIDE 5

Flattening of complex expressions

Models : complex expressions, (partial) functions, nesting. Solvers : primitive constraints implementation (propagators) ⇒ flat relations. ⇒ Complex models are flattened in conjunction of primitives constraints. x ∗ y + 2z = 0 ≡ x ∗ y = xy xy + 2z = 0

5/25

slide-6
SLIDE 6

Reification

A reified constraint b ↔ c associates a thruth value b with a constraint c. x + 2 < y ∨ y + 4 < x ≡    b1 ↔ x + 2 < y b2 ↔ y + 4 < x b1 ∨ b2 bool2int(x = y) < z ≡    bool2int(b, i) i < z b ↔ x = y Reified constraints available for common primitives. Missing for most globals.

6/25

slide-7
SLIDE 7

Flattening and partial functions

x = a[i] ≡ element(i, a, x) array access is a partial function: a = [5, 7, 2], i ∈ [−3, 7] partial functions need to be made safe in reified context: b ∨ x = a[i] ≡                b ∨ b1 b1 ↔ (b2 ∧ b3) b2 ↔ i = i1 b2 ↔ i ∈ 1..3 b3 ↔ x = x1 element(i1, a, x1)

7/25

slide-8
SLIDE 8

Half Reification

The half reification of a constraint c is the constraint b → c. Convention: always use → direction: b ← c ≡ ¬b → ¬c In many case, flattening can be modified to generate half reified constraints. b is the Boolean context of c:

positive : b → c negative : b ← c ≡ ¬b → ¬c reified

8/25

slide-9
SLIDE 9

Flattening with half reified constraints

x + 2 < y ∨ y + 4 < x ≡    b1 ↔ x + 2 < y b2 ↔ y + 4 < x b1 ∨ b2

Half reification:

x + 2 < y ∨ y + 4 < x ≡    b1 → x + 2 < y b2 → y + 4 < x b1 ∨ b2

9/25

slide-10
SLIDE 10

Flattening with half reified constraints

bool2int(x = y) < z ≡    bool2int(b, i) i < z b ↔ x = y

Half reification:

bool2int(x = y) < z ≡    bool2int(b, i) i < z ¬b → x = y

10/25

slide-11
SLIDE 11

The relational semantic for free

b ∨ x = a[i] ≡                b ∨ b1 b1 ↔ (b2 ∧ b3) b2 ↔ i = i1 b2 ↔ i ∈ 1..3 b3 ↔ x = x1 element(i1, a, x1)

Half reification:

b ∨ x = a[i] ≡ b ∨ b1 b1 → element(i, a, x)

11/25

slide-12
SLIDE 12

Full reification as decomposition

b ↔ c ≡ b → c ¬b → ¬c

No Loss of Propagation!

Informally : If b unfixed, both propagates when c or ¬c is infered. If b fixed, both propagates c or ¬c.

12/25

slide-13
SLIDE 13

1

Flattening

2

Implementing half reification

3

Results

4

Conclusions

13/25

slide-14
SLIDE 14

Propagators implementation

A propagator propc for a constraint c is defined by: solvedc : DOM → {true, false}. unsatc : DOM → {true, false}. prunec : DOM → DOM′ ⊆ DOM. eventsc : a set of events which wakes up the propagator. if solvedc(DOM): kill propc. if unsatc(DOM): fails. prunec(DOM).

14/25

slide-15
SLIDE 15

Generic reification implementation

propb↔c(DOM) :

if b = true: prop(c, DOM) if b = false: prop¬c(DOM) if b = undecided :

if unsatc(DOM): b := false, kill propb↔c. if unsat¬c(DOM): b := true, kill propb↔c

eventsb↔c = eventsc ∪ events¬c ∪ fix(b) ⇒ works if primitive is negatable (negated primitive exists) ⇒ most global constraints cannot be negated

15/25

slide-16
SLIDE 16

Generic half reification implementation

propb→c(DOM) :

if b = true: propc(DOM) if b = false: kill propb→c if b = unknown:

if unsatc(DOM) : b := false, kill propb→c if solvedc(DOM) : kill propb→c.

eventsb→c = eventsc ∪ fix(b)

16/25

slide-17
SLIDE 17

Reified vs Half Reified constraints: Example

Linear disequality :

  • aixi = c

Wakes up on fix(xi). At most 1 wake-up per variable down a branch. Reified equality : ¬b ↔

  • aixi = c

Wakes up on fix(b) ∪ bnd(xi). Half reified disequality : b →

  • aixi = c

Wakes up on {fix(b)} ∪ fix(xi). At most 1 wake-up per variable down a branch.

17/25

slide-18
SLIDE 18

Reified vs Half Reified constraints: Example

Linear disequality :

  • aixi = c

Linear cost down a branch Reified equality : ¬b ↔

  • aixi = c

Linear cost per propagation Half reified disequality : b →

  • aixi = c

Linear cost down a branch.

17/25

slide-19
SLIDE 19

All functionalities required are part of a non-reified propagator, Same events that the non reified propagator (plus the context Boolean), If b = true, same as non-reified propagator. No overhead if templates/partial evaluation Works for global constraints !

18/25

slide-20
SLIDE 20

Revised Flattening

Observation : the propagator for l → c can be killed as soon as l is false. ⇒ Add additional constraints to fix introduced Booleans earlier. b ∨ c1 ∨ c2 ≡            b ∨ b1 ∨ b2 b1 → c1 b2 → c2 ¬b ∨ ¬b1 ¬b ∨ ¬b2 c1 ∨ c2 ≡ b1 → c1 ¬b1 → c2

19/25

slide-21
SLIDE 21

1

Flattening

2

Implementing half reification

3

Results

4

Conclusions

20/25

slide-22
SLIDE 22

Results

QCP Max

Quasi Group Completion with soft all-different half and full use decomposition, half-g uses global alldifferent FD, FD + Explanations : same solver with/without lazy clause generation

FD FD + Explanations Inst. full half half-g full half half-g qm10 20 14 20 14 20 14 15 15 15 qm15 205 6 180 7 174 7 2 15 1 15 1 15 qm20 300 289 1 286 1 116 11 127 10 114 10

Table: Avg. times in seconds / Solved instances, 300s timeouts

21/25

slide-23
SLIDE 23

Results

Prize collecting paths

Collect prizes along a path, maximizing total profit, Each node visited at most once, partial element constraints, ext uses a modified model to avoid partiality : extended arrays.

FD FD + Explanations full half ext full half ext 18 2 10 1 10 1 10 1 10 10 10 20 5 10 4 10 4 10 1 10 1 10 1 10 24 46 10 34 10 40 10 7 10 5 10 6 10 25 66 10 51 10 57 10 10 10 7 10 8 10 28 255 5 214 8 241 6 38 10 23 10 35 10 30 286 1 281 2 284 1 100 10 61 10 92 10 32 300 297 1 300 230 5 164 10 215 8

Table: Avg. times in seconds / Solved instances, 300s timeouts

22/25

slide-24
SLIDE 24

Results

Resource Constrained Project Scheduling Problem (RCPSP)

cumulative constraint time decomposition linear inequality over Boolean expressions half reified difference logic

  • i∈tasks bool2int(starti <= t ∧ t < starti + di) ∗ ri <= rc

FD FD + Explanations Instances full half full half BL x40 277.2 5 269.3 5 17.1 39 15.4 39 J30 x480 116.1 300 114.3 304 16.9 463 12.9 468

Table: Avg. times in seconds / Solved instances, 300s timeouts

23/25

slide-25
SLIDE 25

1

Flattening

2

Implementing half reification

3

Results

4

Conclusions

24/25

slide-26
SLIDE 26

Conclusions

Simple ! Given a constraint implementation, half reification for free, Implements relational semantic, ⇒ easier flattening, faster propagation Less expensive to propagate that full reification, Allows using global constraints in positive context ⇒ soft global constraints Fully reified propagators mostly unnecessary. ⇒ less code to write and maintain

25/25

slide-27
SLIDE 27

Conclusions

Simple ! Given a constraint implementation, half reification for free, Implements relational semantic, ⇒ easier flattening, faster propagation Less expensive to propagate that full reification, Allows using global constraints in positive context ⇒ soft global constraints Fully reified propagators mostly unnecessary. ⇒ less code to write and maintain

Thank you.

25/25