Next Article in Journal
An Online Algorithm for Lightweight Grammar-Based Compression
Next Article in Special Issue
A Polynomial-Time Reduction from the 3SAT Problem to the Generalized String Puzzle Problem
Previous Article in Journal / Special Issue
An Integer Programming Approach to Solving Tantrix on Fixed Boards
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Finding All Solutions and Instances of Numberlink and Slitherlink by ZDDs

1
Graduate School of Informatics, Kyoto University, Kyoto, 606-8501, Japan
2
ERATO MINATO Project, Japan Science and Technology Agency, Kitaku North 14, West 9, Sapporo, 060-0814, Hokkaido, Japan
3
Graduate School of Information Science and Technology, Hokkaido University, Kitaku North 14, West 9, Sapporo, 060-0814, Hokkaido, Japan
*
Author to whom correspondence should be addressed.
Algorithms 2012, 5(2), 176-213; https://0-doi-org.brum.beds.ac.uk/10.3390/a5020176
Submission received: 16 November 2011 / Revised: 29 February 2012 / Accepted: 19 March 2012 / Published: 5 April 2012
(This article belongs to the Special Issue Puzzle/Game Algorithms)

Abstract

:
Link puzzles involve finding paths or a cycle in a grid that satisfy given local and global properties. This paper proposes algorithms that enumerate solutions and instances of two link puzzles, Slitherlink and Numberlink, by zero-suppressed binary decision diagrams (ZDDs). A ZDD is a compact data structure for a family of sets provided with a rich family of set operations, by which, for example, one can easily extract a subfamily satisfying a desired property. Thanks to the nature of ZDDs, our algorithms offer a tool to assist users to design instances of those link puzzles.

1. Introduction

Link puzzles, for example Slitherlink, Numberlink, Masyu, etc., are logic puzzles that involve finding paths or a cycle in a grid that satisfy given local and global properties. This paper focuses on two simple link puzzles, Numberlink and Slitherlink, amongst others.
Numberlink is played on a grid where the rules are below [1].
  • Connect pairs of the same numbers with a continuous line.
  • Lines go through the center of the cells, horizontally, vertically, or changing direction, and never twice through the same cell.
  • Lines cannot cross, branch off, or go through the cells with numbers.
 Figure 1 describes an instance of Numberlink. Numberlink is known to be NP-complete [2,3,4]. Numberlink is also studied as a model of VLSI layout design [5].
Slitherlink is played on a grid of lattice dots where we draw a loop satisfying below [1].
  • Connect adjacent dots with vertical or horizontal lines.
  • A single loop is formed with no crossing or branches.
  • The numbers indicate how many lines surround it, while empty cells may be surrounded by any number of lines.
We describe an instance of Slitherlink in  Figure 2. Slitherlink is known to be NP-complete [6,7].
Link puzzles have been popularized by a Japanese publisher Nikoli and many puzzle designers are trying to produce good and interesting instances. The least common criterion on instances to be good is to admit exactly one solution, but what should be good and interesting is quite a subjective issue to respective designers. The complexity barrier suggests difficulties in the instance design.
On the other hand, as is usually the case for logic puzzles, computer scientists and programmers have been proposed several automatic solvers targeting those link puzzles. Sugar [8] is a SAT based constraint solver which is provided with formulation of Numberlink and Slitherlink. While it is often the case that a solution for an instance of Numberlink is found just by inspiration, many local solution methods for Slitherlink are known. Most Slitherlink solvers employ such methods [9,10,11].
Moreover, there are some attempts to automatically generate instances of Slitherlink. Shirai’s algorithm [10] starts from a grid graph with no numbers, which admits many solutions, and repeatedly puts a random number into a random cell one by one until the obtained instance admits a unique solution. The opposite approached has been proposed by Shirai et al. [10] and Wan [11]. Their algorithm takes a cycle, which is a predetermined solution, as input and starts from a grid whose cells are all fulfilled by the numbers compatible with the solution. The algorithm then repeatedly removes the number in a random cell one by one until the obtained instance admits an unexpected solution. The algorithm outputs the instance obtained just before removing the last number.
Our contribution is located in this line of research. We propose solution and instance enumeration algorithms for Numberlink and Slitherlink. Unlike existing algorithms, ours output all the qualified solutions/instances at once in the form of a zero-suppressed binary decision diagram (ZDD). A ZDD is a compressed data structure for representing and manipulating families of sets [12]. Recently, Knuth [13, exercise 225] has proposed an algorithm, called Simpath, that constructs a ZDD representing all s-t paths on a given graph and two vertices s and t, where a path is identified with the set of edges constituting the path. If an instance of Numberlink has only one pair of numbers in a grid, Simpath gives all solutions to it. Knuth has also proposed a modification of Simpath that enumerates all single cycles on an input graph in the form of a ZDD. Recall that to be a cycle is a necessary condition to be a solution for Slitherlink. Our solvers for the link puzzles construct a ZDD representing solutions in the manner of Simpath with taking the constraints from the problem instance into account. By the nature of enumeration, one can immediately decide whether an instance admits exactly one solution.
ZDDs can represent families of sets in a small space, yet an even more important and widely appreciated virtue of ZDDs is that one can quite efficiently perform fundamental mathematical operations on families of sets over ZDDs, like union, intersection, etc. Our algorithms for generating instances of the link puzzles apply the virtue of ZDDs. Our method based on ZDDs offers users flexible means to design puzzle instances. For example, puzzle designers can extract some specific kind of instances from the whole which they think “interesting” by those set operations over ZDDs.
This paper is organized as follows. Formal definitions of ZDDs, Numberlink and Slitherlink are given in Section 2. Section 3 introduces a variant of Simpath that enumerates all path matchings over a graph, on which other algorithms of ours are based. Our Numberlink solver is presented in Section 4 and Numberlink instance enumeration algorithm is proposed in Section 5. On the other hand, our Slitherlink solver and instance enumeration algorithm are presented in Section 6 and Section 7, respectively. We also show experimental results on these algorithms in Section 8, where we compare the performance of known solving algorithms and ours. Moreover, we demonstrate how our method may help puzzle designers through presenting visually attractive instances of Slitherlink obtained by our algorithm. We then conclude the paper in Section 9.

2. Preliminaries

2.1. Zero-Suppressed Binary Decision Diagrams

A zero-suppressed binary decision diagram, ZDD for short, represents a family of sets over a universal set E whose elements are linearly ordered [12]. We index the elements of E as e 1 , , e | E | where we write e i e j if and only if i j . A ZDD is defined to be a labeled directed acyclic graph that satisfies the following properties.
  • There is only one node with indegree 0, called the root node.
  • There are just two nodes 0 and 1 with outdegree 0, called the 0-terminal and 1-terminal.
  • Each node except terminals has just 2 outgoing arcs, which are labeled by 0 and 1 and called the 0-arc and 1-arc, respectively. We call the node pointed by the j-arc of a node n the j-child of n.
  • Each node n except for the terminals is labeled by an element of E.
  • The label of a non-terminal node is strictly smaller than those of its children.
If a node n is the j-child of another node n , we call n a j-parent of n for j { 0 , 1 } . We say that a path from the root node of a ZDD Z is valid if it ends in a node which is not 0 . To each valid path π we assign a set Z ( π ) E by
Z ( π ) = { e j the 1 - arc of a node labeled with e j appears in π }
By representing a path from the root node of a ZDD by a sequence of 0 and 1, which we call a 0 , 1 -sequence, we have an alternative inductive definition of the set:
Z ( π · 0 ) = Z ( π ) Z ( π · 1 ) = Z ( π ) { e }
where e is the label of the node in which π ends. Each node n 0 is assigned a set Z ( n ) 2 E defined by
Z ( n ) = { Z ( π ) a valid   path π ends in n }
An equivalent inductive definition is given by
Z ( n ) = { S S Z ( n ) for some 0 - parent n of n } { S { e } S Z ( n ) for some 1 - parent n of n such that n is labeled with e }
The family of sets that a ZDD represents is defined to be Z ( 1 ) . Figure 3 shows an example of a ZDD.
A ZDD is said to be reduced if
  • there is no distinct nodes that have the same label, 0-child and 1-child,
  • there is no node whose 1-child is 0 .
It is known that every ZDD admits a unique reduced one that represents the same family of sets. Moreover the number of nodes of a ZDD is minimum amongst ZDDs representing the same family if and only if it is reduced. A linear-time algorithm that reduces a ZDD can be found in [13, pp. 84–85, algorithm R].
A (reduced) ZDD can represent a family of sets in a compact way by letting multiple sets in the family share some subgraphs of the ZDD. If sets in the family have some “regular” structures, the size of the ZDD can be logarithmically smaller than the sum of the cardinalities of the sets in it. An even more important and widely appreciated virtue of ZDDs is that one can efficiently perform fundamental mathematical operations on families of sets over ZDDs, like union, intersection, etc. The efficiency depends on the size of the ZDDs rather than the cardinality of the sets in the target families. Some packages of implementation of ZDDs are provided to users of different purposes, where for given two ZDDs representing families of sets A and B, it can compute the ZDD for A B , A B , A B , A B and so on. For e E , it can compute the ZDD for { S { e } S A } , { S { e } S A and e S } , { S S A and e S }  etc. Knuth [13] has discussed further operations for families of sets, which enable us to extract maximal elements { S A ¬ T A , S T } , minimal elements { S A ¬ T A , T S } among others. For more details of ZDDs, readers are referred to [12,13], for example.

2.2. Undirected Graphs

The link puzzles concerned in this paper are played on undirected graphs. This paper uses ZDDs to represent subgraphs of graphs of puzzle instances. To avoid confusion among objects of those two kinds of graphs simultaneously in concern, we reserve words “nodes” and “arcs” for ZDDs, while we call the corresponding notions for graphs of puzzle instances “vertices” and “edges”.
An undirected graph is a pair G = ( V , E ) where V is a set of vertices and E 2 V is a set of edges, which are sets of exactly two elements of V. An edge e E is said to be incident to  v V if v e . The degree of a vertex v in G is defined by | { e E v e } | , that is, the number of edges incident to v. For an edge set E E , we also define the degree of v in E by | { e E v e } | . A vertex v is isolated if its degree is 0.
A nonempty edge set P = { e 1 , , e | P | } E is called a simple path (or just a path) if there are pairwise distinct vertices v 0 , , v | P | V such that e i = { v i 1 , v i } for i = 1 , , | P | . The path P is also called a v 0 - v | P | path.
A nonempty edge set C = { e 1 , , e | C | } E is called a (simple) cycle if | C | 3 and there are pairwise distinct vertices v 1 , , v | C | V such that e 1 = { v 1 , v | C | } and e i = { v i 1 , v i } for i = 2 , , | C | .
A possibly empty edge set P E is called a path matching if there are simple paths P 1 , , P k with k 0 such that P = 1 i k P i and P i P j = for distinct i , j { 1 , , k } (For a family P of sets over a universal set V, we define P = e P e = { v V v e for some e P } .). We remark that for a path matching P, a way of partitioning P into paths satisfying this definition is unique. We say that P contains a u-v path if one of such paths is a u-v path.
A family T 2 V of sets over V is called a pair matching if T consists of pairwise disjoint sets of size 2.
Lemma 1. 
For a graph G = ( V , E ) , an edge set P E is not a path matching if and only if there is a vertex v P of degree more than 2 in P or there is a subset C P that is a simple cycle.

2.3. Link Puzzles

Definition 2 
(Numberlink). An instance of the Numberlink problem is a pair of a graph (Usually the graph G in an instance is a rectangular grid as described in the introduction, but this paper targets the more general problem described here.) G = ( V , E ) and a pair matching h on V. A path matching on G is said to be a solution of ( G , h ) if and only if it contains u - v paths for all { u , v } h  but no other.
An instance ( G , h ) of the Numberlink problem is said to be good if ( G , h ) admits exactly one solution P and moreover the unique solution P covers every vertex: i.e. P = V .
Theorem 3. 
[2,3,5] For input G and h, deciding whether ( G , h ) admits a solution is NP-complete.
Definition 4 
(Slitherlink). An instance of the Slitherlink problem is a pair of a graph G = ( V , E ) and a partial mapping h : 2 E N such that h ( E ) | E | for all E dom ( h ) , where dom ( h ) denotes the domain of h (Usually G is a grid graph and h ( E ) is defined only when E is a cycle consisting of just four edges.). We call h a hint assignment. A solution of ( G , h ) is a cycle C over G such that h ( E ) = | C E | for all E dom ( h ) . An instance ( G , h ) of the Slitherlink problem is said to be good if ( G , h ) admits exactly one solution.
Theorem 5. 
[14] For input G and h, deciding whether ( G , h ) admits a solution is NP-complete. For input ( G , h ) and a solution C, deciding whether ( G , h ) admits another solution C C is NP-complete.
In this paper, we assume that G is connected on both puzzles.

3. ZDD for Path Matchings

Knuth has proposed an algorithm that constructs a ZDD representing all the s-t paths on a given graph G and two vertices s and t in G, as an answer to Exercise 225 in [13]. Based on Knuth’s algorithm, this section presents an algorithm that constructs in a topdown manner a ZDD Z G representing all the path matchings over a graph G = ( V , E ) . This algorithm prepares for our puzzle solvers.
Let G = ( V , E ) be an undirected graph. The edge set E = { e 1 , , e | E | } is the universal set of Z G , where we have e i e j if and only if i j . We define E e i = { e j E e j e i } . The root node n root of Z G is labeled with e 1 and if a node is labeled with e i then its children are labeled with e i + 1 unless they are terminal nodes, 0 or 1 . By N i we denote the set of nodes with the label e i for i = 1 , , | E | . Hence N 1 is the singleton of the root node n root and N i + 1 consists of the children of nodes in N i . Every valid path ending in 1 has length | E | in Z G . For a 0 , 1 -sequence π , we denote the length of π by | π | . For π with | π | | E | , we define
E ( π ) = { e i E the i th number of π is 1 }
We then have Z G ( π ) = E ( π ) if π is a valid path in Z G . For a valid path π , we let n ( π ) denote the node in which π ends. We have Z G ( n ) = { E ( π ) n ( π ) = n } . The ZDD Z G will be constructed so that
E ( π ) E is a path matching if and only if π is valid   in Z G
Note that every subgraph of a path matching is a path matching.
Our algorithm constructs Z G in a top-down manner. The construction consists of | E | phases, where we create nodes in N i + 1 as children of nodes in N i in the ith phase. Figure 4 illustrates an example of G and Z G , which would help the reader understand our algorithm. We first initialize N i to be empty for all i = 2 , , | E | and N 1 to be the singleton of the root node n root . We create nodes in N i after the upper part of Z G consisting of the nodes in j < i N j and the arcs among them have been constructed for i = 2 , , | E | .
The algorithm stores some topological information of the path matching E ( π ) at the node n = n ( π ) reached by a valid path π . Let | π | = i 1 , where we have n N i and n is labeled by e i unless n = 1 . We assign the node n a function mate n : V e i V { 0 } , which we call a mate function, where V e i = E e i and 0 V . It is determined so that
mate n ( v ) = v if v E ( π ) u if E ( π ) contains a u - v path 0 otherwise
for each v V e i . In other words, mate n ( v ) = v if v has degree 0 in E ( π ) , and mate n ( v ) = 0 if v has degree 2 in E ( π ) . Particularly for the root node n root , we have mate n root ( v ) = v for all v V e 1 ; the set V e 1 is identical to V, since G has no isolated vertices. The domain of a mate function mate n is restricted to V e i , which is the set of vertices to which at least one edge in E e i is incident. We are not interested in the topological information on vertices that we will not visit any more. Note that V e i = V e i + 1 e i . Hereafter we stipulate that V e | E | + 1 denotes the empty set.
In the example of Figure 4, we have V = V e 1 = V e 2 = { p , q , r , s } , V e 3 = e 3 e 4 = { q , r , s } and V e 4 = e 4 = { q , s } . For π = 1 · 1 , E ( π ) = { e 1 , e 2 } is a path matching consisting solely of a q-r path. The domain of the mate function mate n ( π ) is V e 3 = { q , r , s } and mate n ( π ) ( q ) = r , mate n ( π ) ( r ) = q and mate n ( π ) ( s ) = s .
Let us consider the ith phase of our algorithm, where we already have constructed an incomplete ZDD until the nodes in N i . We determine the children of a node n ( π ) N i for a valid path π . The arcs given in this phase correspond to the choice whether or not we pick e i in a path matching. Let n = n ( π ) .
Giving a 0-child to n involves no difficulty. By assumption E ( π ) is a path matching and by definition E ( π · 0 ) = E ( π ) . We create a node n in N i + 1 as the 0-child of n and label n by e i + 1 . That is, n ( π · 0 ) = n . The mate function mate n of n should be identical to mate n except that the domain dom ( mate n ) = V e i + 1 may be smaller than dom ( mate n ) = V e i . In the case where i = | E | , the 0-child of n is 1 .
On the other hand, E ( π · 1 ) E ( π ) and it is not always the case that E ( π · 1 ) is a path matching. If E ( π · 1 ) is not a path matching, the 1-child of n should be 0 . Otherwise, we give a node n with an appropriate mate function as the 1-child of n. We must decide whether E ( π ) { e i } is still a path matching or not. Let e i = { u , v } . We note that u and v are in the domain V e i of mate n . There exist several cases depending on the topology of E ( π ) . Recall that an edge set P E is a path matching if and only if the degree of every node in P is at most 2 and no subset P P is a cycle. In the case where mate n ( u ) = 0 , the degree of u in E ( π ) is 2, so the degree of u will be 3 in E ( π ) { e i } , which is therefore not a path matching. The same holds when mate n ( v ) = 0 . Moreover, if mate n ( u ) = v (equivalently mate n ( v ) = u ), which means that E ( π ) contains a u-v path P u , v E ( π ) , then E ( π ) { e i } contains a simple cycle P u , v { e i } . We say that a mate function m rejects an edge { u , v } if m ( u ) { 0 , v } or m ( v ) { 0 , u } . If mate n rejects e i , then E ( π · 1 ) is not a path matching, hence the 1-child of n should be 0 . On the other hand, if mate n does not reject e i , E ( π ) { e i } is a path matching. So we need to give a node as the 1-child of n. Particularly in the case where i = | E | , the 1-child of n will be 1 . If i < | E | , we create a node n in N i + 1 as the 1-child of n (i.e. n = n ( π · 1 ) ) and assign a function mate n that is consistent with the requirement of Equation (2). Actually one can compute mate n from mate n and e i = { u , v }  by
mate n ( w ) = 0 if w e i = { u , v } and mate n ( w ) w mate n ( v ) if mate n ( w ) = u mate n ( u ) if mate n ( w ) = v mate n ( w ) otherwise
for w dom ( mate n ) = V e i + 1 .
We explain why this is correct. The first case means that w has degree 1 in E ( π ) . Hence, the degree of w e i will be 2 in E ( π ) { e i } (Figure 5(a)). In the second case, mate n ( w ) = u means either that E ( π ) has a w-u path or that w = u and w is isolated in E ( π ) . It is convenient for explanation to regard an isolated vertex t as a t-t path. According to this terminology, E ( π ) contains a w-u path and a v- mate n ( v ) path. Then the edge e i = { u , v } will bridge those paths: E ( π ) { e i } contains a w- mate n ( v ) path (Figure 5(b)). The third case is similar to the second case. If none of those three cases apply, adding e i does not matter for the vertex w. We note that by the assumption, the first three cases are mutually exclusive.
Summarizing the above, by observing mate n , one can determine whether E ( π · 1 ) is a path matching or not. Moreover one can compute both mate n and mate n for the 0-child n and 1-child n of n, respectively, unless they are 0 or 1 . Consequently, if two nodes n 1 and n 2 with the same label have the same mate function, their descendants will constitute subgraphs of exactly the same shape in Z G . This means that such equivalent nodes n 1 and n 2 should be merged before generating children.
Our actual algorithm, shown as Algorithm 1, maintains each node set N i not to contain distinct nodes assigned the same mate function. This is realized by a procedure named GN (short for “getting a node”) which takes two arguments: an edge index i { 1 , , | E | } and a mate function m. GN ( i , m ) returns a node labeled e i and assigned m. If such a node has already been created in N i , that node is returned. Otherwise, we create one in N i and return it. It is conveniently assumed that GN ( | E | + 1 , m ) gives the terminal node 1 . Note that this procedure may update N i .
Algorithm 1: Enumeration of path matchings
Algorithms 05 00176 i001
For a node labeled e i and assigned a mate function m which does not reject e i , the mate function of its 1-child is given by MU ( m , e i ) | V e i + 1 in Algorithm 1, which is determined in the way described in Equation (3). That is, MU (short for “mate update”) takes a mate function m and an edge e i and returns a mate function defined by
MU ( m , e i ) ( w ) = 0 if w e i and m ( w ) w m ( v ) if e i = { v , m ( w ) } m ( w ) otherwise
for each w dom ( m ) . The domain of MU ( m , e i ) is the same as that of m. By MU ( m , e i ) | V e i + 1 we denote the subfunction of MU ( m , e i ) whose domain is restricted to V e i + 1 .
We prove the correctness of Algorithm 1 in Appendix A.

4. Numberlink Solver

This section presents a Numberlink solver, which constructs a ZDD that represents all the solutions for a given instance ( G , h ) of Numberlink. Recall that a solution for an instance ( G , h ) of Numberlink is a path matching that satisfies a property represented by the pair matching h. It is in fact rather easy to modify Algorithm 1 to obtain a Numberlink solver.
Let us consider when we should connect an arc of a node to 0 in addition to the cases we have discussed in Section 3. Suppose that we have chosen edges from { e 1 , , e i } and by picking up other edges from E e i + 1 , we would like to form a solution. Let π be a 0 , 1 -sequence of length i that represents the choice. It is easy to see that if one of the following conditions holds, E ( π ) P cannot be a solution of ( G , h ) for any edge set P E e i + 1 .
  • E ( π ) is not a path matching,
  • there is v h of degree 2 in E ( π ) ,
  • there is v h V e i + 1 of degree 0 in E ( π ) ,
  • there are u , v h such that E ( π ) contains a u-v path and { u , v } h ,
  • there is a vertex v h V e i + 1 of degree 1 in E ( π ) .
Our Numberlink solver, shown as Algorithm 2, constructs a ZDD so that if a path π of length i satisfies one of the above, then (a prefix of) π leads to 0 . While Algorithm 1 connects no 0-arcs to 0 , our Numberlink solver sometimes connects 0-arcs to 0 according to the above conditions. This judgement is realized by observing the mate functions. For a mate function m : V e i V { 0 } and an edge index i, we say that ( m , i , 0 ) is incompatible with h if for some v e i V e i + 1 , one of the following conditions holds.
  • v h and m ( v ) = v ,
  • v h and m ( v ) { 0 , v } .
When ( mate n , i , 0 ) is incompatible with h for n N i , the 0-arc of n should be connected to 0 , since P = E ( π · 0 ) E cannot be a solution for any E E e i + 1 . In the first case, the degree of v h is 0 in P. In the second case, the degree of v h is 1 in P.
Algorithm 2: Numberlink solver
Algorithms 05 00176 i002
We prove the correctness of Algorithm 2 in Appendix B.     
We say that ( m , i , 1 ) is incompatible with h if for e i = { u , v } , one of the following conditions holds.
  • m rejects e i , i.e. m ( v ) { 0 , u } ,
  • v h and m ( v ) v ,
  • m ( u ) , m ( v ) h ( V V e i + 1 ) and { m ( u ) , m ( v ) } h .
When ( mate n , i , 1 ) is incompatible with h for n N i , the 1-arc of n should be connected to 0 , since P = E ( π · 1 ) E cannot be a solution for any E E e i + 1 . In the first case, P is not a path matching. In the second case, v has degree more than 1 in P. In the third case, either P contains a mate n ( u ) - mate n ( v ) path or the degree of mate n ( u ) h or mate n ( v ) h is more than 1 in P.
Remark 6. 
It is obvious that no proper superset of a solution for ( G , h ) can be another solution. One can modify Algorithm 2 so that a path π directly leads to 1 if E ( π ) is a solution. Replace GN by GN h  where
GN h ( i , m ) = 1 if for any u dom ( m ) and v V , we have ( { u , v } h iff m ( u ) = v u ) GN ( i , m ) otherwise
Remark 7. 
An alternative definition of Numberlink requires a solution to cover all the vertices. This constraint drastically shrinks the search space. It is easy to modify our algorithm to obtain only such strict solutions. We say that ( m , i , 0 ) is incompatible with h if it is incompatible in the above sense or there is v V e i V e i + 1 such that m ( v ) = v , which means that v is not covered.

5. Numberlink Instance Enumeration

This section presents an algorithm that enumerates all pair matchings h that give a good instance ( G , h ) of the Numberlink problem for a given graph G. Fixing G, we say that a pair matching h is good if ( G , h ) is a good instance. Let us first consider an easier task, which enumerates all the instances that admit at least one solution. A solution for an instance of the Numberlink problem is a path matching and conversely every path matching P on G consisting of u i - v i simple paths for all  i = 1 , , k is a solution for ( G , h P ) where h P consists of { u i , v i } for all i = 1 , , k . Our instance enumeration algorithm, shown as Algorithm 3, is again based on Algorithm 1, but now what we should enumerate is not edge sets but rather pair matchings. The ZDD Z G output by Algorithm 1 will be a part of the input of Algorithm 3.
For a valid path π in Z G , the corresponding path matching E ( π ) consists of two kinds of simple paths: fixed paths and unfixed paths. Fixed paths are u-v paths where u , v V e | π | + 1 = dom ( mate n ( π ) ) . In other words, every fixed path in E ( π ) will be a constituent of any path matching represented as E ( π · ρ ) (We note that whether a simple path in a path matching E ( π ) is fixed or unfixed depends on π rather than E ( π ) itself. Yet we prefer a concise phrasing relying on the reader’s flexibility and assume that the vertex set in concern is understood.). We note that by definition mate n ( π ) does not tell us whether E ( π ) contains a fixed u-v path. On the other hand, the presence of an unfixed u-v path is observed in the mate function. If a u-v path is unfixed, at least one of u , v is in V e | π | + 1 = dom ( mate n ( π ) ) . Without loss of generality, we assume u dom ( mate n ( π ) ) , where we have mate n ( π ) ( u ) = v . Since u has an incident edge in E e | π | + 1 , the path may be extended so that u has degree 2.
Algorithm 3: Numberlink Generator
Algorithms 05 00176 i003
We prove the correctness of Algorithm 3 in Appendix C.     
Let T ( π ) denote the pair matching corresponding to the ends of fixed paths:
T ( π ) = { { u , v } V E ( π ) contains a u - v path with u , v V e | π | + 1 }
Note that T ( π ) T ( π · ρ ) for any π and ρ as long as E ( π · ρ ) is a path matching. We decorate each node n of the ZDD Z G with the family
S n = { T ( π ) n ( π ) = n }
When a path π ends in 1 in Z G , all the simple paths constituting E ( π ) are fixed. By definition, S 1 will be the family of pair matchings h such that ( G , h ) admits a solution. For different valid paths π and ρ ending in the same node n = n ( π ) = n ( ρ ) , E ( π ) and E ( ρ ) may have different fixed paths, but they share the same unfixed paths. We present an example of T ( π ) and S n in Appendix F.
Let us think about how to compute the family S n of a node n from the pair matching families S n assigned to its parents n . By definition, it is not hard to see that
T ( π · 0 ) T ( π ) = { { u , v } V E ( π · 0 ) contains a u - v path with u e i and u , v V e i + 1 } T ( π · 1 ) T ( π ) = { { u , v } V E ( π · 1 ) contains a u - v path P with e i P and u , v V e i + 1 }
where i = | π | + 1 . Define
Fix ( m , i , 0 ) = { { u , m ( u ) } u e i , m ( u ) { u , 0 } and u , m ( u ) V e i + 1 } Fix ( m , i , 1 ) = { { m ( u ) , m ( v ) } { u , v } = e i and m ( u ) , m ( v ) V e i + 1 }
We now have
T ( π · b ) = T ( π ) Fix ( mate n ( π ) , | π | + 1 , b )
for both b = 0 , 1 . Therefore, for n N i + 1 ,
S n = { S n , b n is a b - parent of n for b { 0 , 1 } } where S n , b = { T Fix ( mate n , i , b ) T S n }
In this way, one can recursively compute S n for all nodes except 0 of Z G .
We would like to extract good ones from S 1 . In addition to S n , we assign each node n another family B n S n such that no pair matching T B n will be expanded to a good one. We construct B n so that
B n = { T ( π 1 ) S n there are distinct valid paths π 1 , π 2 ending in n with T ( π 1 ) = T ( π 2 ) }
{ T ( π ) S n there is a valid path π ending in n with E ( π ) V e | π | + 1 V }
This definition is explained as follows. For the first line Equation (4), suppose that there are distinct valid paths π 1 and π 2 ending in the same node n = n ( π 1 ) = n ( π 2 ) such that T ( π 1 ) = T ( π 2 ) . Then, E ( π 1 · ρ ) is a path matching if and only if so is E ( π 2 · ρ ) for any ρ . Moreover, E ( π 1 · ρ ) consists of u i - v i paths for i = 1 , , k for some k if and only if so does E ( π 2 · ρ ) . That is, the instance ( G , { { u i , v i } i = 1 , , k } ) has two distinct solutions E ( π 1 · ρ ) and E ( π 2 · ρ ) . The second part Equation (5) of the definition of B n is easier. If E ( π ) V e | π | + 1 V , then there is a vertex v V V e i + 1 which has degree 0 in E ( π ) and thus in E ( π · ρ ) for any ρ . If E ( π · ρ ) is a path matching consisting of u i - v i paths for i = 1 , , k for some k, the instance ( G , { { u i , v i } i = 1 , , k } ) has a solution that does not cover all the vertices.
We can compute the family B n of a node n from the pair matching families assigned to its parents according to the definition of B n :
B n = { S n 1 , b 1 S n 2 , b 2 n j is a b j - parent of n for j = 1 , 2 and n 1 n 2 }
{ S n , 0 n is a 0 - parent of n such that mate n ( u ) = u for some u e i V e i + 1 }
{ B n , b n is a b - parent of n } ,
where B n , b = { T Fix ( mate n , i , b ) T B n } for b { 0 , 1 } . The lines Equations (6) and (7) come from Equations (4) and (5), respectively. Suppose that T ( π ) B n ( π ) . Then regardless of whether it is due to Equation (4) or Equation (5), we have T ( π · ρ ) B n ( π · ρ ) for any ρ as long as π · ρ is valid. Those pair matchings are captured by Equation (8).

6. Slitherlink Solver

The goal of this section is to give a Slitherlink solver, which constructs a ZDD that represents all the solutions for a given instance ( G , h ) of Slitherlink. Recall that a solution is a simple cycle that satisfies a property represented by the hint assignment h : 2 E N . As a preparation, we present an algorithm that constructs a ZDD representing all the simple cycles on a given graph G. Actually this algorithm is an answer to Exercise 226 of [13].
Based on the fact that any proper subgraph of a cycle is actually a path matching, it is easy to modify Algorithm 1 so that simple cycles shall be enumerated. We allow vertices to have degree 1 temporarily during the construction, but when we have determined which of the edges incident to a vertex v shall be used, the degree of v must be 0 or 2. In addition, we allow to add an edge e = { u , v } to a path matching E ( π ) if E ( π ) consists solely of a single u-v path: it completes a cycle.
Both conditions are judged by observing the mate functions. We say that a mate function m and an edge e i  form a cycle if for any v in the domain of m,
m ( v ) = u if e i = { u , v } v or 0 if v e i
If mate n and e i form a cycle for n N i , the 1-child of n should be 1 .
We say that ( m , i ) has a fixed end if
m ( v ) { 0 , v } for some v e i V e i + 1
For a valid path π in Z G , if ( mate n ( π ) , | π | ) has a fixed end, E ( π ) E has a vertex of degree 1 for any E E e i + 1 . We say that mdeclines e i if either m rejects e i or ( MU ( m , e i ) , i ) has a fixed end. If mate n declines e i for n N i , the 1-child of n should be 0 .
In addition, since the empty edge set is not a cycle, the corresponding path in our ZDD should end in  0 .
Algorithm 4 constructs a ZDD for representing all the simple cycles on a graph G. We prove the correctness of Algorithm 4 in Appendix D.
Algorithm 4: Enumeration of simple cycles
Algorithms 05 00176 i004
     We are now ready to give our Slitherlink solver, shown as Algorithm 5, based on Algorithm 4.
Algorithm 5: Slitherlink solver
Algorithms 05 00176 i005
Let ( G , h ) be a Slitherlink instance. To ensure that the computed cycle is compatible with the hint assignment h, we assign another function count n : dom ( h ) N to each node n in addition to mate n . The function counts the number of picked edges in D in the domain of h. That is, for a valid path π , we shall have count n ( π ) ( D ) = | E ( π ) D | for each D dom ( h ) . Especially count n root ( D ) = 0 for each D dom ( h ) . Updating the counter is very easy. For a mapping c : dom ( h ) N and an edge e E , we define CU ( c , e ) : dom ( h ) N  (it stands for “counter update”) by
CU ( c , e ) ( D ) = c ( D ) if e D c ( D ) + 1 if e D
for every D dom ( h ) .
For π of length i, when it is clear that there is no P E e i + 1 such that E ( π ) P is compatible with h, the path π should end in 0 . We say that ( c , i ) is incompatible with h if there is D dom ( h ) such that either
  • c ( D ) > h ( D ) or
  • c ( D ) + | D E e i + 1 | < h ( D ) .
We say that cmatches h if c ( D ) = h ( D ) for all D dom ( h ) .
The function GN is modified so that it handles a counter function in addition to a mate function. It takes an edge index i { 1 , , | E | } , a mate function m and a counter function c. GN ( i , m , c ) returns a node labeled e i and assigned m and c. If such a node has already been created in N i , that node is returned. Otherwise, we create one in N i and return it. Note that this procedure may update N i .
We give a formal proof for the correctness of Algorithm 5 in Appendix E.

7. Slitherlink Instance Enumeration

In this section, we discuss instance enumeration for the Slitherlink problem, assuming that a graph G = ( V , E ) , a solution cycle C over G, and the maximum domain E 2 E of hint assignments are given. Let h : E N be a hint assignment such that h ( E ) = | C E | for all E E . The objective is to enumerate every E E that leads to a good instance ( G , h ) of the Slitherlink problem such that dom ( h ) = E and h ( E ) = h ( E ) for all E E . A good instance ( G , h ) must not have any compatible cycles other than C. Therefore, the instance enumeration problem is solved by computing
H = E E E E E E h ( E ) | C E | for all C C { C }
where C is the set of all cycles on G. We use Algorithm 4 to construct a ZDD for C . For this sake, we invoke the dynamic virtue of ZDDs that allows us to perform mathematical set operations quite easily.
A ZDD for the family C can be regarded as a function C ( x ) : { 0 , 1 } | E | { 0 , 1 } such that
C ( x ) = 1 if { e x e = 1 } C 0 otherwise
where x = ( x e 1 , , x e | E | ) is a vector of binary variables representing if each edge is taken. A ZDD for { C } can also be regarded as a function C ( x ) : { 0 , 1 } | E | { 0 , 1 } such that
C ( x ) = 1 if { e x e = 1 } = C 0 otherwise
Let y = ( y E 1 , , y E | E | ) be a vector of binary variables representing if the ith element E i of E is included in E . Now we can rewrite Equation (9) in terms of x and y as follows, which can be computed by conventional operations on ZDDs:
H ( y ) = x . ¬ C ( x ) C ( x ) E E y E h ( E ) e E x e
Once H ( y ) is computed, ZDD operations enable us to restrict it easily to some interesting subset, such as instances with the minimum or minimal hints, and to output all instances explicitly.

8. Experiments

The following experiments for the Numberlink solvers, the Slitherlink solvers and the Slitherlink generators are performed on AMD Opteron Processor TM 8393, 3.09 GHz with 512 GB memory running SuSE 10, and those for the Numberlink generators are performed on AMD Opteron Processor TM 6136, 2.40 GHz with 256 GB memory running SuSE 10.

8.1. Solvers for Numberlink and Slitherlink

In this subsection, we discuss our experimental results on the comparison of our algorithm for solving Numberlink and Slitherlink with existing methods which are based on CPLEX 12.3 and Sugar. We implemented Algorithm 2 for Numberlink solver and Algorithm 5 for Slitherlink solver in C + + and compiled them by G + + 4.6 with -O3 optimization option. In our implementation, a variable order (an edge order) is lexicographical on sets of two vertices where vertices are labeled such as  Figure 6.
We prepared the benchmark programs. We formulated solving Numberlink [15] and Slitherlink [16] as integer programs and solve them by CPLEX, which is an integer programming solver. Sugar is a SAT based constraint solver [8]. Sugar provides the formulation of Numberlink [17] and Slitherlink [18]. We also compared them with a heuristic solver slink [9] specialized for Slitherlink, which is published as a C source code.
Table 1 shows the running times of these methods for solving Numberlink. In the table, BNx denotes the xth instance in [19]. C88 is the Vol. 88 instance in Puzzle Championships 2010 [20]. Let G α , β denote the α × β grid graph. In Table 2, we show the running times of these methods with the restriction that requires solutions to cover all vertices (see Remark 7).
Table 3 describes the running time of these methods as Slitherlink solvers. BSx denotes the xth instance in [21]. S10 is a large sample problem on [22]. C95 is the Vol. 95 instance in Puzzle Championships 2010 [20].
This table shows that slink is by far the fastest. A reason is that slink is a heuristic solver for Slitherlink which uses information specialized for Slitherlink. For example, when two adjacent cells are assigned “0” and “3” respectively, 12 of the surrounding edges are immediately determined to be or not to be in any solution (see Figure 7).

8.2. Numberlink Generator

In this subsection, we show experimental results for enumerating all Numberlink instances for grid graphs by a variant of Algorithm 3. Our actual implementation is purely top-down, which is different from Algorithm 3. By interweaving the idea of Algorithm 3 into Algorithm 1, we construct Z G assigning nodes mate functions as well as pair matching families representing the ends of fixed paths simultaneously. In our algorithm, S n and B n are calculated by set operations such as union and intersection. We implemented these sets by ZDDs whose variables are unordered pairs { v , v } of vertices v , v V . For efficiency, our implementation maintains W n , B n instead of S n , B n for each node n in Z G , where W n = S n B n .
Table 4, Table 5 and Table 6 show the running time of our algorithm, the number of good instances and that of nodes of S 1 B 1 for G α , β .
For G 6 , 6 , the computation did not finish within one week. We tried to compute the number of instances with restricting the number of pairs to at most . Table 7 shows the result of this computation for G 6 , 6 and G 7 , 7 . Let W n , i = { T W n | T | = i } and B n , i = { T B n | T | = i } . We maintain W n , 0 , , W n , , B n , 0 , , B n , instead of W n , B n in each node n. We omit the method of computing W n , i and B n , i . Then, we obtain that the number of minimum pairs with which G 6 , 6 gives a good instance is 3 from this result. We give the complete list of those instances on the graph G 6 , 6 with 3 pairs of vertices in Appendix G.

8.3. Slitherlink Generator

For the Slitherlink generator, we tried to generate some interesting examples of Slitherlink instances in order to confirm the usefulness of our tool. Our tool generates Slitherlink instances based on three kinds of input: a graph, a solution cycle, and the maximum domain of hint assignments. In usual cases where instances are made with grid graphs, a domain of hint assignments is represented by a set of rectangular cells.
Figure 8 shows an example of Slitherlink generation. We drew a solution cycle on a 5 × 7 grid of cells and marked all 35 cells as the maximum set of hint cells. When they were given as the input, our tool successfully constructed a ZDD for a family of sets of hint cells in 8 s, from which we can obtain all the 2,912,556,380 good Slitherlink instances that have the given solution cycle. The tool can optionally restrict generated instances to minimal ones (instances such that any hint cannot be removed without making the solution not unique). It took 0.1 s for this example and the number of instances was reduced to 32,639. The output example shown in Figure 8 is the one selected automatically by our tool as the most difficult instance among them in our criteria, in which the difficulty is evaluated by smallness of the number of cells with hint values “4”, “0”, “3”, “1”, and “2” in this order of precedence. Another output example was shown already in Figure 2, which is one of the 81 good instances that consist of minimum hints.
Figure 9 shows another input example, in which the solution cycle is drawn on a 8 × 8 grid of cells. Unfortunately, the computation could not be finished even in a day when all 64 cells are marked as candidates of hint locations. Our tool, however, was still able to assist making instances of the Slitherlink problem according to the designer’s intent. We reduced the candidate locations to 36 cells (the right picture of Figure 9) and got 1,669,424 instances, 1,850 minimal instances, and 4 minimum instances (Figure 10) in 2 s. It is also interesting that the same mechanism can be used to modify existing instances. We found that hand-made instances often include many redundant hints (e.g., 12 out of 40) and our tool can be used to make them more difficult to solve.
Finally, we introduce an enjoyable application of our tool, which can make a puzzle containing a secret message. Unlike the original Slitherlink, we allow multiple cycles as its solution in order to embed multiple letters into the puzzle. The algorithm of Slitherlink instance generation is modified by replacing computation of “all cycles on G” with “all combinations of disjoint cycles on G”, which is actually not difficult to be computed by using conditions on degree of the graph vertices. Figure 11 is our message to readers.

9. Conclusions

This paper has proposed algorithms that enumerate solutions and instances for two link puzzles, Numberlink and Slitherlink, based on Knuth’s path enumeration algorithm Simpath.
Our Numberlink solver (Algorithm 2) is faster than Sugar and CPLEX. In Slitherlink, our solution enumeration algorithm (Algorithm 5) shows better performance than Sugar. CPLEX is sometimes faster than our algorithm. Slink runs much faster than our algorithm and CPLEX to find a solution for Slitherlink instances. The result looks rather reasonable, since Sugar and CPLEX are designed for quite general purposes and find only one solution, while Slink is specially designed to solve Slitherlink problems. Our algorithms are located in between. The core of our algorithms is specialized to enumerate path matchings on a general graph, to which we have plugged mechanisms that decide whether the currently obtained path matchings can be expanded to a solution. It is not difficult to accelerate our algorithms by employing known local solution methods for the link puzzles on grid graphs. Yet we have largely ignored such detailed improvements. Rather we emphasize the generality of our approach that should be valid to design solution enumeration algorithms for various link puzzles including Masyu, Yajirin and others. To build a ZDD representing solutions, what we need to do is to assign each node an appropriate configuration like mate and count which can be locally updated and which tells whether the currently obtained path matchings may be grown up to solutions.
Another point we would like to emphasize is that our algorithms give all the solutions at once as a ZDD unlike existing solvers. Our instance enumeration algorithms rely much on this feature of our approach. We benefit from the virtue of ZDDs as a set manipulation system. As we have demonstrated in Section 8.3, we have flexible means on ZDDs to extract instances with several properties from the whole set of good instances, like non-redundant ones, the hardest ones, ones that use specific cells, and so on. The authors believe manipulating puzzle instances on a ZDD is quite beneficial to puzzle designers. It is future work to develop an assistant tool for puzzle designers that equips several convenient functions with a friendly interface.

Acknowledgements

The authors are very much grateful to the anonymous reviewers for their valuable comments and suggestions that considerably improved the quality of our paper.

Appendix A Correctness of Algorithm 1 (Path Matching Enumeration)

This section proves that Algorithm 1 constructs a ZDD representing the family of path matchings over G. Hereafter mate n refers to the function assigned to the node n by Algorithm 1 rather than the one given in Equation (2). Actually those two coincide as we will prove below.
For a 0 , 1 -sequence π of length i such that E ( π ) is a path matching, we define a mate function mate π : V e i + 1 V { 0 } by
mate π ( v ) = v if v E ( π ) u if E ( π ) contains a u - v path 0 otherwise
In the sequel, we assume that mate 1 represents the special mate function whose domain is empty.
Lemma 8. 
Let π be a 0 , 1 -sequence of length i | E | . If E ( π ) is a path matching, then π is a valid path in Z G and mate n ( π ) = mate π .
Proof. 
We prove the lemma by induction on i. For i = 0 , E ( π ) is the empty set, which is a special case of a path matching, and mate π is the identity function on V e 1 = V by definition. The empty path π ends in the root node n root where we have mate n root = mate π .
Suppose that the lemma holds for π of length i 1 where 0 < i | E | . If E ( π · 0 ) is a path matching, π ends in a node n { 0 , 1 } in Z G such that mate n = mate π . By the algorithm, π · 0 ends in a node n 0 such that
mate n = mate n | V e i + 1 = mate π | V e i + 1 = mate π · 0
Suppose that E ( π · 1 ) is a path matching. Let E ( π · 1 ) consist of pairwise disjoint simple paths P 1 , , P k . Without loss of generality, we may assume that e i P 1 . We note that e i ( P 2 P k ) = . Suppose that there are m distinct vertices v 1 , , v m V such that P 1 = { { v j , v j + 1 } 1 j < m } . For each v V e i + 1 , we have
mate π · 1 ( v ) = v m if v = v 1 v 1 if v = v m 0 if v { v 2 , , v m 1 } mate π ( v ) otherwise
(Case 1) P 1 = { e i } = { { v 1 , v 2 } } . Then E ( π ) consists of simple paths P 2 , , P k . By the assumption we have
mate n ( v 1 ) = mate π ( v 1 ) = v 1 mate n ( v 2 ) = mate π ( v 2 ) = v 2
Hence mate n does not reject e i . Let n be the 1-child of n. We have mate n = MU ( mate n , e i ) | V e i + 1 . Recall the definition of MU :
MU ( mate n , e i ) ( u ) = 0 if u e i and mate n ( u ) u mate n ( v ) if e i = { v , mate n ( u ) } mate n ( u ) otherwise
for all u in the domain of mate n . Since mate n ( v 1 ) = v 1 and mate n ( v 2 ) = v 2 , the first case of the definition does not apply. The only vertices u such that mate n ( u ) MU ( mate n , e i ) ( u ) are v 1 and v 2 . By the second case of the definition, we have MU ( mate n , e i ) ( v 1 ) = v 2 and MU ( mate n , e i ) ( v 2 ) = v 1 . Hence we obtain mate π · 1 = mate n .
(Case 2) P 1 { e i } is a simple path. That is, either e i = { v 1 , v 2 } or e i = { v m 1 , v m } . Without loss of generality, we assume e i = { v 1 , v 2 } . Since P 1 { e i } is not empty, m > 2 . Then E ( π ) consists of simple paths P 1 { e i } , P 2 , , P k . By the assumption we have
mate n ( v 1 ) = mate π ( v 1 ) = v 1 mate n ( v 2 ) = mate π ( v 2 ) = v m
Hence mate n does not reject e i . Also note that
mate n ( v m ) = mate π ( v m ) = v 2
if v m V e i . Let n be the 1-child of n, for which we have mate n = MU ( mate n , e i ) | V e i + 1 . By the definition of MU , we have
MU ( mate n , e i ) ( v 1 ) = mate n ( v 2 ) = v m MU ( mate n , e i ) ( v 2 ) = 0 MU ( mate n , e i ) ( v m ) = mate n ( v 1 ) = v 1 if v m V e i
and for other vertices u V e i + 1 { v 1 , v 2 , v m } we have MU ( mate n , e i ) ( u ) = mate n ( u ) . The induction hypothesis mate n = mate π implies mate n = mate π · 1 .
(Case 3) P 1 { e i } is a path matching consisting of two simple paths P 1 and P 1 . That is, e i = { v j , v j + 1 } for some j { 2 , , m 2 } . Then E ( π ) consists of simple paths P 1 , P 1 , P 2 , , P k . By the assumption we have
mate n ( v j ) = mate π ( v j ) = v 1 mate n ( v j + 1 ) = mate π ( v j + 1 ) = v m
Hence mate n does not reject e i . Let n be the 1-child of n, for which we have mate n = MU ( mate n , e i ) | V e i + 1 . By the definition of MU , we have
MU ( mate n , e i ) ( v 1 ) = mate n ( v j + 1 ) = v m if v 1 V e i MU ( mate n , e i ) ( v j ) = 0 , where v j V e i MU ( mate n , e i ) ( v j + 1 ) = 0 , where v j + 1 V e i MU ( mate n , e i ) ( v m ) = mate n ( v j ) = v 1 if v m V e i
and for other vertices u V e i + 1 { v 1 , v j , v j + 1 , v m } , we have mate n ( u ) = MU ( mate n , e i ) ( u ) . The induction hypothesis mate n = mate π implies mate n = mate π · 1 . □
Lemma 9. 
Let π be a 0 , 1 -sequence of length i | E | . If π ends in a node n 0 in Z G , then E ( π ) is a path matching and mate n = mate π .
Proof. 
We show that if E ( π ) is not a path matching for a 0 , 1 -sequence π of length | E | , then there is a prefix π · 1 of π such that π · 1 ends in 0 in Z G .
Let π be the longest prefix of π such that E ( π ) is a path matching. Indeed such π exists, since E ( ϵ ) is a path matching for the empty sequence  ϵ . Since E ( π ) is a path matching and so is E ( π · 0 ) , hence π · 1 is a prefix of π such that E ( π · 1 ) is not a path matching. By Lemma 8, π is a valid path ending in a node n with mate n = mate π . Let E ( π · 1 ) = E ( π ) { e i } .
(Case 1) There exists a vertex v of degree more than 2 in E ( π · 1 ) . Since E ( π ) is a path matching, v has degree 2 in E ( π ) and v e i . By Lemma 8, we have mate n ( v ) = 0 . Then mate n rejects e i and π · 1 ends in 0 .
(Case 2) There exists no vertex of degree more than 2 in E ( π · 1 ) and there exists a simple cycle C E ( π · 1 ) . Since E ( π ) is a path matching, we have C E ( π ) and thus e i C . There are distinct vertices v 1 , , v m V for some m 3 such that e i = { v 1 , v m } and C { e i } = { { v j , v j + 1 } 1 j < m } . Let C = C { e i } , which is a simple path. Since E ( π · 1 ) has no vertex of degree more than 2, the degrees of v 1 and v m are 1 in C . By v 1 , v m V e i and Lemma 8, we have mate n ( v 1 ) = v m and mate n ( v m ) = v 1 . Thus mate n rejects e i and π · 1 ends in 0 . □
Theorem 10. 
Algorithm 1 constructs a ZDD representing all the path matchings on G.
Proof. 
By Lemmas 8 and 9. □

Appendix B Correctness of Algorithm 2 (Numberlink Solver)

Let Z G , h denote the ZDD constructed by Algorithm 2 for input ( G , h ) .
Lemma 11. 
If a 0 , 1 -sequence π ends in a node n { 0 , 1 } of Z G , h , then E ( π ) is a path matching and mate n = mate π .
Proof. 
Obviously if π is a valid path in Z G , h , then it is also valid in Z G . Moreover, Algorithms 1 and 2 assign the same mate function to the nodes reached by the same valid path π . Thus the lemma follows from Lemma 8. □
Lemma 12 
Let π be a 0 , 1 -sequence of length i 1 such that E ( π ) is a path matching. If ( mate π , i , 0 ) is incompatible with h, then there is no E E e i + 1 such that E ( π · 0 ) E is a solution for ( G , h ) .
Proof. 
Suppose that ( mate π , i , 0 ) is incompatible with h. Recall the definition that ( m , i , 0 ) is incompatible with h if for some  v e i V e i + 1 , either
  • v h and m ( v ) = v , or
  • v h and m ( v ) { 0 , v } .
Accordingly we have two cases.
(Case 1) Suppose that there is u ( e i V e i + 1 ) h such that mate π ( u ) = u . No edges incident to u belong to E ( π )  since  mate π ( u ) = u . No edges incident to u belong to E e i + 1 since u V e i + 1 . The vertex u has degree 0 in E ( π ) E for any E E e i + 1 . Thus E ( π ) E is not a solution, since u h .
(Case 2) Suppose that there is u ( e i V e i + 1 ) h such that mate π ( u ) { 0 , u } . The vertex has degree 1 in E ( π ) . No edges incident to u belong to E e i + 1 by u V e i + 1 . The vertex u h has degree 1 in E ( π ) E for any E E e i + 1 . Thus E ( π ) E is not a solution, since u h . □
Lemma 13. 
Let π be a 0 , 1 -sequence of length i 1 such that E ( π ) is a path matching. If ( mate π , i , 1 ) is incompatible with h, then there is no E E e i + 1 such that E ( π · 1 ) E is a solution for ( G , h ) .
Proof. 
Suppose that ( mate π , i , 1 ) is incompatible with h. Recall the definition that for e i = { u , v } , ( mate π , i , 1 ) is incompatible with h if one of the following conditions holds.
  • mate π ( v ) { 0 , u } ,
  • v h and mate π ( v ) v ,
  • mate π ( u ) , mate π ( v ) h ( V V e i + 1 ) and { mate π ( u ) , mate π ( v ) } h .
Let m = mate π . Accordingly there are three cases.
(Case 1) Suppose that m ( v ) { 0 , u } . In this case, it is easy to see that E ( π · 1 ) is not a path matching. Thus E ( π · 1 ) E is not a solution for any E E e i + 1 .
(Case 2) Suppose that v h { m ( v ) } . If m ( v ) = 0 , then Case 1 applies. Otherwise, E ( π ) contains a v- m ( v ) path. Then v has degree 2 in E ( π · 1 ) = E ( π ) { { u , v } } . Thus E ( π · 1 ) E is not a solution for any E E e i + 1 , since v h .
(Case 3) Suppose that m ( v ) h ( V V e i + 1 ) , m ( u ) V e i + 1 and { m ( u ) , m ( v ) } h . It is easy to see that E ( π · 1 ) has a m ( u ) - m ( v ) path. Let E E e i + 1 be such that E ( π · 1 ) E is a path matching.
(Case 3.1) Suppose that m ( v ) h . If m ( v ) E , then m ( v ) has degree 2 in E ( π · 1 ) E , which is not a solution. If m ( v ) E , then E ( π · 1 ) E contains a m ( u ) - m ( v ) path. Since { m ( u ) , m ( v ) } h , E ( π · 1 ) E is not a solution.
(Case 3.2) Suppose that m ( u ) , m ( v ) V e i + 1 . Then E ( π · 1 ) E contains a m ( u ) - m ( v ) path. Since { m ( u ) , m ( v ) } h , E ( π · 1 ) E is not a solution. □
Corollary 14. 
If E ( π ) is a solution for ( G , h ) and | π | = | E | , then π ends in 1 in Z G , h .
Proof. 
For any prefix π · b of length i of π , ( mate π , i , b ) is never incompatible with h by Lemmas 12 and 13. Together with Lemma 11, π · b is a valid path in Z G , h . □
Lemma 15. 
Suppose that E ( π ) is not a solution for ( G , h ) for a 0 , 1 -sequence π of length | E | . Then there are 0 , 1 -sequences π and π such that π = π · b · π for some  b { 0 , 1 } and ( mate π , | π | + 1 , b ) is incompatible with h.
Proof. 
Suppose that E ( π ) is not a solution for ( G , h ) . By the proofs of Lemmas 9 and 11, it is clear that if E ( π ) is not a path matching, then the lemma holds. We assume that E ( π ) is a path matching. We have the following cases.
1.
E ( π ) contains a u-v path but { u , v } h , where
1.1.
u , v h ,
1.2.
u h and v h ,
1.3.
u , v h .
2.
E ( π ) does not contain a u-v path for some { u , v } h , where
2.1.
u has degree 0,
2.2.
u has degree 2,
2.3.
u has degree 1.
Case 2.3 implies that E ( π ) contains a u-t path for some t v , which is covered by Cases 1.1 or 1.2. We discuss Cases 1.1, 1.2, 1.3, 2.1 and 2.2.
(Case 1.1) u , v h . Let P be the u-v path contained in E ( π ) and e i = max P . Let π be the prefix of length i 1 of π and m = mate π . Clearly π · 1 is a prefix of π . Let u , v e i be such that m ( u ) = u and m ( v ) = v . We then have m ( u ) , m ( v ) h and { m ( u ) , m ( v ) } h . Thus ( m , i , 1 ) is incompatible with h.
(Case 1.2) u h and v h . Let P be the u-v path contained in E ( π ) and e i = max ( P E v ) where E v = { { v , v } E v V } is the set of edges incident to v. We have v V e i + 1 by the choice of e i . Let π be the prefix of length i 1 of π and m = mate π .
Suppose that e i = max P . Then π · 1 is a prefix of π . Let u , v e i be such that m ( u ) = u and m ( v ) = v . Thus m ( u ) h , m ( v ) V e i + 1 and { m ( u ) , m ( v ) } h , which means that ( m , i , 1 ) is incompatible with h.
Suppose that e i max P . Then π · 0 is a prefix of π and E ( π ) contains the u-v path. We have v h and m ( v ) = u { 0 , v } . That is, ( m , i , 0 ) is incompatible with h.
(Case 1.3) u , v h . Let e i = min max E u , max E v . We assume without loss of generality that e i = { u , u } for some u V . We have u V e i + 1 by the choice of e i . Let π be the prefix of length i 1 of π and m = mate π .
Suppose that e i E ( π ) . For the edge e j in the u-v path incident to u, we have e j < e i . Thus we have m ( u ) { 0 , u } and u V e i + 1 , which means that ( m , i , 0 ) is incompatible with h, where π · 0 is a prefix of π .
Suppose that e i E ( π ) . Then m ( u ) = u and π · 1 is a prefix of π . We have u V e i + 1 and { m ( u ) , m ( u ) } h . Hence ( m , i , 1 ) is incompatible with h.
(Case 2.1) Suppose that u h has degree 0 in E ( π ) . Let e i = max E u and π be the prefix of length i 1 of π , where π · 0 is a prefix of π . Then u h V e i + 1 and mate π ( u ) = u , which means that ( mate π , i , 0 ) is incompatible with h,
(Case 2.2) Suppose that u h has degree 2 in E ( π ) . Let e i = max { { u , u } E ( π ) u V } , π be the prefix of length i 1 of π , where π · 1 is a prefix of π . Then u h and mate π ( u ) u , which means that ( mate π , i , 1 ) is incompatible with h. □
Corollary 16. 
If E ( π ) is not a solution for ( G , h ) and | π | = | E | , then π has a prefix π which ends in 0 in Z G , h .
Proof. 
By Lemmas 11 and 15. □

Appendix C Correctness of Algorithm 3 (Numberlink Instance Enumeration)

In this section, for a node n of Z G , by S n and B n we denote the pair matching families assigned to n by Algorithm 3. For each 0 , 1 -sequence π such that E ( π ) is a path matching, let us define
T ( π ) = { { u , v } V E ( π ) contains a u - v path with u , v V e | π | + 1 }
Lemma 17. 
Suppose that E ( π ) is a path matching and let i = | π | + 1 and m = mate π . We have
T ( π · 0 ) = T ( π ) { { u , m ( u ) } V u e i , m ( u ) { u , 0 } and u , m ( u ) V e i + 1 }
If E ( π · 1 ) is a path matching, then
T ( π · 1 ) = T ( π ) { { m ( u ) , m ( v ) } V { u , v } = e i and m ( u ) , m ( v ) V e i + 1 }
Proof. 
By definition,
T ( π · 0 ) = { { u , v } V E ( π · 0 ) contains a u - v path with u , v V e i + 1 } = { { u , v } V E ( π ) contains a u - v path with u , v V e i } { { u , v } V E ( π ) contains a u - v path with u e i V e i + 1 and v V e i + 1 } = T ( π ) { { u , m ( u ) } V u e i V e i + 1 , m ( u ) V e i + 1 and m ( u ) { u , 0 } }
and
T ( π · 1 ) = { { u , v } V E ( π · 1 ) contains a u - v path with u , v V e i + 1 } = { { u , v } V E ( π ) contains a u - v path with u , v V e i } { { u , v } V E ( π · 1 ) contains a u - v path P with e i P and u , v V e i + 1 } = T ( π ) { { u , v } V { u , v } = e i , u = m ( u ) V e i + 1 and v = m ( v ) V e i + 1 }
Lemma 18. 
For each node n of Z G , the algorithm assigns S n = { T ( π ) n ( π ) = n } . Moreover, S n , b = { T ( π · b ) n ( π ) = n } for each b { 0 , 1 } .
Proof. 
We show the lemma by induction on the length of π . If π is empty, then T ( π ) = . Indeed Algorithm 3 sets S n root = { } .
Let π = π · b for some π and b { 0 , 1 } . By the induction hypothesis, we have T ( π ) S n ( π ) . By Lemma 17, we have
T ( π · b ) = T ( π ) Fix ( mate n ( π ) , | π | + 1 , b ) S n ( π ) , b S n ( π · b )
We have proven that { T ( π · b ) n ( π ) = n } S n , b . and { T ( π ) n ( π ) = n } S n .
Conversely, we show by induction on i that if T S n for n N i , then there is π such that n ( π ) = n and T ( π ) = T . For i = 1 , S n = { } and the empty path ϵ satisfies the claim. Suppose that T S n for some n N i + 1 with i 1 . Then by definition there is a b-parent n N i of n for some b { 0 , 1 } such that T S n , b . By definition, there is T S n such that
T = T Fix ( mate n , i , b )
By the induction hypothesis, there is π such that n ( π ) = n and T = T ( π ) . Lemma 17 ensures that T ( π · b ) = T . This proves that S n , b { T ( π · b ) n ( π ) = n } and S n { T ( π ) n ( π ) = n } . □
Corollary 19. ( G , h ) admits a solution if and only if h S 1 .
Proof. 
By Lemma 18. □
Lemma 20. 
If T ( π ) B n for a 0 , 1 -sequence π, then T ( π · b ) B n , b for each b { 0 , 1 } .
Proof. 
Similarly to the proof of Lemma 18. □
Lemma 21. 
If there are distinct valid paths π 0 and π 1 such that n ( π 0 ) = n ( π 1 ) and T ( π 0 ) = T ( π 1 ) , then T ( π 0 ) B n ( π 0 ) .
Proof. 
We prove the lemma by induction on i = | π 0 | = | π 1 | . For i = 0 , the claim holds since only the empty path ends in the root node.
Let π 0 = π 0 · b 0 and π 1 = π 1 · b 1 for some b 0 , b 1 { 0 , 1 } .
(Case 1) n ( π 0 ) = n ( π 1 ) . In this case, we have mate π 0 = mate π 1 and mate π 0 · b 0 = mate π 1 · b 1 . Let m = mate π 0 and m = mate π 0 . Clearly each of u , v e i has the same degree in E ( π 0 ) and in E ( π 1 ) , since u and v are in the domain V e i of mate π 0 = mate π 1 . To derive a contradiction, suppose that b 0 b 1 , where we assume without loss of generality that b 0 = 0 and b 1 = 1 . Then u has different degrees in E ( π 0 ) and in E ( π 1 ) . In this case, the fact that mate π 0 · b 0 = mate π 1 · b 1 implies that u is not in the domain V e i + 1 of those mate functions. The same argument applies to v. Hence, { m ( u ) , m ( v ) } T ( π 1 ) by definition. The fact that E ( π 1 ) is a path matching implies m ( u ) v , which means that E ( π 0 ) does not contain a u-v path. Hence E ( π 0 ) does not have a m ( u ) - m ( v ) path and { m ( u ) , m ( v ) } T ( π 0 ) . This contradicts to the assumption that T ( π 0 ) = T ( π 1 ) . Hence we conclude that b 0 = b 1 . By Lemma 17, we have
T ( π 0 ) T ( π 0 ) = T ( π 1 ) T ( π 1 )
Together with T ( π 0 ) T ( π 0 ) , T ( π 1 ) T ( π 1 ) and T ( π 0 ) = T ( π 1 ) , we conclude that T ( π 0 ) = T ( π 1 ) . By π 0 = π 0 · b 0 π 1 · b 0 = π 1 , we have π 0 π 1 . By the induction hypothesis, T ( π 0 ) = T ( π 1 ) B n . Thus by Lemma 20, T ( π 0 ) = T ( π 0 · b 0 ) B n , b 0 B n .
(Case 2) n ( π 0 ) n ( π 1 ) . By Lemma 18, we have T ( π 0 · b 0 ) S n ( π 0 ) , b 0 and T ( π 1 · b 1 ) S n ( π 1 ) , b 1 . Hence T ( π 0 ) = T ( π 0 · b 0 ) = T ( π 1 · b 1 ) B n . □
Lemma 22. 
For any valid path π such that E ( π ) V e | π | + 1 V , it holds that T ( π ) B n ( π ) .
Proof. 
We prove the lemma by induction on i = | π | . For i = 0 , the claim holds trivially by V e 1 = V . Let π = π · b for some b { 0 , 1 } .
(Case 1) e i E ( π ) V e i + 1 . We have
E ( π ) V e i E ( π ) V e i = E ( π ) V e i + 1 { e i } = E ( π ) V e i + 1 V
By the induction hypothesis, we have T ( π ) B n ( π ) . Hence T ( π ) = T ( π · b ) B n ( π ) , b B n ( π ) .
(Case 2) e i E ( π ) V e i + 1 . The fact e i E ( π ) implies that b = 0 . Let u e i ( E ( π ) V e | π | + 1 ) . We have mate π ( u ) = u . By Lemma 18 and the fact u V e | π | + 1 , we have
T ( π ) = T ( π · 0 ) S n ( π ) , 0 B n ( π )
Lemma 23. 
If T B n for some node in Z G , then one of the following holds:
  • there are distinct π 1 and π 2 such that n = n ( π 1 ) = n ( π 2 ) and T = T ( π 1 ) = T ( π 2 ) ,
  • there is π such that n = n ( π ) , T = T ( π ) and E ( π ) V e | π | + 1 V .
Proof. 
We prove the lemma by induction on i such that n N i . For i = 0 , the claim holds trivially by B n root = .
For i 1 , there are three cases according to the definition of B n in the algorithm.
(Case 1) T S n 1 , b 1 S n 2 , b 2 for some b j -parents n j of n for j = 1 , 2 such that n 1 n 2 . By Lemma 18, there are π j such that T = T ( π j · b j ) S n j , b j and T ( π j ) S n j for j = 1 , 2 . The fact n 1 n 2 implies that π 1 · b 1 π 2 · b 2 . We have n = n ( π 1 · b 1 ) = n ( π 2 · b 2 ) and T = T ( π 1 ) = T ( π 2 ) .
(Case 2) T S n , 0 for some 0-parent n of n such that mate n ( u ) = u for some u e i V e i + 1 . By Lemma 18, there is π such that T = T ( π · 0 ) S n , 0 and T ( π ) S n . The fact that mate n ( u ) = u implies that the degree of u is 0 in E ( π ) = E ( π · 0 ) . Let π = π · 0 . Then, we have n = n ( π ) , T = T ( π ) and u E ( π ) V e | π | + 1 .
(Case 3) T B n , b for some b-parent n of n. There is T B n such that T = T Fix ( mate n , i , b ) . By the induction hypothesis on the fact T B n , one of the following holds:
  • there are distinct π 1 and π 2 such that n = n ( π 1 ) = n ( π 2 ) and T = T ( π 1 ) = T ( π 2 ) ,
  • there is π such that n = n ( π ) , T = T ( π ) and E ( π ) V e | π | V .
In the former case, π j = π j · b for j = 1 , 2 satisfies the lemma. In the latter case, let u V ( E ( π ) V e | π | ) . By e i V e | π | , we have u E ( π · b ) . Thus we have u E ( π ) V e | π | + 1 for π = π · b . □

Appendix D Correctness of Algorithm 4 (Cycle Enumeration)

Let Y G be the output by Algorithm 4 for G. The following lemma, which we will use without explicit reference, is implied by the proof of Lemma 8.
Lemma 24. 
If π is a valid path in Y G and n ( π ) 1 , then E ( π ) is a path matching and mate n ( π ) = mate π .
For Y G , we have the following stronger lemma.
Lemma 25. 
Let π be a 0 , 1 -sequence of length at most | E | . If E ( π ) is a path matching such that every vertex in V V e | π | + 1 has degree 0 or 2 in E ( π ) , then π is a valid path ending in a node n 0 , 1 in the constructed ZDD and we have mate n = mate π .
Proof. 
We prove the lemma by induction on the length of π . Clearly the lemma holds if π is the empty sequence. Suppose that π of length i 1 satisfies the condition of the lemma. Let n = n ( π ) . It is enough to show the following by Lemma 24.
  • If ( mate n , e i ) has a fixed end, then there is a vertex in V V e i + 1 of degree 1 in E ( π · 0 ) .
  • If E ( π · 1 ) is a path matching and ( MU ( mate n , e i ) , e i ) has a fixed end, then there is a vertex in V V e i + 1 of degree 1 in E ( π · 1 ) .
Suppose that ( mate n , e i ) has a fixed end. By definition, there is v e i V e i + 1 with mate n ( v ) { 0 , v } , which means that v has degree 1 in E ( π · 0 ) .
Suppose that E ( π · 1 ) is a path matching and ( MU ( mate n , e i ) , e i ) has a fixed end. By definition, there is v e i V e i + 1 with MU ( mate n ( v ) , e i ) ( v ) { 0 , v } , which means that v has degree 1 in E ( π · 1 ) by the arguments on the function MU in the proof of Lemma 8. □
Corollary 26. 
Let π be a 0 , 1 -sequence of length i | E | . If E ( π · 1 ) is a simple cycle, then π · 1 ends in 1 .
Proof. 
Suppose that E ( π · 1 ) is a cycle. Let i = | π | + 1 and e i = { u , v } . That is, E ( π · 1 ) = E ( π ) { { u , v } } . Since E ( π ) is a u-v simple path, the only vertices of degree 1 in E ( π ) are u and v. Since u , v V e i , Lemma 25 implies that π ends in a node n 0 , 1 . We have mate n ( u ) = v , mate n ( v ) = u and mate n ( w ) { 0 , w } for other w V e i . That is, mate n and e i form a cycle. The algorithm connects n and 1 by a 1-arc. □
Lemma 27. 
Let π be a 0 , 1 -sequence of length i | E | . If π ends in a node n { 0 , 1 } , then E ( π ) is a path matching such that mate π = mate n and every vertex in E ( π ) V e i + 1 has degree 0 or 2 in E ( π ) .
Proof. 
We show the lemma by induction on i. A proof almost identical to that for Lemma 9 applies to the claim that if π ends in a node n { 0 , 1 } , then E ( π ) is a path matching such that mate π = mate n . We here show that in that case every vertex in V V e i + 1 has degree 0 or 2 in E ( π ) .
If π is empty, then V V e i + 1 is the empty set.
Suppose that π = π · 0 for some π . We have E ( π ) = E ( π ) . By the induction hypothesis, every vertex in V V e i has degree 0 or 2 in E ( π ) where i = | π | . If V e i + 1 = V e i , there is nothing to prove. If there is u V e i V e i + 1 , then u e i . By definition, ( mate n ( π ) , i ) does not have a fixed end, i.e., mate π ( u ) = mate n ( π ) ( u ) { 0 , u } . That is, u has degree 0 or 2.
The case where π = π · 1 for some π can be proven by combining the discussions for the case where π = π · 0 and the correctness of the mate updating function MU , established in the proof of Lemma 8. □
Corollary 28. 
If a 0 , 1 -sequence π ends in 1 , then E ( π ) is a simple cycle.
Proof. 
By the algorithm, π must have the form π · 1 and mate n ( π ) and e i form a cycle for i = | π | . That is, we have
mate n ( π ) ( v ) = u if e i = { u , v } v or 0 if v e i
Applying Lemma 27 to π , we conclude that E ( π ) is a path matching consisting solely of a u-v path for e i = { u , v } . Clearly E ( π ) = E ( π ) { e i } is a simple cycle. □
Theorem 29. 
Algorithm 4 constructs a ZDD that represents all the simple cycles on G.
Proof. 
By Corollaries 26 and 28. □

Appendix E Correctness of Algorithm 5 (Slitherlink Solver)

Let Y G , h be the output by Algorithm 5 for ( G , h ) .
Lemma 30. 
If a 0 , 1 -sequence π ends in 1 in Y G , h , then E ( π ) is a solution for ( G , h ) .
Proof. 
By Lemma 27, If π ends in a node n { 0 , 1 } , then E ( π ) is a path matching such that every vertex in V V e i + 1 has degree 0 or 2 in E ( π ) and mate π = mate n . Moreover, it is easy to show by induction on i that | E ( π ) D | = count n ( D ) for all D dom ( h ) .
If π ends in 1 , by definition of GN , E ( π ) is a cycle such that | E ( π ) D | = h ( D ) for all D dom ( h ) . That is, E ( π ) is a solution for ( G , h ) . □
Lemma 31. 
If a 0 , 1 -sequence π of length i ends in 0 in Y G , h , then E ( π ) E is not a solution for ( G , h ) for any E E e i + 1 .
Proof. 
Suppose that π = π · b ends in 0 where b { 0 , 1 } . Let n = n ( π ) , i = | π | and
c ( D ) = count n ( D ) if b = 0 CU ( count n , e i ) ( D ) if b = 1
for all D dom ( h ) . The proof of Lemma 25 shows that if ( mate n , i ) has a fixed end or mate n declines e i , then the lemma holds. It is enough to discuss the case where ( c , i ) is incompatible with h. In this case, either c ( D ) > h ( D ) or c ( D ) + | D E e i + 1 | < h ( D ) for some D dom ( h ) . In the former case, | E ( π ) D | = c ( D ) > h ( D ) implies that | ( E ( π ) E ) D | > h ( D ) for any E E e i + 1 . That is, E ( π ) E cannot be a solution. In the latter case,
| E ( π ) D | + | D E e i + 1 | = c ( D ) + | D E e i + 1 | < h ( D )
implies that | ( E ( π ) E ) D | < h ( D ) for any E E e i + 1 . That is, E ( π ) E cannot be a solution. □
Corollary 32. 
Y G , h represents the set of all solutions for ( G , h ) .
Proof. 
By Lemmas 30 and 31. □

Appendix F Computation Example for Numberlink Instance Enumeration

We explain an example of T ( π ) and S n for some valid path π and some node n defined in Section 5 (see Figure 12).
Figure 12. An example of computing T(π) and Sn.
Figure 12. An example of computing T(π) and Sn.
Algorithms 05 00176 g012aAlgorithms 05 00176 g012b
A given graph G = ( V , E ) and Z G are shown in the top half of the figure. The dashed lines represent valid paths π 1 = 100100001 and π 2 = 100101010 . The four graphs in the bottom half of the figure are subgraphs whose vertex sets are V and whose edge sets are E ( π 1 ) , E ( π 2 ) , E ( π 1 · 1 ) and E ( π 2 · 0 ) , which are drawn as bold lines. Since mate n ( π 1 · 1 ) ( v ) = mate n ( π 2 · 0 ) ( v ) = v , mate n ( π 1 · 1 ) ( w ) = mate n ( π 2 · 0 ) ( w ) = t and mate n ( π 1 · 1 ) ( x ) = mate n ( π 2 · 0 ) ( x ) = x and for any other vertices u, both mate n ( π 1 · 1 ) ( u ) and mate n ( π 2 · 0 ) ( u ) are undefined, mate n ( π 1 · 1 ) = mate n ( π 2 · 0 ) holds. Therefore, n ( π 1 · 1 ) = n ( π 2 · 0 ) . Let n = n ( π 1 · 1 ) = n ( π 2 · 0 ) . Let P 1 = { { p , q } } , P 2 = { { r , s } } and P 3 = { { r , s } , { s , u } } . E ( π 1 ) , E ( π 2 ) , E ( π 1 · 1 ) and E ( π 2 · 0 ) include two fixed paths P 1 and P 2 , one fixed path P 1 , two fixed paths P 1 and P 2 , and two fixed paths P 1 and P 3 respectively. It is easy to verify that T ( π 1 ) = { { p , q } , { r , s } } , T ( π 2 ) = { { p , q } } , and S n = { T ( π 1 · 1 ) , T ( π 2 · 0 ) } = { { { p , q } , { r , s } } , { { p , q } , { r , u } } } hold.

Appendix G Minimum Good Numberlink Instances over G 6,6

Figure 13 and Figure 14 complete all of the 38 good instances of Numberlink ( G 6 , 6 , h ) with | h | = 3 modulo symmetry.
Figure 13. Good instances on G 6 , 6 (1).
Figure 13. Good instances on G 6 , 6 (1).
Algorithms 05 00176 g013
Figure 14. Good instances on G 6 , 6 (2).
Figure 14. Good instances on G 6 , 6 (2).
Algorithms 05 00176 g014

References

  1. Nikoli: Web Nikoli. Available online: http://www.nikoli.co.jp/ (accessed on 21 March 2012).
  2. Kotsuma, K.; Takenaga, Y. NP-Completeness and Enumeration of Number Link Puzzle [in Japanese]; IEICE Technical Report, COMP2009-49; The Institute of Electronics, Information and Communication Engineering: Tokyo, Japan, 2010; pp. 1–7. [Google Scholar]
  3. Kramer, M.R.; van Leeuwen, J. Wire-Routing is NP-Complete; Report No. RUU-CS-82-4; Department of Computer Science, University of Utrecht: Utrecht, The Netherlands, 1982. [Google Scholar]
  4. Takahashi, J.; Suzuki, H.; Nishizeki, T. Shortest noncrossing paths in plane graphs. Algorithmica 1996, 16, 339–357. [Google Scholar] [CrossRef]
  5. Richards, D. Complexity of single-layer routing. IEEE Trans. Comput. 1984, 33, 286–288. [Google Scholar] [CrossRef]
  6. Yato, T. On the NP-Completeness of the Slither Link Puzzle [in Japanese]; IPSJ SIG Notes AL-74; Information Processing Society of Japan: Tokyo, Japan, 2000; pp. 25–32. [Google Scholar]
  7. Hearn, R.A.; Demaine, E.D. Games, Puzzles, and Computation; A K Peters, Ltd.: Boca Raton, FL, USA, 2009. [Google Scholar]
  8. Tamura, N. Sugar: A SAT-Based Constraint Solver. Available online: http://bach.istc.kobe-u.ac.jp/ sugar/ (accessed on 21 March 2012).
  9. Itogawa, A. Slither Link Kaito Program (Solving Slither Link Program: In Japanese). Available online: http://www2.ttcn.ne.jp/~itogawa/product/slitherlink.html (accessed on 21 March 2012).
  10. Shirai, H.; Igarashi, C.; Tajima, Y.; Kotani, Y. Solving and Making Problems of Slither Link [in Japanese]. In Proceedings of the 11th Game Programming Workshop in Japan 2006, Kanagawa, Japan, 10–12 November 2006; pp. 32–39. [Google Scholar]
  11. Wan, J. Logical Slither Link. Bsc These, University of Manchester, Manchester, UK, 2009. [Google Scholar]
  12. Minato, S. Zero-Suppressed BDDs for Set Manipulation in Combinatorial Problems. In Proceedings of the 30th International Design Automation Conference (DAC ’93), Dallas, TX, USA, 14–18 June 1993; pp. 272–277. [Google Scholar]
  13. Knuth, D. The Art of Computer Programming, Volume 4, Fascicle 1; Addison-Wesley Professional: Boston, MA, USA, 2009. [Google Scholar]
  14. Yato, T.; Seta, T. Complexity and completeness of finding another solution and its application to puzzles. IEICE Trans. Fundam. Electron. Commun. Comput. Sci. 2003, E86-A, 1052–1060. [Google Scholar]
  15. GLPK deno Pencil Puzzle Koryakuho (Solving Pencil Puzzle Using GLPK : In Japanese). Available online: http://www21.tok2.com/home/kainaga11/glpk/glpk.htm (accessed on 21 March 2012).
  16. Sugimura, Y. Seisu Keikakuho niyoru Slither Link no Kaiho (Slither Link Algorithm Using Integer Programming: In Japanese). In Proceedings of the 1st Games and Puzzles Mini Workshop, Kyoto, Japan, 12 September 2005. [Google Scholar]
  17. Tamura, N. Solving Number Link Puzzles with Sugar Constraint Solver [in Japanese]. Available online: http://bach.istc.kobe-u.ac.jp/sugar/puzzles/numberlink.html (accessed on 21 March 2012).
  18. Tamura, N. Solving Slither Link Puzzles with Sugar Constraint Solver [in Japanese]. Available online: http://bach.istc.kobe-u.ac.jp/sugar/puzzles/slitherlink.html (accessed on 21 March 2012).
  19. Nikoli. Numberlink 1; Nikoli: Tokyo, Japan, 1989. [Google Scholar]
  20. Nikoli: Nikoli.com Puzzle Championship. Available online: http://www.nikoli.com/en/event/ puzzle_hayatoki.html (accessed on 21 March 2012).
  21. Nikoli. Slitherlink 1; Nikoli: Tokyo, Japan, 1992. [Google Scholar]
  22. Nikoli: Sample Problems of Slitherlink Puzzle. Available online: http://www.nikoli.com/en/ puzzles/slitherlink/ (accessed on 21 March 2012).
Figure 1. An instance of Numberlink and its solution.
Figure 1. An instance of Numberlink and its solution.
Algorithms 05 00176 g001
Figure 2. An instance of Slitherlink and its solution.
Figure 2. An instance of Slitherlink and its solution.
Algorithms 05 00176 g002
Figure 3. The reduced ZDD representing Z ( 1 ) = { { a } , { b } , { c } , { a , c } , { b , c } } . E = { a , b , c } where a < b < c . Dotted lines represent 0-arcs and solid lines represent 1-arcs.
Figure 3. The reduced ZDD representing Z ( 1 ) = { { a } , { b } , { c } , { a , c } , { b , c } } . E = { a , b , c } where a < b < c . Dotted lines represent 0-arcs and solid lines represent 1-arcs.
Algorithms 05 00176 g003
Figure 4. An example of G and Z G .
Figure 4. An example of G and Z G .
Algorithms 05 00176 g004
Figure 5. updating mate.
Figure 5. updating mate.
Algorithms 05 00176 g005
Figure 6. Grid graph G b , a and its vertex labels.
Figure 6. Grid graph G b , a and its vertex labels.
Algorithms 05 00176 g006
Figure 7. An example of information used by a heuristic Slitherlink solver.
Figure 7. An example of information used by a heuristic Slitherlink solver.
Algorithms 05 00176 g007
Figure 8. Input and output of Slitherlink generation; example #1.
Figure 8. Input and output of Slitherlink generation; example #1.
Algorithms 05 00176 g008
Figure 9. Input of Slitherlink generation; example #2.
Figure 9. Input of Slitherlink generation; example #2.
Algorithms 05 00176 g009
Figure 10. Output of Slitherlink generation; example #2.
Figure 10. Output of Slitherlink generation; example #2.
Algorithms 05 00176 g010
Figure 11. An example of message puzzle instance.
Figure 11. An example of message puzzle instance.
Algorithms 05 00176 g011
Table 1. Running time in seconds for solving Numberlink. Our algorithm could not solve C88 due to insufficient memory.
Table 1. Running time in seconds for solving Numberlink. Our algorithm could not solve C88 due to insufficient memory.
Instance GraphTime CPLEXTime SugarTime
Algorithm 2
Memory
Algorithm 2 (MB)
BN1 G 8 , 8 0.021.1790.0082
BN15 G 8 , 8 13.951.3360.0042
BN30 G 10 , 10 88.321.8960.0165
BN43 G 10 , 10 6,410.671.9240.07218
BN52 G 10 , 10 0.451.5200.0123
BN64 G 10 , 10 108.071.7040.13611
BN72 G 10 , 10 276.071.3880.0124
BN79 G 10 , 10 15,117.471.4960.22037
BN85 G 20 , 15 >100,0007,213.079862.51843,846
BN99 G 20 , 15 >100,00014.0971,658.77267,094
C88 G 20 , 36 >100,000>100,000
Table 2. Running time in seconds for solving Numberlink with restriction that requires solutions to cover all vertices.
Table 2. Running time in seconds for solving Numberlink with restriction that requires solutions to cover all vertices.
InstanceGraphTime CPLEXTime SugarTime
Algorithm 2
Memory
Algorithm 2 (MB)
BN1 G 8 , 8 0.011.1480.0042
BN15 G 8 , 8 0.400.9640.0002
BN30 G 10 , 10 0.821.5760.0243
BN43 G 10 , 10 21.971.5520.0125
BN52 G 10 , 10 0.101.2960.0042
BN64 G 10 , 10 18.401.3680.0125
BN72 G 10 , 10 1.501.6480.0122
BN79 G 10 , 10 26.741.4520.04810
BN85 G 20 , 15 >100,0005,431.991185.2648,761
BN99 G 20 , 15 >100,00012.585175.1479,727
Table 3. Running time in seconds for solving Slitherlink. Our algorithm could not solve C95 due to insufficient memory.
Table 3. Running time in seconds for solving Slitherlink. Our algorithm could not solve C95 due to insufficient memory.
InstanceGraphTime CPLEX Time SugarTime slinkTime
Algorithm 5
Memory
Algorithm 5 (MB)
BS1 G 11 , 11 0.075.4600.0010.11634
BS12 G 11 , 11 0.284.6960.0040.38441
BS25 G 11 , 11 0.126.4960.0010.06034
BS37 G 11 , 11 0.148.7730.0040.04434
BS43 G 19 , 11 0.178.3490.0010.06036
BS54 G 19 , 11 0.407.3800.0080.30437
BS68 G 25 , 15 0.3912.4330.0040.38439
BS77 G 25 , 15 0.9013.2810.0040.37642
BS89 G 37 , 21 1.5648.0350.0169.329407
BS96 G 37 , 21 3.07186.6120.10426.286904
S10 G 21 , 37 41.431,411.9440.0364,569.330138,053
C95 G 32 , 46 95.931,076.8390.088
Table 4. Running time of Numberlink generator for G α , β .
Table 4. Running time of Numberlink generator for G α , β .
α β 234567
2<0.01<0.01<0.01<0.010.010.02
3 <0.010.010.080.482.67
4 0.213.5644.13488.12
5 107.993,553.29>100,000
6 >100,000>100,000
7 >100,000
Table 5. The number of good instances of Numberlink for G α , β .
Table 5. The number of good instances of Numberlink for G α , β .
α β 234567
2210361264541,632
3868076,69058,422499,733
416,410338,4606,901,105141,123,690
516,027,290784,030,205Time Out
6Time OutTime Out
7Time Out
Table 6. The number of ZDD nodes of W 1 in Numberlink generator for G α , β .
Table 6. The number of ZDD nodes of W 1 in Numberlink generator for G α , β .
α β 234567
241850117235419
3994911,6864,91812,255
43,49922,599108,954439,506
5226,8001,977,335Time Out
6Time OutTime Out
7Time Out
Table 7. Running time, the number of good instances with at most pairs of numbers, and that of ZDD nodes of W 1 = S 1 B 1 .
Table 7. Running time, the number of good instances with at most pairs of numbers, and that of ZDD nodes of W 1 = S 1 B 1 .
GraphTimeGood instances | W n , |
G 6 , 6 039.6301
G 6 , 6 1141.1301
G 6 , 6 21,329.3501
G 6 , 6 312,161.5304472
G 6 , 6 4>1,000,000
G 7 , 7 02,732.8601
G 7 , 7 114,22601
G 7 , 7 2>1,000,000
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Yoshinaka, R.; Saitoh, T.; Kawahara, J.; Tsuruma, K.; Iwashita, H.; Minato, S.-i. Finding All Solutions and Instances of Numberlink and Slitherlink by ZDDs. Algorithms 2012, 5, 176-213. https://0-doi-org.brum.beds.ac.uk/10.3390/a5020176

AMA Style

Yoshinaka R, Saitoh T, Kawahara J, Tsuruma K, Iwashita H, Minato S-i. Finding All Solutions and Instances of Numberlink and Slitherlink by ZDDs. Algorithms. 2012; 5(2):176-213. https://0-doi-org.brum.beds.ac.uk/10.3390/a5020176

Chicago/Turabian Style

Yoshinaka, Ryo, Toshiki Saitoh, Jun Kawahara, Koji Tsuruma, Hiroaki Iwashita, and Shin-ichi Minato. 2012. "Finding All Solutions and Instances of Numberlink and Slitherlink by ZDDs" Algorithms 5, no. 2: 176-213. https://0-doi-org.brum.beds.ac.uk/10.3390/a5020176

Article Metrics

Back to TopTop