
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]:

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} |
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}\] |
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
b c d e f g a 6 5 1 |
Alternative formulations
We can model the absolute value \(v^y_{i,j} = | v^x_i - v^x_j |\) slightly differently by introducing an objective:
| \[\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}\] |
This will save us a number of binary variables \(\delta\). This is a more standard formulation.
An alternative alternative is to use variable splitting:
| \[\begin{align} \min & \sum_{(i,j)\in E} v^y_{i,j}\\ &v^y_{i,j} = w^+_{i,j}+w^-_{i,j}\\ &w^+_{i,j} - w^-_{i,j}= v^x_i - v^x_j\\ &w^+_{i,j}, w^-_{i,j}\ge 0 \end{align}\] |
Note: we should check afterwards if the correct absolute value was found (if not then the conjecture does not hold).
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. Note: if we used one of the alternative approaches, I suspect we may see the objective deteriorate instead of the model just becoming infeasible, so we would need to keep track of that.
If we repeat this, we find a surprisingly large number of solutions. Below are the node labels we collected in the solve loop:
---- 119 PARAMETER vxall collected node labels a b c d e f g k1 7 1 4 2 5 3 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
- Graceful Labeling, https://en.wikipedia.org/wiki/Graceful_labeling
- The von Koch conjecture, https://codegolf.stackexchange.com/questions/119263/the-von-koch-conjecture
- Mike Appleby, https://github.com/appleby/graceful-tree
- Helge von Koch, https://en.wikipedia.org/wiki/Helge_von_Koch