Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bound callback tests #532

Merged
merged 6 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions test/bound_callback_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function bound_callback_tests()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a little comment to describe what you do ?

data = CLD.GeneralizedAssignment.data("play2.txt")

coluna = JuMP.optimizer_with_attributes(
CL.Optimizer,
"default_optimizer" => GLPK.Optimizer,
"params" => CL.Params(solver = ClA.TreeSearchAlgorithm(maxnumnodes = 2))
)

model, x, dec = CLD.GeneralizedAssignment.model_without_knp_constraints(data, coluna)

# Subproblem models are created once and for all
# One model for each machine
# Subproblem models are created once and for all
# One model for each machine
sp_models = Dict{Int, Any}()
for m in data.machines
sp = JuMP.Model(GLPK.Optimizer)
@variable(sp, y[j in data.jobs], Bin)
@variable(sp, lb_y[j in data.jobs] >= 0)
@variable(sp, ub_y[j in data.jobs] >= 0)
@variable(sp, max_card >= 0) # this sets the maximum solution cardinality for heuristic pricing
@constraint(sp, card, sum(y[j] for j in data.jobs) <= max_card)
laradicp marked this conversation as resolved.
Show resolved Hide resolved
@constraint(sp, knp, sum(data.weight[j,m]*y[j] for j in data.jobs) <= data.capacity[m])
@constraint(sp, lbs[j in data.jobs], y[j] + lb_y[j] >= 0)
@constraint(sp, ubs[j in data.jobs], y[j] - ub_y[j] <= 0)
sp_models[m] = (sp, y, lb_y, ub_y, max_card)
laradicp marked this conversation as resolved.
Show resolved Hide resolved
end

lb = 0.0
ub = 1.0
function my_pricing_callback(cbdata)
machine_id = BD.callback_spid(cbdata, model)

sp, y, lb_y, ub_y, max_card = sp_models[machine_id]
laradicp marked this conversation as resolved.
Show resolved Hide resolved

red_costs = [BD.callback_reduced_cost(cbdata, x[machine_id, j]) for j in data.jobs]

# Update the model
## Bounds on subproblem variables
for j in data.jobs
JuMP.fix(lb_y[j], BD.callback_lb(cbdata, x[machine_id, j]), force = true)
JuMP.fix(ub_y[j], BD.callback_ub(cbdata, x[machine_id, j]), force = true)
end
JuMP.fix(max_card, (cbdata.stage == 1) ? length(data.jobs) : 3, force = true)
laradicp marked this conversation as resolved.
Show resolved Hide resolved

if(machine_id == 1)
laradicp marked this conversation as resolved.
Show resolved Hide resolved
lb = BD.callback_lb(cbdata, x[1, 1])
ub = BD.callback_ub(cbdata, x[1, 1])
end

## Objective function
@objective(sp, Min, sum(red_costs[j]*y[j] for j in data.jobs))

JuMP.optimize!(sp)

# Retrieve the solution
solcost = JuMP.objective_value(sp)
solvars = JuMP.VariableRef[]
solvarvals = Float64[]
for j in data.jobs
val = JuMP.value(y[j])
if val ≈ 1
push!(solvars, x[machine_id, j])
push!(solvarvals, 1.0)
end
end

# Submit the solution
MOI.submit(
model, BD.PricingSolution(cbdata), solcost, solvars, solvarvals
)
return
end

master = BD.getmaster(dec)
subproblems = BD.getsubproblems(dec)

BD.specify!.(subproblems, lower_multiplicity = 0, solver = my_pricing_callback)

JuMP.optimize!(model)

@test_broken lb == 1.0
@test ub == 1.0
end
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ include("full_instances_tests.jl")
include("user_algorithms_tests.jl")
include("preprocessing_tests.jl")
include("pricing_callback_tests.jl")
include("bound_callback_tests.jl")
include("optimizer_with_attributes_test.jl")
include("subproblem_solvers_tests.jl")

Expand All @@ -52,6 +53,10 @@ end
pricing_callback_tests()
end

@testset "bound callback" begin
bound_callback_tests()
end

@testset "Base.show functions " begin
backup_stdout = stdout
(rd_out, wr_out) = redirect_stdout()
Expand Down