Thursday, September 21, 2017

The von Koch conjecture

Helge von Koch.jpg
Helge von Koch (1870-1924)

Consider a tree graph \(G=(V,E)\) with \(n\) nodes and \(n-1\) arcs. We can label the nodes with unique numbers \(1,\dots,n\) and the arcs with unique numbers \(1,\dots,n-1\) such that each arc has a label equal to the (absolute value) of difference of the labels of the attached nodes. This is also called “Graceful Labeling” [1].

Here is a picture from [2]:

enter image description here

We see that:

  • Each node has a unique label between 1 and 7 (the black numbers),
  • Each arc has a unique label between 1 and 6 (the red numbers),
  • Each arc has a label value equal to the difference in the labels of the associated nodes.

In [3] an interesting MIP formulation is proposed to find such a graceful labeling. There is no objective, i.e. we just look for a feasible solution. The uniqueness of node and arc labels is established by using an assignment block using binary variables (i.e. constraints we recognize from an assignment problem). A formulation can look like:

\[ \bbox[lightcyan,10px,border:3px solid darkblue]{ \begin{align}
\text{Node labels}\\&\sum_i x_{i,v} = 1\>\>\forall v&&\text{assignments of node labels}\\
&\sum_v x_{i,v} = 1 \>\>\forall i\\
&v^x_i  = \sum_v v \cdot x_{i,v}&&\text{value of node labels}\\
\hline
\text{Arc labels}\\&\sum_{(i,j)\in E} y_{i,j,e} = 1\>\forall e&&\text{assignment of arc labels}\\
&\sum_e  y_{i,j,e} = 1 \>\>\forall (i,j)\in E\\
&v^y_{i,j}  = \sum_e e \cdot y_{i,j,e}&&\text{value of arc labels}\\
\hline
\text{Relate arc/node}\\&v^y_{i,j} = | v^x_i - v^x_j | \>\>\forall (i,j)\in E&&\text{absolute value}&\\
\hline
\text{Variables}\\&x_{i,v} \in \{0,1\}&&\text{assign label $v$ to node $i$} \\
&y_{i,j,e} \in \{0,1\}&&\text{assign label $e$ to arc $(i,j)$}\\
&v^x_i \in \{1,\dots,n\}&&\text{value of node labels}\\
&v^y_{i,j} \in \{1,\dots,n-1\}&&\text{value of arc labels}
\end{align}} \]

It makes sense to form the set \(E\) only with arcs \(i<j\) to prevent duplication (if we have an arc \(a \rightarrow b\) we don’t want to check also \(b \rightarrow a\)).

The absolute value equation still needs to be linearized, which we detail next.

Linearizing the absolute value

A standard formulation for \(y=|x|\) uses “\(y= -x\) or \(y=x\)”, i.e.

\[\begin{align} & –x – \delta M \le y \le –x + \delta M\\
& x –(1-\delta) M \le y \le x + (1-\delta) M\\&\delta \in \{0,1\} \end{align} \]

We can slightly improve, by using:

\[\begin{align} & –x \le y \le –x + \delta M\\
& x \le y \le x + (1-\delta) M\\&\delta \in \{0,1\} \end{align} \]

For our model we can get good values for the big-M's:

\[\begin{align}
&v^y_{i,j} \ge v^x_i - v^x_j\\
&v^y_{i,j} \ge v^x_j - v^x_i\\
&v^y_{i,j} \le v^x_j - v^x_i  + 2 n \delta_{i,j} \\
&v^y_{i,j} \le v^x_j - v^x_j  + 2 n (1-\delta_{i,j}) \\
& \delta_{i,j} \in \{0,1\}
\end{align}\]

This is the formulation presented in [3]. The solution is not unique. I see:

----     74 VARIABLE vx.L  node labels

a 7,    b 1,    c 4,    d 2,    e 5,    f 3,    g 6


----     74 VARIABLE vy.L  arc labels

            b           c           d           e           f           g

a           6                       5                                   1
b                       3                       4
e                                                           2

This is different from the solution in the picture.

Alternatives?

It seems tempting to try using an alternative approach to the absolute value constraint. May be something like:

\[\begin{align}\min\>&\sum_{(i,j)\in E} v^y_{i,j}\\
&v^y_{i,j} \ge v^x_i - v^x_j\\
&v^y_{i,j} \ge v^x_j - v^x_i\end{align}\]

These formulations do not work (in this case the objective is actually constant and does not really drive down the individual \(v^y\)’s).

Enumerate solutions

We already established that the solution is not unique. How many solutions are there for this small example problem?

We can add a simple cut:

\[\sum_{i,v} \alpha_{i,v} x_{i,v} \le n-1\]

where \(\alpha_{i,v}=x^*_{i,v}\)  is a previously found solution. This will forbid this solution to be found again. If we solve again we will either find a new, different solution, or we see the model has become infeasible. In the latter case we can conclude there are no more solutions to be found. 

If we repeat this, we find a surprisingly large number of solutions (I expected to see a dozen or so). Below are the node and arc labels we collected in the solve loop:

----    124 PARAMETER vxall  collected node labels

              a           b           c           d           e           f           g

k1            7           1           4           2           5           3           6
k2            5           7           3           4           1           6           2
k3            1           6           4           5           3           2           7
k4            3           6           2           4           1           7           5
k5            7           3           6           2           5           4           1
k6            1           7           5           4           3           2           6
k7            1           5           2           7           3           4           6
k8            6           2           4           5           7           1           3
k9            7           2           4           3           5           6           1
k10           2           7           5           6           1           4           3
k11           4           7           3           2           1           6           5
k12           3           7           4           2           1           6           5
k13           2           1           6           5           7           3           4
k14           4           7           3           5           1           6           2
k15           7           3           6           1           5           4           2
k16           6           1           3           2           7           4           5
k17           7           2           6           4           3           5           1
k18           5           1           4           3           7           2           6
k19           5           1           4           6           7           2           3
k20           6           7           2           3           1           5           4
k21           1           6           2           4           5           3           7
k22           7           2           6           1           3           5           4
k23           1           6           4           7           3           2           5
k24           1           6           2           7           5           3           4
k25           4           7           2           3           1           5           6
k26           7           1           4           6           5           3           2
k27           7           2           4           1           5           6           3
k28           5           7           3           2           1           6           4
k29           7           1           3           4           5           6           2
k30           1           7           5           6           3           2           4
k31           4           1           5           3           7           2           6
k32           3           7           4           5           1           6           2
k33           1           5           2           6           3           4           7
k34           3           6           2           5           1           7           4
k35           4           1           6           2           7           3           5
k36           2           7           5           3           1           4           6
k37           4           1           5           6           7           2           3
k38           1           7           4           6           3           5           2
k39           6           1           3           5           7           4           2
k40           6           7           2           4           1           5           3
k41           4           7           2           6           1           5           3
k42           6           2           4           3           7           1           5
k43           2           1           6           4           7           3           5
k44           4           1           6           5           7           3           2
k45           7           1           3           2           5           6           4
k46           5           2           6           3           7           1           4
k47           3           1           5           6           7           2           4
k48           5           2           6           4           7           1           3
k49           2           6           4           3           1           7           5
k50           3           1           5           4           7           2           6
k51           1           7           4           2           3           5           6
k52           2           6           4           5           1           7           3


----    124 PARAMETER vyall  collected arc labels

            a.b         a.d         a.g         b.c         b.e         e.f

k1            6           5           1           3           4           2
k2            2           1           3           4           6           5
k3            5           4           6           2           3           1
k4            3           1           2           4           5           6
k5            4           5           6           3           2           1
k6            6           3           5           2           4           1
k7            4           6           5           3           2           1
k8            4           1           3           2           5           6
k9            5           4           6           2           3           1
k10           5           4           1           2           6           3
k11           3           2           1           4           6           5
k12           4           1           2           3           6           5
k13           1           3           2           5           6           4
k14           3           1           2           4           6           5
k15           4           6           5           3           2           1
k16           5           4           1           2           6           3
k17           5           3           6           4           1           2
k18           4           2           1           3           6           5
k19           4           1           2           3           6           5
k20           1           3           2           5           6           4
k21           5           3           6           4           1           2
k22           5           6           3           4           1           2
k23           5           6           4           2           3           1
k24           5           6           3           4           1           2
k25           3           1           2           5           6           4
k26           6           1           5           3           4           2
k27           5           6           4           2           3           1
k28           2           3           1           4           6           5
k29           6           3           5           2           4           1
k30           6           5           3           2           4           1
k31           3           1           2           4           6           5
k32           4           2           1           3           6           5
k33           4           5           6           3           2           1
k34           3           2           1           4           5           6
k35           3           2           1           5           6           4
k36           5           1           4           2           6           3
k37           3           2           1           4           6           5
k38           6           5           1           3           4           2
k39           5           1           4           2           6           3
k40           1           2           3           5           6           4
k41           3           2           1           5           6           4
k42           4           3           1           2           5           6
k43           1           2           3           5           6           4
k44           3           1           2           5           6           4
k45           6           5           3           2           4           1
k46           3           2           1           4           5           6
k47           2           3           1           4           6           5
k48           3           1           2           4           5           6
k49           4           1           3           2           5           6
k50           2           1           3           4           6           5
k51           6           1           5           3           4           2
k52           4           3           1           2           5           6

Note that there are \(7!=5040\) ways to order seven different labels, so from that perspective this is indeed a small subset of feasible node labels.

Instead of doing this solve loop ourselves we can also use the Solution Pool technology available in some solvers such as Cplex and Gurobi. This automates this loop (and does it way smarter and more efficient).

References
  1. Graceful Labeling, https://en.wikipedia.org/wiki/Graceful_labeling
  2. The von Koch conjecture, https://codegolf.stackexchange.com/questions/119263/the-von-koch-conjecture
  3. Mike Appleby, https://github.com/appleby/graceful-tree
  4. Helge von Koch, https://en.wikipedia.org/wiki/Helge_von_Koch
  5. Barbara M. Smith, Jean-Francois Puget, Constraint Models for graceful graphs, Constraints (2010), vol. 15, pp.64-92, https://link.springer.com/article/10.1007/s10601-009-9071-6. This paper discusses some interesting alternative models when attacking this as a Constraint Programming problem.