lightestPath method
Returns the path connecting start
and target
with
the smallest summed edge-weight.
- Returns an empty list if no path could be found.
Implementation
List<T> lightestPath(T start, T target) {
final paths = crawler.paths(start, target);
if (paths.isEmpty) return [];
var minWeight = summation(weight, weight);
var result = <T>[];
for (final path in paths) {
final currentWeight = weightAlong(path);
if (currentWeight.compareTo(minWeight) < 0) {
// Reset minimum weight.
minWeight = currentWeight;
result = path;
}
}
return result;
}