This reminds me more than a bit of the
TSP, or rather a subtask for solving the TSP, being to generate and test paths through a network until a certain type of solution is found. The most standard algorithm I know is the
Neural Network, albeit that the TSP itself was eventually solved by just a better brute force algorithm than had been found earlier and I suspect the same to be true of this variant. But whereas there are modules like
Math:Combinatorics and
Algorithm::Loops to get you started, finding the best solution will still require some hard grind I think.