Files
git.stella-ops.org/src/__Libraries/StellaOps.ElkSharp/ElkEdgeRouterIterative.WinnerRefinement.FastTerminalCandidates.cs

59 lines
1.7 KiB
C#

namespace StellaOps.ElkSharp;
internal static partial class ElkEdgeRouterIterative
{
private static bool TryPromoteFastTerminalCandidates(
CandidateSolution current,
ElkPositionedNode[] nodes,
ElkLayoutDirection direction,
double minLineClearance,
IReadOnlyList<string> orderedEdgeIds,
out CandidateSolution promoted)
{
promoted = current;
if (orderedEdgeIds.Count == 0)
{
return false;
}
var candidatePromotions = new CandidateSolution?[orderedEdgeIds.Count];
var parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = Math.Min(
orderedEdgeIds.Count,
Math.Max(1, Environment.ProcessorCount)),
};
Parallel.For(
0,
orderedEdgeIds.Count,
parallelOptions,
index =>
{
var candidateEdges = BuildFastTerminalOnlyHardRuleCandidate(
current.Edges,
nodes,
direction,
minLineClearance,
[orderedEdgeIds[index]]);
if (TryPromoteFinalHardRuleCandidate(current, candidateEdges, nodes, out var candidatePromoted))
{
candidatePromotions[index] = candidatePromoted;
}
});
for (var index = 0; index < candidatePromotions.Length; index++)
{
if (candidatePromotions[index] is not { } candidatePromoted)
{
continue;
}
promoted = candidatePromoted;
return true;
}
return false;
}
}