traversal = {
let totalBest;
for (let i = 0; i < perimeterNodes.length; i++) {
const start = perimeterNodes[i];
const longestShortestPath = perimeterNodes.slice(i + 1).reduce((nodeBest, node) => {
const path = graph.path(node.id, start.id, { cost: true });
if (path && (!nodeBest || path.cost > nodeBest.cost)) {
return path;
}
return nodeBest;
}, null);
if (longestShortestPath && longestShortestPath.path) {
longestShortestPath.path = longestShortestPath.path.map(id => nodes[+id]);
if (!totalBest || longestShortestPath.cost > totalBest.cost) {
totalBest = longestShortestPath;
}
yield Promises.delay(+speed, {
bestPath: totalBest.path,
currentPath: longestShortestPath.path
});
}
}
if (totalBest) {
yield {
bestPath: totalBest.path
};
}
}