Backtracking algorithms for constructing the Hamiltonian decomposition of a 4-regular multigraph

We consider a Hamiltonian decomposition problem of partitioning a regular graph into edge-disjoint Hamiltonian cycles. It is known that verifying vertex non-adjacency in the 1-skeleton of the symmetric and asymmetric traveling salesperson polytopes is NP-complete. On the other hand, a sufficient condition for two vertices to be non-adjacent can be formulated as a combinatorial problem of finding a second Hamiltonian decomposition of a 4-regular multigraph. We present two backtracking algorithms for constructing a second Hamiltonian decomposition and verifying vertex non-adjacency: an algorithm based on a simple path extension and an algorithm based on the chain edge fixing procedure. Based on the results of computational experiments for undirected multigraphs, both backtracking algorithms lost to the known general variable neighborhood search heuristics. However, for directed multigraphs, the algorithm based on chain fixing of edges showed results comparable to heuristics on instances with an existing solution and better results on infeasible instances where the Hamiltonian decomposition does not exist.


Introduction
Hamiltonian decomposition of a regular multigraph is a partition of its edge set into Hamiltonian cycles. The problem of finding edge-disjoint Hamiltonian cycles in a given regular graph finds applications in combinatorial optimization [23], coding theory [5,6], algorithms for distributed data mining [12], analysis of interconnected networks [18] and other areas. See also theoretical results on estimating the number of Hamiltonian decompositions of regular graphs [16]. In this paper, the problem of constructing a Hamiltonian decomposition arises from the field of polyhedral combinatorics.

Traveling salesperson polytope
We consider the classic formulation of the traveling salesperson problem: given a complete weighted graph (or digraph) = ( , ), find a Hamiltonian cycle of minimum weight. Denote by the set of all Hamiltonian cycles in the graph and assign to each Hamiltonian cycle ∈ the characteristic vector ∈ ℝ according to the following rule: = 1, if the cycle contains an edge , 0, otherwise.

Hamiltonian decomposition and sufficient condition for vertex non-adjacency
As a result of Papadimitriou's theorem on the NP-completeness of verifying the vertex non-adjacency in the 1-skeleton of the traveling salesperson polytope, sufficient conditions for non-adjacency are of interest. In particular, polynomial sufficient conditions are known for pyramidal tours [10], pyramidal tours with step-backs [24], and pedigrees [3,4]. In this paper, we consider the most general of the known -sufficient condition by Rao [28]. Let = ( , ) and = ( , ) be two Hamiltonian cycles on the vertex set . We denote by ∪ a union multigraph ( , ∪ ) that contains a copy of each edge of and . Note that if two cycles contain the same edge , then both copies of the edge are added to the multigraph ∪ .
Lemma 2 (Rao [28]). Given two Hamiltonian cycles and , if the union multigraph ∪ contains two edge-disjoint Hamiltonian cycles and different from and , then the corresponding vertices and of the traveling salesperson polytope STSP( ) (or ATSP( )) are not adjacent.
From a geometric point of view, the sufficient condition by Rao means that the segment connecting two vertices and intersects the segment connecting two other vertices and of the traveling salesperson polytope, therefore, they cannot be adjacent. An example of a satisfied sufficient condition is shown in Fig. 1.
Thus, verifying the vertex non-adjacency in the 1-skeleton of the traveling salesperson polytope can be reduced to finding a Hamiltonian decomposition of the union multigraph ∪ that is different from the Second Hamiltonian decomposition problem. Instance: let and be two Hamiltonian cycles. Question: does the union multigraph ∪ contain a pair of edge-disjoint Hamiltonian cycles and different from and ?
Note that checking whether an arbitrary graph contains a Hamiltonian decomposition is an NP-complete problem already for 4-regular undirected multigraphs and 2-regular directed multigraphs [27].
Previously, the second Hamiltonian decomposition problem and its application to verifying the vertex non-adjacency in the 1-skeletons of the polytopes STSP( ) and ATSP( ) were considered in [22,25], where several heuristic algorithms were proposed based on constructing vertex-disjoint cycle covers of a graph: simulated annealing and general variable neighborhood search. Heuristic algorithms have proven to be very efficient on instances that have a solution, especially on undirected graphs. However, in instances that do not have a solution, heuristics face significant difficulties. In this paper, we consider two exact backtracking algorithms for constructing the second Hamiltonian decomposition of a 4-regular multigraph.

Backtracking algorithm based on simple path extension
Recall that backtracking is one of the general methods for finding a solution to a problem by exhaustive search. The procedure consists of a successive extension of a partial solution. If at the next step such an extension fails, then we backtrack to a shorter partial solution and continue the search further [29].
In [21], a backtracking algorithm was presented for the problem of finding a second Hamiltonian decomposition of a 4-regular multigraph based on extending a simple path. Below is a modified version of this algorithm.
Let here and below the partial solution consist of two components and . The idea of the algorithm is to sequentially construct a simple path in the component . Whereas edges not included in are sent to the component .
Consider the example of the ∪ multigraph shown in Fig. 1. Let us construct a partial solution for it, corresponding to the simple path 2 − 3 − 5 − 6 ( Fig. 2). Here, the edges of the component are solid, and the edges of the component are dashed. Since the degree of each vertex in the multigraph ∪ is equal to 4, then we can continue a simple path in from the vertex 6 in no more than three ways: (6, 1), (6,2) and (6,4). Moreover, whichever edge we choose to continue the path, since two edges incident to the vertex 6 have already been added to , the other two edges can only fall into the component . We sequentially consider all three options and for each we check the correctness of the partial solution: • extension 1 is invalid because it contains a cycle at vertices 2, 3, 4, 6 in the component ; • extension 2 is invalid because it contains a cycle at vertices 2, 3, 5, 6 in the component ; • extension 3 is correct.
In the general case, the correctness conditions for a partial solution have the following form: • contains a simple path (by construction) or a Hamiltonian cycle; • contains a forest (a graph without cycles) with vertex degrees at most 2 or a Hamiltonian cycle.
If the extension of the partial solution turned out to be incorrect, then we backtrack and consider the next option. If all three extensions are invalid, then this partial solution cannot be extended, and we backtrack to a shorter partial solution.
The general scheme for undirected graphs is presented in the Algorithm 1. The only difference for directed graphs is that the outdegree of each vertex of the multigraph ∪ is equal to two, hence there are at most two options for extending a simple path in . All other steps are completely similar. Add the edge ( , ) to 3: if Vertex in has 2 incident edges then 4: Add free edges incident to to the component 5: end if 6: if partial solution , is not correct then 7: return ⊳ Backtrack to the previous step 8: end if 9: if and are Hamiltonian cycles (different from and ) then 10: return Hamiltonian decomposition of and ⊳ Solution found 11: end if 12: Sort edges ( , ) from in ascending order of free degrees of vertices 13: for each free edge ( , ) from the vertex do 14: , ← Backtracking_Simple_Path( , , ( , ), ∪ ) 15: if Hamiltonian decomposition is found then 16: return Choose an initial edge ( , ) of the multigraph ∪ 23: , ← Backtracking_Simple_Path( , , ( , ), ∪ ) 24: if and are found then 25: return The Hamiltonian decomposition and is found (vertices are not adjacent) 26: end if 27: return Hamiltonian decomposition not found (vertices are probably adjacent) 28: end procedure 4 Backtracking algorithm based on chain edge fixing The second backtracking algorithm is based on the chain fixation of edges in the components and . Algorithms for directed and undirected graphs are slightly different, so we describe them separately.

Directed multigraphs
We consider a directed 2-regular multigraph ∪ for which the indegrees and outdegrees of each vertex are equal to two. Let us choose some edge ( , ) and fix it in the component , then the second edge ( , ) outcoming from and the second edge (ℎ, ) incoming into cannot get into . We will fix these edges in (Fig. 3).
The main idea of the algorithm is that the edges ( , ) and (ℎ, ) fixed in , in turn, start recursive chains of fixing edges in , and so on.
At the output, given only one edge (1, 2) fixed in , we obtain unique Hamiltonian cycles and (Fig. 4). Considering that the edge (1, 2) must belong to at least one Hamiltonian cycle, this 2-regular directed multigraph contains a unique Hamiltonian decomposition, which was found. The general backtracking scheme for directed multigraphs is given in the pseudocode of the Algorithm 2. At the data preprocessing step (line 28, Algorithm 2), we find all multiple edges in the multigraph ∪ and fix one copy in and , since these edges cannot get into the same Hamiltonian cycle.
A partial solution is considered correct if the components and are directed acyclic graphs with indegrees and outdegrees at most one or directed Hamiltonian cycles. By construction, the indegrees and outdegrees of vertices in and cannot be equal to two, so to check the correctness it suffices to verify that there are no non-Hamiltonian cycles.
In contrast to the backtracking algorithm based on the simple path extension (Algorithm 1), we choose the vertex ′ to extend the partial solution (line 18, Algorithm 2) in such a way that the chain edge fixing starts from both head and tail of the edge ( ′ , ′ ). The more edges are fixed at one step, the smaller the recursion depth will be.
Note that we do not branch when choosing and fixing the first free edge ( , ) (line 29, Algorithm 2), since this edge must get into one of the solution components. Let's call the component the one that contains the edge ( , ).
It should also be noted that although the procedure Chain_Edge_Fixing_Directed (lines 1-9, Algorithm 2) at each step calls up to two of its subroutines, the total complexity is linear ( ( )) since each edge can be fixed at most once, and | | = 2| |. Chain_Edge_Fixing_Directed(( , ) in ) 12: if and are Hamiltonian cycles (different from and ) then 13: return and ⊳ Solution is found 14: end if 15: if or contains a non-Hamiltonian cycle then ⊳ Partial solution is incorrect 16: return ⊳ Backtrack to the previous step 17: end if 18: Select vertex ′ with free outcoming edges 19: for each free edge ( ′ , ′ ) outcoming from the vertex ′ do 20: , ← Backtracking_Chain_Edge_Fixing_Directed( , , ( ′ , ′ ), ∪ ) 21: if Hamiltonian decomposition is found then

Undirected multigraphs
The pseudo-code of the algorithm for undirected multigraphs is presented in Algorithm 3.

Algorithm 3
Backtracking based on chained edge fixing for undirected graphs 1: procedure Chain_Edge_Fixing_Undirected(( , ) in ) 2: Fix the edge ( , ) in 3: if vertex in is incident with 2 fixed edges then if vertex in is incident with 2 fixed edges then Chain_Edge_Fixing_Undirected(( , ) in ) 14: if and are Hamiltonian cycles (different from and ) then 15: return and ⊳ Solution is found 16: end if 17: if or contains a non-Hamiltonian cycle then ⊳ Partial solution is incorrect 18: return ⊳ Backtrack to the previous step 19: end if 20: Choose a vertex with the minimum degree of free edges 21: Sort edges ( , ) incident to in ascending order of free powers 22: for ← 1 to do 23: , ←Backtracking_Chain_Edge_Fixing_Undirected( , , ( , ), ∪ ) 24: if Hamiltonian decomposition is found then 25: return Hamiltonian decomposition and 26: end if 27: end for 28: end procedure The chain edge fixing procedure is triggered as soon as 2 edges are incident to a vertex in one of the partial solutions, then the other two edges are sent to another partial solution (lines 3-10, Algorithm 3).
A partial solution is considered correct if the components and are forests with vertex degrees at most two or Hamiltonian cycles. By construction, we add to and one edge at a time. Moreover, as soon as the degree of some vertex in one of the components becomes equal to two, then the two remaining edges are sent to another component. Thus, to check the correctness of a partial solution, it suffices to verify that and do not contain non-Hamiltonian cycles. Note that at each step, to expand the partial solution, we choose a vertex with the minimum degree over free edges in order to reduce the branching factor of the recursion. Edges incident to are considered in ascending order of degrees of adjacent vertices along free edges (lines 20-27, Algorithm 3).

Vertex adjacency and data preprocessing
Let's note that the algorithms considered in this paper were developed for the problem of constructing a Hamiltonian decomposition of a 4-regular multigraph ∪ . The algorithms refer directly to the cycles and only when checking that the second decomposition and is different from the original one. If we omit this check, then we get algorithms for constructing a Hamiltonian decomposition without any reference to polyhedral combinatorics. Otherwise, if we are interested in exactly the adjacency of vertices in the 1skeleton of the traveling salesperson polytope, then we can strengthen the considered algorithms by adding a data preprocessing step and checking the known polynomial sufficient conditions for non-adjacency: pyramidal tours [10], pyramidal tours with step-backs [24], pedigrees [3,4], etc.

Computational experiments
The algorithms were tested on random directed and undirected 4-regular multigraphs. For each graph size, 100 pairs of random permutations with a uniform probability distribution were generated using the Fisher-Yates shuffle algorithm [20]. For comparison, we chose 3 algorithms: • backtracking based on simple path extension (BSP); • backtracking based on chain edge fixing (BCEF); • general variable neighborhood search (GVNS) heuristic algorithm from [25], which is a modification of the simulated annealing algorithm [22] and is based on constructing a vertex-disjoint cycle covers by reduction to perfect matching and several cycle merging operations.
Backtracking algorithms are implemented in Python, for the general variable neighborhood search heuristics, a ready-made implementation in Node.js [25] is taken. Computational experiments were carried out on an Intel(R) Core(TM) i5-4460 machine with a 3.20GHz CPU and 16GB RAM.
The results of computational experiments for undirected graphs are presented in the Table 1 and in Fig. 5. Results for directed graphs are presented in Table 2 and in Fig. 6 and Fig. 7.
For each set of 100 tests, the average running time of the algorithms in seconds is given separately for feasible and infeasible instances. For two backtracking algorithms (BSP and BCEF), a time limit of 2 hours was set for each set of 100 test problems. Accordingly, the tables indicate how many instances out of 100 the algorithm managed to solve in 2 hours. The general variable neighborhood search heuristics (GVNS) was set to a limit of 1 minute per instance. This is because the heuristic algorithm has a one-sided error. If the algorithm finds a solution, then the instance is feasible. However, the heuristic algorithm cannot guarantee that the problem is infeasible, only that the solution is not found in a given time or number of iterations.
It is known that random undirected regular graphs have a Hamiltonian decomposition with a very high probability [19]. Indeed, for all test problems on undirected multigraphs (Table 1), there was a second Hamiltonian decomposition into cycles different from the original ones, and the vertices of the traveling salesperson polytope were not adjacent. From a geometric point of view, this means that the degrees of vertices in a 1-skeleton are much less than the total number of vertices, so two random vertices are not adjacent with a high probability.
According to the computational results for undirected Hamiltonian cycles, both backtracking algorithms lost out to the general variable neighborhood search heuristics (GVNS). In the allotted time, the algorithm based on simple path extension (BSP) solved 709 instances, the algorithm based on chain edge fixing (BCEF) solved 1486 instances, and the general variable neighborhood search (GVNS) solved all 1500 out of 1500 instances. GVNS was on average 13 times faster than BCEF and 640 times faster than BSP. Among the two backtracking algorithms, the chain edge fixing (BCEF) algorithm proved to be significantly more efficient, solving all test instances up to 3072 vertices and showing the running time on the solved problems on average 48 times faster than the simple path construction (BSP).
The computational results for directed multigraphs ( Table 2, Fig. 6 and 7) turned out to be fundamentally different. Only about 20% of random instances were feasible. Note that this does not mean that the     corresponding vertices of the traveling salesperson polytope are adjacent since the second Hamiltonian decomposition problem only verifies a sufficient condition for the non-adjacency in a 1-skeleton.
The worst results of the three considered algorithms were shown by backtracking based on simple path extension (BSP). In the allotted time, the algorithm solved only 225 instances out of 1500, without solving a single problem for graphs with more than 64 vertices. While chain edge fixing (BCEF) solved 1495 instances, and the general variable neighborhood search (GVNS) solved all instances. In terms of running time on feasible problems, the GVNS heuristic algorithm showed an advantage over BCEF on small graphs up to 512 vertices by an average of 6 times. However, on graphs with more than 512 vertices, BCEF turned out to be on average 2 times faster than GVNS. In general, for feasible problems, the BCEF and GVNS algorithms showed comparable results. Some variations in performance may be due to different implementations of the algorithms. However, we note that with an increase in the graph order, the advantage of BCEF over GVNS also increased. On the other hand, the general variable neighborhood search heuristics (GVNS) has encountered significant difficulties in infeasible instances. The algorithm cannot determine this scenario and exits only when the limit on running time or number of iterations is reached. On such problems, the algorithm based on chain fixing of edges (BCEF) turned out to be on average 16 times faster than GVNS. In part, this means that the iteration threshold for the heuristic algorithm could be lowered. However, in this case, there would be a danger of losing existing solutions.

Conclusion
In this paper, two backtracking algorithms were considered for the problem of constructing a second Hamiltonian decomposition of a 4-regular multigraph. According to the results of computational experiments on random directed and undirected multigraphs, the backtracking algorithm based on chain edge fixing turned out to be much more efficient than backtracking based on simple path extension. In addition, on directed multigraphs, the chain edge fixing showed comparable results with the previously known general variable neighborhood search heuristics on feasible instances and significantly outperformed the heuristics on infeasible problems.
The considered backtracking algorithms were developed for the problem of verifying the vertex nonadjacency in a 1-skeleton of a traveling salesperson polytope. However, they can also be applied directly to the problem of constructing the Hamiltonian decomposition of a regular multigraph and many of its applications.