TAOCP 7.2.2.1 Exercise 412

Let the slitherlink grid have integer lattice vertices and unit edges between adjacent vertices.

Section 7.2.2.1: Dancing Links

Exercise 412. ▶ [22] [22] A "weak solution" to a slitherlink diagram is a set of edges that obeys the numeric constraints, and touches every vertex of the grid either twice or not at all; but it may form arbitrarily many loops. For example, the diagram of exercise 410(i) has six weak solutions, three of which are shown in 410(iii), (iv), and (v).

Show that there's a nice way to obtain all the weak solutions of a given diagram, by formulating a suitable XCC problem. Hint: Think of the edges as constructed from tiles centered at the vertices, and use even/odd coordinates as in answer 133.

Verified: no
Solve time: 1m23s


Solution

Let the slitherlink grid have integer lattice vertices and unit edges between adjacent vertices. A weak solution is a set $S$ of edges such that every cell constraint is satisfied and every vertex is incident with either $0$ or $2$ edges of $S$.

We construct an XCC instance whose solutions are in bijection with weak solutions.

Each grid edge $e$ is split into two half-edge items, $e^{(u)}$ and $e^{(v)}$, one for each endpoint $u$ and $v$. These half-edge items are primary items. A choice of an edge must cover both of its half-edge items, forcing consistency that the edge is either selected globally or not selected at all.

For each cell $C$ with clue $k$, let $\partial C = {e_1,e_2,e_3,e_4}$ be its four boundary edges (fewer on the outer boundary, treated in the same way). We introduce a primary item $C^{(k)}$ representing the requirement that exactly $k$ of the boundary edges are chosen.

For each vertex $v$, let $E(v)$ be the set of incident edges. We introduce a secondary item $v$ whose constraint enforces that the number of selected incident edges is either $0$ or $2$.

Each edge $e = (u,v)$ gives rise to an option that selects both half-edge items $e^{(u)}$ and $e^{(v)}$, and also participates in the cell constraints of the two cells (one or two) that contain $e$ on their boundary. Thus each edge-option includes the corresponding $C^{(k)}$ items for all cells $C$ incident with $e$.

To enforce the vertex condition, we introduce, for each vertex $v$, auxiliary pairing options. For every unordered pair ${e_i,e_j} \subseteq E(v)$ of distinct edges incident with $v$, we create an option that includes the vertex item $v$ together with the two half-edge items $e_i^{(v)}$ and $e_j^{(v)}$. In addition, we include a null option at $v$ containing only the item $v$, representing the choice of no incident edges.

Each vertex item $v$ is thereby covered either by the null option or by exactly one pairing option. In the first case no half-edge items at $v$ are covered, so no incident edge is selected at $v$. In the second case exactly two half-edge items at $v$ are covered, so exactly two incident edges are selected at $v$.

Each edge half-item $e^{(v)}$ must be covered exactly once in the XCC solution, because it is a primary item. Hence an edge can be chosen only if both of its endpoints select pairing options that include it. Since each vertex selects at most one pairing option, no vertex can use more than two incident edges, and consistency across endpoints forces each selected edge to appear at both endpoints.

Each cell item $C^{(k)}$ is also a primary item. The constraint that it is covered exactly once enforces that exactly $k$ of its boundary edges are selected.

Any selection of edge-options and vertex-options satisfying all XCC constraints yields a subgraph in which each vertex has degree $0$ or $2$ and each cell constraint is satisfied. Conversely, any weak slitherlink solution determines, for each vertex of degree $2$, a unique pairing option, and for each isolated vertex the null option, together with exactly those edge-options corresponding to selected edges. This establishes a bijection between XCC solutions and weak solutions.

This completes the construction. ∎