Specialised (user defined) constraints in JChoco 2 examples: max and subtour elimination

Preview:

Citation preview

Specialised (user defined) constraints in JChoco

2 examples: max and subtour elimination

Consider the following contraint

),,,max( 110 nvvvx

This can be implemented in JChoco using primitives as follows

)(:),,max( cxbxaxcxbxaxcbax

Due to Chris Unsworth

Could I define my own constraint to do this?

Why would I want to do that?

Possibly:• more compact• faster• more propagation

Define a constraint called Max that extends AbstractLargeIntConstraint

V[0] = max(v[1],v[2],…,v[n-1])

Methods to be implemented

inf: lower boundsup: upper bound

instantiate

initiation

removal of value

V[0] = max(v[1],v[2],…,v[n-1])

A demoV[0] = max(v[1],v[2],…,v[n-1])

Cart before the horse?

Note: output always has a 4 or a 5 in it

V[0] = max(v[1],v[2],…,v[n-1])

Backtrackable Variables(Stored*)

We haven’t used them yet, but ….

Small TSP’s

The single successor model

An array of n variables

}1..0{ nnexti

iji citycityjnext followsy immediatel

)(nextntallDiffere

But this aint enough

“single successor” model of a graphLimits what kind of graph can be modelled• out-degree of 1

The single successor model }1..0{ nnexti

iji citycityjnext followsy immediatel )(nextntallDiffere

1 2 3 0 5 6 7 4

0 1 72 3 4 5 6

NOT A TOUR!

We need subtour elimination

Associate with each variable next[i] the following reversible variables

i involves path that theoflength the

i involves path that theof end the

i involves path that theofstart the

i

i

i

l

e

s

When making an instantiationnext[i] = j

• We now join the path that ends in i to path that starts with j• If the path involves less that n vertices/cities

• next[e[j]] != s[i]• i.e. we cannot close that loop!

Yikes! Show me a picture!

0

3

2

1

5

4

7

next[1] = 5

s[1] = 0

e[0] = 1

e[5] = 7

s[7] = 5

8

6

e[8] = 6

s[6] = 8

0

3

2

1

5

4

7

e[0] = 7

s[7] = 0

8

6

e[8] = 6

s[6] = 8

0

3

2

1

5

4

7

e[0] = 7

s[7] = 0

8

6

e[8] = 6

s[6] = 8

next[7] ≠ 0

Otherwise we have a subtour/loop

This is the “propagation” .

Note: this is a constraint that may be used in a richer problem

Example application: knight’s tour

Wot! Show me a picture!

Is there a dvo heuristic for this?

Is there an alternative model for this?

A knights-graph with a degree sequence 2* that is connected i.e. adjacency matrix model of the graph

So?

• Jean-Francois Puget called this “the glass box”• Note how this fits with AC5• Note that we need to consider state and backtracking• Why bother?