Hamiltonian cycle taking too long

I have to find out if there is Hamiltonian cycle in a giant graph (1000 vertices in the smallest instance and 5000 vertices in the largest).

My initial idea was to do backtracking, and in small instances, it worked right. But for instance of 1000 vertices, I left 6 hours and no response.

My idea was to take a code from the ready traveling clerk (only found using array) and put the edges that exist with weight 1, and those that do not exist with weight 9.

If the result of the execution of the function gives the number of vertices, there is a Hamiltonian cycle.

If it does not, then there is no Hamiltonian cycle (as it had to use some edge of weight 9 to find the way).

For small instances, it continued to work, but with the 1000 Vertex instance, it also crashed.

Nobody in the class has the knowledge to do something that escapes much of the backtracking, therefore, it is assumed that we find some code already implemented on the internet. At most, we will have to make some small changes.

Does anyone have any traveling clerk or a code that would detect a Hamiltonian loop with adjacency list? Or instances up to 5000 in less than 3 hours?

Would someone try to help me by giving at least one hint?

Links with the codes and entries I used:

Author: peetorres, 2016-07-29

1 answers

Determining whether a graph has a Hamiltonian Cycle is an NP-Complete problem (source: Wikipedia ).

Problem NP-Complete means that there is no known polynomial algorithm for finding a solution (just to check if a solution is valid).

The algorithms as brute force (backtracking, complexity n!), Dynamic Programming (n22^n) or other more sophisticated are all exponential.

What I suggest is to search meta-heuristics to solve this problem in a sub-optimal way (Ant Colony, Hill Climbing, Genetic Algorithms) - will hit many times, but may fail for some instances of graphs. At least you will have more control over the runtime and quality of the solutions.

 2
Author: Rafael B., 2017-03-12 20:48:56