2023-08-29 12:57:46 +02:00
|
|
|
"""
|
|
|
|
is_connected(graph::DAG)
|
|
|
|
|
|
|
|
Return whether the given graph is connected.
|
|
|
|
"""
|
2023-08-24 15:11:54 +02:00
|
|
|
function is_connected(graph::DAG)
|
2023-08-25 10:48:22 +02:00
|
|
|
nodeQueue = Deque{Node}()
|
|
|
|
push!(nodeQueue, get_exit_node(graph))
|
|
|
|
seenNodes = Set{Node}()
|
2023-08-24 15:11:54 +02:00
|
|
|
|
2023-08-25 10:48:22 +02:00
|
|
|
while !isempty(nodeQueue)
|
|
|
|
current = pop!(nodeQueue)
|
|
|
|
push!(seenNodes, current)
|
2023-08-24 15:11:54 +02:00
|
|
|
|
2023-08-25 10:48:22 +02:00
|
|
|
for child in current.children
|
|
|
|
push!(nodeQueue, child)
|
|
|
|
end
|
|
|
|
end
|
2023-08-24 15:11:54 +02:00
|
|
|
|
2023-08-25 10:48:22 +02:00
|
|
|
return length(seenNodes) == length(graph.nodes)
|
2023-08-24 15:11:54 +02:00
|
|
|
end
|
|
|
|
|
2023-08-29 12:57:46 +02:00
|
|
|
"""
|
|
|
|
is_valid(graph::DAG)
|
|
|
|
|
|
|
|
Validate the entire graph using asserts. Intended for testing with `@assert is_valid(graph)`.
|
|
|
|
"""
|
2023-08-24 15:11:54 +02:00
|
|
|
function is_valid(graph::DAG)
|
2023-08-25 10:48:22 +02:00
|
|
|
for node in graph.nodes
|
|
|
|
@assert is_valid(graph, node)
|
|
|
|
end
|
|
|
|
|
|
|
|
for op in graph.operationsToApply
|
|
|
|
@assert is_valid(graph, op)
|
|
|
|
end
|
|
|
|
|
|
|
|
for nr in graph.possibleOperations.nodeReductions
|
|
|
|
@assert is_valid(graph, nr)
|
|
|
|
end
|
|
|
|
for ns in graph.possibleOperations.nodeSplits
|
|
|
|
@assert is_valid(graph, ns)
|
|
|
|
end
|
|
|
|
for nf in graph.possibleOperations.nodeFusions
|
|
|
|
@assert is_valid(graph, nf)
|
|
|
|
end
|
|
|
|
|
|
|
|
for node in graph.dirtyNodes
|
|
|
|
@assert node in graph "Dirty Node is not part of the graph!"
|
|
|
|
@assert ismissing(node.nodeReduction) "Dirty Node has a NodeReduction!"
|
|
|
|
@assert ismissing(node.nodeSplit) "Dirty Node has a NodeSplit!"
|
|
|
|
if (typeof(node) <: DataTaskNode)
|
|
|
|
@assert ismissing(node.nodeFusion) "Dirty DataTaskNode has a Node Fusion!"
|
|
|
|
elseif (typeof(node) <: ComputeTaskNode)
|
|
|
|
@assert isempty(node.nodeFusions) "Dirty ComputeTaskNode has Node Fusions!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@assert is_connected(graph) "Graph is not connected!"
|
|
|
|
|
|
|
|
return true
|
2023-08-24 15:11:54 +02:00
|
|
|
end
|