This is an implementation of the global paths matching algorithm.