Skip to content

Commit f2c2be1

Browse files
committed
Add tests
1 parent 5d4c054 commit f2c2be1

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

src/algorithms/TambyVanderpooten.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@ reformulation is solved using one of the defining points as a starting solution.
2626
struct TambyVanderpooten <: AbstractAlgorithm end
2727

2828
function _update_search_region(
29-
U_N::Dict{Vector{Float64}, Vector{Vector{Vector{Float64}}}},
30-
y::Vector{Float64},
31-
yN::Vector{Float64},
29+
U_N::Dict{Vector{Float64},Vector{Vector{Vector{Float64}}}},
30+
y::Vector{Float64},
31+
yN::Vector{Float64},
3232
)
3333
p = length(y)
3434
bounds_to_remove = Vector{Float64}[]
35-
bounds_to_add = Dict{Vector{Float64}, Vector{Vector{Vector{Float64}}}}()
35+
bounds_to_add = Dict{Vector{Float64},Vector{Vector{Vector{Float64}}}}()
3636
for u in keys(U_N)
3737
if all(y .< u)
3838
push!(bounds_to_remove, u)
3939
for l in 1:p
4040
u_l = _get_child(u, y, l)
41-
N = [k == l ? [y] : [yi for yi in U_N[u][k] if yi[l] < y[l]] for k in 1:p]
41+
N = [
42+
k == l ? [y] : [yi for yi in U_N[u][k] if yi[l] < y[l]]
43+
for k in 1:p
44+
]
4245
if all(!isempty(N[k]) for k in 1:p if k != l && u_l[k] != yN[k])
4346
bounds_to_add[u_l] = N
4447
end
@@ -60,17 +63,20 @@ end
6063

6164
function _get_child(u::Vector{Float64}, y::Vector{Float64}, k::Int)
6265
@assert length(u) == length(y)
63-
return vcat(u[1:k-1], y[k], u[k+1:length(y)])
66+
return vcat(u[1:(k-1)], y[k], u[(k+1):length(y)])
6467
end
6568

6669
function _select_search_zone(
6770
U_N::Dict{Vector{Float64},Vector{Vector{Vector{Float64}}}},
68-
yI::Vector{Float64},
69-
yN::Vector{Float64},
71+
yI::Vector{Float64},
72+
yN::Vector{Float64},
7073
)
7174
upper_bounds = collect(keys(U_N))
7275
p = length(yI)
73-
hvs = [u[k] == yN[k] ? 0. : prod(_project(u, k) .- _project(yI, k)) for k in 1:p, u in upper_bounds]
76+
hvs = [
77+
u[k] == yN[k] ? 0.0 : prod(_project(u, k) .- _project(yI, k)) for
78+
k in 1:p, u in upper_bounds
79+
]
7480
k_star, j_star = argmax(hvs).I
7581
return k_star, upper_bounds[j_star]
7682
end

test/algorithms/TambyVanderpooten.jl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,44 @@ function test_vector_of_variables_objective()
621621
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
622622
MOI.add_constraint(model, sum(1.0 * xi for xi in x), MOI.GreaterThan(1.0))
623623
MOI.optimize!(model)
624-
MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
624+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
625+
return
626+
end
627+
628+
function test_issue_105()
629+
cost = [100.0, 120.0, 150.0, 110.0, 200.0, 170.0]
630+
time = [8.0, 3.0, 4.0, 2.0, 5.0, 4.0]
631+
capacity = [10.0, 8.0]
632+
demand = [5.0, 8.0, 5.0]
633+
m, n = 2, 3
634+
model = MOI.instantiate(; with_bridge_type = Float64) do
635+
return MOA.Optimizer(HiGHS.Optimizer)
636+
end
637+
MOI.set(model, MOA.Algorithm(), MOA.TambyVanderpooten())
638+
MOI.set(model, MOI.Silent(), true)
639+
x = MOI.add_variables(model, m * n)
640+
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
641+
MOI.add_constraint.(model, x, MOI.Integer())
642+
X = reshape(x, m, n)
643+
for i in 1:m
644+
f_i = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(1.0, X[i, :]), 0.0)
645+
MOI.add_constraint(model, f_i, MOI.LessThan(capacity[i]))
646+
end
647+
for j in 1:n
648+
f_j = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(1.0, X[:, j]), 0.0)
649+
MOI.add_constraint(model, f_j, MOI.EqualTo(demand[j]))
650+
end
651+
f = MOI.Utilities.operate(
652+
vcat,
653+
Float64,
654+
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(cost, x), 0.0),
655+
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(time, x), 0.0),
656+
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(1.0, x), 0.0),
657+
)
658+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
659+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
660+
MOI.optimize!(model)
661+
@test MOI.get(model, MOI.ResultCount()) == 6
625662
return
626663
end
627664

0 commit comments

Comments
 (0)