Working correct propagation

master
D4VID 7 months ago
parent 0e1184c32c
commit 78c6142689

@ -95,6 +95,8 @@ namespace CriticalPathAnalyzer.Client.Tool {
return; return;
} }
_logger.Info($"Critical path length is: {response.CriticalPathLength}");
PathHighLighter.RemoveHighLighting(); PathHighLighter.RemoveHighLighting();
PathHighLighter.HighlightWires(response); PathHighLighter.HighlightWires(response);
} }

@ -4,9 +4,9 @@ using LogicWorld.Server.Circuitry;
namespace CriticalPathAnalyzer.Server.Tool { namespace CriticalPathAnalyzer.Server.Tool {
public class ClusterNode { public class ClusterNode {
public int Index; // "identifier" public int Index; // "identifier"
public List<Cluster> Clusters; // bidirectionally connected clusters without delay public HashSet<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 node index / delay between them public Dictionary<int, int> NextNodes; // next node index / delay between them
public int? PrevNodeIndex; // the last cluster that updated this one public HashSet<int> PrevNodeIndexes; // the last cluster that updated this one
} }
} }

@ -4,7 +4,6 @@ using System.Linq;
using CriticalPathAnalyzer.Shared.Packets.S2C; using CriticalPathAnalyzer.Shared.Packets.S2C;
using EccsLogicWorldAPI.Server; using EccsLogicWorldAPI.Server;
using EccsLogicWorldAPI.Shared.AccessHelper; using EccsLogicWorldAPI.Shared.AccessHelper;
using JimmysUnityUtilities;
using LogicAPI.Data; using LogicAPI.Data;
using LogicAPI.Server.Components; using LogicAPI.Server.Components;
using LogicAPI.Services; using LogicAPI.Services;
@ -65,6 +64,9 @@ namespace CriticalPathAnalyzer.Server.Tool {
var collectedClusters = new HashSet<Cluster>(); var collectedClusters = new HashSet<Cluster>();
CollectMainClusters(start, collectedClusters); CollectMainClusters(start, collectedClusters);
var endingClusters = new HashSet<Cluster>();
CollectMainClusters(end, endingClusters);
foreach (Cluster startingCluster in collectedClusters) { foreach (Cluster startingCluster in collectedClusters) {
// ignore already mapped clusters // ignore already mapped clusters
if (clusterToNodeMapping.ContainsKey(startingCluster)) { if (clusterToNodeMapping.ContainsKey(startingCluster)) {
@ -77,9 +79,9 @@ namespace CriticalPathAnalyzer.Server.Tool {
int index = clusterNodes.Count; int index = clusterNodes.Count;
var node = new ClusterNode() { var node = new ClusterNode() {
Index = index, Index = index,
Clusters = new List<Cluster>() {startingCluster}, Clusters = new HashSet<Cluster>() {startingCluster},
Time = 0, Time = 0,
PrevNodeIndex = null, PrevNodeIndexes = new HashSet<int>(),
NextNodes = new Dictionary<int, int>(), NextNodes = new Dictionary<int, int>(),
}; };
clusterNodes.Add(node); clusterNodes.Add(node);
@ -100,8 +102,6 @@ namespace CriticalPathAnalyzer.Server.Tool {
break; break;
} }
logger.Warn(">> cluster node iter <<");
// var perimeterComponents = new HashSet<ComponentAddress>(); // var perimeterComponents = new HashSet<ComponentAddress>();
var collectedNextClusters = new HashSet<Cluster>(); var collectedNextClusters = new HashSet<Cluster>();
foreach (Cluster cluster in node.Clusters) { foreach (Cluster cluster in node.Clusters) {
@ -112,7 +112,6 @@ namespace CriticalPathAnalyzer.Server.Tool {
} }
// 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);
} }
@ -122,9 +121,19 @@ namespace CriticalPathAnalyzer.Server.Tool {
foreach (Cluster nextCluster in collectedNextClusters) { foreach (Cluster nextCluster in collectedNextClusters) {
// ignore already mapped clusters // ignore already mapped clusters
if (clusterToNodeMapping.TryGetValue(nextCluster, out int nextNodeIndex)) { if (clusterToNodeMapping.TryGetValue(nextCluster, out int nextNodeIndex)) {
ClusterNode nextNode = clusterNodes[nextNodeIndex];
// only add the link, don't propagate // only add the link, don't propagate
if (!nextNode.PrevNodeIndexes.Add(node.Index)) {
logger.Warn("Loop detected");
// already been here - there is a cycle
continue;
}
// Replace the time with a later one and continue
int timeDelay = 1; int timeDelay = 1;
node.NextNodes.Add(nextNodeIndex, 1); node.NextNodes.TryAdd(nextNodeIndex, 1);
nextNode.Time = node.Time + timeDelay;
queue.Enqueue(nextNode);
} else { } else {
// var nextClusters = new HashSet<Cluster>(); // var nextClusters = new HashSet<Cluster>();
// var twoWayConnectedClusters = new HashSet<Cluster>(); // var twoWayConnectedClusters = new HashSet<Cluster>();
@ -133,15 +142,16 @@ namespace CriticalPathAnalyzer.Server.Tool {
nextNodeIndex = clusterNodes.Count; nextNodeIndex = clusterNodes.Count;
var nextNode = new ClusterNode() { var nextNode = new ClusterNode() {
Index = nextNodeIndex, Index = nextNodeIndex,
Clusters = new List<Cluster>() {nextCluster}, Clusters = new HashSet<Cluster>() {nextCluster},
Time = node.Time + timeDelay, Time = node.Time + timeDelay,
PrevNodeIndex = node.Index,
NextNodes = new Dictionary<int, int>(), NextNodes = new Dictionary<int, int>(),
PrevNodeIndexes = new HashSet<int>() {node.Index},
}; };
node.NextNodes.Add(nextNodeIndex, timeDelay);
clusterNodes.Add(nextNode); clusterNodes.Add(nextNode);
node.NextNodes.TryAdd(nextNodeIndex, timeDelay);
foreach (Cluster nextNodeCluster in nextNode.Clusters) { foreach (Cluster nextNodeCluster in nextNode.Clusters) {
clusterToNodeMapping.Add(nextNodeCluster, nextNodeIndex); clusterToNodeMapping.Add(nextNodeCluster, nextNodeIndex);
} }
@ -156,6 +166,8 @@ namespace CriticalPathAnalyzer.Server.Tool {
RequestGuid = requestGuid, RequestGuid = requestGuid,
Clusters = clusterNodes.SelectMany(node => Clusters = clusterNodes.SelectMany(node =>
node.Clusters.Select(cluster => CollectClusterInformation(cluster, node.Time))).ToList(), node.Clusters.Select(cluster => CollectClusterInformation(cluster, node.Time))).ToList(),
CriticalPathLength = clusterNodes[clusterToNodeMapping[endingClusters.First()]].Time,
// PerimeterComponents = perimeterComponents.ToList(), // PerimeterComponents = perimeterComponents.ToList(),
// NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(), // NextClusters = collectedNextClusters.Select(CollectClusterInformation).ToList(),
}; };
@ -305,7 +317,7 @@ namespace CriticalPathAnalyzer.Server.Tool {
float x = c * (1 - Math.Abs((h / 60.0f) % 2 - 1)); float x = c * (1 - Math.Abs((h / 60.0f) % 2 - 1));
float m = v - c; float m = v - c;
float r = 0, g = 0, b = 0; float r, g, b;
if (h < 60) { if (h < 60) {
r = c; r = c;

@ -9,8 +9,10 @@ namespace CriticalPathAnalyzer.Shared.Packets.S2C {
public class AnalyzePathResponse : Packet { public class AnalyzePathResponse : Packet {
[Key(0)] public Guid RequestGuid; [Key(0)] public Guid RequestGuid;
[Key(1)] public List<ClusterDetails> Clusters; [Key(1)] public List<ClusterDetails> Clusters;
// [Key(2)] public List<ComponentAddress> PerimeterComponents;
// [Key(3)] public List<ClusterDetails> NextClusters; [Key(2)] public int CriticalPathLength;
// [Key(3)] public List<ComponentAddress> PerimeterComponents;
// [Key(4)] public List<ClusterDetails> NextClusters;
} }
[MessagePackObject] [MessagePackObject]

Loading…
Cancel
Save