A Heuristic Algorithm for Optimal Hamiltonian Cycles in Weighted Graphs

The paper focuses on finding of the optimal Hamiltonian cycle, when it is regarded with respect to cost, time, distance or difficulty level of the route. The problem is strictly related to the traveling salesman problem proved to be NP-complete for general graphs. The paper gives a heuristic algorithm for finding the optimal spanning cycle in a weighted graph. Its idea is based on optimization of weight losses and reduction the complexity of a problem by reduction the dimension of the graph payoff matrix.


INTRODUCTION
Investigating cycles (closed paths) running through every vertex of a weighted undirected graph we will restrict out to simple graphs, i.e. the graphs have no self loops and no parallel arcs (multi-edges). Otherwise, the loops can be removed and the arc with the optimal weight -the smallest or the biggest -out of the parallel arcs can be chosen. The study of Hamiltonian cycles has been motivated by practical applications (see, for example, [4] or [9]).
Let be given a set of n objects (vertices of a graph). Between any of those two vertices there is a path but it can also happen that two vertices are not directly connected and from a vertex to another vertex you can get through one or even more different vertices. Every path is related to exactly one number (weight) which expresses cost, time, distance or difficulty of the given path. Hamilton cycle does not exist for all graphs. Unfortunately, there is no specific way to find whether Hamilton cycle exists or not.

Losses Minimization (Maximization) Algorithm
In the paper is assumed that the graph is not trivial and all paths connected with a vertex are not related to the same number. For the given graph we can construct a payoff matrix C n, n , called often a distance matrix, where for all k, l = 1, 2, …, n the elements of the payoff matrix are as follow: ckl is a positive number, if there is a path from k to l, It is also assumed that if there are no loops then the weight of "the path" from any vertex to itself is equal to zero. It can be said zero indicates the forbidden path or there is no path. Some authors adopt infinity for k = l.
If ckl = clk (k, l = 1, 2, …, n), then the payoff matrix C is symmetric, i.e. C = C T , where C T denotes transposed matrix. In general, it is not necessary for the matrix C to be symmetric. But if C is symmetric then only rows or only columns can be investigated. Suppose that the given payoff matrix C represents a graph containing Hamiltonian cycles. Losses Minimization (Maximization) Algorithm (LMA to be short), as adopted to obtain minimum total weight, goes as follows: -for all rows and columns of the payoff matrix C differences between the smallest nonzero elements are determined; -the bigger difference gives the loss of higher weights so the smallest element in the row or column with the biggest difference indicates one path of the optimal Hamiltonian cycle; -the element, containing the obtained path, is replaced with zero ant it leads to the new reduced payoff matrix; -differences between the smallest nonzero elements in the reduced payoff matrix are investigated, and so on.
Formally, denote for any fixed k = 1, …, n where c‫׳‬ik, c‫׳׳‬ik (c‫׳‬kj, c‫׳׳‬kj) are two smallest elements in the k-th column (k-th row, respectively) of the payoff matrix C. Let denote The smallest element in the row (or column), containing the difference m, determines the path which must be chosen. It implies that the smallest element of the row (or column) can be replaced by zero, and as the result new payoff matrix is created. The procedure has to be continued (n -1) times, and the last path of the optimal Hamiltonian cycle will be determined uniquely.
If LMA is adopted to maximum total weight, then for all rows and columns of the payoff matrix C differences of the biggest nonzero elements should be determined because bigger difference implies losing smaller weights. Next in the row (column) with the biggest difference the biggest element in that row (column, respectively) must be chosen. As the result, one path of the optimal Hamiltonian cycle is obtained. Formally, let denote for any fixed k = 1, …, n where now c‫׳‬ik, c‫׳׳‬ik (c‫׳‬kj, c‫׳׳‬kj) mean two biggest elements of the k-th column (k-th row, respectively) of the payoff matrix C. Denote The biggest element in the row (or column), containing the difference M, indicates the path which must be chosen. As the result we obtain a reduced payoff where the biggest element is replaced by zero. The procedure above has to be continued (n -1) times, and the last path is determined.
Given a graph of weighted edges of a tourist route with nodes A, B, C, D, E, which state for some tourist objects. Assume that weights express time, cost or level of difficulty of the edges (the less, the better) for minimum, and beauty of view or attractiveness (the more, the better) for maximum. The objective functions (minimum and maximum) should be find for the following payoff matrix of the route graph (9) Let start from the minimum. The payoff matrix is symmetric (the graph is undirected) and according to (3) we have Therefore, by (5), m = max(dij) = d4j = d5j.
and two paths of the route are determined. The two paths are DB (or BD) and EC (or CE). Putting c23 = c32 = c45 = c54 = 0, the payoff matrix (9) will have the form (10) Since d2j = | c‫32׳‬ -‫|52׳׳‪c‬‬ = 3 is the maximal difference, it implies that the path of the minimal route must be BC (or CB). Because the nodes B, C have been taken twice, therefore all elements of the second and third row, column in (10) are equal to zero and can be omitted.
It is easy to see in (11) that d5j = | c‫15׳‬ -‫|45׳׳‪c‬‬ = 2 is the maximal difference and next path should be AE (or EA). At last the path AD (or DA) is obtained and the minimal route (if A is the beginning of the cycle and D is its next node) has the form minC = A→D→B→C→E→A, f(minC) = 5 + 1 + 2 + 2 + 4 = 14.
Applying LMM for maximum, according to (6) we have now Both first and second row has the same maximal element, but second row should be chosen because the loss sum of weights is less than for first row. Therefore one path of the route, AB (or BA) is determined. The reduced matrix has the form It is easy to see that Max(Dij) = D2j = 3 and c25 = 5 is the maximal element in second row. Since then the next determined path is BE (or EB), and the node B appears twice (both as the beginning and as the end of a path). In (12) all elements of second row and columns, will be replaced by zero and the reduced matrix is now as follows (13) The next path must be ED (or DE). Reducing it we get the payoff matrix (14) The next chosen path must be DC (or CD). Note that it cannot be DA (or AD), because it leads to the closed path but not Hamiltonian cycle. At the end we get the path CA (or AC), and the maximal route (if A is the beginning of the cycle and B is its next node) is maxC = A→B→E→D→C→A, f(maxC) = 7 + 5 + 6 + 3 + 4 = 25

Example (not symmetric payoff matrix)
Let be given a weighted graph of a route with nodes A, B, C, D, E, which state for some tourist objects. Assume that weights express time, cost or level of difficulty, beauty of view or attractiveness of the edges, and the weights depend on direction of the path between nodes. The objective function is the minimum (maximum, respectively) of weights, and the payoff matrix of the graph has the form (15) At first the minimum will be found. Since the payoff matrix is asymmetric now, therefore differences of nonzero minimal elements both rows and columns should be investigated. By formulas (3) and (4), we obtain for rows: and for columns: Since then, by (5), we have Therefore min(ci3) = c23 = 7.
And we obtain one path of the route; it is BC. Consequently, the payoff matrix (15) reduces now to the form given below and for columns: Since then, by (5), we have m = max(dij) = di2 = 9. Therefore min(ci2) = c42 = 3.
And we obtain another path of the route; it is DB. Since the node B occurs both as the beginning and the end of the path, the payoff matrix reduces now to the form as follows (17) Another path of the route is AD, and it implies, since the node D occurs both as the beginning and the end of paths, that the payoff matrix reduces now to the form as follows (18) The reduced payoff matrix (18) implies that the last path must be CA, and the minimum (if A is the beginning of the cycle) is minC = A→D→B→C→A, f(minC) = 7 + 3 + 7 + 8 = 25.
The maximal sum of weights will be determined for the same payoff matrix (15). According to (6), (7) we have for rows: and for columns: Since then, by (5) And we obtain one path of the maximum route; it is DC. Since then, third column must consist all zeros and, the payoff matrix reduces to the form given below It is easy to check that next paths of the maximum are CA, AB and BD. Therefore (if A is the beginning of the cycle) we obtain maxC = A→B→D→C→A, f(maxC) = 12 + 8 + 14 + 8 = 42. As it is well known Richard M. Karp showed that the Hamiltonian cycle problem was NP-hard in combinatorial optimization. For n nodes the number of possible Hamiltonian cycles may be equal to (n -1)! / 2 what implies increase in very rapid speed with the number of nodes (dimension of the payoff matrix). Evaluating and testing all Hamiltonian cycles has exponential order and is generally too time consuming to be feasible for most problems (for instance, for 20 nodes it takes many months). Therefore, finding a solution with the LMA seems to be useful in practice.

DISCUSSION, REMARKS
In literature can be found many algorithms used to determine a solution to traveling salesman problem. One of the first was The Nearest Neighbour Algorithm (see, for example [2], [3], [6]) in which, general idea, the tourist starts at a random node and repeatedly visits the nearest vertex until all have been visited. It quickly yields a short tour, but there are some disadvantagesit might not give the optimal route or might lead to an incomplete route or might not find a feasible route at all, even when one exists. Very successful in solving the traveling salesman problem are evolutionary algorithms like Genetic Algorithmswhich consist of Encoding, Evaluation, Crossover, Mutation and Decoding (more details can be found in [1], [8])) or Ant Colony Algorithms, proposed by Marco Dorigo in his PhD thesis (see [5] or [7]).
In LMA if the payoff matrix is non symmetric, then in the payoff matrix one row or one column can be reduced, when the vertex stands for the beginning or the end of a path.
It is easy to see that minC and maxC are dual concepts and searching maxC can be easy replaced by searching minC. If in an investigating graph there is no Hamiltonian cycle then the LMA method will stop at some step.
If in some rows (columns) the biggest differences are equal then the biggest (the smallest element in the row (column) with smallest sum of weights (biggest sum of weights, respectively) should be chosen Tourism, for example, has become a very popular global and local leisure activity and designing for a tourist route is very important. Having a lot of options of a route for walking, cycling, horse riding, hiking, … is beneficial to a decision maker in tourism industry. The decision maker has to propose the optimal cycle for his clients. From that point of view, or more precisely, in combinatorial optimization the problem is related to the travelling salesman problem which is one of the most intensively studied problems in computational mathematics and might seem to be of interest to tourist companions.
The problem appears when a tourist companion wants to design a route containing interesting cultural and historic attractions (nodes or vertices of a graph) in a city. Therefore the resulting route will start from one node and pass all other vertices of the graph and come back to the beginning node. The route should be optimal, giving minimum or maximum total weight, from some point of view (for example, should be the most interesting, not necessarily the shortest) and passing through every edge of the graph (a street of the city) only once. In other words, the route should create Hamiltonian cycle.