• No results found

Constructing Magic Squares

A square matrix of distinct numbers (1, ..., n2) in which every row, column and both diagonals has the same total is referred to as a magic square. Constructing a magic square of a given order is considered as a computationally difficult permutation problem, particularly when additional constraints are imposed. The history of magic squares

dates back to 2200 B.C. [32]. An unusual numerical pattern found by Emperor Yu on a tortoise’s shell was the oldest known magic square. The Emperor decided to call this unique diagram “Lo-Shu” (Figure 2.2).

Figure 2.2: The Loh-Shu tortoise and the magic square [1]

The Chinese have used the magic squares in the interpretation of philosophy, human behaviour, natural phenomena and other areas of study; and interestingly, some of the porcelain plates in some private collections and museums in China were decorated with magic squares. It is thought that the magic squares were transmitted to the Arabs from the Chinese, probably through India. Magic squares were then introduced to Europe, then journeyed to Japan. Magic squares in India were used in applications other than only in the traditional mathematical context. A sequence of na¨ıve rules to construct magic squares were made by Islamic mathematicians. The seventeenth century witnessed a serious consideration to the study of magic squares when Antoine de la Loubere, a French aristocrat, studied the theory behind the construction of magic squares. The extension of magic squares to 3-dimension was brought by Adamas Kochansky in 1686. Recently, the magic squares attracted researchers and applied in statistics, combinatorial mathematics, artificial intelligence, graph theory, industrial arts, experiment designs, location analytics, electronic circuits and more [1, 32].

Kraitchik [31] provided an exact solver to construct the magic squares. A magic square of an odd order can be generated using the Siamese method (also known as De la Loub´ere’s method). An odd order magic square is of the form n = 2m + 1, where m is an integer greater than 0. In the Siamese method, the number 1 is written in the middle of the first row. The remaining numbers are placed in ascending order as an upward diagonal to the empty right square cells. In case the cell is already filled, then the cell below the previous number is used to place the number. A magic square of a doubly even order can be generated using cross method. A doubly even order magic square is of the form n = 4m, where m is an integer greater than 0. The idea is to draw a cross through every 4x4 sub-square and then fill out all the square cells with all numbers in ascending order

from the top left of the square to the bottom right. Then, each number, aij, along a

diagonal of the cross is replaced by (n2 + 1) − a

ij. Finally, a magic square of a singly

even order can be generated using the “LUX” method which has been proposed by J. H. Conway. A singly even order magic square is of the form n = 4m + 2, where m is an integer greater than 0. The method starts by creating m + 1 rows of L, then 1 row of U followed by m − 1 rows of X. Then replacing the U in the centre with the L above it. The resulted letters form a square of an odd order 2m + 1. Constructing the singly even order magic square is done by using the Siamese method and filling out each set of square cells surrounding a letter sequentially according to the shape of the letter. Weisstein [162] reported other methods for generating magic squares.

Although there is at most only one distinct magic square of order less than 4, the number of magic squares of order 4 is 880 as has been known since the seventeenth century. The exact number of distinct magic squares of order 5 is 275,305,224 [32]. Researchers claimed that determining the number of distinct magic squares of order of 6 and more is a hard unsolved computationally problem [163, 164]. Pinn and Wieczerkowski [164] used a Monte Carlo method to predict the number of magic squares of order 6 and their estimate was (0.17745 ± 0.00016) × 1020.

The exact deterministic methods for constructing magic squares similar to the ones pre- sented above can only produce a single magic square of a given order. Such methods may fail when some constraints are imposed. Xie and Kang [32] proposed a stochas- tic constructor method based on an improved evolutionary algorithm. The constraint version of the magic squares problem was then the subject of a competition hosted by SolveIT Software7 with the goal of finding the quickest approach. The winner approach

emerged among hundreds of competing algorithms as a late acceptance hill climbing al- gorithm [165] which handles a given instance in two separate ways based on its size. The approach mixes two heuristics with a certain probability for problems larger than a cer- tain size and uses a different algorithm for smaller instances. The winner approach was able to construct the constrained version of the 2600x2600 magic square. Geoffrey Chu developed a solver in which a random square is transformed into the magic square by the iterative heuristic improvement of rows and columns. Chu’s solver ranked the second on the competition and it was able to construct the constrained version of a 1000x1000 magic square in one minute. The multi-step iterative local search took the third place on the competition. It was developed by Xiao-Feng Xie and it was able to construct

constrained version of a 400x400 magic square in one minute. The detailed descriptions of the top three solvers are available online at http://www.cs.nott.ac.uk/~yxb/IOC/. Kheiri and ¨Ozcan [166] extended the framework of the winning approach to enable the use of selection hyper-heuristics for any given constraint version of the magic square problem. They presented a range of effective selection hyper-heuristics combining differ- ent heuristic selection methods and acceptance criteria and mixing the same set of per- turbative low level heuristics for constructing the constrained version of magic squares. The seven heuristic selection methods {GR, SR, RD, RP, RPD, CF, TABU} are com- bined with six move acceptance methods {accepting all moves, accepting only improving moves, accepting improving or equal moves, simulated annealing, great deluge, na¨ıve move acceptance} producing a total of 42 selection hyper-heuristics for experimenta- tion. All selection hyper-heuristics are tested with the goal of detecting the quickest one. Greedy based hyper-heuristics and any hyper-heuristic using one of the move acceptance methods in {accepting all moves, accepting only improving moves, accept- ing improving or equal moves, simulated annealing, great deluge} failed to construct the constraint-version of magic squares within the time limits. The experiments show that hyper-heuristics using the na¨ıve move acceptance method, which accepts a wors- ening solution with a probability of 0.004%, is the most successful approach. The ran- dom permutation based selection hyper-heuristic combined a na¨ıve acceptance method (RP − N AM ) turns out to be an extremely effective and efficient approach which runs faster than all other hyper-heuristics using different move acceptance methods. It has been observed that learning requires time slowing down a selection hyper-heuristic and so hyper-heuristics with no learning using the na¨ıve acceptance method are more success- ful than the learning hyper-heuristics regardless of whether the learning occurs within the heuristics selection or move acceptance component. RP − N AM outperforms the best known heuristic approach based on late acceptance for constructing a constrained magic squares.