Journal of Optimization

Volume 2018, Article ID 9328103, 10 pages

https://doi.org/10.1155/2018/9328103

## HybridHAM: A Novel Hybrid Heuristic for Finding Hamiltonian Cycle

Department of Computer Science & Engineering, Indira Gandhi Delhi Technical University for Women, Kashmere Gate, Delhi 110006, India

Correspondence should be addressed to K. R. Seeja; moc.liamg@ajeesrk

Received 9 May 2018; Revised 7 September 2018; Accepted 25 September 2018; Published 16 October 2018

Academic Editor: Jun He

Copyright © 2018 K. R. Seeja. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

#### Abstract

Hamiltonian Cycle Problem is one of the most explored combinatorial problems. Being an NP-complete problem, heuristic approaches are found to be more powerful than exponential time exact algorithms. This paper presents an efficient hybrid heuristic that sits in between the complex reliable approaches and simple faster approaches. The proposed algorithm is a combination of greedy, rotational transformation and unreachable vertex heuristics that works in three phases. In the first phase, an initial path is created by using greedy depth first search. This initial path is then extended to a Hamiltonian path in second phase by using rotational transformation and greedy depth first search. Third phase converts the Hamiltonian path into a Hamiltonian cycle by using rotational transformation. The proposed approach could find Hamiltonian cycles from a set of hard graphs collected from the literature, all the Hamiltonian instances (1000 to 5000 vertices) given in TSPLIB, and some instances of FHCP Challenge Set. Moreover, the algorithm has O(n^{3}) worst case time complexity. The performance of the algorithm has been compared with the state-of-the-art algorithms and it was found that HybridHAM outperforms others in terms of running time.

#### 1. Introduction

The Hamiltonian Cycle Problem (HCP) is to identify a cycle in an undirected graph connecting all the vertices in the graph. It is considered as a subproblem of the most popular NP-complete problem, the Travelling Salesman Problem (TSP), where the problem is to find the minimum weighted Hamiltonian cycle. Hamiltonian cycles have many applications like reconstructing genome sequences, solving games like Icosian game, finding a knight's tour on a chessboard, and finding circular embeddings for regular graphs. There is no single efficient algorithm for this problem till date. The state-of-the-art algorithms are mainly classified into two: exponential time exhaustive search algorithms and polynomial time heuristic algorithms. While the first category guarantees giving solution, the latter does not. The latter gives solution in sufficiently less time in most of the cases compared to the first. The algorithms in the first category generally find some efficient pruning rules for reducing the search space and thus improving the running time, while those in the second category find some general thump rules for finding the solution in as many problem instances as possible, in less time. The objective of this research is to design a heuristic which is quicker than the established sophisticated heuristics, but which is more reliable than the very fast techniques.

Many theorems can be found in literature, giving the necessary and sufficient conditions [1–4] for Hamiltonian cycle. These conditions are used for checking whether the graph is Hamiltonian or not. A good study [5] on these theorems and algorithms for solving HCP is given by Vandegriend & Basil. Rubin & Frank [6] proposed an exhaustive search method for finding all Hamiltonian paths or cycles in a directed or undirected graph. Christophides [7] proposed a multipath algorithm that was again an intelligent search algorithm with exponential complexity. Christophides algorithm has been improved by Kocay & William [8] by proposing two operations for pruning the search space. Martello [9] proposed a backtrack search algorithm that uses low degree first heuristic for selecting the next vertex. Ejov et al [10] solved HCP by solving equations drawn from the adjacent matrix of the graph. Even though they could find long cycles in case of non-Hamiltonian graphs, they could not reduce the exponential time complexity. Posa’s algorithm [11] is considered as the base algorithm for the heuristic algorithms for HCP. Posa’s idea of rotational transformation and its variants formed the basis of almost all heuristic algorithms proposed later. Angluin and Valiant [12] proposed a much more complicated transformation for directed graph, as the rotational transformation is not suitable for directed graph. Bollobas et al. [13] proposed a Hamiltonian cycle algorithm called HAM that uses rotational transformation and cycle extension. Various versions of HAM algorithm like SparseHam [14] and HideHam [15] are also proposed for different kinds of graphs. Brunacci [16] proposed two algorithms DB2 and DB2A, which consider the HCP as a version of TSP and the nonedges as highly weighted edges. DB2A algorithm is a modification of DBA algorithm for directed graphs where directed graph is transformed into undirected graph. Many TSP heuristics like the famous Lin-Kernighan heuristic [17, 18] use a technique called “k-opt” transformation [19, 20], which is an exchange of k edges. Baniasadi et al. [21] proposed a “snakes and ladders” heuristic for solving HCP inspired from k-opt transformations. There are very few published HCP heuristics that sit in the “middle” area between sophisticated reliable heuristics and very simplistic (usually linear or quadratic time) approaches.

The proposed heuristic is a combination of greedy depth first search, unreachable vertex, and rotational transformation heuristics. The greedy depth first search reduces the running time considerably. The search is greedy since it always selects the unvisited low degree vertex for extending the path. While the unreachable vertex heuristic reduces the chances of reaching dead end, the rotational transformation helps to come out of the dead end condition. Thus the proposed method is faster than the complex exact algorithms and more reliable than the faster heuristics.

#### 2. Materials and Methods

##### 2.1. Hamiltonian Cycle Problem

Hamiltonian cycle is a cycle connecting all the vertices in a given graph only once. A graph containing at least one Hamiltonian cycle is called Hamiltonian graph. This optimization problem can be formally defined as follows:

Given a graph G=(E,V), where E is the set of edges of the graph, V is the set of vertices of the graph and .

The problem is to find a cycle, HC=(v_{1},v_{2},………,), where all () and () are elements of E.

It is a hard problem that attracted both mathematicians and computer scientists. It is considered as one of the strong representatives of the NP-complete problem.

##### 2.2. Greedy Depth First Search

The large search space of the HCP can be explored either breadth wise or depth wise. In depth first search, search is performed in depth wise manner starting from a given vertex till the point where the search cannot proceed further or a dead end is reached. The proposed heuristic uses greedy depth first search to create a Hamiltonian path. The path construction starts from the highest degree vertex because it increases the probability of returning to the starting vertex. Degree of a vertex is the number of edges connected to that vertex. The other vertices of the path are selected greedily by selecting the smallest degree neighbour among the unvisited neighbours. The lowest degree vertices are added first into the path since they may become unreachable with the selection of its neighbours. For example, if the degree of a vertex is two then both the edges of that vertex must be present in the Hamiltonian path/cycle and these edges are added to the path first. The vertices that are part of the path constructed so far are considered as “visited.” Since in Hamiltonian cycle a vertex appears only once, only the unvisited neighbours of the current vertex need to be considered. In order to guide the greedy depth first search further to longer paths, an unreachable vertex heuristic is proposed. According to this heuristic, before adding a vertex to the path, an unreachable condition is checked for each of its neighbours. This heuristic is explained in Section 2.3.

##### 2.3. Unreachable Vertex Heuristic

This research proposes a new heuristic, namely, unreachable vertex heuristic, to reduce the chance of reaching a dead end while constructing the Hamiltonian path.

*Definition 1. *Let P be the partial path and x be the end vertex on partial path. Select the next vertex y* ∈*Adj(x) in the path such that the number of unvisited adjacent vertices of all Adj(y) vertices is greater than one.

A vertex is said to be unreachable if all its neighbours are already a part of the path constructed so far. In this case, there is no way to reach the vertex and it becomes unreachable. In this proposed heuristic, if the selection of a vertex is making any of its unvisited neighbours unreachable then that vertex will not be added to path.

For example, consider the graph shown in Figure 1.