131 lines
2.8 KiB
Julia
Raw Normal View History

2023-07-03 01:15:04 +02:00
using MetagraphOptimization
using Plots
using Random
function gen_plot(filepath)
name = basename(filepath)
name, _ = splitext(name)
2023-08-23 13:38:02 +02:00
filepath = joinpath(@__DIR__, "../input/", filepath)
2023-07-03 01:15:04 +02:00
if !isfile(filepath)
println("File ", filepath, " does not exist, skipping")
return
end
g = parse_abc(filepath)
2023-07-03 01:15:04 +02:00
Random.seed!(1)
println("Random Walking... ")
2023-08-25 10:48:22 +02:00
for i in 1:30
2023-07-03 01:15:04 +02:00
print("\r", i)
# push
opt = get_operations(g)
# choose one of fuse/split/reduce
option = rand(1:3)
if option == 1 && !isempty(opt.nodeFusions)
push_operation!(g, rand(collect(opt.nodeFusions)))
println("NF")
elseif option == 2 && !isempty(opt.nodeReductions)
push_operation!(g, rand(collect(opt.nodeReductions)))
println("NR")
elseif option == 3 && !isempty(opt.nodeSplits)
push_operation!(g, rand(collect(opt.nodeSplits)))
println("NS")
else
2023-08-25 10:48:22 +02:00
i = i - 1
2023-07-03 01:15:04 +02:00
end
end
println("\rDone.")
props = graph_properties(g)
x0 = props.data
y0 = props.compute_effort
x = Vector{Float64}()
y = Vector{Float64}()
names = Vector{String}()
opt = get_operations(g)
for op in opt.nodeFusions
push_operation!(g, op)
props = graph_properties(g)
push!(x, props.data)
push!(y, props.compute_effort)
pop_operation!(g)
2023-08-25 10:48:22 +02:00
push!(
names,
"NF: (" *
string(props.data) *
", " *
string(props.compute_effort) *
")",
)
2023-07-03 01:15:04 +02:00
end
for op in opt.nodeReductions
push_operation!(g, op)
props = graph_properties(g)
push!(x, props.data)
push!(y, props.compute_effort)
pop_operation!(g)
2023-08-25 10:48:22 +02:00
push!(
names,
"NR: (" *
string(props.data) *
", " *
string(props.compute_effort) *
")",
)
2023-07-03 01:15:04 +02:00
end
for op in opt.nodeSplits
push_operation!(g, op)
props = graph_properties(g)
push!(x, props.data)
push!(y, props.compute_effort)
pop_operation!(g)
2023-08-25 10:48:22 +02:00
push!(
names,
"NS: (" *
string(props.data) *
", " *
string(props.compute_effort) *
")",
)
2023-07-03 01:15:04 +02:00
end
2023-08-25 10:48:22 +02:00
plot(
[x0, x[1]],
[y0, y[1]],
linestyle = :solid,
linewidth = 1,
color = :red,
legend = false,
)
2023-07-03 01:15:04 +02:00
# Create lines connecting the reference point to each data point
for i in 2:length(x)
2023-08-25 10:48:22 +02:00
plot!(
[x0, x[i]],
[y0, y[i]],
linestyle = :solid,
linewidth = 1,
color = :red,
)
2023-07-03 01:15:04 +02:00
end
#scatter!(x, y, label=names)
print(names)
2023-08-25 10:48:22 +02:00
return gui()
2023-07-03 01:15:04 +02:00
end
gen_plot("AB->ABBB.txt")