Added function for finding the closest distance between two nodes
in a graph
Modifications to make intra H migration use smallest ring template.

Temporary hack.  This code may be suspicious.