Specialised (user defined) constraints in JChoco 2 examples: max and subtour elimination
Consider the following contraint This can be implemented in JChoco using primitives as follows
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 bound sup: upper bound instantiate initiation removal of value V[0] = max(v[1],v[2],…,v[n-1])
A demo V[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 But this aint enough “single successor” model of a graph Limits what kind of graph can be modelled out-degree of 1
The single successor model NOT A TOUR! We need subtour elimination
Associate with each variable next[i] the following reversible variables When making an instantiation next[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!
next[1] = 5 s[1] = 0 e[0] = 1 e[5] = 7 s[7] = e[8] = 6 s[6] = 8
e[0] = 7 s[7] = e[8] = 6 s[6] = 8
e[0] = 7 s[7] = 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?
Warnsdorff's rule
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?