master
D4VID 7 months ago
parent 79def5270b
commit fbec14b7d8

@ -6,7 +6,7 @@ namespace CriticalPathAnalyzer.Server.Tool {
public int Index; // "identifier" public int Index; // "identifier"
public List<Cluster> Clusters; // bidirectionally connected clusters without delay public List<Cluster> Clusters; // bidirectionally connected clusters without delay
public int Time; // what point in time has been this cluster last updated public int Time; // what point in time has been this cluster last updated
public Dictionary<int, int> NextNodes; // next cluster StateID / delay between them public Dictionary<int, int> NextNodes; // next node index / delay between them
public int? PrevNodeStateId; // the last cluster that updated this one public int? PrevNodeIndex; // the last cluster that updated this one
} }
} }

@ -47,7 +47,7 @@ namespace CriticalPathAnalyzer.Server.Tool {
ILogicLogger logger = CriticalPathAnalyzerServer.LoggerInstance; ILogicLogger logger = CriticalPathAnalyzerServer.LoggerInstance;
response = null; response = null;
logger.Info("Trace start"); logger.Info($"Trace start from {start} to {end}");
// Validate, that the peg is actually existing: // Validate, that the peg is actually existing:
if (!PegExists(start) || !PegExists(end)) { if (!PegExists(start) || !PegExists(end)) {
@ -57,7 +57,7 @@ namespace CriticalPathAnalyzer.Server.Tool {
var clusterNodes = new List<ClusterNode>(); var clusterNodes = new List<ClusterNode>();
var clusterToNodeMapping = new Dictionary<Cluster, int>(); // Cluster / index of node var clusterToNodeMapping = new Dictionary<Cluster, int>(); // Cluster / index of node
var queue = new Queue<(Cluster, int)>(); var queue = new Queue<ClusterNode>();
// An input peg, only has a single cluster. // An input peg, only has a single cluster.
// An output peg however can be connected to multiple clusters. // An output peg however can be connected to multiple clusters.
@ -65,90 +65,97 @@ namespace CriticalPathAnalyzer.Server.Tool {
var collectedClusters = new HashSet<Cluster>(); var collectedClusters = new HashSet<Cluster>();
CollectMainClusters(start, collectedClusters); CollectMainClusters(start, collectedClusters);
foreach (Cluster cluster in collectedClusters) { foreach (Cluster startingCluster in collectedClusters) {
queue.Enqueue((cluster, 0)); // ignore already mapped clusters
} if (clusterToNodeMapping.ContainsKey(startingCluster)) {
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");
continue; continue;
} }
// Collect clusters that get powered by the original cluster using relays or fast buffers
// var nextClusters = new HashSet<Cluster>(); // var nextClusters = new HashSet<Cluster>();
// var twoWayConnectedClusters = new HashSet<Cluster>(); // var twoWayConnectedClusters = new HashSet<Cluster>();
//
// GetLinkedClusters(cluster, nextClusters, twoWayConnectedClusters, GetFollowers); // 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; int index = clusterNodes.Count;
var node = new ClusterNode() {
Index = index,
Clusters = new List<Cluster>() {startingCluster},
Time = 0,
PrevNodeIndex = null,
NextNodes = new Dictionary<int, int>(),
};
clusterNodes.Add(node);
foreach (Cluster cluster in node.Clusters) {
clusterToNodeMapping.Add(cluster, index);
}
// foreach (Cluster connectedCluster in twoWayConnectedClusters) { queue.Enqueue(node);
// if (!clusterToNodeMapping.TryAdd(connectedCluster, index)) { }
// // already been here
// logger.Error("Adding already mapped cluster");
// break;
// }
// }
// foreach (Cluster connectedCluster in nextClusters) { logger.Info($"collected {collectedClusters.Count} main clusters");
// var nextClusters = new HashSet<Cluster>();
// var twoWayConnectedClusters = new HashSet<Cluster>();
// GetLinkedClusters(connectedCluster, nextClusters, twoWayConnectedClusters, GetFollowers);
// }
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() { logger.Warn(">> cluster node iter <<");
Index = index,
Clusters = new List<Cluster>() {cluster},
Time = index,
PrevNodeStateId = null,
NextNodes = new Dictionary<int, int>(),
});
// var perimeterComponents = new HashSet<ComponentAddress>(); // var perimeterComponents = new HashSet<ComponentAddress>();
var collectedNextClusters = new HashSet<Cluster>(); var collectedNextClusters = new HashSet<Cluster>();
foreach (InputPeg inputPeg in cluster.ConnectedInputs) { foreach (Cluster cluster in node.Clusters) {
if (inputPeg.LogicComponent == null) { foreach (InputPeg inputPeg in cluster.ConnectedInputs) {
// These are regular pegs, they are not attached to any logic component, skip them if (inputPeg.LogicComponent == null) {
continue; // 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) { foreach (IOutputPeg outputPeg in inputPeg.LogicComponent.Outputs) {
CollectMainClusters(outputPeg.Address, collectedNextClusters); CollectMainClusters(outputPeg.Address, collectedNextClusters);
}
} }
} }
foreach (Cluster nextCluster in 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<Cluster>();
// var twoWayConnectedClusters = new HashSet<Cluster>();
// GetLinkedClusters(cluster, nextClusters, twoWayConnectedClusters, GetFollowers);
int timeDelay = 1;
nextNodeIndex = clusterNodes.Count;
var nextNode = new ClusterNode() {
Index = nextNodeIndex,
Clusters = new List<Cluster>() {nextCluster},
Time = node.Time + timeDelay,
PrevNodeIndex = node.Index,
NextNodes = new Dictionary<int, int>(),
};
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: // Collect information about each cluster:
response = new AnalyzePathResponse() { response = new AnalyzePathResponse() {
RequestGuid = requestGuid, 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(), // PerimeterComponents = perimeterComponents.ToList(),
// NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(), // NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(),
}; };

Loading…
Cancel
Save