Graph: Forbid paths trough already locked valves
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user