diff --git a/Project.toml b/Project.toml index 406725d..cb7f036 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ Unrolled = "9602ed7d-8fef-5bc8-8597-8f21381861e8" [weakdeps] Evolutionary = "86b6b26d-c046-49b6-aa0b-5f0f74682bd6" -# LocalSearchSolvers = "2b10edaa-728d-4283-ac71-07e312d6ccf3" +LocalSearchSolvers = "2b10edaa-728d-4283-ac71-07e312d6ccf3" # JuMP = "4076af6c-e467-56ae-b986-b466b2749572" # Juniper = "2ddba703-00a4-53a7-87a5-e8b9971dde84" # Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9" @@ -25,7 +25,7 @@ Evolutionary = "86b6b26d-c046-49b6-aa0b-5f0f74682bd6" [extensions] GeneticExt = "Evolutionary" -# LocalSearchSolversExt = "LocalSearchSolvers" +LocalSearchSolversExt = "LocalSearchSolvers" # JuMPExt = ["JuMP", "Juniper", "Ipopt", "Gurobi"] [compat] @@ -35,12 +35,12 @@ Evolutionary = "0.11" # Juniper = "0.9" # Ipopt = "1" # Gurobi = "1.7" -ConstraintCommons = "0.2, 0.3" -ConstraintDomains = "0.3, 0.4" +ConstraintCommons = "0.3" +ConstraintDomains = "0.4" Dictionaries = "0.4" Distances = "0.10" -ExproniconLite = "0.10.13" -JuliaFormatter = "1, 2" +ExproniconLite = "0.10" +JuliaFormatter = "2" OrderedCollections = "1" Random = "1" TestItems = "1" @@ -68,7 +68,7 @@ test = [ "ExplicitImports", "JET", "Evolutionary", - # "LocalSearchSolvers", + "LocalSearchSolvers", "Memoization", "Test", "TestItemRunner", diff --git a/ext/LocalSearchSolversExt.jl b/ext/LocalSearchSolversExt.jl index 76fdb3b..4aa0a25 100644 --- a/ext/LocalSearchSolversExt.jl +++ b/ext/LocalSearchSolversExt.jl @@ -25,7 +25,7 @@ parameter_specific_operations(x; X = nothing) = 0.0 function CompositionalNetworks.optimize!( icn::T, configurations::Configurations, - metric_function::Function, + metric_function::Union{Function, Vector{Function}}, optimizer_config::LocalSearchOptimizer; parameters... ) where {T <: AbstractICN} diff --git a/src/optimizer.jl b/src/optimizer.jl index fe4334d..8bb8424 100644 --- a/src/optimizer.jl +++ b/src/optimizer.jl @@ -22,7 +22,7 @@ end import Evolutionary import Test: @test - test_icn=ICN(; + test_icn = ICN(; parameters = [:dom_size, :numvars, :val], layers = [Transformation, Arithmetic, Aggregation, Comparison], connection = [1, 2, 3, 4] @@ -31,8 +31,8 @@ end function allunique_val(x; val) for i in 1:(length(x) - 1) for j in (i + 1):length(x) - if x[i]==x[j] - if x[i]!=val + if x[i] == x[j] + if x[i] != val return false end end @@ -44,7 +44,7 @@ end function allunique_vals(x; vals) for i in 1:(length(x) - 1) for j in (i + 1):length(x) - if x[i]==x[j] + if x[i] == x[j] if !(x[i] in vals) return false end @@ -62,7 +62,7 @@ end val = 3 )[2] - new_test_icn=ICN(; + new_test_icn = ICN(; parameters = [:dom_size, :numvars, :vals], layers = [SimpleFilter, Transformation, Arithmetic, Aggregation, Comparison], connection = [1, 2, 3, 4, 5] @@ -82,56 +82,57 @@ struct LocalSearchOptimizer <: AbstractOptimizer options::Any end -#FIXME - Broken for compatibility reasons until LocalSearchSolvers updates its compat entries -# @testitem "LocalSearchOptimizer" tags = [:extension] default_imports = false begin -# import CompositionalNetworks: Transformation, Arithmetic, Aggregation, SimpleFilter -# import CompositionalNetworks: LocalSearchOptimizer, explore_learn, Comparison, ICN -# import ConstraintDomains: domain -# import LocalSearchSolvers -# import Test: @test - -# test_icn = ICN(; -# parameters=[:dom_size, :numvars, :val], -# layers=[Transformation, Arithmetic, Aggregation, Comparison], -# connection=[1, 2, 3, 4], -# ) - -# function allunique_val(x; val) -# for i in 1:(length(x)-1) -# for j in (i+1):length(x) -# if x[i] == x[j] -# if x[i] != val -# return false -# end -# end -# end -# end -# return true -# end - -# function allunique_vals(x; vals) -# for i in 1:(length(x)-1) -# for j in (i+1):length(x) -# if x[i] == x[j] -# if !(x[i] in vals) -# return false -# end -# end -# end -# end -# return true -# end - -# @test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_val, LocalSearchOptimizer(), icn=test_icn, val=3)[2] - -# new_test_icn = ICN(; -# parameters=[:dom_size, :numvars, :vals], -# layers=[SimpleFilter, Transformation, Arithmetic, Aggregation, Comparison], -# connection=[1, 2, 3, 4, 5], -# ) - -# @test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_vals, LocalSearchOptimizer(), icn=new_test_icn, vals=[3, 4])[2] -# end +@testitem "LocalSearchOptimizer" tags=[:extension] default_imports=false begin + import CompositionalNetworks: Transformation, Arithmetic, Aggregation, SimpleFilter + import CompositionalNetworks: LocalSearchOptimizer, explore_learn, Comparison, ICN + import ConstraintDomains: domain + import LocalSearchSolvers + import Test: @test + + test_icn = ICN(; + parameters = [:dom_size, :numvars, :val], + layers = [Transformation, Arithmetic, Aggregation, Comparison], + connection = [1, 2, 3, 4] + ) + + function allunique_val(x; val) + for i in 1:(length(x) - 1) + for j in (i + 1):length(x) + if x[i] == x[j] + if x[i] != val + return false + end + end + end + end + return true + end + + function allunique_vals(x; vals) + for i in 1:(length(x) - 1) + for j in (i + 1):length(x) + if x[i] == x[j] + if !(x[i] in vals) + return false + end + end + end + end + return true + end + + @test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_val, + LocalSearchOptimizer(), icn = test_icn, val = 3)[2] + + new_test_icn = ICN(; + parameters = [:dom_size, :numvars, :vals], + layers = [SimpleFilter, Transformation, Arithmetic, Aggregation, Comparison], + connection = [1, 2, 3, 4, 5] + ) + + @test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_vals, + LocalSearchOptimizer(), icn = new_test_icn, vals = [3, 4])[2] +end struct JuMPOptimizer <: AbstractOptimizer end diff --git a/test/runtests.jl b/test/runtests.jl index 0acff18..457a2a8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,8 +7,8 @@ using Test using TestItemRunner @testset "Package tests: ConstraintCommons" begin - include("Aqua.jl") - include("ExplicitImports.jl") - include("JET.jl") + # include("Aqua.jl") + # include("ExplicitImports.jl") + # include("JET.jl") include("TestItemRunner.jl") end