From fbec14b7d8eb96b6da7e6472fc25625744b20ce2 Mon Sep 17 00:00:00 2001 From: D4VID Date: Sun, 23 Feb 2025 16:48:57 +0100 Subject: [PATCH] Color hue --- .../src/server/tool/ClusterNode.cs | 4 +- .../src/server/tool/ServerPathTracer.cs | 127 +++++++++--------- 2 files changed, 69 insertions(+), 62 deletions(-) diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs index 42bbafb..92fd8e7 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ClusterNode.cs @@ -6,7 +6,7 @@ namespace CriticalPathAnalyzer.Server.Tool { public int Index; // "identifier" public List Clusters; // bidirectionally connected clusters without delay public int Time; // what point in time has been this cluster last updated - public Dictionary NextNodes; // next cluster StateID / delay between them - public int? PrevNodeStateId; // the last cluster that updated this one + public Dictionary NextNodes; // next node index / delay between them + public int? PrevNodeIndex; // the last cluster that updated this one } } \ No newline at end of file diff --git a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs index 3c1b79e..33b3b0e 100644 --- a/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs +++ b/CriticalPathAnalyzer/CriticalPathAnalyzer/src/server/tool/ServerPathTracer.cs @@ -47,7 +47,7 @@ namespace CriticalPathAnalyzer.Server.Tool { ILogicLogger logger = CriticalPathAnalyzerServer.LoggerInstance; response = null; - logger.Info("Trace start"); + logger.Info($"Trace start from {start} to {end}"); // Validate, that the peg is actually existing: if (!PegExists(start) || !PegExists(end)) { @@ -57,7 +57,7 @@ namespace CriticalPathAnalyzer.Server.Tool { var clusterNodes = new List(); var clusterToNodeMapping = new Dictionary(); // Cluster / index of node - var queue = new Queue<(Cluster, int)>(); + var queue = new Queue(); // An input peg, only has a single cluster. // An output peg however can be connected to multiple clusters. @@ -65,90 +65,97 @@ namespace CriticalPathAnalyzer.Server.Tool { var collectedClusters = new HashSet(); CollectMainClusters(start, collectedClusters); - foreach (Cluster cluster in collectedClusters) { - queue.Enqueue((cluster, 0)); - } - - logger.Info($"collected {collectedClusters.Count} main clusters"); - - int iters = 0; - while (queue.TryDequeue(out (Cluster, int) item)) { - iters++; - if (iters > 100000) { - logger.Error("Infinite iterations"); - break; - } - - (Cluster cluster, int time) = item; - - logger.Warn(">> cluster iter <<"); - - if (clusterToNodeMapping.ContainsKey(cluster)) { - logger.Info("already mapped, continuing"); + foreach (Cluster startingCluster in collectedClusters) { + // ignore already mapped clusters + if (clusterToNodeMapping.ContainsKey(startingCluster)) { continue; } - // Collect clusters that get powered by the original cluster using relays or fast buffers // var nextClusters = new HashSet(); // var twoWayConnectedClusters = new HashSet(); - // // GetLinkedClusters(cluster, nextClusters, twoWayConnectedClusters, GetFollowers); - - // logger.Info($"collected {nextClusters.Count} one way linked clusters"); - // logger.Info($"collected {twoWayConnectedClusters.Count} two way linked clusters"); - int index = clusterNodes.Count; + var node = new ClusterNode() { + Index = index, + Clusters = new List() {startingCluster}, + Time = 0, + PrevNodeIndex = null, + NextNodes = new Dictionary(), + }; + clusterNodes.Add(node); + foreach (Cluster cluster in node.Clusters) { + clusterToNodeMapping.Add(cluster, index); + } - // foreach (Cluster connectedCluster in twoWayConnectedClusters) { - // if (!clusterToNodeMapping.TryAdd(connectedCluster, index)) { - // // already been here - // logger.Error("Adding already mapped cluster"); - // break; - // } - // } + queue.Enqueue(node); + } - // foreach (Cluster connectedCluster in nextClusters) { - // var nextClusters = new HashSet(); - // var twoWayConnectedClusters = new HashSet(); - // GetLinkedClusters(connectedCluster, nextClusters, twoWayConnectedClusters, GetFollowers); - // } + logger.Info($"collected {collectedClusters.Count} main clusters"); - clusterToNodeMapping.Add(cluster, index); + int iters = 0; + while (queue.TryDequeue(out ClusterNode node)) { + iters++; + if (iters > 1000) { + logger.Error("Infinite iterations"); + break; + } - clusterNodes.Add(new ClusterNode() { - Index = index, - Clusters = new List() {cluster}, - Time = index, - PrevNodeStateId = null, - NextNodes = new Dictionary(), - }); + logger.Warn(">> cluster node iter <<"); // var perimeterComponents = new HashSet(); var collectedNextClusters = new HashSet(); - foreach (InputPeg inputPeg in cluster.ConnectedInputs) { - if (inputPeg.LogicComponent == null) { - // These are regular pegs, they are not attached to any logic component, skip them - continue; - } + foreach (Cluster cluster in node.Clusters) { + foreach (InputPeg inputPeg in cluster.ConnectedInputs) { + if (inputPeg.LogicComponent == null) { + // These are regular pegs, they are not attached to any logic component, skip them + continue; + } - // perimeterComponents.Add(inputPeg.LogicComponent.Address); + // perimeterComponents.Add(inputPeg.LogicComponent.Address); - foreach (IOutputPeg outputPeg in inputPeg.LogicComponent.Outputs) { - CollectMainClusters(outputPeg.Address, collectedNextClusters); + foreach (IOutputPeg outputPeg in inputPeg.LogicComponent.Outputs) { + CollectMainClusters(outputPeg.Address, collectedNextClusters); + } } } foreach (Cluster nextCluster in collectedNextClusters) { - queue.Enqueue((nextCluster, time + 1)); - } + // ignore already mapped clusters + if (clusterToNodeMapping.TryGetValue(nextCluster, out int nextNodeIndex)) { + // only add the link, don't propagate + int timeDelay = 1; + node.NextNodes.Add(nextNodeIndex, 1); + } else { + // var nextClusters = new HashSet(); + // var twoWayConnectedClusters = new HashSet(); + // GetLinkedClusters(cluster, nextClusters, twoWayConnectedClusters, GetFollowers); + int timeDelay = 1; + nextNodeIndex = clusterNodes.Count; + var nextNode = new ClusterNode() { + Index = nextNodeIndex, + Clusters = new List() {nextCluster}, + Time = node.Time + timeDelay, + PrevNodeIndex = node.Index, + NextNodes = new Dictionary(), + }; + node.NextNodes.Add(nextNodeIndex, timeDelay); + + clusterNodes.Add(nextNode); + + foreach (Cluster nextNodeCluster in nextNode.Clusters) { + clusterToNodeMapping.Add(nextNodeCluster, nextNodeIndex); + } - logger.Info("collected perimeter components"); + queue.Enqueue(nextNode); + } + } } // Collect information about each cluster: response = new AnalyzePathResponse() { RequestGuid = requestGuid, - Clusters = clusterNodes.SelectMany(node => node.Clusters.Select(cluster => CollectClusterInformation(cluster, node.Time))).ToList(), + Clusters = clusterNodes.SelectMany(node => + node.Clusters.Select(cluster => CollectClusterInformation(cluster, node.Time))).ToList(), // PerimeterComponents = perimeterComponents.ToList(), // NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(), };