53 lines
1.4 KiB
Julia
53 lines
1.4 KiB
Julia
# check whether the given graph is connected
|
|
function is_connected(graph::DAG)
|
|
nodeQueue = Deque{Node}()
|
|
push!(nodeQueue, get_exit_node(graph))
|
|
seenNodes = Set{Node}()
|
|
|
|
while !isempty(nodeQueue)
|
|
current = pop!(nodeQueue)
|
|
push!(seenNodes, current)
|
|
|
|
for child in current.children
|
|
push!(nodeQueue, child)
|
|
end
|
|
end
|
|
|
|
return length(seenNodes) == length(graph.nodes)
|
|
end
|
|
|
|
function is_valid(graph::DAG)
|
|
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
|
|
end
|