# FindHamiltonianPath quits kernel

Wolfram Tech Support has confirmed a bug in FindHamiltonianPath that affects Mathematica 11.3.0 under Windows 10. I reported it when the function would sometimes cause the kernel to quit. The function usually works fine.

When weighted graph G causes the function to fail on my Windows machine, I simply run FindHamiltonianPath@G in MathematicaOnline to get an answer (or a friend runs it on his Mac). The offending weighted graphs seem perfectly normal (unfortunately, I cannot post the geolocation data used to build the graphs).

Has anyone encountered this problem under Windows and if so, did you find a workaround? Thanks.

The context SparseArray contains a routine SparseArrayFindHamiltonianCycle that you might use as a workaround. I am not sure, maybe it is also used as backend for FindHamiltonianCycle and FindHamiltonianPath. (I belief that it's not.) Just give it a try.

SparseArrayFindHamiltonianCycle works on sparse matrices, so the AdjacencyMatrix of your graph has to be supplied. Since it only searches for cycles, we just add an artificial vertex that is connected to all other vertices and remove it later. This can be done by appending a row and a column of ones.

G = RandomGraph[{10, 20}, VertexLabels -> "Name"];

a = SparseArray[ConstantArray[1, {1, VertexCount[G]}]];
A = ArrayFlatten[{
path = SparseArrayFindHamiltonianCycle[A];

The drawback of this method is that it is randomized, so you will usually get a different path when calling SparseArrayFindHamiltonianCycle again.