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