Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

School of Computer Science and Engineering

Department of Computer Science and Engineering


Jain Global Campus, Kanakapura Taluk
Ramanagaram District, Karnataka, India -562112

2022-2023

A Code Demonstration Report on

“Application of TSP to solve source to source path problem”

Submitted as part of assessment for the course

21CIC32 – DESIGN AND ANALYSIS OF ALGORITHM

IN

COMPUTER SCIENCE AND ENGINEERING

Submitted by

21BTRCS239 Arastu Thakur


21BTRCS266 Prabin Dumre
21BTRCS271 Somnath Bhattarai
21BTRCS258 Muskan Gupta

Dr. Manjunath C R
Associate Professor
Department of Computer Science and Engineering
School of Computer Science and Engineering
Faculty of Engineering and Technology
JAIN (Deemed-to-be University)
2022-2023
School of Computer Science and Engineering
Department of Computer Science and Engineering
Jain Global Campus, Kanakapura Taluk
Ramanagara District, Karnataka, India -562112

CERTIFICATE

This is to certify that the report entitled “Application of TSP in solving source to source path
problem” is carried out by Arastu Thakur (21BTRCS239) Prabin Dumre (21BTRCS266)
Somnath Bhattarai (21BTRCS271) Muskan Gupta (21BTRCS258) , a bonafide student of
Bachelor of Technology at the Faculty of Engineering and Technology, JAIN (Deemed-to-be
University) in partial fulfilment for the course 21CIC32 - DESIGN AND ANALYSIS OF
ALGORITHMS of the degree of Bachelor of Technology in Computer Science and
Engineering, during the academic year 2022-2023.

Dr Manjunath CR
Associate Professor
Dept. of CSE School of CSE
Faculty of Engineering & Technology
JAIN (Deemed-to- be University).
Table Of Contents

Index Page No.

Introduction 1

Algorithm 9

Code 12

Complexity Table 15
1. Introduction
1.2 Basic of TSP
Travelling salesperson problem is stated
with a salesperson along with a set of cities.
The approach is basic that we start with the
source node i.e., the starting city and from
that we calculate minimal cost to every other
city and return back to the starting city. The
challenge or the major problem that is to be
solved here is minimalizing the final cost of
the trip. Here the salesman visits every city
exactly once. It’s an NP-hard problem in the combinatorial optimization (finding an
optimal object from a set of objects.
The travelling sales person problem is generalized
into the form of travelling purchaser or vehicle routing. As the TSP is a problem of class
NP-problems of computational complexity so the worst case in the scenario can be for
any algorithm superpolynomially (An algorithm is defined to take super polynomial time
if T(n) is not bounded above by any polynomial. Using little omega notation, it is ω(n c)
time for all constants c, where n is the input parameter, typically the number of bits in
the input.)

The traveling salesman problem can be described as follows:


TSP = {(G, f, t): G = (V, E) a complete graph,
f is a function V×V → Z,
t ∈ Z,
G is a graph that contains a traveling salesman tour with cost that does not
exceed t}.

The TSP problem can be analyzed as the following scenarios: -

i) As a graph Problem: TSP can be viewed as an undirected graph in which cities are the
graph's vertices, paths are the graph's edges, and a path's distance is the edge's weight. The
problem here is minimization i.e., visiting each vertex from a specific vertex and returning
to the vertex after travelling exactly once. In this scenario the recommended case is of
connected Graph. In case there is no path between two cities a long edge is added that won’t
affect the cost of the optimal tour.

1
ii) Asymmetric and Symmetric: In the case of symmetric TSP, we consider an undirected
graph which is formed by the distance between two cities in opposite direction.

iii) In symmetry there is near about half of the possible solution. In case of asymmetric TSP,
the graph can be directed i.e., the graph has not path in both of the directions. Traffic
management or the routing of vehicle or the airfare distribution between cities are all the
real-world examples where this can be visualized.
1.2 Dynamic Programming
Dynamic programming is an optimization approach that
transforms a complex problem into a sequence of
simpler problems; its essential characteristic is the
multistage nature of the optimization procedure.
More so than the optimization techniques described
previously, dynamic programming provides a general
framework for analyzing many problem types.
Dynamic
Programming is a powerful technique that can be used
to solve many problems in time O(n2) or O(n3) for Figure: Dynamic Programming Matrix
which a naive approach would take exponential time. (Usually, to get running time below
that—if it is possible—one would need to add other ideas as well.) Dynamic programming is a
general approach to solving problems, much like “divide-and-conquer” is a general method,
except that unlike divide-and-conquer, the subproblems will typically overlap.
Dynamic programming
is an algorithm design method that can be used when the solution to a problem can be viewed
as the result of a sequence of decisions. Dynamic programming is applicable when the sub-
problems are not independent, that is when sub-problems share subsub-problems. A dynamic
programming algorithm solves every sub-sub-problem just once and then saves its answer in a
table, thereby avoiding the work of re-computing the answer every time the sub-problem is
encountered.
A dynamic programming problem can be divided into a number of stages where
an optimal decision must be made at each stage. The decision made at each stage must take
into account its effects not only on the next stage, but also on the entire subsequent stages.
Dynamic programming provides a systematic procedure whereby starting with the last stage of
the problem and working backwards one makes an optimal decision for each stage of problem.
The information for the last stage is the information derived from the previous stage.

Dynamic programming design involves 4 major steps.


1) Characterize the structure of optimal solution.
2) Recursively define the value of an optimal solution.
3) Compute the value of an optimum solution in a bottom-up fashion.
4) Construct an optimum solution from computed information.

2
The Dynamic programming technique was developed by Bellman based upon his principle
known as principle of optimality. This principle states that “An optimal policy has the
property that, whatever the initial decisions are, the remaining decisions must constitute an
optimal policy with regard to the state resulting from the first decision”.

1.2.1 General Characteristics of Dynamic Programming:


The general characteristics of Dynamic programming are
1) The problem can be divided into stages with a policy decision required at each stage.
2) Each stage has number of states associated with it.
3) Given the current stage an optimal policy for the remaining stages is independent of the
policy adopted.
4) The solution procedure begins be finding the optimal policy for each state of the last
stage.
5) A recursive relation is available which identifies the optimal policy for each stage
with n stages remaining given the optimal policy for each stage with (n-1) stages
remaining.

1.2.2 APPLICATIONS OF DYNAMIC PROGRAMMING

a) Matrix Chain Multiplication: Given the dimension of a sequence of matrices in an


array arr[], where the dimension of the ith matrix is (arr[i-1] * arr[i]), the task is to find the most
efficient way to multiply these matrices together such that the total number of element
multiplications is minimum.

b) Optimal Binary search Trees: Given a sorted array key [0.. n-1] of search keys and an
array freq[0.. n-1] of frequency counts, where freq[i] is the number of searches for keys[i].
Construct a binary search tree of all keys such that the total cost of all the searches is as small
as possible.

c) 0/1 Knapsack Problem: Given weights and values of n items, put these items in a knapsack
of capacity W to get the maximum total value in the knapsack. In other words, given two
integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n
items respectively. Also given an integer W which represents knapsack capacity, find out the
maximum value subset of val[] such that sum of the weights of this subset is smaller than or
equal to W.

d) Multi stage Graph: A Multistage graph is a directed, weighted graph in which the nodes can
be divided into a set of stages such that all edges are from a stage to next stage only (In other
words there is no edge between vertices of same stage and from a vertex of current stage to
previous stage).
The vertices of a multistage graph are divided into n number of disjoint subsets S = { S 1 , S2
, S3 ……….. Sn }, where S1 is the source and Sn is the sink ( destination ).

3
e) Traveling sales person problem: Given a set of cities and the distance between every pair of
cities, the problem is to find the shortest possible route that visits every city exactly once and
returns to the starting point.

1.3 TSP Detail

The Traveling Salesman Problem (TSP) is a problem whose solution has eluded many
mathematicians for years. Currently there is no solution to the TSP that has satisfied
mathematicians. Historically, mathematics related to the TSP was developed in the 1800’s by
Sir William Rowan Hamilton and Thomas Penyngton Kirkman, Irish and British
mathematicians, respectively. Hamilton was the creator of the Icosian Game in 1857. It was a
pegboard with twenty holes that required each vertex to be visited only once, no edge to be
visited more than once, and the ending point being the same as the starting point.This kind of
path was eventually referred to as a Hamiltonian circuit.However, the general form of the
TSP was first studied by Karl Menger in Vienna and Harvard in the late 1920’s or early
1930’s.
TSP’s were first studied in the 1930?s by mathematician and economist Karl Menger
in Vienna and Harvard. It was later investigated by Hassler Whitney and Merrill Flood at
Princeton. In 1994, Applegate, Bixby , Chvatal, and Cook solved TSP containing 7,397 cities.
Later in 1998, they solved it using 13,509 cities in United States. In 2001, Applegate, Bixby,
Chvtal, and Cook found the optimal tour of 15,112 cities in Germany. Later in 2004, TSP of
visiting all 24,978 cities in Sweden was solved; a tour of length of approximately 72,500
kilometers was found and it was proven that no shorter tour exists. This is currently the
largest solved TSP.

Application of TSP and linkages with other problems

i. Drilling of printed circuit boards


A direct application of the TSP is in the drilling problem of printed circuit boards (PCBs). To
connect a conductor on one layer with a conductor on another layer, or to position the pins of
integrated circuits, holes have to be drilled through the board. The holes may be of different
sizes. To drill two holes of different diameters consecutively, the head of the machine has to
move to a tool box and change the drilling equipment. This is quite time consuming. Thus it is
clear that one has to choose some diameter, drill all holes of the same diameter, change the
drill, drill the holes of the next diameter, etc. Thus, this drilling problem can be viewed as a
series of TSPs, one for each hole diameter, where the 'cities' are the initial position and the set
of all holes that can be drilled with one and the same drill. The 'distance' between two cities is
given by the time it takes to move the drilling head from one position to the other. The aim is
to minimize the travel time for the machine head.

4
ii. Overhauling gas turbine engines
It occurs when gas turbine engines of aircraft have to be overhauled. To guarantee a uniform
gas flow through the turbines there are nozzle-guide vane assemblies located at each turbine
stage. Such an assembly basically consists of a number of nozzle guide vanes affixed about its
circumference. All these vanes have individual characteristics and the correct placement of
the vanes can result in substantial benefits (reducing vibration, increasing uniformity of flow,
reducing fuel consumption). The problem of placing the vanes in the best possible way can be
modeled as a TSP with a special objective function.
iii. X-Ray crystallography
Analysis of the structure of crystals is an important application of the TSP. Here an X-ray
diffractometer is used to obtain information about the structure of crystalline material. To this
end a detector measures the intensity of Xray reflections of the crystal from various positions.
Whereas the measurement itself can be accomplished quite fast, there is a considerable
overhead in positioning time since up to hundreds of thousands positions have to be realized
for some experiments. In the two examples that we refer to, the positioning involves moving
four motors. The time needed to move from one position to the other can be computed very
accurately. The result of the experiment does not depend on the sequence in which the
measurements at the various positions are taken. However, the total time needed for the
experiment depends on the
sequence. Therefore, the problem consists of finding a sequence that minimizes the total
positioning time. This leads to a traveling salesman problem.
iv. Computer wiring
It is a special case of connecting components on a computer board. Modules are located on a
computer board and a given subset of pins has to be connected. In contrast to the usual case
where a Steiner tree connection is desired, here the requirement is that no more than two
wires are attached to each pin. Hence we have the problem of finding a shortest Hamiltonian
path with unspecified starting and terminating points. A similar situation occurs for the so-
called testbus wiring. To test the manufactured board one has to realize a connection which
enters the board at some specified point, runs through all the modules, and terminates at some
specified point. For each module we also have a specified entering and leaving point for this
test wiring. This problem also amounts to solving a Hamiltonian path problem with the
difference that the distances are not symmetric and that starting and terminating point are
specified.
v. The order-picking problem in warehouses
This problem is associated with material handling in a warehouse. Assume that at a
warehouse an order arrives for a certain subset of the items stored in the warehouse. Some
vehicle has to collect all items of this order to ship them to the customer. The relation to the
TSP is immediately seen. The storage locations of the items correspond to the nodes of the
graph. The distance between two nodes is given by the time needed to move the vehicle from
one location to the other. The problem of finding a shortest route for the vehicle with
minimum pickup time can now be solved as a TSP.

5
vi. Vehicle routing
Suppose that in a city n mail boxes have to be emptied every day within a certain period of
time, say 1 hour. The problem is to find the minimum number of trucks to do this and the
shortest time to do the collections using this number of trucks. As another example, suppose
that n customers require certain amounts of some commodities and a supplier has to satisfy all
demands with a fleet of trucks. The problem is to find an assignment of customers to the
trucks and a delivery schedule for each truck so that the capacity of each truck is not exceeded
and the total travel distance is minimized. Several variations of these two problems, where
time and capacity constraints are combined, are common in many real world applications.
This problem is solvable as a TSP if there are no time and capacity constraints and if the
number of trucks is fixed (say m ). In this case we obtain an m -salesmen problem.
Nevertheless, one may apply methods for the TSP to find good feasible solutions for this
problem.
vii. Mask plotting in PCB production
For the production of each layer of a printed circuit board, as well as for layers of integrated
semiconductor devices, a photographic mask has to be produced. In our case for printed
circuit boards this is done by a mechanical plotting device. The plotter moves a lens over a
photosensitive coated glass plate. The shutter may be opened or closed to expose specific
parts of the plate. There are different apertures available to be able to generate different
structures on the board. Two types of structures have to be considered. A line is exposed on
the plate by moving the closed shutter to one endpoint of the line, then opening the shutter
and moving it to the other endpoint of the line. Then the shutter is closed. A point type
structure is generated by moving (with the appropriate aperture) to the position of that point
then opening the shutter just to make a short flash, and then closing it again. Exact modeling
of the plotter control problem leads to a problem more complicated than the TSP and also
more complicated than the rural postman problem.

Example of TSP:

6
Distance Matrix

Solution
g(2, Φ ) = C21
=5
g(3, Φ ) = C31
=6
g(4, Φ ) = C41
=8
K = 1 , consider set of one element :
Set {2}:
g(3,{2}) = c32 + g(2, Φ )
= c32 + c21
= 13 + 5
= 18
g(4,{2}) = c42 + g(2, Φ )
= c42 + c21
= 8+ 5
= 13
Set {3} :
g(2,{3}) = c23 + g(3, Φ )
= c23 + c31
=9+6
= 15
g(4,{3}) = c43 + g(3, Φ )
= c43 + c31
= 9+ 6
= 15
Set {4} :
g(2,{4}) = c24 + g(4, Φ )
= c24 + c41
= 10 + 8

7
= 18
g(3,{4}) = c34 + g(4, Φ )
= c34 + c41
= 12 + 8
= 20

K = 2 , consider set of two element :


Set {3,4} :
g {2,{3,4}} = min {c23 + g(3,{4}) , c24 + g(4,{3})}
= min { 9 + 20 , 10 + 15}
= min { 29, 25}
= 25
Set {2,4} :
g {3,{2,4}} = min {c32 + g(2,{4}), c34 + g(4,{2})}
= min { 13+ 18, 12 + 13}
= min { 31, 25}
= 25
Set {2,3} :
g(4,{2,3}) = min {c42 + g(2,{3}), c43 + g(3,{2})}
= min { 8 + 15 , 9 + 18}
= min { 23, 27}
= 23
Length of an optimal tour,
g { 1, {2,3,4}} = min{ c12 + g(2,{3,4}), c13 + g(3,{2,4}), c14 + g(4,{2,3})}
= min { (25 + 10 ) , (25 + 15) , (23 + 20) }
= min { ( 35), (40), (43)}
= 35
The minimum cost path is 35.
The optimal tour route is, 1 -> 2 -> 4 -> 3 -> 1 .

8
2. Algorithm

The Traveling Salesman Problem is the most famous math problem. A brute force approach can
be used to evaluate each possible tour and select the best one. For n nodes in the graph, the
number of (n - 1)! possibilities.

No polynomial time algorithm, but a fast alternative to brute force using a dynamic programming
approach.

Consider the graph G = (V, E). where V is the set of cities and E is the set of weighted edges. An
edge e(u,v) represents that node u and node v are connected. The distance between vertices u
and v is d(u,v) and must not be negative.

Suppose you started in city 1, visited several cities, and are now in city j. So, this is a partial tour.
To determine the most convenient city to visit next, we need to know j. We also need to
know all the cities we've visited so far, so we don't repeat any cities. So, this is a proper sub-
problem.

For a subset of cities S ´ {1, 2, 3, ..., n} containing 1 and j ´ S, let C (S, j) be the length of the
shortest path that visits all nodes of S exactly. increase. Starts with 1 and ends with j.

For |S| > 1, we define C (S, 1) = ∝, because the path cannot start and end at 1.

Now let's express C (S, j) in smaller subproblems. Must start with 1 and end with j. We
should choose next city like this formulation: -

C(S,j)=minC(S−{j},i)+d(i,j)wherei∈Sandi≠jc
(S,j)=minC(s−{j},i)+d(i,j)wherei∈Sandi≠j

Approach: Traveling-Salesman-Problem
C ({1}, 1) = 0
for s = 2 to n do
for all subsets S Є {1, 2, 3, … , n} of size s and containing 1
C (S, 1) = ∞
for all j Є S and j ≠ 1
C (S, j) = min {C (S – {j}, i) + d(i, j) for i Є S and i ≠ j}
Return minj C ({1, 2, 3, …, n}, j) + d(j, i)

9
Algorithm: Dynamic Approach For TSP
Data: s: starting point; N: a subset of input cities; dist. ():
Distance among the cities
Result: Cost: TSP result
Visited[N] = 0;
Cost = 0;
Procedure TSP (N, s)
Visited [s] =1;
if |N| =2 and k ≠ s then
Cost (N, k) = dist. (s, k);
Return Cost;
Else
For j ϵ N do
For i ϵ N and visited[i]= 0 do
If j ≠ I and j ≠ s then
Cost(N,j) = min( TSP (N-{i},j) + dist (j,i))
Visited[j]=1;
End
End
End
End
Return Cost;
End

The algorithm takes as input the subset N of cities that need to be visited, the distance
between them dist, and the starting city s. Each city is identified by a unique city ID, such as
{1, 2, 3,…., n}.

Initially, all cities are unvisited and visits start at city s. Assume the initial move cost is equal
to 0. Then a TSP distance value is calculated based on a recursive function. If the number of
cities in the subset is 2, the recursive function will return their distance as the base case.

On the other hand, if the number of cities is greater than 2, calculate the distance from the
current city to the next city, and recursively calculate the minimum distance between the
remaining cities.
Finally, the algorithm returns the minimum distance as the TSP solution.

10
The analysis of algorithm:

1. Construct a minimum spanning tree, T, from G


2. Next find all the odd degree vertices in T and place them in set O. A vertex with an odd
degree means that an odd number of edges are connected to the vertex
3. Connect odd degree vertices using the minimum weight perfect matching adding the edges
to the matched odd degree vertices, which would create an Euler cycle for T. Every vertex in
T should have an even degree after this step
4. Remove repeated edges from vertices with a degree greater than 2 to create a Hamiltonian
cycle

3. Time Complexity
i. Simple Approach/ Naïve Approach
 Let city 1 be the start and end points.
 Generate all (n-1)! Permutations of cities.
 Calculate the cost of each permutation, keeping in mind the minimum cost
permutation.
 Returns the minimum cost permutation.
 Time complexity:
o Θ(n!)
ii. Dynamic Approach
 For a set of size n, we consider n-2 subsets of size n-1 each, so not all subsets contain
n.
 We can create dynamic program-based solutions using the above iteration
relationships.
 There are at most O(n*2n) subproblems, each taking linear time to solve.
 So, the total running time is O(n2*2n).
 The time complexity is much less than O(n!), but still exponential.
 Space requirements are also exponential.
 So even if the number of vertices is slightly higher, this approach is not viable.
In the below code the approach that we have used is:
This code recursively finds the shortest tour starting from each neighborhood and returns its
minimum value. As we have done this with dynamic programming, we can calculate the
amount of work as follows:
There are n starting nodes and 2n possible subgraphs. So, the function will be called with at
most n⋅2n different arguments (the target will not change). Each call does at most O(n) work
(there are at most n neighbors). So, the total work you do is O (n 2.2n).

11
4. Code:
Python Code for Demonstration of “Source to Source” Problem.

//Coding Part
import random
import numpy as np
from sys import maxsize
import itertools
import timeit
import networkx as nx

start = timeit.default_timer()
array = np.random.randint(20, size=(20, 20))
print("The Main Array")
print(array)
size_of_matrix = (random.randint(1,20))
V=size_of_matrix
print("The size of Sub matrix is ",size_of_matrix,"X",size_of_matrix )
val = (array[0:size_of_matrix,0:size_of_matrix])
np.fill_diagonal(val,0)
print("The extracted matrix")
print(val)
Q = nx.from_numpy_matrix(np.array(val))
nx.draw(Q,with_labels=True)
A = np.array(val)
M = nx.from_numpy_array(A)
M.edges(data=True)

def initMatrix(n):
adjMatrix = np.random.randint(0, 100, size=(n, n), dtype=int)
np.fill_diagonal(adjMatrix, 0)
return adjMatrix

def initialize(n):
setofvertices = [i for i in range(1, n + 1)]
listSubsets = [[i for i in itertools.combinations(setofvertices, j)] for j in range(0, n)]
listSubsets = [x for xs in listSubsets for x in xs]
dict = {k: {i: 'Infinity' for i in range(1, n + 1)} for k in listSubsets}
return dict
def calculateDistance(pathlist, adjMatrix):
distance = 0
for i in range(0, len(pathlist)-1):
distance += adjMatrix[pathlist[i]-1][pathlist[i+1]-1]
return distance

def TSP_single_path(vertex, dict, adjMatrix):

12
pathlist = []
pathlist.append(vertex)
firstminvalue = []
setofvertices = [i for i in range(1, len(adjMatrix) + 1) if i != vertex]
for v in setofvertices:
dict[()][v] = adjMatrix[v-1][vertex-1]
firstminvalue.append((v, dict[()][v]))
pathlist.append(min(firstminvalue, key=lambda t: t[1])[0])
for k in range(1, len(adjMatrix)):
subpaths = []
setofsetsK = [i for i in itertools.combinations(setofvertices, k)]
for setOfsizeK in setofsetsK:
for startvertex in setofvertices:
if startvertex not in setOfsizeK:
candidates = []
for i in setOfsizeK:
setMinus_i = tuple(sorted(set(setOfsizeK).difference(set([i]))))
candidates.append(adjMatrix[startvertex-1][i-1] + dict[setMinus_i][i])
dict[setOfsizeK][startvertex] = np.min(candidates)
for set_k in setofsetsK:
for v2 in setofvertices:
if vertex not in set_k and v2 not in set_k:
subpaths.append((v2, dict[set_k][v2]))
subpaths.sort(key=lambda x: x[1])
if subpaths:
for ele in subpaths:
if ele[0] in pathlist:
continue
elif ele[0] not in pathlist:
pathlist.append(ele[0])
pathlist.append(vertex)
pathlist.reverse()
return pathlist
def TSP_solve(adjMatrix):
paths = []
for i in range(1, len(adjMatrix) + 1):
dict = initialize(len(adjMatrix))
path = TSP_single_path(i, dict, adjMatrix)
paths.append((path, calculateDistance(path, adjMatrix)))
min_cost_path = min(paths, key=lambda x: x[1])
min_cost = min_cost_path[1]
listOfMinPaths = [path for (path, cost) in paths if cost == min_cost]
if len(listOfMinPaths) == 1:
print("The minimum cost tour is: ", min_cost_path[0])
print("The cost of the tour is: ", min_cost_path[1])
else:
print("There is more than one minimum cost tour, they are: ")

13
for i, path in enumerate(listOfMinPaths, 1):
print("Tour {}: {}".format(i, path))

print("The cost of the tours are all: ", min_cost_path[1])


return min_cost_path

if __name__ == '__main__':
matrix = np.array(val)
TSP_solve(matrix)
stop = timeit.default_timer()
print('Time: ', stop - start ,"s")

14
5. Complexity Table

S. N Size of Matrix Tour Path Cost of Time elapsed


Extracted The Tour
1. 6X6 [1, 4, 2, 5, 6, 3, 1] 18 0.6413905 s

2. 15 X 15 [13, 11, 5, 14, 12, 6, 3, 93 28.07930149999993 s


7, 4, 9, 2, 10, 15, 8, 1,
13]
3. 11 X 11 [9, 2, 7, 1, 5, 8, 10, 11, 76 0.9951314999998431 s
3, 4, 6, 9]
4. 14 X 14 [3, 11, 5, 10, 13, 12, 7, 80 11.30078919999869 s
6, 8, 9, 1, 2, 14, 4, 3]

5. 2X2 Tour 1: [1, 2, 1] 19 0.4801716999991186 s


Tour 2: [2, 1, 2]

6. 6X6 Tour 1: [1, 4, 2, 5, 3, 6, 30 0.7079149 s


1]
Tour 2: [4, 2, 5, 3, 6, 1,
4]

7. 8X8 [2, 5, 3, 6, 1, 8, 7, 4, 2] 30 0.7608319000000001 s

8. 14 X 14 [12, 13, 11, 14, 2, 3, 5, 96 14.354099600000001 s


7, 10, 8, 1, 9, 6, 4, 12]

9. 9X9 [4, 1, 3, 6, 7, 2, 9, 8, 5, 38 0.7979801999999998 s


4]

10. 17 X 17 [1, 4, 5, 2, 8, 16, 15, 17, 77 168.12782300000072 s


7, 6, 9, 14, 13, 11, 12,
10, 3, 1]

11. 13 X 13 [7, 6, 4, 5, 13, 1, 10, 8, 68 3.9742372000000614 s


3, 11, 12, 2, 9, 7]

12. 5X5 [5, 1, 2, 4, 3, 5] 47 0.47067520000018 s

13. 13 X 13 [13, 8, 7, 3, 9, 6, 2, 12, 77 5.217858 s


11, 4, 10, 1, 5, 13]
14. 9X9 [4, 3, 7, 9, 6, 8, 2, 1, 5, 55 0.5542382000003272 s
4]

15. 13 X 13 [12, 4, 13, 7, 1, 8, 10, 72 4.154057300000204 s


11, 2, 3, 9, 6, 5, 12]

15

You might also like