diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d92f26..9b6f17b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,7 @@ jobs: strategy: matrix: version: - - '1.0' - - '1.6' + - '1' - 'nightly' os: - ubuntu-latest diff --git a/Project.toml b/Project.toml index 9bab082..d04afb6 100644 --- a/Project.toml +++ b/Project.toml @@ -4,21 +4,20 @@ authors = ["Lyndon White and contributors"] version = "0.1.0" [deps] -Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44" -ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19" -ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" -Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" -VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" [compat] julia = "1" [extras] +ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" +Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92" [targets] -test = ["Test"] +test = ["ImageIO", "ImageMagick", "Plots", "Test", "VisualRegressionTests"] \ No newline at end of file diff --git a/src/min_dist_one.jl b/src/min_dist_one.jl index 4551a47..632c1c6 100644 --- a/src/min_dist_one.jl +++ b/src/min_dist_one.jl @@ -15,6 +15,9 @@ function solve_positions(layout::LayeredMinDistOne, graph) m = Model(Ipopt.Optimizer) set_silent(m) + set_optimizer_attribute(m, "print_level", 0) + + ys = map(enumerate(layer_groups)) do (layer, nodes) y_min = 0 # IPOpt can't find a solution without this @@ -25,9 +28,12 @@ function solve_positions(layout::LayeredMinDistOne, graph) end node_vars = Dict{Int, VariableRef}() # lookup list from vertex index to variable - for (y, nodes) in zip(ys, layer_groups) + node_layer_indexes = Dict{Int, Int}() + for (layer_ind, (y, nodes)) in enumerate(zip(ys, layer_groups)) for n in nodes @assert !haskey(node_vars, n) + @assert !haskey(node_layer_indexes, n) + node_layer_indexes[n] = layer_ind node_vars[n] = y[n] # remember this for later end end @@ -49,14 +55,14 @@ function solve_positions(layout::LayeredMinDistOne, graph) )) optimize!(m) + @show termination_status(m) xs = Float64[] ys = Float64[] - for (layer, nodes) in enumerate(layer_groups) - for node in nodes - push!(xs, layer) - push!(ys, value(node_vars[node])) - end + for node in vertices(graph) + layer_ind = node_layer_indexes[node] + push!(xs, layout.interlayer_seperation * layer_ind) + push!(ys, value(node_vars[node])) end return xs, ys end diff --git a/test/examples.jl b/test/examples.jl index b0c1613..b4e16fb 100644 --- a/test/examples.jl +++ b/test/examples.jl @@ -18,4 +18,20 @@ module Examples 9 => 10 10 => 11 ])) -end \ No newline at end of file + + chainrule_dependants = SimpleDiGraph(Edge.([ + 1 => 2 + 2 => 4 + 2 => 5 + 2 => 6 + 3 => 2 + 3 => 4 + 3 => 7 + 3 => 5 + 3 => 8 + 3 => 6 + 4 => 9 + 4 => 10 + 4 => 11 + ])) +end diff --git a/test/min_dist_one.jl b/test/min_dist_one.jl index f3b22aa..9e0c11c 100644 --- a/test/min_dist_one.jl +++ b/test/min_dist_one.jl @@ -1,6 +1,4 @@ +@plottest quick_plot_solve(LayeredMinDistOne(), Examples.medium_pert) ref"medium_pert" -ref(fn) = joinpath(@__DIR__, "references", fn * ".png") - -xs, ys = solve_positions(LayeredMinDistOne(), Examples.medium_pert) - -@plottest quick_plot(Examples.medium_pert, xs, ys) ref("1") \ No newline at end of file +# Lays out very poorly due to running out of iterations +@plottest quick_plot_solve(LayeredMinDistOne(), Examples.chainrule_dependants) ref"chainrule_dependants" diff --git a/test/references/min_dist_one/chainrule_dependants.png b/test/references/min_dist_one/chainrule_dependants.png new file mode 100644 index 0000000..3cdc628 Binary files /dev/null and b/test/references/min_dist_one/chainrule_dependants.png differ diff --git a/test/references/1.png b/test/references/min_dist_one/medium_pert.png similarity index 100% rename from test/references/1.png rename to test/references/min_dist_one/medium_pert.png diff --git a/test/references/quick_plot.png b/test/references/test_utils/quick_plot.png similarity index 100% rename from test/references/quick_plot.png rename to test/references/test_utils/quick_plot.png diff --git a/test/runtests.jl b/test/runtests.jl index 4767b94..7f64e0e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,12 @@ using VisualRegressionTests include("test_utils.jl") include("examples.jl") - include("min_dist_one.jl") - + @testset "$fn" for fn in ( + "min_dist_one.jl" + ) + include(fn) + end end + + + diff --git a/test/test_utils.jl b/test/test_utils.jl index 2302d0b..a88611d 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -1,3 +1,13 @@ +"Returns a directory in /test/references//.png" +macro ref_str(fn) + all_references_dir = joinpath(@__DIR__, "references") + quote + filename = splitext(basename(string($(QuoteNode(__source__)).file)))[1] + file_reference_dir = mkpath(joinpath($all_references_dir, filename)) + joinpath(file_reference_dir, string($fn, ".png")) + end |> esc +end + function quick_plot(graph, xs, ys) nv(graph)==length(xs) == length(ys) || error("need 1 position per vertex") scatter(xs, ys; markeralpha=0, text=string.(vertices(graph))) @@ -12,10 +22,10 @@ function quick_plot(graph, xs, ys) plot!(lxs, lys; legend=false) end -ref(fn) = joinpath(@__DIR__, "references", fn * ".png") +quick_plot_solve(layout, graph) = quick_plot(graph, solve_positions(LayeredMinDistOne(), graph)...) @testset "test_utils.jl" begin @testset "quick_plot" begin - @plottest quick_plot(SimpleDiGraph(Edge.([1=>2, 2=>3])), [1,2,5], [1,2,3]) joinpath(@__DIR__, "references", "quick_plot.png") + @plottest quick_plot(SimpleDiGraph(Edge.([1=>2, 2=>3])), [1,2,5], [1,2,3]) ref"quick_plot" end -end +end \ No newline at end of file