Graph: Forbid paths trough already locked valves

This commit is contained in:
2026-08-05 14:31:54 +02:00
parent db5702c0a7
commit 47455d9291
+8 -4
View File
@@ -55,14 +55,18 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
}
public Path? GetPath(IEnumerable<INode> points, Func<INode, bool>? valid = null) {
if (points.Count() < 2) throw new ArgumentException("Path is too short");
if (points.Count() < 2) return null;
var start = points.First();
var path = new Path(start, []);
foreach (var end in points.Skip(1)) {
if (GetPath(start, end, valid, visited: [..path.Hops.Select(h => h.Node)]) is not Path p)
if (valid != null && !valid(start)) {
return null;
path.Hops = [..path.Hops, ..p.Hops];
start = end;
} else if (GetPath(start, end, valid, visited: [.. path.Hops.Select(h => h.Node)]) is not Path p) {
return null;
} else {
path.Hops = [.. path.Hops, .. p.Hops];
start = end;
}
}
return path;
}