Skip to content

Commit

Permalink
Compat depenendices
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzaare committed Nov 15, 2021
1 parent cd34500 commit 982a9c8
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
*.mem
/docs/build/
.gitignore
_git2_*
Expand Down
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LocalSearchSolvers"
uuid = "2b10edaa-728d-4283-ac71-07e312d6ccf3"
authors = ["Jean-Francois Baffier"]
version = "0.3.12"
version = "0.3.13"

[deps]
CompositionalNetworks = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
Expand All @@ -15,9 +15,9 @@ Lazy = "50d2b5c4-7a5e-59d5-8109-a42b560f39c0"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"

[compat]
CompositionalNetworks = "0.2"
ConstraintDomains = "0.2"
Constraints = "0.2"
CompositionalNetworks = "0.3"
ConstraintDomains = "0.3"
Constraints = "0.3"
Dictionaries = "0.3"
JSON = "0.21"
Lazy = "0.15"
Expand Down
1 change: 0 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[deps]
CompositionalNetworks = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
ConstraintDomains = "5800fd60-8556-4464-8d61-84ebf7a0bedb"
ConstraintModels = "841a6ec5-cac3-4c42-9a0a-4b21c9553698"
Constraints = "30f324ab-b02d-43f0-b619-e131c61659f7"
Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
4 changes: 2 additions & 2 deletions test/internal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end


m = model()
describe(m)
# LocalSearchSolvers.describe(m)

x1 = variable([4,3,2,1])
x2 = variable(d2)
Expand Down Expand Up @@ -116,7 +116,7 @@ objs = Dictionary(1:2, [o1, o2])
add_value!(m, 1, 1)
delete_var_from_cons!(m, 1, 1)
add_var_to_cons!(m, 1, 1)
describe(m)
# describe(m)
end

## Test Solver
Expand Down
108 changes: 103 additions & 5 deletions test/raw_solver.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,108 @@
function mincut(graph; source, sink, interdiction =0)
m = model(; kind=:cut)
n = size(graph, 1)

d = domain(0:n)

separator = n + 1 # value that separate the two sides of the cut

# Add variables:
foreach(_ -> variable!(m, d), 0:n)

# Extract error function from usual_constraint
e1 = (x; param=nothing, dom_size=n + 1) -> error_f(
usual_constraints[:ordered])(x; param, dom_size
)
e2 = (x; param=nothing, dom_size=n + 1) -> error_f(
usual_constraints[:all_different])(x; param, dom_size
)

# Add constraint
constraint!(m, e1, [source, separator, sink])
constraint!(m, e2, 1:(n + 1))

# Add objective
objective!(m, (x...) -> o_mincut(graph, x...; interdiction))

return m
end

function golomb(n, L = n^2)
m = model(; kind=:golomb)

# Add variables
d = domain(0:L)
foreach(_ -> variable!(m, d), 1:n)

# Extract error function from usual_constraint
e1 = (x; param=nothing, dom_size=n) -> error_f(
usual_constraints[:all_different])(x; param, dom_size
)
e2 = (x; param=nothing, dom_size=n) -> error_f(
usual_constraints[:all_equal_param])(x; param, dom_size
)
e3 = (x; param=nothing, dom_size=n) -> error_f(
usual_constraints[:dist_different])(x; param, dom_size
)

# # Add constraints
constraint!(m, e1, 1:n)
constraint!(m, x -> e2(x; param=0), 1:1)
for i in 1:(n - 1), j in (i + 1):n, k in i:(n - 1), l in (k + 1):n
(i, j) < (k, l) || continue
constraint!(m, e3, [i, j, k, l])
end

# Add objective
objective!(m, o_dist_extrema)

return m
end

function sudoku(n; start=nothing)
N = n^2
d = domain(1:N)

m = model(;kind=:sudoku)

# Add variables
if isnothing(start)
foreach(_ -> variable!(m, d), 1:(N^2))
else
foreach(((x, v),) -> variable!(m, 1 v N ? domain(v) : d), pairs(start))
end


e = (x; param=nothing, dom_size=N) -> error_f(
usual_constraints[:all_different])(x; param=param, dom_size=dom_size
)

# Add constraints: line, columns; blocks
foreach(i -> constraint!(m, e, (i * N + 1):((i + 1) * N)), 0:(N - 1))
foreach(i -> constraint!(m, e, [j * N + i for j in 0:(N - 1)]), 1:N)

for i in 0:(n - 1)
for j in 0:(n - 1)
vars = Vector{Int}()
for k in 1:n
for l in 0:(n - 1)
push!(vars, (j * n + l) * N + i * n + k)
end
end
constraint!(m, e, vars)
end
end

return m
end

@testset "Raw solver: internals" begin
models = [
sudoku(2; modeler=:raw),
sudoku(2),
]

for m in models
@info describe(m)
# @info describe(m)
s = solver(m; options=Options(print_level=:verbose, time_limit = Inf, iteration=Inf, info_path="info.json"))
for x in keys(get_variables(s))
@test get_name(s, x) == "x$x"
Expand Down Expand Up @@ -60,14 +158,14 @@ end
0 7 0 0 0 0 0 5 3
]))

s = solver(sudoku(3; start = sudoku_instance, modeler = :raw); options = Options(print_level = :minimal, iteration = Inf, time_limit = 10))
s = solver(sudoku(3; start = sudoku_instance); options = Options(print_level = :minimal, iteration = Inf, time_limit = 10))
display(Dictionary(1:length(sudoku_instance), sudoku_instance))
solve!(s)
display(solution(s))
end

@testset "Raw solver: golomb" begin
s = solver(golomb(5, modeler = :raw); options = Options(print_level = :minimal, iteration = 1000))
s = solver(golomb(5); options = Options(print_level = :minimal, iteration = 1000))
solve!(s)

@info "Results golomb!"
Expand Down Expand Up @@ -99,7 +197,7 @@ end
@info "Sol (vals): $(!isnothing(best_value(s)) ? best_values(s) : nothing)"

s = solver(mincut(graph, source=1, sink=5, interdiction=2); options = Options(print_level=:minimal, time_limit = 15, iteration=Inf))
@info describe(s)
# @info describe(s)
solve!(s)
@info "Results 2-mincut!"
@info "Values: $(get_values(s))"
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

using Distributed
# Add a process with two threads
addprocs(1; exeflags = "-t 2")
# addprocs(1; exeflags = ["-t 2", "--project"])
# addprocs(1)

import ConstraintDomains
import CompositionalNetworks
using ConstraintModels
using Constraints
@everywhere using Constraints
using Dictionaries
@everywhere using LocalSearchSolvers
using Test
Expand Down

0 comments on commit 982a9c8

Please sign in to comment.