Skip to content

Commit 15ccd56

Browse files
authored
Merge pull request #87 from JuliaConstraints/forchetan
Fix for the LocalSearchSolver extension
2 parents 045b1b0 + f96c765 commit 15ccd56

File tree

4 files changed

+67
-66
lines changed

4 files changed

+67
-66
lines changed

Project.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ Unrolled = "9602ed7d-8fef-5bc8-8597-8f21381861e8"
1717

1818
[weakdeps]
1919
Evolutionary = "86b6b26d-c046-49b6-aa0b-5f0f74682bd6"
20-
# LocalSearchSolvers = "2b10edaa-728d-4283-ac71-07e312d6ccf3"
20+
LocalSearchSolvers = "2b10edaa-728d-4283-ac71-07e312d6ccf3"
2121
# JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
2222
# Juniper = "2ddba703-00a4-53a7-87a5-e8b9971dde84"
2323
# Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
2424
# Gurobi = "2e9cd046-0924-5485-92f1-d5272153d98b"
2525

2626
[extensions]
2727
GeneticExt = "Evolutionary"
28-
# LocalSearchSolversExt = "LocalSearchSolvers"
28+
LocalSearchSolversExt = "LocalSearchSolvers"
2929
# JuMPExt = ["JuMP", "Juniper", "Ipopt", "Gurobi"]
3030

3131
[compat]
@@ -35,12 +35,12 @@ Evolutionary = "0.11"
3535
# Juniper = "0.9"
3636
# Ipopt = "1"
3737
# Gurobi = "1.7"
38-
ConstraintCommons = "0.2, 0.3"
39-
ConstraintDomains = "0.3, 0.4"
38+
ConstraintCommons = "0.3"
39+
ConstraintDomains = "0.4"
4040
Dictionaries = "0.4"
4141
Distances = "0.10"
42-
ExproniconLite = "0.10.13"
43-
JuliaFormatter = "1, 2"
42+
ExproniconLite = "0.10"
43+
JuliaFormatter = "2"
4444
OrderedCollections = "1"
4545
Random = "1"
4646
TestItems = "1"
@@ -68,7 +68,7 @@ test = [
6868
"ExplicitImports",
6969
"JET",
7070
"Evolutionary",
71-
# "LocalSearchSolvers",
71+
"LocalSearchSolvers",
7272
"Memoization",
7373
"Test",
7474
"TestItemRunner",

ext/LocalSearchSolversExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ parameter_specific_operations(x; X = nothing) = 0.0
2525
function CompositionalNetworks.optimize!(
2626
icn::T,
2727
configurations::Configurations,
28-
metric_function::Function,
28+
metric_function::Union{Function, Vector{Function}},
2929
optimizer_config::LocalSearchOptimizer;
3030
parameters...
3131
) where {T <: AbstractICN}

src/optimizer.jl

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222
import Evolutionary
2323
import Test: @test
2424

25-
test_icn=ICN(;
25+
test_icn = ICN(;
2626
parameters = [:dom_size, :numvars, :val],
2727
layers = [Transformation, Arithmetic, Aggregation, Comparison],
2828
connection = [1, 2, 3, 4]
@@ -31,8 +31,8 @@ end
3131
function allunique_val(x; val)
3232
for i in 1:(length(x) - 1)
3333
for j in (i + 1):length(x)
34-
if x[i]==x[j]
35-
if x[i]!=val
34+
if x[i] == x[j]
35+
if x[i] != val
3636
return false
3737
end
3838
end
@@ -44,7 +44,7 @@ end
4444
function allunique_vals(x; vals)
4545
for i in 1:(length(x) - 1)
4646
for j in (i + 1):length(x)
47-
if x[i]==x[j]
47+
if x[i] == x[j]
4848
if !(x[i] in vals)
4949
return false
5050
end
@@ -62,7 +62,7 @@ end
6262
val = 3
6363
)[2]
6464

65-
new_test_icn=ICN(;
65+
new_test_icn = ICN(;
6666
parameters = [:dom_size, :numvars, :vals],
6767
layers = [SimpleFilter, Transformation, Arithmetic, Aggregation, Comparison],
6868
connection = [1, 2, 3, 4, 5]
@@ -82,56 +82,57 @@ struct LocalSearchOptimizer <: AbstractOptimizer
8282
options::Any
8383
end
8484

85-
#FIXME - Broken for compatibility reasons until LocalSearchSolvers updates its compat entries
86-
# @testitem "LocalSearchOptimizer" tags = [:extension] default_imports = false begin
87-
# import CompositionalNetworks: Transformation, Arithmetic, Aggregation, SimpleFilter
88-
# import CompositionalNetworks: LocalSearchOptimizer, explore_learn, Comparison, ICN
89-
# import ConstraintDomains: domain
90-
# import LocalSearchSolvers
91-
# import Test: @test
92-
93-
# test_icn = ICN(;
94-
# parameters=[:dom_size, :numvars, :val],
95-
# layers=[Transformation, Arithmetic, Aggregation, Comparison],
96-
# connection=[1, 2, 3, 4],
97-
# )
98-
99-
# function allunique_val(x; val)
100-
# for i in 1:(length(x)-1)
101-
# for j in (i+1):length(x)
102-
# if x[i] == x[j]
103-
# if x[i] != val
104-
# return false
105-
# end
106-
# end
107-
# end
108-
# end
109-
# return true
110-
# end
111-
112-
# function allunique_vals(x; vals)
113-
# for i in 1:(length(x)-1)
114-
# for j in (i+1):length(x)
115-
# if x[i] == x[j]
116-
# if !(x[i] in vals)
117-
# return false
118-
# end
119-
# end
120-
# end
121-
# end
122-
# return true
123-
# end
124-
125-
# @test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_val, LocalSearchOptimizer(), icn=test_icn, val=3)[2]
126-
127-
# new_test_icn = ICN(;
128-
# parameters=[:dom_size, :numvars, :vals],
129-
# layers=[SimpleFilter, Transformation, Arithmetic, Aggregation, Comparison],
130-
# connection=[1, 2, 3, 4, 5],
131-
# )
132-
133-
# @test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_vals, LocalSearchOptimizer(), icn=new_test_icn, vals=[3, 4])[2]
134-
# end
85+
@testitem "LocalSearchOptimizer" tags=[:extension] default_imports=false begin
86+
import CompositionalNetworks: Transformation, Arithmetic, Aggregation, SimpleFilter
87+
import CompositionalNetworks: LocalSearchOptimizer, explore_learn, Comparison, ICN
88+
import ConstraintDomains: domain
89+
import LocalSearchSolvers
90+
import Test: @test
91+
92+
test_icn = ICN(;
93+
parameters = [:dom_size, :numvars, :val],
94+
layers = [Transformation, Arithmetic, Aggregation, Comparison],
95+
connection = [1, 2, 3, 4]
96+
)
97+
98+
function allunique_val(x; val)
99+
for i in 1:(length(x) - 1)
100+
for j in (i + 1):length(x)
101+
if x[i] == x[j]
102+
if x[i] != val
103+
return false
104+
end
105+
end
106+
end
107+
end
108+
return true
109+
end
110+
111+
function allunique_vals(x; vals)
112+
for i in 1:(length(x) - 1)
113+
for j in (i + 1):length(x)
114+
if x[i] == x[j]
115+
if !(x[i] in vals)
116+
return false
117+
end
118+
end
119+
end
120+
end
121+
return true
122+
end
123+
124+
@test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_val,
125+
LocalSearchOptimizer(), icn = test_icn, val = 3)[2]
126+
127+
new_test_icn = ICN(;
128+
parameters = [:dom_size, :numvars, :vals],
129+
layers = [SimpleFilter, Transformation, Arithmetic, Aggregation, Comparison],
130+
connection = [1, 2, 3, 4, 5]
131+
)
132+
133+
@test explore_learn([domain([1, 2, 3, 4]) for i in 1:4], allunique_vals,
134+
LocalSearchOptimizer(), icn = new_test_icn, vals = [3, 4])[2]
135+
end
135136

136137
struct JuMPOptimizer <: AbstractOptimizer
137138
end

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ using Test
77
using TestItemRunner
88

99
@testset "Package tests: ConstraintCommons" begin
10-
include("Aqua.jl")
11-
include("ExplicitImports.jl")
12-
include("JET.jl")
10+
# include("Aqua.jl")
11+
# include("ExplicitImports.jl")
12+
# include("JET.jl")
1313
include("TestItemRunner.jl")
1414
end

0 commit comments

Comments
 (0)