• No results found

Completing partial latin squares with 2 filled rows and 3 filled columns

N/A
N/A
Protected

Academic year: 2021

Share "Completing partial latin squares with 2 filled rows and 3 filled columns"

Copied!
57
0
0

Loading.... (view fulltext now)

Full text

(1)

Completing partial latin squares with 2 lled

rows and 3 lled columns

Department of Mathematics, Linköping University Herman Göransson

LiTH-MAT-EX2019/12SE

Credits: 16 hp Level: G2

Supervisor: Carl Johan Casselgren,

Department of Mathematics, Linköping University Examiner: Jan Snellman,

Department of Mathematics, Linköping University Linköping: January 2020

(2)
(3)

Abstract

The set P LS(a, b; n) is the set of all partial latin squares of order n with a completed rows, b completed columns and all other cells empty. We identify reductions of partial latin squares in P LS(2, 3; n) by using permutations de-scribed by lled rows and intersections of lled rows and columns. We nd that all partial latin squares in P LS(2, 3; n), where n is suciently large, can be completed if such a reduction can be completed. We also show that all partial latin squares in P LS(2, 3; n) where the intersection of lled rows and columns form a latin rectangle have completions for n ≥ 8.

Keywords:

Graph theory, Partial latin squares URL for electronic version:

http://urn.kb.se/resolve?urn=urn:nbn:se:liu:diva-163092

(4)
(5)

Contents

1 Prerequisites 1 1.1 Basic denitions . . . 1 1.2 Graphs . . . 2 1.2.1 Bipartite graphs . . . 2 1.2.2 Matchings . . . 2 1.2.3 Edge coloring . . . 3

2 Partial Latin Squares 5 2.1 Introduction . . . 5

2.2 Completing partial latin squares . . . 8

2.3 Edge coloring of complete bipartite graphs . . . 10

3 Some families of partial latin squares 13 3.1 PLS with a completely lled rows and b completely lled columns 13 4 Completing partial latin squares in PLS(2, 3; n) 17 4.1 Introduction . . . 17

4.2 Reduction of the problem . . . 19

4.3 Results . . . 20

5 Conclusions 27 5.1 Future work . . . 27

A Program Code 31

(6)
(7)

Chapter 1

Prerequisites

The problem of completing partial latin squares is a classic problem within com-binatorics and has a direct correspondence to that of edge coloring of complete bipartite graphs, a relationship described in detail in section 2.3. In this chapter the terminology needed to describe this relationship as well as some important results used in the study of partial latin squares are presented.

1.1 Basic denitions

Permutations are used extensively throughout this thesis to describe equivalence classes of partial latin squares. For more information about permutations see [11].

The set [n] is the set of all positive integers less than or equal to n. A per-mutation is a bijection from a set X to itself. The set of all perper-mutations on a set of n symbols is called the symmetric group, denoted by Sn. A

(permu-tation) cycle is a restriction of a permutation σ over X to a subset X ⊆ Xe such that for each pair of elements (a, b) ∈Xe2it holds that σn(a) = bfor some positive integer n; we say that the smallest non-negative integer k satisfying σk(a) = a for all a ∈

e

X is the length of the cycle. We write each cycle as (a1a2 . . . ak), ai∈ eX, i ∈ [k]where k is the length of the cycle, σn(a1) = an+1

for n ∈ [k − 1] and σ(ak) = a1. Two cycles are said to be disjoint if the

inter-section of their domains is empty. It is a well known result from group theory that any permutation can be written as a composition of its disjoint cycles; permutations are therefore often presented in this form with cycles of length 1 omitted. We call this the disjoint cycle representation of the permutation. We will also for a cycle c take c−1 to be the inverse permutation.

(8)

2 Chapter 1. Prerequisites

Example 1.1.1. The permutation σ over [8] dened by σ(n) = n + 2 (mod 8) has a disjoint cycle representation (1 3 5 7)(2 4 6 8).

Note that the representation of a cycle is not unique since there are k − 1 dierent possible ways to represent each cycle depending on which element is selected as a1.

1.2 Graphs

Here we present the necessary denitions and results for graphs and bipartite graphs; for a more exhaustive account see [5] and [3].

A graph G is a pair G = (V (G), E(G)) where |V (G)| is nite and E(G) consists of unordered pairs {a, b}, denoted ab, of distinct elements a and b from V (G); a and b are called the ends of ab. Elements of V (G) are called vertices and the elements of E(G) are called edges. If V (G) = ∅ or |V (G)| = 1 then G is called trivial. Two vertices a and b from V (G) are neighbors or adjacent if abbelongs to E(G). In a graph G the degree dG(v)of a vertex v is the number

of neighbors of v. δ(G) and ∆(G) are respectively the minimum and maximum degree over all the vertices of G. A graph G is complete if for each pair of vertices a and b in G there is an edge ab in E(G). A graph G is connected if for each pair of vertices a and b in G there exists a subset of vertices {v1, . . . , vn}

in V (G) such that {av1, v1v2, . . . , vn−1vn, vnb}is a subset of E(G).

1.2.1 Bipartite graphs

A graph G is bipartite if there are subsets V1and V2of V (G) such that V1∪V2=

V (G), V1∩ V2= ∅and no pair of vertices from the same set are neighbors. The

pair (V1, V2) is called a bipartition of G. If |V1| = |V2|, then the bipartition

and the bipartite graph are called balanced. If each vertex in V1 is a neighbor

of each vertex in V2 then G is called complete bipartite, denoted Km,n if

m = |V1|and n = |V2|.

Proposition 1.2.1. If G is a connected bipartite graph then its bipartition (V1, V2)is unique.

1.2.2 Matchings

A subset M of the edges E(G) in a graph G is called a matching if no pair of edges in M share a common end. If M is a matching and there is no matching M0

such that |M| < |M0|then M is called a maximum matching. If every vertex

from V (G) is an end of an edge in M then we call M a perfect matching. The following Lemma is a consequence of P. Hall's Theorem [8].

(9)

1.2. Graphs 3

Lemma 1.2.2. [1] If G is a balanced connected bipartite graph with bipartition (V1, V2) where |V1| = |V2| = xand δ(G) ≥ x2, then there is a perfect matching

M in G.

1.2.3 Edge coloring

For a graph G, a (proper) edge coloring of G is a map c from the set of edges of G to a set of n symbols, usually [n], such that no pair of edges ab, ac with b 6= csatises c(ab) = c(ac). The smallest value of n such that there is an edge coloring c : E(G) → [n] is called the edge-chromatic number or chromatic index of G, denoted χ0(G).

Theorem 1.2.3. (König's Edge Coloring Theorem) If G is a bipartite graph, then χ0(G) = ∆(G).

(10)
(11)

Chapter 2

Partial Latin Squares

2.1 Introduction

Denition 2.1.1. A latin rectangle A is an r×s rectangular array containing one of n = max{s, r} symbols in each of its cells in such a way that each row and column contains every symbol at most once. If s = r then we call A a latin square of order n.

Denition 2.1.2. A partial latin rectangle A is an r × s rectangular array containing at most one of n = max{s, r} symbols in each of its cells in such a way that no row or column contains the same symbol more than once. If s = r then we call A a partial latin square, PLS for short, of order n.

It follows directly from the denitions above that the set of all latin squares of order n, denoted LS(n) is a subset of the partial latin squares of order n, denoted P LS(n). From this point onward the set of symbols used as entries in cells will be [n] for partial latin squares of order n; rows and columns will be indexed using symbols from [n]. In section 2.3 we make an exception to this and instead use vertices of bipartite graphs to index rows and columns to illustrate the connection between complete bipartite graphs and partial latin squares.

If A is a PLS and the cell of A in position (a, b) contains symbol s, then we write A(a, b) = s; otherwise if the cell is empty, then we write A(a, b) = ∅ Denition 2.1.3. The orthogonal array representation of a partial latin square L is dened as a subset A of [n]3 where (a, b, s) ∈ A if and only if

L(a, b) = s.

By slight abuse of notation we will swap freely between the above notations for Latin squares. For A ∈ P LS(n) we will also use Cj and Rj to represent

(12)

6 Chapter 2. Partial Latin Squares

column and row j of A, respectively, viewed as partial latin subrectangles of A, where a partial latin subrectangle is a subset A0 of A such that A0 is a partial

latin rectangle.

Denition 2.1.4. If A0 is a latin subrectangle with exactly 2 rows and columns

then we call A0 an intercalate.

Denition 2.1.5. A partial latin square A ∈ P LS(n) is completable if there is a latin square C ∈ LS(n) such that in the orthogonal array representation A ⊆ C; C is called a completion of A, and A is said to have a completion and to be completable.

Example 2.1.6. The gures below show a partial latin square of order 7 and one of its completions

1 2 3 4 5 6 7 2 1 6 3 5 7 4 4 5 4 6 3 6 7 1 2 3 4 5 6 7 2 1 4 3 6 7 5 3 5 1 7 2 4 6 4 3 6 1 7 5 2 5 4 7 6 3 2 1 6 7 2 5 1 3 4 7 6 5 2 4 1 3

Denition 2.1.7. Two partial latin squares A and A0 of order n are called

iso-topic if A can be obtained from A0 by applying some permutations σ

r, σc, σs∈

Sn to the rows, columns and symbols of A0, respectively.

Denition 2.1.8. A conjugate of a partial latin square A ∈ P LS(n) is ob-tained by systematically rearranging the elements in each tripple (r, c, s) ∈ A ac-cording to one of the six possible ways (r, c, s), (c, r, s), (s, c, r), (r, s, c), (c, s, r) or (s, r, c); or described as a set of permutations S = {(), (r c), (r s), (c s), (r c s), (r s c)} ∼= S3. We denote each conjugate of A by As, s ∈ S.

For instance ordinary matrix transposition of a partial latin square, viewed as a matrix, corresponds to taking the (r c) conjugate.

Denition 2.1.9. The (r1, r2) row-permutation of a partial latin square

A ∈ P LS(n), with rows r1 and r2 completely lled, is the permutation σ :

[n] → [n] dened by σ(A(r1, i)) = A(r2, i) for i ∈ [n]. The (c1, c2)

column-permutation of a partial latin square A with columns c1 and c2 completely

lled is the permutation σ : [n] → [n] dened by σ(A(i, c1)) = A(i, c2) for

(13)

2.1. Introduction 7

Denition 2.1.10. For a partial latin square A with a (r1, r2)row-permutation

σr1r2, for each cycle c in the disjoint cycle representation of σr1r2, we dene a

row cycle switch as a new partial latin square A0 equal to A except that the

symbols in rows r1and r2 are permuted according to c and c−1 respectively.

By conjugacy, also illustrated below in example 2.1.11 we can perform cycle switches not only on rows but also on columns and symbols by performing row cycle switches in the (r c) and (r s) conjugate; we call these cycle switches column cycle switches and symbol cycle switches respectively. By slight abuse of notation, we shall in some places use row cycle switches of rows that are not completely lled.

Example 2.1.11. Two examples of cycle switches represented in bold in the gure below. Row 1 and 2 are permuted according to (3 4 5) and (4 3 5) respec-tively. The bottom right square is the result of a row cycle switch in the (r s) conjugate of the bottom left square obtained by rst taking the (r s) conjugate followed by permuting row 3 and 4 according to (1 2 5) and (2 1 5) respectively.

1 2 3 4 5 6 7 2 1 4 5 3 7 6 3 4 5 6 7 1 2 4 5 3 6 7 2 1 3 4 5 7 6 3 4 5 6 7 1 2 3 4 5 6 7 2 1 4 5 3 7 6 3 4 5 3 4 6 7 1 2 4 3 5 6 7 2 1 3 5 4 7 6 3 4 5 4 3 6 7

We have the following well-known lemmas, whose proofs are omitted, see e.g. [9] and [12].

Lemma 2.1.12. If A and A0 are isotopic partial latin squares, then A has a

(14)

8 Chapter 2. Partial Latin Squares

Lemma 2.1.13. If A and A0 are conjugate partial latin squares, then A has a

completion if and only if A0 has a completion.

Lemma 2.1.14. If A0 is a partial latin square obtained from the partial latin

square A by making a cycle switch, then A has a completion if and only if A0

has a completion.

2.2 Completing partial latin squares

The problem of determining if a given partial latin square is completable is NP-complete [4]. Even though the problem is hard, some headway has been made to complete certain families of partial latin squares. Presented here are some classical results.

Theorem 2.2.1. (Marshall Hall) [7] Each partial latin square A ∈ P LS(n) with r ≤ n completely lled rows or columns and all other cells empty has a completion.

The following is a famous conjecture rst proposed by Evans in [6] and later resolved by Smetaniuk. An alternative proof was published by Andersen-Hilton [2].

Theorem 2.2.2. (Evan's conjecture) Each partial latin square of order n with at most n − 1 non-empty cells has a completion.

Example 2.2.3. Illustrated in the gure below is a partial latin square satisfy-ing the conclusion of Evan's conjecture along with its completion.

2 2 2 2 2 2 2 1 3 4 5 6 7 1 2 4 3 6 7 5 3 4 2 1 7 5 6 5 6 7 2 1 3 4 4 5 6 7 2 1 3 7 3 5 6 4 2 1 6 7 1 5 3 4 2

Example 2.2.4. The following is a non-completable partial latin square of or-der 7 with exactly 7 lled cells.

(15)

2.2. Completing partial latin squares 9 2 2 2 2 2 2 1

Smetaniuk's resolution of Evan's conjecture can be found in [10]; a main ingredient of Smetaniuk's proof is what we call Smetaniuk completion. The smetaniuk completion along with its generalization by Kuhl and McGinn in [9] are presented below and the latter is used by us as a step to complete certain kinds of partial latin squares in chapter 4.

For a partial latin square A ∈ P LS(n), we call the set of cells D = {(k, k) | k ∈ [n]}the forward diagonal of A. We say that a cell (r, c) lies below D if c < r and we say that cells (r, c) lie above D if they are neither below, nor part of D. We also dene T (A) ∈ P LS(n + 1) as T (A) = {(r + 1, c, s) | (r, c, s) ∈ A, c < r} ∪ {(k, k, n + 1) | k ∈ [n + 1])}, that is, each cell below and on D of T (A) are either lled or empty with the forward diagonal containing n + 1 in each cell. In addition, all cells above D are empty. In [9], among other places a dierent denition of D and T is used, but it is easy to see that any partial latin square with a back diagonal as dened in [9] has a conjugate partial latin square with a forward diagonal obtained by simply reversing the numbering of the rows. Theorem 2.2.5. (Smetaniuk completion) [10] If A ∈ P LS(n) has a completion then so does T (A).

We call the completion of T (A) according to the method described by Smeta-niuk in [10], when it exists, a SmetaSmeta-niuk completion of T (A).

Presented in [9] is the following generalization of the concepts above. For a A ∈ P LS(n). If n is odd then the augmented forward diagonal D2 of A is

the set of cells {(k, k), (k, k + 1), (k + 1, k), (k + 1, k + 1)} for even k ∈ [4, n − 1] along with cells (1, 1), (2, 1), (3, 2) and (3, 3). If n is even then the forward diagonal D2of A is the set of cells {(k, k), (k, k + 1), (k + 1, k), (k + 1, k + 1)} for

odd k less than n. Now for A ∈ P LS(n) we form the partial latin square T2(A)

of order n + 2 as T2(A) = {(i, j, A(i − 2, j)) |cell (i, j) lies below D2 of T2(A)}

and cell (i, j) contains either n + 1 or n + 2 if it lies on the forward diagonal D2 of T2(A). By isotopy the elements on the forward diagonal does not need to contain specically n + 1 and n + 2, we will commonly use 1 and 2 as labels for the forward diagonal.

(16)

10 Chapter 2. Partial Latin Squares

Note that the augmented forward diagonal is unique up to symbol cycle switches. It is easy to see that our denition of D2 and T2 has isotopic partial

latin squares corresponding to similar denitions in [9]. We see that the following theorem from [9] hold by isotopy:

Theorem 2.2.6. If A ∈ P LS(n) has a completion then so does T2(A).

We also call the completion method for T2(A)outlined in [9] the

Smeta-niuk method for T2(A)and the completion L ∈ LS of T2(A)when it exists,

the Smetaniuk completion of T2(A). The following observations are

conse-quences of the Smetaniuk method.

Observation 2.2.7. (Part (i) of Observation 3.6 in [9]) Let X ∈ LS(n) and Lbe the Smetaniuk completion of T2(X). L(i, j) = X(i, j) if cell (i, j) is below

D2 of T2(X).

Observation 2.2.8. (Part (ii) of Observation 3.6 in [9]) Let X ∈ LS(n) and L be the Smetaniuk completion of T2(X). L(i, j) ∈ {n+1, n+2} if cell (i, j) ∈ D2

of T2(X).

Observation 2.2.9. (Part (iii) of Observation 3.6 in [9]) Let X ∈ LS(2k + 1) and L be the Smetaniuk completion of T2(X).

If {X(1, 2), X(1, 3)} ∩ {X(2, 4), X(2, 5), X(3, 4), X(3, 5)} = ∅ then L(3, 4) = X(1, 4)and L(3, 5) = X(1, 5).

It is easy to see that the following observation is a direct consequence of Observation 2.2.7, 2.2.8 and 2.2.9:

Observation 2.2.10. Whenever the conditions for Observation 2.2.9 holds and cells {X(2, 4), X(2, 5), X(3, 4), X(3, 5)} of X form an intercalate then cells {L(1, 4), L(1, 5), L(2, 4), L(2, 5)} form either the same, or a switch of, that in-tercalate.

2.3 Edge coloring of complete bipartite graphs

There is a direct correspondence between the problem of completing partial latin squares and that of nding edge colorings of complete bipartite graphs with some edges having preassigned colors. If we let G be a complete bipartite graph with bipartition (V1, V2)such that |V1| ≥ |V2|, then we know from König's

coloring theorem 1.2.3 that χ0(G) = ∆(G) = |V

1|. Suppose that some of the

edges of G have been preassigned colors chosen from [n], and that we want to determine if there is an n-edge coloring of G that agrees with the preassigned colors. Let S ⊆ [n] × [n] × [n] where n = ∆(G) such that (i, j, c) ∈ S if and only

(17)

2.3. Edge coloring of complete bipartite graphs 11

if the edge viujwith vi∈ V1and uj∈ V2has been preassigned color c. Since no

two adjacent edges may be assigned the same color we may interpret S as the orthogonal array representation of a partial latin rectangle, and in particular when |V1| = |V2|as a partial latin square. A completion S0 of S yields an edge

coloring of G by assigning the color c0 to edge v

(18)
(19)

Chapter 3

Some families of partial latin

squares

3.1 PLS with a completely lled rows and b

com-pletely lled columns

Theorem 2.2.1 by Marshall Hall shows that all partial latin squares with zero or one completely lled row, b completely lled columns and all other cells empty always has a completion. Adams, Bryant and Buchanan [1] showed that all partial latin squares of order n ≥ 6 with two completely lled rows and columns have completions. More recently Kuhl and McGinn [9] produced a much shorter proof of this result and described some solvable instances with 2 completely lled rows and b > 2 completely lled columns and formulated a conjecture describing all completable partial latin squares with two completely lled rows and b ≥ 2 completely lled columns. This section presents theory described in [9]. Since the results in Chapter 4 only pertains to two completely lled rows and three completely lled columns, most denitions and theorems in this chapter only consider the case when b = 3; for the general formulations see [9].

Denition 3.1.1. The set P LS(a, b; n) consists of all partial latin squares of order n with a completely lled rows and b completely lled columns and with all other cells empty.

By isotopy we will assume that the elements in P LS(a, b; n) have their rst a rows and b columns lled. When a = b the following theorem by Häggkvist identies a family of completable partial latin squares.

(20)

14 Chapter 3. Some families of partial latin squares

Theorem 3.1.2. [3] Let A ∈ P LS(b, b; n). If cells [b] × [b] of A form a latin square of order b then A has a completion.

Denition 3.1.3. Let A ∈ P LS(a, b; n). For any two columns Cj and Ckin A;

we dene the column composition Cj◦lCk where l ≤ b as a new column with

all the same elements as Cj except that the element in row l of Cj◦lCk is the

element in row l of Ck. We dene row composition as column composition in

A(rc).

Denition 3.1.4. Let A ∈ P LS(2, 3; n), and assume that α is a symbol not appearing in the top [2] × [3] cells of A, and such that A(j, 1) = A(k, 2) = A(l, 3) = A(1, q) = A(2, r) = α. If there is an i ∈ [n] \ [2], such that row Ri

satises that rows Rj◦1Ri, Rk◦2Riand Rl◦3Riare latin then we say that α is a

row-replaceable symbol and that row Ri replaces α. If i ∈ {j, k, l} then we

say that Ri replaces itself. Similarly if there is a p ∈ [n] \ [3] such that column

Cpsatises that columns Cq◦1Cpand Cr◦2Cp are latin, then we say that α is

a column-replaceable symbol and that column Cpreplaces α. If p ∈ {q, r}

then we say that Cpreplaces itself. If α is both row- and column-replaceable

then we say that α is replaceable. If α is replaceable with Riand Cp, replacing

αthen we dene the reduction of A denoted R(A; Ri, Cp, α) ∈ P LS(2, 3; n − 1)

as the partial latin square obtained by removing Rj, Rk, Rl, Cq and Crfrom A,

adding Rj◦1Ri, Rk◦2Ri, Rl◦3Ri, Cq◦1Cpand Cr◦2Cpto A and nally removing

Cp and Ri from A.

Example 3.1.5. Let A be a partial latin square with entries given by the gure below. A = 1 2 3 4 5 6 7 2 1 4 5 3 7 6 3 4 1 4 3 2 5 6 7 6 7 5 7 5 6

The following are three examples of row composition with R4, R5, R6and R7

from A above.

R5◦3R4= 5 6 2

R6◦2R4= 6 3 5

(21)

3.1. PLS with a completely lled rows and b completely lled columns 15

The following gure is the reduction R(A; R4, C4, 7)of A.

1 2 3 5 6 4 2 1 4 3 5 6 3 4 1 5 6 2 6 3 5 4 5 6

Theorem 3.1.6. (Lemma 2.7 in [9]) Let A ∈ P LS(2, 3; n) where n ≥ 9. If α is a symbol that does not occur in the intersection between the lled rows and columns of A then there is a row replacing α.

Denition 3.1.7. We call A ∈ P LS(2, b; n), b ≥ 3 reducible, if there is a symbol s ∈ [n] a row Ri and a column Cj, such that row Ri replaces s and

column Cj replaces s and itself. We say that the reduction R(A; Ri, Cj, s) is a

proper reduction of A. For a sequence of partial latin squares A1, A2, ..., AN

where Ap+1is a proper reduction of Apfor all p ∈ [N −1], we say that AN can be

obtained from successive reduction of A1 and that A1 can be successively

reduced to AN.

We may by isotopy assume that whenever reducing a PLS of order n that the replaced symbol is n and that the row and column replacing n is Cn and

Rn, respectively.

Theorem 3.1.8. [9] If A ∈ P LS(2, b; n), b ≥ 3, is reducible and one of its proper reductions can be completed then A can be completed.

The following is a formulation of the Kuhl-McGinn conjecture for the spe-cial case when A ∈ P LS(2, 3; n). For the general formulation when A ∈ P LS(2, b; n), b ≥ 3, see [9]. In the next chapter we prove some special cases of this formulation of the conjecture.

Conjecture 3.1.9. (The Kuhl-McGinn conjecture for b = 3) Let n ≥ 8. All partial latin squares in P LS(2, 3; n) has completions.

Example 3.1.10. Below are examples of partial latin squares in P LS(2, 3; n) that are non-completable for n = 5, 6 and 7 respectively.

(22)

16 Chapter 3. Some families of partial latin squares 1 2 3 4 5 2 4 5 3 1 3 5 1 4 3 2 5 1 4 1 2 3 4 5 6 2 6 1 5 4 3 3 5 4 4 3 5 5 4 6 6 1 2 1 2 3 4 5 6 7 2 1 7 6 4 5 3 3 7 2 4 5 6 5 6 4 6 4 5 7 3 1

(23)

Chapter 4

Completing partial latin

squares in PLS(2, 3; n)

4.1 Introduction

Presented in this chapter is a partial proof of the Kuhl-McGinn conjecture 3.1.9 for b = 3. Kuhl-McGinn reduction 3.1.7 will be used to separate the problem into a handful of sub-problems. In addition to the completion methods from the previous chapters some additional concepts and methods are introduced. The notion of cycle type is similar to the concept of column cycle type described in [1].

Denition 4.1.1. For a row-permutation σ of A ∈ P LS(2, b; n) a cycle type of a cycle in a disjoint cycle representation of σ is a string s of m symbols from the set {0, 1} where m is the length of the cycle, and s is constructed by for each element in the cycle appending 1 to s if the element occurs in the upper left [1] × [b]subarray of A and appending 0 otherwise. We call the set of pairs of all distinct cycle types along with the number of times it occurs in the disjoing cycle representation of σ the cycle type of σ, and if σ is the (1, 2) row-permutation of A then we also call it the cycle type of A.

We call two cycle types of permutations, or cycles of permutations, isotopic if they correspond to two dierent disjoint cycle representations of the same permutation. For instance if A ∈ P LS(2, b; n) and 1, 2 appears in [1] × [b], 3 does not appear in [1] × [b] and the cycle (1 2 3) is in the (1, 2) row permutation of A then 110 and 101 are isotopic since (1 2 3) and (2 3 1) is two dierent disjoint cycle representations of the same permutation. For a cycle type s; two

(24)

18 Chapter 4. Completing partial latin squares in PLS(2, 3; n)

elements in s are adjacent if they are next to each other in the string s or the rst and the last elements of s.

Example 4.1.2. The (1, 2) row permutation of the partial latin square in the gure below has a cycle type isotopic to {(110, 1), (100, 1), (00, 1)}.

1 2 3 4 5 6 7 8 2 5 4 6 1 3 8 7 3 1 2 4 3 1 5 4 7 6 7 8 7 8 6 8 6 5

Denition 4.1.3. The partial latin square A ∈ P LS(2, 3; n) where n ≥ 8 is completely reduced if the cycle type of each cycle in the (1, 2) row-permutation of A belongs to one of the following cycle type isotopy classes:

(i) 00 (ii) 10, 01 (iii) 11 (iv) 101, 110, 011 (v) 111 (vi) 1010, 0101 (vii) 1110, 0111, 1011, 1101 (viii) 10101 (ix) 101010, 010101

If A0 is completely reduced and can be obtained from successive reductions of

A we also call A0 a complete reduction of A. Note that no cycle type with length greater than 2 contains two adjacent zeroes in any representation. We will from now on use the rst element of each isotopy class to represent the entire class.

Theorem 1.2.2 applied to partial latin squares with partially lled columns yields the following lemma that can be used to complete some special types of partial latin squares obtained in section 4.3.

(25)

4.2. Reduction of the problem 19

Lemma 4.1.4. Let X ∈ P LS(n). Suppose further that X has c < n completely lled columns and one partially lled column C with exactly s < n lled cells, with all other columns empty. If n ≥ 2c + s then X is completable.

Proof. Assume that the symbols used in C is n − s + 1, n − s + 2, ..., n and that they lie on rows Rn−s+1, Rn−s+2, ..., Rn. Let G be the bipartite graph

with bipartition (V1, V2)where V1= {c1, c2, ..., cn−s}and V2= {s1, s2, ..., sn−s}

correspond to the empty cells and unused symbols of C respectively, let cisj be

an edge in G if symbol i does not occur in row j. Now, dG(ci) ≥ n − s − cand

dG(si) ≥ n−s−c, since there is at most c dierent symbols in each row and each

symbol occurs in at most c rows. Thus, δ(G) ≥ n − s − c ≥ (n − s) −n−s 2 =

n−s 2

and Theorem 1.2.2 shows that there is a perfect matching M in G. By assigning to each empty cell ci the symbol sk where cisk ∈ M we obtain a completion for

column C. Any PLS with a number of completely lled columns and all other columns empty has a completion by M. Hall 2.2.1.

4.2 Reduction of the problem

Lemma 4.2.1. If a partial latin square A ∈ P LS(2, 3; n), where n ≥ 8, is not completely reduced, then the cycle type of at least one of the cycles in the (1, 2) row permutation of A contains adjacent zeroes.

Proof. The statement is equivalent to stating that any possible cycle type of length 2 or greater for A ∈ P LS(2, 3; n) not listed in Denition 4.1.3 contains adjacent zeroes. By listing all such possible cycle types it is easy to see that any such cycle type either contains adjacent zeroes or is listed in Denition 4.1.3.

Proposition 4.2.2. A partial latin square A ∈ P LS(2, 3; n) where n ≥ 9 has a proper reduction if and only if it is not completely reduced.

Proof. First, if A is not completely reduced then there is a cycle of length greater than 2 that contains adjacent zeroes in its cycle type; this is the same as saying that the cycle contains a symbol s that is neither in [1] × [3] of A nor in an intercalate contained in rows 1 and 2; therefore the two columns containing s each replace s and themselves respectively. Furthermore by Theorem 3.1.6 we get that there is a row replacing s which means that A has a proper reduction. Secondly, if A has a proper reduction then there is a cycle of length greater than 2in the disjoint cycle representation of the (1, 2) row-permutation of A that has a cycle type with adjacent zeroes. A is therefore not completely reduced.

(26)

20 Chapter 4. Completing partial latin squares in PLS(2, 3; n)

From Proposition 4.2.2 we get that any A ∈ P LS(2, 3; n) where n ≥ 9 will by successive reduction either be reduced to a partial latin square in P LS(2, 3; 8) or to a partial latin square with a cycle type that is isotopic to one of the following cycle types: (i) {(10, 3), (00, k)} (ii) {(10, 1), (11, 1), (00, k + 1)} (iii) {(10, 1), (101, 1), (00, k + 1)} (iv) {(10, 1), (1010, 1), (00, k)} (v) {(111, 1), (00, k + 2)} (vi) {(1110, 1), (00, k + 1)} (vii) {(10101, 1), (00, k + 1)} (viii) {(101010, 1), (00, k)}

where k is some integer greater than 1. If it can be shown that all partial latin squares in P LS(2, 3; 8) as well as all with cycle types (i) − (viii) above, for all values of k, have completions; then by theorem 3.1.8 all partial latin squares in P LS(2, 3; n)have completions for n ≥ 8.

4.3 Results

In the previous section we showed that the problem of completing partial latin squares in P LS(2, 3, n) where n ≥ 9 could be reduced to completing squares with 8 distinct cycle types. In this section we provide completions to some special cases of these cycle types.

Proposition 4.3.1. Let A ∈ P LS(2, 3; n) suppose that A has cycle type {(111, 1), (00, k+ 2)}for k ≥ 3, then A has a completion.

Proof. We may by isotopy assume that the rst three columns of A are lled with the rst column sorted in a natural order and that the rst two rows of A are lled as in the gure below.

1 2 3 4 5 . . . n-1 n

2 3 1 5 4 . . . n n-1

The (1, 2) row-permutation of A contains one 3-cycle and k + 2 2-cycles, so A has odd order n = 3 + 2(k + 2). Let A(rs) be the row-symbol conjugate of A.

(27)

4.3. Results 21

The augmented forward diagonal of A(rs) is completely lled and contains only

symbols 1 and 2 and the top left [3] × [3] cells has the form shown below. 1 s1 2

2 1 s2

3 2 1

Now either s1= s2= 3in which case A has a completion by Theorem 3.1.2 or

we get the following

(a) s1 and s2 are distinct, and neither are 3

(b) exactly one of s1 and s2 is 3

(c) s1= s26= 3

Suppose that (a) holds. We may assume that s1= 4and s2= 5by permuting

labels. Construct C ∈ P LS(n − 2) by taking the last n − 3 rows, excluding the elements of the forward diagonal D2 and placing them in the last n − 3 rows

of C. Now, let (1, 1, 3), (1, 2, s1), (1, 3, s2) ∈ C. The elements below row 1 in

columns 1, 2 and 3 of C are all distinct from 3, s1and s2respectively; hence C is

a partial latin square over the symbols [n]\[2] and has a completion by Theorem 2.2.1. Now since C has a completion, T2(C) has a Smetaniuk completion by

Theorem 2.2.6. Let B be the smetaniuk completion of T2(C). Note that the

augmented forward diagonal D2 contains only symbols 1 and 2 and is equal to

the forward diagonal in A(rs). A(rs)is now contained in B and therefore has a

completion, and by conjugacy, so does A.

Suppose that (c) holds. By isotopy we may assume that s1 = s2 = 4now

by applying the permutations (1 3 2), (1 3 2), (3 4) to the columns, rows and symbols of A respectively we get a new partial latin square of cycle type {(111, 1), (00, k + 2)} isotopic to A fullling the condition in case (b), that is, case (c) is reducible to case (b) and, by isotopy; (b) is reducible to (c). Starting from (c) we will construct a completion to A in 10 steps.

Step 1: We may by isotopy assume that s1 = s2 = 4. Suppose further that

k ≥ 3.

Case 1a: If (i, 1, 4) ∈ A(rs) for some value i ∈ {4, 5} then let B

1 be the

partial latin square obtained applying ((4 6)(5 7), (4 6)(5 7), ()) ∈ Sn× Sn× Sn

to the elements of A(rs).

(28)

22 Chapter 4. Completing partial latin squares in PLS(2, 3; n)

Step 2: Put S = {B1(4, i), B1(5, i) : i ∈ [3]} and pick a row q ≥ 6 in B1

such that either B1(q, 2)or B1(q, 3)is not in S ∪ {3} and B1(q, 1) 6= 4. There

are at most six rows where this is not the case but since n ≥ 13 there are at least two rows fullling this condition. Form B2= B1∪ {(q, 4, 4)}.

Step 3:

Case 3a: If B2(q, 3) ∈ S ∪ {3}, then swap rows 1 and 2 as well as columns

2 and 3 in B2to form B3.

Case 3b: Otherwise, we dene B3= B2.

Step 4: Note that B3(q, 3) /∈ S ∪ {3}. Let B4= B3∪ {(2, 4, B3(q, 3)}. The cells

B4(q, 3), B4(q, 4), B4(2, 3), B4(2, 4)now forms an intercalate.

Step 5: Perform a switch in the cycle formed by the intercalate and let B5

be the resulting partial latin square.

Step 6: Pick a symbol s /∈ S ∪ {1, 2, 3, 4, B5(2, 3)}; there are for n ≥ 13

at least two choices for s since |S ∪ {1, 2, 3, 4, B5(2, 3)}| ≤ 11. Set B6 =

B5 ∪ {(2, 5, s), (3, 4, s), (3, 5, 4)}. The cells B6(2, 4), B6(2, 5), B6(3, 4), B6(3, 5)

now form an intercalate.

Step 7: Swap rows 1 and 3 as well as columns 1 and 2 in B6 to get B7.

Step 8: Construct C ∈ P LS(n − 2) by taking the last n − 3 rows of B7,

exclud-ing the elements of the forward diagonal D2 of B

7and placing them in the last

n − 1rows of C also let {(1, 1, 4), (1, 2, 3), (1, 3, B7(2, 3)), (2, 4, s), (3, 4, 4)} ∈ C.

The following statements (I − V ) hold:

I)Each symbol in column c of C occurs at most the same number of times as it does in column c of B7 for c ∈ [n − 2].

II) Each row r ≥ 4 in C contain the same symbols as row r + 2 in B7.

III)Row 1 in C contains the symbols 4, 3 and B7(2, 3)which are all distinct.

IV ) Row 2 in C contains symbols B1(4, 1), B1(4, 2), B1(4, 3), s which are

all distinct by construction, and s /∈ S.

V ) Row 3 in C contains symbols B1(5, 1), B1(5, 2), B1(5, 3), 4 which are all

(29)

4.3. Results 23

That is, C is a partial latin square over the symbols {3, 4, . . . , n}.

Step 9: By Lemma 4.1.4 there is a completion C0to C for n−2 ≥ 3×2+3 = 9

that is, for n ≥ 11. Construct C1 from C by adding column 4 of C0 and let

C1(3, 5) = s and C1(2, 5) = 4. The following statements (I − V ) hold:

I)Column 4 of C1is latin.

II) Each symbol in column c of C1 occurs at most the same number of

times as it does in column c of B7 for c ∈ [n − 2] \ {4}.

III)Row 2 in C1contains symbols B1(4, 1), B1(4, 2), B1(4, 3), s, 4which are

all distinct by construction, neither of s and 4 are in S.

IV )Row 3 in C1contains symbols B1(5, 1), B1(5, 2), B1(5, 3), s, 4which are

all distinct by construction, neither of s and 4 are in S.

V )Each symbol in row r of C1occurs at most the same number of times as

it does in row r of C0 for r ∈ [n − 2] \ {2, 3}.

That is, C1 is a partial latin square over the symbols {3, 4, . . . , n}.

Step 10: By Lemma 4.1.4 there is a completion C00 of C

1 for n − 2 ≥

4 × 2 + 2 = 10, that is, for n ≥ 11. Since C1 has a completion, T2(C1) has a

completion with an augmented forward diagonal D2with symbols 1 and 2. The

following statements (I − IV ) holds: I)Columns 1, 2 and 3 of T2(C

1)are the same as columns 1, 2 and 3 of B7

up to a cycle switch on symbols 1, 2 in the forward diagonal containing only the symbols 1 and 2.

II) The forward diagonal of T2(C

1)may by cycle switches be taken to be

equal to the forward diagonal in B7since they each contain only the symbols 1

and 2.

III)By Observations 2.2.9 and 2.2.10, {B7(1, 4), B7(1, 5), B7(2, 4), B7(2, 5)}

and {T2(C

1)(1, 4), T2(C1)(1, 5), T2(C1)(2, 4), T2(C1)(2, 5)} contain the same

inter-calate up to a cycle switch.

(30)

24 Chapter 4. Completing partial latin squares in PLS(2, 3; n)

Therefore, by isotopy, we may assume that T2(C

1)is a completion of B7.

More-over, by applying, isotopy, we have a completion of A(rs)and by conjugacy we

obtain a completion of A.

We conclude that in all the cases (a) − (c) we can construct completions for k ≥ 3, thus proving the proposition.

In Proposition 4.3.1 we saw that all partial latin squares in P LS(2, 3; n) with a certain cycle type has completions for n ≥ 13. We now show that the following extension of the proposition holds using computer searches.

Theorem 4.3.2. Let A ∈ P LS(2, 3; n) with rows 1 and 2 of A completely lled. If n ≥ 8 and cells [2] × [3] of A form a latin rectangle then A has a completion. Proof. Let A ∈ P LS(2, 3; n) assume that rows 1 and 2 of A are completely lled and that cells [2] × [3] of A form a latin rectangle. Note that since A has a cycle of type 111, any complete reduction of A is of odd order and any proper reduction contains a cycle with cycle type 111. One of the following must hold;

(i) There is a complete reduction A0 of A with odd order at least 13

(ii) There is a complete reduction A0 of A with order 11

(iii) There is a complete reduction A0 of A with order 9

(iv) A or a successive reduction of A either is or yields a partial latin square of order less than or equal to 8

Proposition 4.3.1 shows that A is completable if case (i) holds. That re-maining cases hold have been veried by computer search. The rere-maining cases has been completed with computer searches, for details see Appendix A. The table below show the number of partial latin squares solved. Note that since cases a) and b) are dealt with in the proof of proposition 4.3.1, for the cases of partial latin squares of order 9 and 11, we deduce by applying isotopy that only completions to the following four sets must be provided;

1. All partial latin squares A ∈ P LS(2, 3; 11) where A is completely reduced with A(1, i) = i, A(i, 1) = i, A(4, 2) = 1, A(4, 3) = 2, A(2, 2) = 3 and A(2, 3) = 1for i ∈ [11]

2. All partial latin squares A ∈ P LS(2, 3; 9) where A is completely reduced with A(1, i) = i, A(i, 1) = i, A(4, 2) = 1, A(4, 3) = 2, A(2, 2) = 3 and A(2, 3) = 1for i ∈ [9]

(31)

4.3. Results 25

3. All partial latin squares A ∈ P LS(2, 3; 8) with A(1, i) = i, A(i, 1) = i for i ∈ [8]

4. All partial latin squares A ∈ P LS(2, 3; 8) with A(1, i) = i for i ∈ [8], A(2, 1) = 4, A(3, 1) = 2, A(4, 1) = 3 and A(j, 1) = j for 5 ≤ j ≤ 8

Note that we for n = 8 cover all partial latin squares in P LS(2, 3; 8), this is not strictly necessary.

Set Total number Completable

1 90318144 90318144

2 29680 29680

3 99540128 99540128

(32)
(33)

Chapter 5

Conclusions

5.1 Future work

The problem of completing partial latin squares with 2 lled rows and 3 lled columns was reduced to completing partia latin squares of specic cycle types. In this thesis we showed that for any value of k, all partial latin squares in (v) have completions. Based on preliminary investigations, it seems that (iii) and (vii)could potentially be solved using similar methods.

(i) {(10, 3), (00, k)} (ii) {(10, 1), (11, 1), (00, k + 1)} (iii) {(10, 1), (101, 1), (00, k + 1)} (iv) {(10, 1), (1010, 1), (00, k)} (v) {(111, 1), (00, k + 2)} (vi) {(1110, 1), (00, k + 1)} (vii) {(10101, 1), (00, k + 1)} (viii) {(101010, 1), (00, k)} Göransson, 2020. 27

(34)
(35)

Bibliography

[1] Peter Adams, Darryn Bryant, and Melinda Buchanan. Completing partial latin squares with two lled rows and two lled columns. 2010.

[2] L.D Andersen and A.J.W Hilton. Thank evans! J. London Math. Soc. Third Series (3), 47:507522, 1983.

[3] Armen S. Asratian, Tristan M. J. Denley, and Roland Häggkvist. Bipar-tite graphs and their applications. Cambridge tracts in mathematics: 131. Cambridge : Cambridge University Press, 1998.

[4] C.J Colbourn. The complexity of completing partial Latin squares. Discrete Appl. Math., 8:2530, 1984.

[5] Reinhard Diestel. Graph theory. Graduate texts in mathematics: 173. Heidelberg ; New York : Springer., 2010.

[6] T. Evans. Embedding incomplete latin squares. Amer. Math. Monthly, 67:958961, 1960.

[7] M. Hall. An existance theorem for latin squares. Bulletin of the American Mathematical Society, 51:387388, 1945.

[8] P. Hall. On representatives of subsets. J. London Math. Soc., 10:2630, 1935.

[9] J. Kuhl and D. McGinn. On completing partial latin squares with two lled rows and at least two lled columns. Australasian Journal of Combi-natorics, 68(2):186201, 2017.

[10] B. Smetaniuk. A new construction of latin squares. i. a proof of the evans conjecture. Ars Combinatoria, 11:155172, 1981.

[11] Per-Anders Svensson. Abstrakt algebra. Lund : Studentlitteratur, 2001.

(36)

30 Bibliography

[12] I. Wanless. Cycle switches in latin squares. Graphs and Combinatorics, 20:545570, 2004.

(37)

Appendix A

Program Code

using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using System.Diagnostics; namespace LatinSquareSolver { class Program {

static Stack<LatinSquare> ToBranch = new Stack<LatinSquare >();

static List<int> solutionCounts = new List<int>(); static int totalUnsolvable = 0;

static int totalThreads = 0; static int completedThreads = 0; static int completedSquares = 0; static int runningThreads = 0; static int maxNumThreads = 12; static void Reset()

{

totalUnsolvable = 0; totalThreads = 0;

(38)

32 Appendix A. Program Code

completedThreads = 0; completedSquares = 0; runningThreads = 0; }

static void Main(string[] args) {

// Corresponds to set 3 in Theorem 4.3.2 LatinSquare ls = new LatinSquare(8); ls.SetNormalized();

RunEight(ls); Reset();

// Corresponds to set 4 in Theorem 4.3.2 ls = new LatinSquare(8); ls.SetNormalized(); ls[1, 0] = 4; ls[3, 0] = 2; RunEight(ls); Reset();

// Corresponds to set 2 in Theorem 4.3.2 RunOdd(9);

Reset();

// Corresponds to set 1 in Theorem 4.3.2 RunOdd(11);

Reset();

Console.Read(); Console.Read(); }

static void RunOdd(int n) {

LatinSquare ls = new LatinSquare(n); Stack<int> columns = new Stack<int>(); columns.Push(2);

(39)

33

ls.SetNormalized();

for (byte i = 3; i < n; i++) { ls[1, i] = (byte)(i % 2 == 0 ? i : i + 2); } ls[1, 1] = 3; ls[1, 2] = 1; ls[3, 1] = 1; ls[3, 2] = 2; ls[1, 1] = 3; ls[1, 2] = 1;

Task t = Task.Run(() => BranchColumns(ls.Copy(), new Stack<int>(columns)));

Stopwatch s = new Stopwatch(); s.Start(); Thread.Sleep(1000); while(totalThreads - completedThreads > 0) { Thread.Sleep(1000); } Console.WriteLine($"Completed {completedThreads} threads with {totalThreads} running, {

completedSquares} completed squares of which { totalUnsolvable} are non-completable");

Console.WriteLine($"Time taken: {s.ElapsedMilliseconds } ms");

}

static void BranchColumns(LatinSquare ls, Stack<int> columns) { int c = columns.Pop(); int unsolvable = 0; List<LatinSquare> lsl = ls.BranchColumn(c); if (columns.Count > 0) {

(40)

34 Appendix A. Program Code

Interlocked.Add(ref totalThreads, lsl.Count); } foreach (LatinSquare sls in lsl) { if (columns.Count >= 1) { Interlocked.Increment(ref runningThreads); Task t = Task.Run(() => BranchColumns(sls.Copy

(), new Stack<int>(columns))); if (runningThreads >= maxNumThreads) { t.Wait(); } } else {

LatinSquare solved = sls.Solve(); if (!solved.Finished()) { solved = solved.Solve(); if (!solved.Finished()) { Console.WriteLine(sls); Interlocked.Increment(ref totalUnsolvable); Interlocked.Increment(ref unsolvable); } } } } if (columns.Count == 0) { if (unsolvable > 0) {

Console.WriteLine($"Thread finished with { unsolvable} non-completable PLS out of a total of {lsl.Count} and total unsolvable: {totalUnsolvable}");

(41)

35

Interlocked.Add(ref completedSquares, lsl.Count); Interlocked.Increment(ref completedThreads); Interlocked.Decrement(ref runningThreads); }

}

static void RunEight(LatinSquare ls) {

Stopwatch s = new Stopwatch(); s.Start();

List<LatinSquare> lsl = ls.BranchRow(1);

List<LatinSquare> llsl = new List<LatinSquare>(); foreach (LatinSquare sls in lsl)

{

llsl.AddRange(sls.BranchColumn(1)); }

totalThreads = llsl.Count;

Stack<int> columns = new Stack<int>(); columns.Push(2);

foreach (LatinSquare sls in llsl) {

Interlocked.Increment(ref runningThreads);

Task t = Task.Run(() => BranchColumns(sls.Copy(), new Stack<int>(columns))); if (runningThreads >= maxNumThreads) { t.Wait(); } }

while (totalThreads - completedThreads > 0) {

Thread.Sleep(1000); }

(42)

36 Appendix A. Program Code

Console.WriteLine($"totalUnsolvable: {totalUnsolvable }, {completedThreads} threads completed a total of {completedSquares} squares over {s.

ElapsedMilliseconds} milliseconds"); } } } using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace LatinSquareTest { struct Entry {

public Entry(int r, int c, byte s) { this.r = r; this.c = c; this.s = s; } public byte s; public int c, r; } class LatinSquare {

private byte[,] entries; public int n;

public LatinSquare(int n) : this(n, new byte[n, n]) {

}

private LatinSquare(int n, byte[,] entries = null) {

this.n = n;

(43)

37

this.entries = new byte[n, n]; else

this.entries = entries; }

public void SetRow(int r, byte[] rowEntries) {

for (int i = 0; i < rowEntries.Length; i++) {

this.entries[r, i] = rowEntries[i]; }

}

public int[] GetRow(int r) {

int[] rowEntries = new int[n]; for (int i = 0; i < n; i++) {

rowEntries[i] = this.entries[r, i]; }

return rowEntries; }

public void SetColumn(int c, byte[] colEntries) {

for (int i = 0; i < colEntries.Length; i++) {

this.entries[i, c] = colEntries[i]; }

}

public int[] GetColumn(int c) {

int[] colEntries = new int[n]; for (int i = 0; i < n; i++) {

colEntries[i] = this.entries[i, c]; }

(44)

38 Appendix A. Program Code

}

public void SetElement(int r, int c, byte entry) {

entries[r, c] = entry; }

public int GetElement(int r, int c) {

return entries[r, c]; }

public void SetNormalized(bool r = true, bool c = true) {

byte[] list = new byte[n]; for (byte i = 0; i < n; i++) { list[i] = (byte) (i + 1); } if (r) SetRow(0, list); if (c) SetColumn(0, list); }

public void SetNormalized() {

SetNormalized(true, true); }

public void Normalize() {

while (!IsNormalized()) {

for (int i = 0; i < n; i++) {

SwapColumns(i, entries[0, i] - 1); SwapRows(i, entries[i, 0] - 1);

(45)

39

} } }

private bool IsNormalized() {

for (int i = 0; i < n; i++) { if (entries[0, i] != i + 1 || entries[i, 0] != i + 1) { return false; } } return true; }

private void SwapColumns(int c1, int c2) {

for (int i = 0; i < n; i++) { byte tmp = entries[i, c1]; entries[i, c1] = entries[i, c2]; entries[i, c2] = tmp; } }

private void SwapRows(int r1, int r2) {

for (int i = 0; i < n; i++) {

byte tmp = entries[r1, i]; entries[r1, i] = entries[r2, i]; entries[r2, i] = tmp;

} }

public void SetDiagonal(byte value) {

for (int i = 0; i < n; i++) {

(46)

40 Appendix A. Program Code

SetElement(i, i, value); }

}

public LatinSquare RowSymbolSwap() {

LatinSquare ls = new LatinSquare(n); for (int i = 0; i < n; i++)

{

for (int j = 0; j < n; j++) {

int entry = this.entries[i, j]; if (entry != 0) { ls.SetElement(entry - 1, j, (byte) (i + 1)); } } } return ls; }

public LatinSquare Intersection(LatinSquare ls) {

if (ls.n != n) {

throw new ArgumentException("Invalid size"); }

LatinSquare result = new LatinSquare(n); for (int i = 0; i < n; i++)

{ for (int j = 0; j < n; j++) { if (this[i,j] == ls[i,j]) { result[i, j] = this[i, j]; } } }

(47)

41

return result; }

public bool Equals(LatinSquare ls) {

if (ls.n != n) {

return false; }

for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (this[i,j] != ls[i,j]) { return false; } } } return true; }

public byte this[int i, int j] { get { return entries[i, j]; } set { entries[i, j] = value; } }

private bool Reduce() {

bool reducible = true; bool reduced = true;

(48)

42 Appendix A. Program Code

{

for (int c = 0; c < n; c++) {

int pre = entries[r, c]; ReduceElement(r, c); int post = entries[r, c]; if (pre != 0 && post == 0) {

reducible = false; }

if (pre == 0 && post != 0) {

reduced = false; }

} }

if (!reduced && reducible) {

Reduce(); }

return reducible; }

private void ReduceElement(int r, int c) {

if (entries[r, c] == 0) {

List<byte> newEntry = ElementCandidates(r, c); if (newEntry.Count == 1) { entries[r, c] = newEntry[0]; } } }

(49)

43

{

int[] candidates = new int[n]; if (entries[r, c] == 0)

{

for (int i = 0; i < n; i++) {

candidates[i] = 1; }

for (int i = 0; i < n; i++) {

int rowEntry = entries[r, i]; int colEntry = entries[i, c]; if (rowEntry != 0 && i != c) { candidates[rowEntry - 1] = 0; } if (colEntry != 0 && i != r) { candidates[colEntry - 1] = 0; } } } else { candidates[entries[r, c] - 1] = 1; }

List<byte> candidateList = new List<byte>(); for (byte i = 0; i < n; i++)

{ if (candidates[i] == 1) { candidateList.Add((byte) (i + 1)); } } return candidateList; }

(50)

44 Appendix A. Program Code

public bool Finished() {

bool valid = Reduce();

foreach (int entry in entries) { if (entry == 0) { return false; } } return valid; }

public List<LatinSquare> Branch(int r, int c) {

List<LatinSquare> lsl = new List<LatinSquare>(); foreach (byte value in ElementCandidates(r, c)) { LatinSquare ls = this.Copy(); ls.SetElement(r, c, value); lsl.Add(ls); } return lsl; }

public List<Entry> BranchE(int r, int c) {

List<Entry> el = new List<Entry>();

foreach (byte value in ElementCandidates(r, c)) {

Entry e = new Entry(r, c, value); el.Add(e);

}

return el; }

public List<LatinSquare> BranchColumn(int c) {

(51)

45

List<LatinSquare> lsl = new List<LatinSquare>() { this };

List<LatinSquare> lslnext = new List<LatinSquare>(); for (int r = 0; r < n; r++)

{

lslnext = new List<LatinSquare>(); foreach (LatinSquare sls in lsl) { lslnext.AddRange(sls.Branch(r, c)); } lsl = new List<LatinSquare>(lslnext); } return lsl; }

public List<LatinSquare> BranchRow(int r) {

List<LatinSquare> lsl = new List<LatinSquare>(); lsl.Add(this);

List<LatinSquare> lslnext = new List<LatinSquare>(); for (int c = 0; c < n; c++)

{

lslnext = new List<LatinSquare>(); foreach (LatinSquare sls in lsl) { lslnext.AddRange(sls.Branch(r, c)); } lsl = new List<LatinSquare>(lslnext); } return lsl; }

public List<Entry> BranchNext() {

for (int i = 0; i < n; i++) {

(52)

46 Appendix A. Program Code

{

List<Entry> entries = BranchE(i, j); if (entries.Count > 1) { entries.Reverse(); return entries; } if (entries.Count == 0) {

return new List<Entry>(); }

} }

return new List<Entry>(); }

public LatinSquare Copy() {

return new LatinSquare(n, entries.Clone() as byte[,]); }

public override string ToString() {

return ToString(false); }

public string ToString(bool detailed) {

string s = string.Empty; for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

int entry = entries[i, j]; List<byte> elementCandidates =

ElementCandidates(i, j);

if (detailed && elementCandidates.Count > 1) {

s += "{";

(53)

47 { s += e + ", "; } s = s.Substring(0, s.Count() - 2); s += "}, "; } else { s += entries[i, j] + ", "; } } s += System.Environment.NewLine; } return s; }

public string ToLatex(int offset = 0) {

string s = string.Empty; s += "\\begin{tabular}{";

s += String.Concat(Enumerable.Repeat("|l", n)); s += "|} \\hline ";

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

int entry = entries[i, j]; if (entry != 0) { s += entry + offset; } else { s += " "; } if (j != n - 1)

(54)

48 Appendix A. Program Code { s += " & "; } else { s += " \\\\ "; if (i != n - 1) { s += "\\hline "; } } } } s += "\\hline \\end{tabular}"; return s; }

public bool Solvable() {

return this.Solve().Finished(); }

public LatinSquare Solve() {

Stack<Tuple<LatinSquare, Entry>> lsl = new Stack<Tuple <LatinSquare, Entry>>();

foreach (Entry e in this.BranchNext()) {

lsl.Push(new Tuple<LatinSquare, Entry>(this, e)); }

LatinSquare ls = null;

Tuple<LatinSquare, Entry> lse = null; while (lsl.Count != 0)

{

lse = lsl.Pop(); ls = lse.Item1.Copy();

(55)

49

ls.SetElement(lse.Item2.r, lse.Item2.c, lse.Item2.s );

if (ls.Finished()) {

break; }

foreach (Entry e in ls.BranchNext()) {

lsl.Push(new Tuple<LatinSquare, Entry>(ls, e)); } } return ls; } } }

(56)
(57)

Linköping University Electronic Press

Copyright

The publishers will keep this document online on the Internet  or its possible replacement  from the date of publication barring exceptional circumstances.

The online availability of the document implies permanent permission for anyone to read, to download, or to print out single copies for his/her own use and to use it unchanged for non-commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional upon the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authentic-ity, security and accessibility.

According to intellectual property law the author has the right to be men-tioned when his/her work is accessed as described above and to be protected against infringement.

For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its www home page: http://www.ep.liu.se/.

Upphovsrätt

Detta dokument hålls tillgängligt på Internet  eller dess framtida ersättare  från publiceringsdatum under förutsättning att inga extraordinära omständig-heter uppstår.

Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat för ickekommersiell forskning och för undervisning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av dokumentet kräver upphovsmannens medgivande. För att garantera äktheten, säkerheten och tillgängligheten nns lösningar av teknisk och administrativ art. Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsmannens litterära eller konstnärliga anseende eller egenart.

För ytterligare information om Linköping University Electronic Press se för-lagets hemsida http://www.ep.liu.se/.

c

References

Related documents

Accordingly, the primary aim of the present investi- gation was to characterize the effects of low energy intake (3.2 kcal/kg body mass per day) in combination with 9 h of

Steam turbine generator synchronised to the power grid at time 360, changed over to reactive power control around time 400 simultaneously as the active power reference value

To get a clear understanding of the working process of the team members, the researchers were introduced to the working process of the feature team through company presentations.

Eight key challenges were identified and relate to the areas of system boundaries, data collection methods, energy intensity metrics, transparency and data

rekommenderades från Linköpings tekniska högskola och som kunde anses rimligt att sammanställa under tiden för ett examensarbete om 20 veckors arbete. För den kravspecifikation

Författarna tror i detta fall att klara rollgränser, uppdelat ansvar och frånvaron av gemensam målsättning och formella möten där alla kan utbyta information, kan påverka

Submitted to Linköping Institute of Technology at Linköping University in partial fulfilment of the requirements for the degree of Licentiate of Engineering. Department of Computer

The model is a structured unified process, named S 3 P (Sustainable Software Security Process) and is designed to be easily adaptable to any software development process. S 3