Add GraphProperties and property caching

This commit is contained in:
2023-08-28 13:32:22 +02:00
parent 065236be22
commit 7387fa86b1
18 changed files with 300 additions and 101 deletions

View File

@ -3,7 +3,7 @@ using Random
function test_known_graph(name::String, n, fusion_test = true)
@testset "Test $name Graph ($n)" begin
graph = parse_abc(joinpath(@__DIR__, "..", "input", "$name.txt"))
props = graph_properties(graph)
props = get_properties(graph)
if (fusion_test)
test_node_fusion(graph)
@ -14,13 +14,13 @@ end
function test_node_fusion(g::DAG)
@testset "Test Node Fusion" begin
props = graph_properties(g)
props = get_properties(g)
options = get_operations(g)
nodes_number = length(g.nodes)
data = props.data
compute_effort = props.compute_effort
compute_effort = props.computeEffort
while !isempty(options.nodeFusions)
fusion = first(options.nodeFusions)
@ -29,13 +29,13 @@ function test_node_fusion(g::DAG)
push_operation!(g, fusion)
props = graph_properties(g)
props = get_properties(g)
@test props.data < data
@test props.compute_effort == compute_effort
@test props.computeEffort == compute_effort
nodes_number = length(g.nodes)
data = props.data
compute_effort = props.compute_effort
compute_effort = props.computeEffort
options = get_operations(g)
end
@ -49,7 +49,7 @@ function test_random_walk(g::DAG, n::Int64)
@test is_valid(g)
properties = graph_properties(g)
properties = get_properties(g)
for i in 1:n
# choose push or pop
@ -82,7 +82,7 @@ function test_random_walk(g::DAG, n::Int64)
@test is_valid(g)
@test properties == graph_properties(g)
@test properties == get_properties(g)
end
end

View File

@ -69,7 +69,7 @@ import MetagraphOptimization.partners
@test length(graph.nodes) == 26
@test length(graph.dirtyNodes) == 26
# now for all the edgese
# now for all the edges
insert_edge!(graph, d_PB, PB, false)
insert_edge!(graph, d_PA, PA, false)
insert_edge!(graph, d_PBp, PBp, false)
@ -142,12 +142,12 @@ import MetagraphOptimization.partners
@test operations == get_operations(graph)
nf = first(operations.nodeFusions)
properties = graph_properties(graph)
@test properties.compute_effort == 134
properties = get_properties(graph)
@test properties.computeEffort == 134
@test properties.data == 62
@test properties.compute_intensity 134 / 62
@test properties.nodes == 26
@test properties.edges == 25
@test properties.computeIntensity 134 / 62
@test properties.noNodes == 26
@test properties.noEdges == 25
push_operation!(graph, nf)
# **does not immediately apply the operation**
@ -161,17 +161,17 @@ import MetagraphOptimization.partners
(addedNodes = 0, removedNodes = 0, addedEdges = 0, removedEdges = 0)
# this applies pending operations
properties = graph_properties(graph)
properties = get_properties(graph)
@test length(graph.nodes) == 24
@test length(graph.appliedOperations) == 1
@test length(graph.operationsToApply) == 0
@test length(graph.dirtyNodes) != 0
@test properties.nodes == 24
@test properties.edges == 23
@test properties.compute_effort == 134
@test properties.noNodes == 24
@test properties.noEdges == 23
@test properties.computeEffort == 134
@test properties.data < 62
@test properties.compute_intensity > 134 / 62
@test properties.computeIntensity > 134 / 62
operations = get_operations(graph)
@test length(graph.dirtyNodes) == 0
@ -205,12 +205,12 @@ import MetagraphOptimization.partners
@test length(graph.appliedOperations) == 0
@test length(graph.operationsToApply) == 0
properties = graph_properties(graph)
@test properties.nodes == 26
@test properties.edges == 25
@test properties.compute_effort == 134
properties = get_properties(graph)
@test properties.noNodes == 26
@test properties.noEdges == 25
@test properties.computeEffort == 134
@test properties.data == 62
@test properties.compute_intensity 134 / 62
@test properties.computeIntensity 134 / 62
operations = get_operations(graph)
@test length(operations) ==