From b557c4bf5f3576eeb18fa2e03bd0edb81c767fbf Mon Sep 17 00:00:00 2001 From: VoidX Date: Sun, 21 Jul 2024 01:10:37 +0200 Subject: [PATCH] Fix incorrect channel mapping by removing channel mapping --- .../Utilities/FilterGraphNodeUtils.Mapping.cs | 83 +------------------ 1 file changed, 1 insertion(+), 82 deletions(-) diff --git a/Cavern/Filters/Utilities/FilterGraphNodeUtils.Mapping.cs b/Cavern/Filters/Utilities/FilterGraphNodeUtils.Mapping.cs index ca8a3ad..eaeb463 100644 --- a/Cavern/Filters/Utilities/FilterGraphNodeUtils.Mapping.cs +++ b/Cavern/Filters/Utilities/FilterGraphNodeUtils.Mapping.cs @@ -49,88 +49,7 @@ public static HashSet MapGraph(this IEnumerable /// Node - channel mapping to optimize, virtual channels take negative indices public static void OptimizeChannelUse(this (FilterGraphNode node, int channel)[] mapping) { - // Trivial: if a member's only parent is before it, don't assign it to a new virtual channel - int lowestChannel = 0; - for (int i = 0; i < mapping.Length; i++) { - if (mapping[i].channel >= 0) { - continue; // Don't touch already assigned physical channels - } - - FilterGraphNode node = mapping[i].node; - if (node.Parents.Count == 1) { - FilterGraphNode parent = node.Parents[0]; - if (parent.Children.Count == 1 && parent.Children[0] == node) { - for (int j = i - 1; j >= 0; j--) { - if (mapping[j].node == parent) { - mapping[i].channel = mapping[j].channel; - break; - } - } - } - } - if (mapping[i].channel < lowestChannel) { // Erases gaps in virtual channel indices - mapping[i].channel = --lowestChannel; - } - } - - int virtualChannels = -mapping.Min(x => x.channel); - - // Partition channels to "time" intervals (mapping indices) - (int channel, int first, int last)[] intervals = new (int, int, int)[virtualChannels]; - for (int i = 0; i < intervals.Length; i++) { - intervals[i].channel = -1 - i; - intervals[i].first = -1; - } - for (int i = 0; i < mapping.Length; i++) { - int interval = -1 - mapping[i].channel; - if (interval < 0) { - continue; // Virtual channels only - } - if (intervals[interval].first == -1) { - intervals[interval].first = i; - } - intervals[interval].last = i; - } - - // True creation is when the channel was separated, and true disappearance is when the channel was merged back - for (int i = 0; i < intervals.Length; i++) { - FilterGraphNode firstNode = mapping[intervals[i].first].node, - lastNode = mapping[intervals[i].last].node; - for (int j = 0; j < mapping.Length; j++) { - if (mapping[j].node.Children.Contains(firstNode)) { - intervals[i].first = j; - } - if (mapping[j].node.Parents.Contains(lastNode)) { - intervals[i].last = j; // Might never be merged, but it's not a problem, we get our thread back faster - } - } - } - - // Interval graph optimization problem - Array.Sort(intervals, (a, b) => { - int first = a.first.CompareTo(b.first); - return first != 0 ? first : a.last.CompareTo(b.last); - }); - - List channelUsedUntil = new List(); - for (int i = 0; i < intervals.Length; i++) { - int slots = channelUsedUntil.Count, - needFrom = intervals[i].first; - bool handled = false; - for (int slot = 0; slot < slots; slot++) { - if (channelUsedUntil[slot] <= needFrom) { - intervals[i].channel = -1 - slot; - channelUsedUntil[slot] = intervals[i].last; - handled = true; - break; - } - } - - if (!handled) { - channelUsedUntil.Add(intervals[i].last); - intervals[i].channel = -channelUsedUntil.Count; - } - } + // TODO: implement some day } ///