Deep search through relays

master
D4VID 6 months ago
parent 3f4d73bc97
commit 2d075f6c16

@ -133,6 +133,7 @@ namespace CriticalPathAnalyzer.Server.Tool {
if (iterations % 1000 == 0) { if (iterations % 1000 == 0) {
CriticalPathAnalyzerServer.LoggerInstance.Info($"{iterations} propagation iterations"); CriticalPathAnalyzerServer.LoggerInstance.Info($"{iterations} propagation iterations");
} }
ClusterNode node = clusterNodes[index]; ClusterNode node = clusterNodes[index];
foreach ((int nextNodeIndex, int delay) in node.NextNodes) { foreach ((int nextNodeIndex, int delay) in node.NextNodes) {
clusterNodes[nextNodeIndex].Time = node.Time + delay; clusterNodes[nextNodeIndex].Time = node.Time + delay;
@ -169,6 +170,7 @@ namespace CriticalPathAnalyzer.Server.Tool {
if (iterations % 1000 == 0) { if (iterations % 1000 == 0) {
CriticalPathAnalyzerServer.LoggerInstance.Info($"{iterations} loop iterations"); CriticalPathAnalyzerServer.LoggerInstance.Info($"{iterations} loop iterations");
} }
foreach ((int nextNodeIndex, int _) in node.NextNodes) { foreach ((int nextNodeIndex, int _) in node.NextNodes) {
ClusterNode nextNode = clusterNodes[nextNodeIndex]; ClusterNode nextNode = clusterNodes[nextNodeIndex];
nextNode.PrevNodeIndexes.Remove(node.Index); nextNode.PrevNodeIndexes.Remove(node.Index);
@ -250,24 +252,40 @@ namespace CriticalPathAnalyzer.Server.Tool {
logger.Info($"Finished after {iterations} iterations"); logger.Info($"Finished after {iterations} iterations");
} }
private static HashSet<Cluster> GetClustersConnectedThroughRelays(Cluster cluster) { private static HashSet<Cluster> GetClustersConnectedThroughRelays(Cluster origin) {
var clusters = new HashSet<Cluster>() {cluster}; var clusters = new HashSet<Cluster> {origin};
foreach (InputPeg inputPeg in cluster.ConnectedInputs) { var queue = new Queue<Cluster>();
LogicComponent component = inputPeg.LogicComponent; queue.Enqueue(origin);
if (component == null) {
// These are regular pegs, they are not attached to any logic component, skip them while (queue.TryDequeue(out Cluster cluster)) {
continue; foreach (InputPeg inputPeg in cluster.ConnectedInputs) {
} LogicComponent component = inputPeg.LogicComponent;
if (component == null) {
// These are regular pegs, they are not attached to any logic component, skip them
continue;
}
if (component.GetType() == typeof(Relay)) { if (component.GetType() == typeof(Relay)) {
// Collect all next clusters connected via a relay (from the control input side) // Collect all next clusters connected via a relay (from the control input side)
if (inputPeg.Address == component.Inputs[1].Address) { if (inputPeg.Address == component.Inputs[1].Address) {
// one of the sides // one of the sides
// TODO: need to recursively check for further relays if (component.Inputs[2].Address.IsInputAddress(out InputAddress inputAddress)) {
CollectPegClusters(component.Inputs[2].Address, clusters); Cluster nextCluster = GetClusterAt(inputAddress);
} else if (inputPeg.Address == component.Inputs[2].Address) { if (clusters.Add(nextCluster)) {
// the other side // found a new cluster, continue searching
CollectPegClusters(component.Inputs[1].Address, clusters); queue.Enqueue(nextCluster);
}
}
} else if (inputPeg.Address == component.Inputs[2].Address) {
// the other side
if (component.Inputs[1].Address.IsInputAddress(out InputAddress inputAddress)) {
Cluster nextCluster = GetClusterAt(inputAddress);
if (clusters.Add(nextCluster)) {
// found a new cluster, continue searching
queue.Enqueue(nextCluster);
}
}
}
} }
} }
} }

Loading…
Cancel
Save