Skip to content

Commit

Permalink
reduce log + show functions (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitornesello authored May 21, 2019
1 parent 0f9550c commit 41f6021
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 81 deletions.
87 changes: 87 additions & 0 deletions test/full_instances_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
function full_instances_tests()
@testset "play gap" begin
data = CLD.GeneralizedAssignment.data("play2.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer))

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

JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 75.0) <= 0.00001
@test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
end

@testset "gap - JuMP/MOI modeling" begin
data = CLD.GeneralizedAssignment.data("smallgap3.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer))

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

JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 438.0) <= 0.00001
@test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
end

@testset "gap with penalties - pure master variables" begin
data = CLD.GeneralizedAssignment.data("smallgap3.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer)
)

problem, x, y, dec = CLD.GeneralizedAssignment.model_with_penalties(data, coluna)
JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 416.4) <= 0.00001
end

@testset "gap with maximisation objective function" begin
data = CLD.GeneralizedAssignment.data("smallgap3.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer)
)

problem, x, dec = CLD.GeneralizedAssignment.model_max(data, coluna)
JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 580.0) <= 0.00001
end

# @testset "gap BIG instance" begin
# data = CLD.GeneralizedAssignment.data("gapC-5-100.txt")

# coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
# master_factory = with_optimizer(GLPK.Optimizer),
# pricing_factory = with_optimizer(GLPK.Optimizer)
# )

# problem, x, dec = CLD.GeneralizedAssignment.model(data, coluna)
# JuMP.optimize!(problem)
# @test abs(JuMP.objective_value(problem) - 1931.0) <= 0.00001
# @test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
# end

# To redirect logging output
io = IOBuffer()
global_logger(ConsoleLogger(io, LogLevel(-4)))

@testset "play gap" begin
data = CLD.GeneralizedAssignment.data("play2.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer)
)

problem, x, dec = CLD.GeneralizedAssignment.model(data, coluna)
JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 75.0) <= 0.00001
@test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
end
end
93 changes: 13 additions & 80 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,88 +13,21 @@ global const CL = Coluna
global const CLD = ColunaDemos

include("unit/unit_tests.jl")
include("show_functions_tests.jl")
include("full_instances_tests.jl")

unit_tests()

@testset "play gap" begin
data = CLD.GeneralizedAssignment.data("play2.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer))

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

JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 75.0) <= 0.00001
@test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
end

@testset "gap - JuMP/MOI modeling" begin
data = CLD.GeneralizedAssignment.data("smallgap3.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer))

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

JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 438.0) <= 0.00001
@test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
end

@testset "gap with penalties - pure master variables" begin
data = CLD.GeneralizedAssignment.data("smallgap3.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer)
)

problem, x, y, dec = CLD.GeneralizedAssignment.model_with_penalties(data, coluna)
JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 416.4) <= 0.00001
end

@testset "gap with maximisation objective function" begin
data = CLD.GeneralizedAssignment.data("smallgap3.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer)
)

problem, x, dec = CLD.GeneralizedAssignment.model_max(data, coluna)
JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 580.0) <= 0.00001
@testset "Full instances " begin
full_instances_tests()
end

# @testset "gap BIG instance" begin
# data = CLD.GeneralizedAssignment.data("gapC-5-100.txt")

# coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
# master_factory = with_optimizer(GLPK.Optimizer),
# pricing_factory = with_optimizer(GLPK.Optimizer)
# )

# problem, x, dec = CLD.GeneralizedAssignment.model(data, coluna)
# JuMP.optimize!(problem)
# @test abs(JuMP.objective_value(problem) - 1931.0) <= 0.00001
# @test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
# end

@testset "play gap" begin
global_logger(ConsoleLogger(stderr, LogLevel(-4)))
data = CLD.GeneralizedAssignment.data("play2.txt")

coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer)
)

problem, x, dec = CLD.GeneralizedAssignment.model(data, coluna)
JuMP.optimize!(problem)
@test abs(JuMP.objective_value(problem) - 75.0) <= 0.00001
@test CLD.GeneralizedAssignment.print_and_check_sol(data, problem, x)
end
@testset "Base.show functions " begin
# Test show functions
backup_stdout = stdout
(rd_out, wr_out) = redirect_stdout()
show_functions_tests()
close(wr_out)
close(rd_out)
redirect_stdout(backup_stdout)
end
10 changes: 10 additions & 0 deletions test/show_functions_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function show_functions_tests()
data = CLD.GeneralizedAssignment.data("play2.txt")
coluna = JuMP.with_optimizer(Coluna.Optimizer,# #params = params,
master_factory = with_optimizer(GLPK.Optimizer),
pricing_factory = with_optimizer(GLPK.Optimizer))
problem, x, dec = CLD.GeneralizedAssignment.model(data, coluna)
JuMP.optimize!(problem)
@show fieldnames(typeof(problem.moi_backend))
@test_nowarn CL._show_optimizer(problem.moi_backend.optimizer.inner.re_formulation.master.moi_optimizer)
end
1 change: 0 additions & 1 deletion test/unit/vcids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function id_unit_tests()

@test var_id < constr_id
@test CL.getsortid(constr_id) == 100 + 1000000 * 3
@test_nowarn Base.show(var_id)

return
end

0 comments on commit 41f6021

Please sign in to comment.