<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>On polynomial reduction of problems based on diagonal Latin squares to the exact cover problem</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Eduard Vatutin</string-name>
          <email>evatutin@rambler.ru</email>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Natalia Nikitina</string-name>
          <email>nikitina@krc.karelia.ru</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Alexey Belyshev</string-name>
          <email>alexey-bell@yandex.ru</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Maxim Manzyuk</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Institute of Applied Mathematical Research, Karelian Research Center RAS</institution>
          ,
          <addr-line>11 Pushkinskaya St, Petrozavodsk, 185910, Russian Federation</addr-line>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Internet portal BOINC.ru</institution>
          ,
          <addr-line>Russian Federation</addr-line>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Southwest State University</institution>
          ,
          <addr-line>94 50 Let Oktyabrya St, Kursk, 305040, Russian Federation</addr-line>
        </aff>
      </contrib-group>
      <abstract>
        <p>The paper discusses the reduction of problems based on Latin squares to the exact cover problem aiming at its subsequent solution using the dancing links algorithm. The former problems include generation of Latin squares and diagonal Latin squares of a general form/with a given normalization, generation of orthogonal Latin and diagonal Latin squares directly/through the set of transversals, obtaining a set of transversals for a given square, forming a subset of disjoint transversals. For each subproblem, we describe in detail the process of forming the corresponding binary coverage matrices. We show that the use of the proposed approach in comparison with the classical one, i.e. the formation of sets of transversals and their coverages using exhaustive enumeration, allows one to increase the e ective processing pace of diagonal Latin squares by 2.5{5.6 times. The developed software implementations of the algorithms are used in computational experiments as part of the Gerasim@Home volunteer distributed computing project on the BOINC platform</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        One of the known types of combinatorial objects are the Latin Squares (LS) [
        <xref ref-type="bibr" rid="ref1 ref2">1, 2</xref>
        ], which are
square tables of size N N cells, where N is the order of the square, lled with elements of
some alphabet U (for de niteness in this paper, by integers from 0 to N 1), so that in each
row and each column the elements of the alphabet are not repeated. For Diagonal Latin Squares
(DLS), an additional restriction is introduced on the absence of the same values on the main and
secondary diagonals. A number of scienti c publications study the properties of LS and DLS. A
number of open questions from the eld of enumerative combinatorics [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] and open mathematical
problems are related to them, the most famous of which is the problem of the existence or
nonexistence of a triple of mutually orthogonal LS/DLS of order 10. Orthogonal, abbr. OLS/ODLS,
are such squares A = (aij ) and B = (bij ) for which all ordered pairs (aij ; bij ); i; j = 0; N 1 are
di erent.
      </p>
      <p>
        Currently, all ODLS of orders 1{8 and their properties are known up to an isomorphism in
the corresponding main classes1. For higher orders, it is currently not possible to obtain all
ODLS due to their large number on the one hand and, as a consequence, huge computational
costs on the other hand. Currently, in the projects of volunteer computing RakeSearch [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]
and Gerasim@Home [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], the lists of canonical forms (lexicographically minimal representatives
within the corresponding main classes) of the ODLS of orders 9 and 10 are being constructed.
Moreover, the computations within the RakeSearch project are based on the existence of such
ODLS pairs, for some orders [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], in which an orthogonal mate is obtained from the original
one by rearranging its rows (a special case of orthogonality of the ESOLS type (Extended
SelfOrthogonal Latin Squares) [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], which allows one to raise the processing rate of squares to a value
of about 70,000{80,000 DLS/s. The Gerasim@Home project uses a general classical approach
based on the Euler-Parker method [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], in which the presence of a general-type ODLS mate for a
given square is checked in two stages. They are construction of a set of diagonal transversals and
search for subsets of N disjoint transversals in its composition. At the same time, both tasks are
actually polynomially reduced to solving the exact cover problem that is NP-complete [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ], the
solution of which is possible both directly, using the appropriate recursive algorithms, and using
the well-known dancing links algorithm (DLX [
        <xref ref-type="bibr" rid="ref10 ref11">10, 11</xref>
        ]). This paper provides meticulous study
of the details of this procedure for polynomial reduction of initial particular problems on the
basis of LS/DLS to DLX and estimation of speed characteristics of the corresponding software
implementations.
      </p>
    </sec>
    <sec id="sec-2">
      <title>2. DLX algorithm for solving the exact cover problem</title>
      <p>The DLX algorithm for solving the exact cover problem is based on constructing the
corresponding binary coverage matrix of size R rows by C columns, followed by nding such
subsets of rows whose units exactly (without intersections) cover all columns. To solve problems
based on LS/DLS, it is necessary to form various coverage matrices, which is non-trivial and is
discussed in detail below.</p>
      <p>When forming an LS , the rows of the binary matrix correspond to all possible combinations
of triples (i; j; ), where i is the row number of the formed square, j is the column number,
is the value placed in the cell aij , the total number of rows is N 3. The columns of the binary
matrix correspond to three semantic groups of N 2 elements each:
(i) The i-th row ri of the square contains the value of (N 2 columns of the binary matrix),
(ii) The j-th column cj contains the value of (N 2 columns of the binary matrix),
(iii) The cell of a square with coordinates [i; j] is used (N 2 columns of a binary matrix).</p>
      <p>The binary matrix that corresponds to forming an LS of order 3 is shown in Fig. 1.</p>
      <p>When forming a DLS , two more groups of columns are added to the matrix considered above:
(i) The main diagonal of the square contains the value (N columns),
(ii) The secondary diagonal of the square contains the value (N columns).</p>
      <p>The binary matrix that corresponds to forming an LS of order 3 is shown in Fig. 2.</p>
      <p>When forming LS/DLS normalized by their rst row , by de nition, the elements of the rst
row are speci ed: a00 = 0; a01 = 1; : : : ; a0;N 1 = N 1, and one cannot set any other values in
their places, which corresponds to the special rst row and gaps (empty rows without units) in
the binary matrix. An example of such a binary matrix is shown in Fig. 3, where blank lines
are highlighted in gray. In order to reduce the problem dimension, empty rows can be removed
from the matrix.</p>
      <p>To search for a set of diagonal transversals in the LS/DLS , the rows of the binary matrix
correspond to the elements aij of the square, included in the transversal. The columns of the
matrix correspond to the following semantic groups of elements:
1 http://evatutin.narod.ru/evatutin odls 1 to 8.zip
(i) Transversal element aij covers the i-th row of the square (N columns),
(ii) Transversal element aij covers the j-th column of the square (N columns),
(iii) Transversal element aij =
(N columns),</p>
      <p>covers the value of in the set of values used in the transversal
(iv) Element aij is located on the main diagonal (1 column),
(v) Element aij is located on the secondary diagonal (1 column).</p>
      <p>When forming transversals of a general form (non-diagonal), the last two semantic groups
and the corresponding two columns of the matrix should be excluded from consideration. Note
that when forming a coverage, the values of groups 1, 2, 4, and 5 are general and independent
of the processed DLS, while the values of group 3 are determined by the speci c values of the
elements of the processed DLS, for which a set of transversals is formed. An example of a binary
00 1 21
matrix for the formation of a set of diagonal transversals for an LS @1 2 0A is shown in
2 0 1</p>
      <p>To search for an ODLS mate B for a given DLS A directly (without using transversals),
the binary matrix has N 3 rows corresponding, as in the search for LS/ DLS, to all possible
combinations of triples (i; j; ). The columns of the matrix correspond to two semantic groups:
(i) The formation of the correct DLS B (3N 2 + 2N columns),
(ii) The uniqueness of pairs of values ( 1; 2), 1 = aij , 2 = bij (N 2 columns by the number of
pairs).</p>
      <p>(3N 2 + 2N ) for the formation of DLS of order N = 3.</p>
      <p>To form an OLS from the rst semantic group of the matrix, it is necessary to exclude 2N
columns corresponding to restrictions on the uniqueness of values on the diagonals.</p>
      <p>To form the reduced OLS/ODLS pairs , it is necessary, as already discussed above, to form a
special rst row of the binary matrix corresponding to the pairs of elements (0; 0); (1; 1); : : : ; (N
1; N 1) in the rst rows of squares of the formed pair, and to remove from the binary matrix
the empty lines corresponding to the assignment (a0i := 1) ^ (b0i := 2) of values of the xed
elements. An example of a binary matrix corresponding to the formation of the ODLS mate to
a given DLS is shown in Fig. 5.</p>
      <p>When forming an ODLS from a set of transversals , each row of the binary matrix corresponds
to one of the transversals, the columns of the matrix correspond to the elements aij of the formed
orthogonal square that are part of the transversal. An example of a square, its set of transversals
and the corresponding binary matrix are shown in Fig. 6.</p>
      <p>When forming ODLS pairs directly (without transversals), the corresponding binary matrix
will have N 4 rows corresponding to all possible combinations of values (i; j; 1; 2), and</p>
      <p>DL{Sz A
(3N 2 + 2N ) + (3N 2 + 2N ) +
| } | }</p>
      <p>DL{Sz B</p>
      <p>N 2
pairs (ai|j;{bzij})=( 1; 2)
= 7N 2 + 4N
columns that correspond to the correctness conditions for the pair of squares A and B in
conjunction with the uniqueness of the pairs ( 1; 2).</p>
      <p>It is easy to notice that the binary matrices given above, corresponding to various problems
based on LS/DLS/OLS/ODLS, are signi cantly sparse, which makes it e cient to use the DLX
dancing links algorithm in the search for coverages.</p>
      <p>(3N +2) to form the set of diagonal transversals of the</p>
      <p>(4N 2 + 2N ) for forming the ODLS for the given LS
dimension of the problem being solved (from the LS/DLS order N ), and the corresponding
algorithms for their formation are quite simple and have an asymptotic polynomial time
complexity not exceeding O(N 3).</p>
      <p>Construction of the set Construction of the set
of transversals of LS/DLS of diagonal transversals of LS/DLS</p>
      <p>
        In the early software implementation the search for transversals and covers from them was
implemented using the exhaustive search method. In this case, the strategy of early cutting
o unpromising solutions (branches and bound method [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ]), the variation of the lling order
of transversal elements in accordance with the principle of minimum capabilities and the use
of bit arithmetic were tested and the processing rate 357 DLS/s was reached [
        <xref ref-type="bibr" rid="ref13">13</xref>
        ]. Reduction
of the problem of checking random DLS for the presence of ODLS to the search for the exact
covers through transversals in two stages (searching for diagonal transversals, searching for the
cover of a square with disjoint diagonal transversals), using the developed DLX implementation,
allowed us to increase the processing rate to 900 DLS/s for single-threaded implementation in
Delphi on the processor Intel Core i7 4770 (Haswell). In fact, two implementations of the DLX
algorithm were developed: one based on a two-dimensional array, the other based on a dynamic
list. Array-based implementation is suitable for debugging, but list-based implementation turned
out to be faster. In [
        <xref ref-type="bibr" rid="ref14">14</xref>
        ], DLX was used to nd all orthogonal mates for randomly generated
DLS of order 10. The resulting performance was about 899 DLS/s on 1 CPU core. Note, that
in [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] DLX outperformed both SAT approach and backtrack search. Using a similar software
implementation in C++ allows one to achieve an e ective processing rate of about 7 000 8 000
DLS/s in the same conditions within the special procedure named canonization (search for
symmetrically placed transversals in the LS, putting them in place of the main and secondary
diagonals of a square by rearranging its rows and columns [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ]). The way to build a faster
procedure for checking the DLS for the presence of ODLS is currently unknown.
0 4
(3 { ?)
(0 { 8)
(3 { 15)
(0 { 32)
(3 { 133)
(0 { 384)
(68 { ?)
(0 { 5504)
100
Note: symbol "?" in the table indicates the quantities whose exact value is currently unknown.
      </p>
    </sec>
    <sec id="sec-3">
      <title>3. Conclusion</title>
      <p>
        Thus, the problems considered above allow e ective polynomial reduction to the exact cover
problem and its solution using DLX. The developed software implementations of the algorithms
for constructing cover matrices, DLX, and reconstructing solutions from the found covers are
currently actively used in the Gerasim@Home volunteer computing project within the BOINC
platform [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ], and the speed characteristics of the search for ODLS of order 10 are limited by this
combination of software implementations of these algorithms. At the moment, their use made
it possible to nd a list of 9.7 million canonical forms of ODLS, including 24 di erent types
of combinatorial structures (graphs from DLS on the set of binary orthogonality relation) [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ].
Most part of them were found via the approach proposed in the paper in combination with
di erent LS generators (for general type DLS, plane symmetric DLS, generalized symmertic DLS,
neighborhoods of generalized symmetries of DLS) in the input of the considered Euler-Parker
algorithm. In some experiments within the project the search for ODLS with special types of
orthogonality can be performed without the use of transversals (for example, for Self-Orthogonal
DLS (abbr. SODLS) [
        <xref ref-type="bibr" rid="ref18">18</xref>
        ] and Extended Self-Orthogonal DLS (abbr. ESODLS)) and limited by
the speed characteristics of the appropriate generators, however, post-processing of the obtained
results still requires the use of the Euler-Parker method with DLX inside. Unfortunately, no
one of the found combinatorial structures includes a triple of pairwise orthogonal DLS or a
clique of greater cardinality. Also, these program implementations have been used in solving
some enumeration problems that allowed us to discover a set of new numerical series within
the Online Encyclopedia of Integer Sequences (OEIS) [
        <xref ref-type="bibr" rid="ref19 ref20">19, 20</xref>
        ] (A287644, A287645, A287647,
A287648, A287651, A287695, A305568, A305569, A305570, A305571, A328873, etc.).
      </p>
    </sec>
    <sec id="sec-4">
      <title>Acknowledgments</title>
      <p>The work was supported by the Russian Foundation of Basic Research, project 18-07-00628.
Authors thank citerra [Russia Team] from the internet portal BOINC.ru for his help in the
development and implementation of some algorithms and corresponding productive discussions.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Colbourn</surname>
            <given-names>C J</given-names>
          </string-name>
          and
          <string-name>
            <surname>Dinitz J H 2006</surname>
          </string-name>
          <article-title>Handbook of Combinatorial Designs, Second Edition (Discrete Mathematics and Its Applications) (Chapman</article-title>
          &amp; Hall/CRC) ISBN 1584885068 URL http://dx.doi.org/10.1201/9781420010541
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <surname>Keedwell</surname>
            <given-names>A D</given-names>
          </string-name>
          and
          <string-name>
            <surname>Denes J 2015 Latin</surname>
          </string-name>
          <article-title>Squares and their applications (Elsevier) URL http</article-title>
          ://dx.doi.org/10.1016/C2014-0-03412-0
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <surname>Bona</surname>
            <given-names>M 2015</given-names>
          </string-name>
          <article-title>Handbook of Enumerative Combinatorics (Apple Academic Press Inc</article-title>
          .) ISBN 1482220857
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          <article-title>[4] 2020 Volunteer computing</article-title>
          project RakeSearch Available at https://rake.boincfast.ru/rakesearch/
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>[5] 2020 Volunteer computing project Gerasim@Home Available at http://gerasim.boinc.ru</mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <surname>Manzyuk</surname>
            <given-names>M</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Nikitina</surname>
            <given-names>N</given-names>
          </string-name>
          and
          <string-name>
            <surname>Vatutin E 2019 Russian Supercomputing Days</surname>
          </string-name>
          (Springer) pp
          <volume>725</volume>
          {
          <fpage>734</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          <article-title>[7] 2020 Extended self-orthogonal diagonal latin squares Available at</article-title>
          https://oeis.org/A309210
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <surname>Parker</surname>
            <given-names>E T</given-names>
          </string-name>
          <year>1959</year>
          Proc. Natl.
          <source>Acad. Sci. USA</source>
          45
          <volume>859</volume>
          {
          <fpage>862</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <surname>Karp R M 1972</surname>
          </string-name>
          <article-title>Complexity</article-title>
          of Computer Computations pp
          <volume>85</volume>
          {
          <fpage>103</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <surname>Knuth D E 2000 Millenial</surname>
            <given-names>Perspectives</given-names>
          </string-name>
          <source>in Computer Science</source>
          <volume>187</volume>
          {
          <fpage>214</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>Knuth D E 2013</surname>
          </string-name>
          <article-title>The art of computer programming</article-title>
          , Volume
          <volume>4A</volume>
          :
          <article-title>combinatorial algorithms (Addison-Wesley Professional) ISBN 0201038048</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <surname>Land A H and Doig</surname>
            <given-names>A G</given-names>
          </string-name>
          <year>1960</year>
          Econometrica 28
          <volume>497</volume>
          {520 ISSN 00129682
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <surname>Vatutin</surname>
            <given-names>E I</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kochemazov</surname>
            <given-names>S</given-names>
          </string-name>
          and
          <string-name>
            <surname>Zaikin O S 2017</surname>
          </string-name>
          <article-title>Visual analytic 2017 (Kuzbassvuzizdat</article-title>
          ) pp
          <fpage>44</fpage>
          {
          <fpage>49</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <surname>Kochemazov</surname>
            <given-names>S</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zaikin</surname>
            <given-names>O</given-names>
          </string-name>
          and
          <string-name>
            <surname>Semenov</surname>
            <given-names>A 2017</given-names>
          </string-name>
          <year>2017</year>
          40th
          <article-title>International Convention on Information and Communication Technology, Electronics and Microelectronics (MIPRO</article-title>
          ) pp
          <volume>1166</volume>
          {
          <fpage>1171</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <surname>Brown J W</surname>
            , Cherry
            <given-names>F</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Most</surname>
            <given-names>L</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Most</surname>
            <given-names>M</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Parker E T and Wallis</surname>
            <given-names>W D</given-names>
          </string-name>
          <source>1992 Lecture notes in pure and applied mathematics 139</source>
          <volume>43</volume>
          {
          <fpage>49</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <surname>Anderson</surname>
            <given-names>D P</given-names>
          </string-name>
          <year>2019</year>
          <source>Journal of Grid Computing</source>
          <volume>1</volume>
          {
          <fpage>24</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <surname>Vatutin</surname>
            <given-names>E I</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Titov</surname>
            <given-names>V S</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zaikin</surname>
            <given-names>O S</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kochemazov</surname>
            <given-names>S E</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Manzuk</surname>
            <given-names>M O</given-names>
          </string-name>
          and
          <string-name>
            <surname>Nikitina N N 2018 CEUR Workshop</surname>
          </string-name>
          <article-title>Proceedings</article-title>
          .
          <source>Proceedings of the VIII International Conference "Distributed Computing and Gridtechnologies in Science and Education" (GRID</source>
          <year>2018</year>
          )
          <volume>2267 282</volume>
          {
          <fpage>287</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          [18]
          <string-name>
            <surname>Brayton R K</surname>
            , Coppersmith
            <given-names>D</given-names>
          </string-name>
          <source>and Ho man A J 1974 Bulletin of the American Mathematical Society</source>
          <volume>80</volume>
          116{
          <fpage>118</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [19]
          <string-name>
            <surname>Sloane N J A 1994 Electr. J. Comb</surname>
          </string-name>
          . 1
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          [20]
          <string-name>
            <surname>Sloane N J A 2020</surname>
          </string-name>
          <article-title>The on-line encyclopedia of integer sequences Available at</article-title>
          https://oeis.org
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>