Skip to content

Commit

Permalink
Merge pull request #3 from oxinabox/ox/MinDistOne
Browse files Browse the repository at this point in the history
Files missing from main
  • Loading branch information
oxinabox authored Jul 21, 2020
2 parents 944cfe2 + 025fdbe commit 788ced9
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ jobs:
strategy:
matrix:
version:
- '1.0'
- '1.6'
- '1'
- 'nightly'
os:
- ubuntu-latest
Expand Down
11 changes: 5 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ authors = ["Lyndon White <lyndon.white@invenialabs.co.uk> 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"]
18 changes: 12 additions & 6 deletions src/min_dist_one.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
18 changes: 17 additions & 1 deletion test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,20 @@ module Examples
9 => 10
10 => 11
]))
end

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
8 changes: 3 additions & 5 deletions test/min_dist_one.jl
Original file line number Diff line number Diff line change
@@ -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")
# Lays out very poorly due to running out of iterations
@plottest quick_plot_solve(LayeredMinDistOne(), Examples.chainrule_dependants) ref"chainrule_dependants"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
10 changes: 8 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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



16 changes: 13 additions & 3 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"Returns a directory in <Pkg>/test/references/<filename>/<fn>.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)))
Expand All @@ -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

0 comments on commit 788ced9

Please sign in to comment.