Skip to content

Commit 85ee593

Browse files
committed
Process another TODO comment
1 parent b356190 commit 85ee593

File tree

1 file changed

+41
-48
lines changed

1 file changed

+41
-48
lines changed

Code/Graph+Algorithms/Graph+NonEssentialEdges.swift

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,62 +20,55 @@ public extension Graph
2020
func findEssentialEdges() -> EdgeIDs
2121
{
2222
var idsOfEssentialEdges = EdgeIDs()
23+
24+
// TODO: Do we even need to create the MEG of the condensation graph here? AS SOON AS our algorithm to find all transitive edges (or inverted: the transitive reduction) correctly returns all edges that ARE NOT in cycles (even if the graph is cyclic) then we only need to filter out the edges which ARE in cycles for which we only need the SCCs ... this is about making the code more straight forward, we'll assess performance much later and based on measurement ...
25+
26+
// make condensation graph
27+
let condensationGraph = makeCondensationGraph()
28+
29+
// remember in which condensation node each original node is contained
30+
var condensationNodeIDByNodeID = [NodeID: StronglyConnectedComponent.ID]()
2331

24-
// TODO: decomposing the graph into its components is probably legacy from before the algorithm extraction from Codeface ... this also seems to have no performance benefit here ... better just ensure makeCondensationGraph() (or find SCCs) and makeMinimumEquivalentGraph() work on disconnected graphs and then do this algorithm here on the whole graph in one go ...
25-
// for each component graph individually ...
26-
for component in findComponents()
32+
for condensationNode in condensationGraph.nodes
2733
{
28-
let componentGraph = subGraph(nodeIDs: component)
29-
30-
// TODO: Do we even need to create the MEG of the condensation graph here? AS SOON AS our algorithm to find all transitive edges (or inverted: the transitive reduction) correctly returns all edges that ARE NOT in cycles (even if the graph is cyclic) then we only need to filter out the edges which ARE in cycles for which we only need the SCCs ... this is about making the code more straight forward, we'll assess performance much later and based on measurement ...
34+
for node in condensationNode.value.nodeIDs
35+
{
36+
condensationNodeIDByNodeID[node] = condensationNode.id
37+
}
38+
}
39+
40+
// make minimum equivalent condensation graph
41+
let minimumCondensationGraph = condensationGraph.makeMinimumEquivalentGraph()
42+
43+
// for each original edge in the component graph ...
44+
for edge in edges
45+
{
46+
guard let originCondensationNodeID = condensationNodeIDByNodeID[edge.originID],
47+
let destinationCondensationNodeID = condensationNodeIDByNodeID[edge.destinationID]
48+
else
49+
{
50+
log(error: "Nodes don't have their condensation node IDs set (but must have at this point)")
51+
continue
52+
}
3153

32-
// make condensation graph
33-
let condensationGraph = componentGraph.makeCondensationGraph()
34-
35-
// remember in which condensation node each original node is contained
36-
var condensationNodeIDByNodeID = [NodeID: StronglyConnectedComponent.ID]()
54+
// add this edge if it is within the same condensation node (within a strongly connected component and thereby within a cycle)
3755

38-
for condensationNode in condensationGraph.nodes
56+
if originCondensationNodeID == destinationCondensationNodeID
3957
{
40-
for node in condensationNode.value.nodeIDs
41-
{
42-
condensationNodeIDByNodeID[node] = condensationNode.id
43-
}
58+
idsOfEssentialEdges += edge.id
59+
continue
4460
}
4561

46-
// make minimum equivalent condensation graph
47-
let minimumCondensationGraph = condensationGraph.makeMinimumEquivalentGraph()
48-
49-
// for each original edge in the component graph ...
50-
for edge in componentGraph.edges
62+
// the non-cyclic edge is essential if its equivalent is in the minimum equivalent condensation graph
63+
64+
let condensationEdgeID = CondensationEdge.ID(originCondensationNodeID,
65+
destinationCondensationNodeID)
66+
67+
let edgeIsEssential = minimumCondensationGraph.contains(condensationEdgeID)
68+
69+
if edgeIsEssential
5170
{
52-
guard let originCondensationNodeID = condensationNodeIDByNodeID[edge.originID],
53-
let destinationCondensationNodeID = condensationNodeIDByNodeID[edge.destinationID]
54-
else
55-
{
56-
log(error: "Nodes don't have their condensation node IDs set (but must have at this point)")
57-
continue
58-
}
59-
60-
// add this edge if it is within the same condensation node (within a strongly connected component and thereby within a cycle)
61-
62-
if originCondensationNodeID == destinationCondensationNodeID
63-
{
64-
idsOfEssentialEdges += edge.id
65-
continue
66-
}
67-
68-
// the non-cyclic edge is essential if its equivalent is in the minimum equivalent condensation graph
69-
70-
let condensationEdgeID = CondensationEdge.ID(originCondensationNodeID,
71-
destinationCondensationNodeID)
72-
73-
let edgeIsEssential = minimumCondensationGraph.contains(condensationEdgeID)
74-
75-
if edgeIsEssential
76-
{
77-
idsOfEssentialEdges += edge.id
78-
}
71+
idsOfEssentialEdges += edge.id
7972
}
8073
}
8174

0 commit comments

Comments
 (0)