-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore some unit tests of Algorithms (#986)
- Loading branch information
Showing
7 changed files
with
405 additions
and
753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
@testset "Algorithm - Presolve" begin | ||
@testset "RemovalOfFixedVariables" begin | ||
@test ClA._fix_var(0.99, 1.01, 0.1) | ||
@test !ClA._fix_var(0.98, 1.1, 0.1) | ||
@test ClA._fix_var(1.5, 1.5, 0.1) | ||
|
||
@test_broken !ClA._infeasible_var(1.09, 0.91, 0.1) | ||
@test ClA._infeasible_var(1.2, 0.9, 0.1) | ||
|
||
# Create the following formulation: | ||
# min x1 + 2x2 + 3x3 | ||
# st. x1 >= 1 | ||
# x2 >= 2 | ||
# x3 >= 3 | ||
# x1 + 2x2 + 3x3 >= 10 | ||
env = CL.Env{ClMP.VarId}(CL.Params()) | ||
form = ClMP.create_formulation!(env, ClMP.DwMaster()) | ||
vars = Dict{String, ClMP.Variable}() | ||
for i in 1:3 | ||
x = ClMP.setvar!(form, "x$i", ClMP.OriginalVar; cost = i, lb = i) | ||
vars["x$i"] = x | ||
end | ||
|
||
members = Dict{ClMP.VarId,Float64}( | ||
ClMP.getid(vars["x1"]) => 1, | ||
ClMP.getid(vars["x2"]) => 2, | ||
ClMP.getid(vars["x3"]) => 3 | ||
) | ||
c = ClMP.setconstr!(form, "c", ClMP.OriginalConstr; | ||
rhs = 10, sense = ClMP.Greater, members = members | ||
) | ||
DynamicSparseArrays.closefillmode!(ClMP.getcoefmatrix(form)) | ||
|
||
@test ClMP.getcurrhs(form, c) == 10 | ||
# @testset "Algorithm - Presolve" begin | ||
# @testset "RemovalOfFixedVariables" begin | ||
# @test ClA._fix_var(0.99, 1.01, 0.1) | ||
# @test !ClA._fix_var(0.98, 1.1, 0.1) | ||
# @test ClA._fix_var(1.5, 1.5, 0.1) | ||
|
||
# @test_broken !ClA._infeasible_var(1.09, 0.91, 0.1) | ||
# @test ClA._infeasible_var(1.2, 0.9, 0.1) | ||
|
||
# # Create the following formulation: | ||
# # min x1 + 2x2 + 3x3 | ||
# # st. x1 >= 1 | ||
# # x2 >= 2 | ||
# # x3 >= 3 | ||
# # x1 + 2x2 + 3x3 >= 10 | ||
# env = CL.Env{ClMP.VarId}(CL.Params()) | ||
# form = ClMP.create_formulation!(env, ClMP.DwMaster()) | ||
# vars = Dict{String, ClMP.Variable}() | ||
# for i in 1:3 | ||
# x = ClMP.setvar!(form, "x$i", ClMP.OriginalVar; cost = i, lb = i) | ||
# vars["x$i"] = x | ||
# end | ||
|
||
# members = Dict{ClMP.VarId,Float64}( | ||
# ClMP.getid(vars["x1"]) => 1, | ||
# ClMP.getid(vars["x2"]) => 2, | ||
# ClMP.getid(vars["x3"]) => 3 | ||
# ) | ||
# c = ClMP.setconstr!(form, "c", ClMP.OriginalConstr; | ||
# rhs = 10, sense = ClMP.Greater, members = members | ||
# ) | ||
# DynamicSparseArrays.closefillmode!(ClMP.getcoefmatrix(form)) | ||
|
||
# @test ClMP.getcurrhs(form, c) == 10 | ||
|
||
ClMP.setcurlb!(form, vars["x1"], 2) | ||
ClMP.setcurub!(form, vars["x1"], 2) | ||
@test ClMP.getcurrhs(form, c) == 10 | ||
# ClMP.setcurlb!(form, vars["x1"], 2) | ||
# ClMP.setcurub!(form, vars["x1"], 2) | ||
# @test ClMP.getcurrhs(form, c) == 10 | ||
|
||
ClA.treat!(form, ClA.RemovalOfFixedVariables(1e-6)) | ||
# ClA.treat!(form, ClA.RemovalOfFixedVariables(1e-6)) | ||
|
||
@test ClMP.getcurrhs(form, c) == 10 - 2 | ||
# @test ClMP.getcurrhs(form, c) == 10 - 2 | ||
|
||
ClMP.setcurlb!(form, vars["x2"], 3) | ||
ClMP.setcurub!(form, vars["x2"], 3) | ||
# ClMP.setcurlb!(form, vars["x2"], 3) | ||
# ClMP.setcurub!(form, vars["x2"], 3) | ||
|
||
ClA.treat!(form, ClA.RemovalOfFixedVariables(1e-6)) | ||
# ClA.treat!(form, ClA.RemovalOfFixedVariables(1e-6)) | ||
|
||
@test ClMP.getcurrhs(form, c) == 10 - 2 - 2*3 | ||
# @test ClMP.getcurrhs(form, c) == 10 - 2 - 2*3 | ||
|
||
ClMP.unfix!(form, vars["x1"]) | ||
ClMP.setcurlb!(form, vars["x1"], 1) | ||
ClA.treat!(form, ClA.RemovalOfFixedVariables(1e-6)) | ||
@test ClMP.getcurrhs(form, c) == 10 - 2*3 | ||
return | ||
end | ||
end | ||
# ClMP.unfix!(form, vars["x1"]) | ||
# ClMP.setcurlb!(form, vars["x1"], 1) | ||
# ClA.treat!(form, ClA.RemovalOfFixedVariables(1e-6)) | ||
# @test ClMP.getcurrhs(form, c) == 10 - 2*3 | ||
# return | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,53 @@ | ||
@testset "Algorithm - Subsolvers" begin | ||
@testset "MoiOptimize - Parameters reset after optimize_with_moi!" begin | ||
# Create the formulation: | ||
# Min x | ||
# s.t. x >= 1 | ||
|
||
env = Env{ClMP.VarId}(Coluna.Params()) | ||
form = ClMP.create_formulation!(env, ClMP.Original(), obj_sense = ClMP.MinSense) | ||
ClMP.setvar!(form, "x", ClMP.OriginalVar; cost = 1, lb = 1) | ||
closefillmode!(ClMP.getcoefmatrix(form)) | ||
|
||
algo1 = ClA.MoiOptimize( | ||
time_limit = 1200, | ||
silent = false, | ||
custom_parameters = Dict( | ||
"it_lim" => 60 | ||
) | ||
function reset_parameters_after_optimize_with_moi() | ||
# Create the formulation: | ||
# Min x | ||
# s.t. x >= 1 | ||
|
||
env = Env{ClMP.VarId}(Coluna.Params()) | ||
form = ClMP.create_formulation!(env, ClMP.Original(), obj_sense = ClMP.MinSense) | ||
ClMP.setvar!(form, "x", ClMP.OriginalVar; cost = 1, lb = 1) | ||
closefillmode!(ClMP.getcoefmatrix(form)) | ||
|
||
algo1 = ClA.MoiOptimize( | ||
time_limit = 1200, | ||
silent = false, | ||
custom_parameters = Dict( | ||
"it_lim" => 60 | ||
) | ||
) | ||
|
||
algo2 = ClA.MoiOptimize( | ||
silent = false, | ||
custom_parameters = Dict( | ||
"mip_gap" => 0.03 | ||
) | ||
algo2 = ClA.MoiOptimize( | ||
silent = false, | ||
custom_parameters = Dict( | ||
"mip_gap" => 0.03 | ||
) | ||
) | ||
|
||
optimizer = ClMP.MoiOptimizer(MOI._instantiate_and_check(GLPK.Optimizer)) | ||
optimizer = ClMP.MoiOptimizer(MOI._instantiate_and_check(GLPK.Optimizer)) | ||
|
||
get_time_lim() = MOI.get(optimizer.inner, MOI.TimeLimitSec()) | ||
get_silent() = MOI.get(optimizer.inner, MOI.Silent()) | ||
get_it_lim() = MOI.get(optimizer.inner, MOI.RawOptimizerAttribute("it_lim")) | ||
get_mip_gap() = MOI.get(optimizer.inner, MOI.RawOptimizerAttribute("mip_gap")) | ||
get_time_lim() = MOI.get(optimizer.inner, MOI.TimeLimitSec()) | ||
get_silent() = MOI.get(optimizer.inner, MOI.Silent()) | ||
get_it_lim() = MOI.get(optimizer.inner, MOI.RawOptimizerAttribute("it_lim")) | ||
get_mip_gap() = MOI.get(optimizer.inner, MOI.RawOptimizerAttribute("mip_gap")) | ||
|
||
default_time_lim = get_time_lim() | ||
default_silent = get_silent() | ||
default_it_lim = get_it_lim() | ||
default_mip_gap = get_mip_gap() | ||
default_time_lim = get_time_lim() | ||
default_silent = get_silent() | ||
default_it_lim = get_it_lim() | ||
default_mip_gap = get_mip_gap() | ||
|
||
ClA.optimize_with_moi!(optimizer, form, algo1, ClA.OptimizationState(form)) | ||
ClA.optimize_with_moi!(optimizer, form, algo1, ClA.OptimizationState(form)) | ||
|
||
@test get_time_lim() == default_time_lim | ||
@test get_silent() == default_silent | ||
@test get_it_lim() == default_it_lim | ||
@test get_mip_gap() == default_mip_gap | ||
@test get_time_lim() == default_time_lim | ||
@test get_silent() == default_silent | ||
@test get_it_lim() == default_it_lim | ||
@test get_mip_gap() == default_mip_gap | ||
|
||
ClA.optimize_with_moi!(optimizer, form, algo2, ClA.OptimizationState(form)) | ||
ClA.optimize_with_moi!(optimizer, form, algo2, ClA.OptimizationState(form)) | ||
|
||
@test get_time_lim() == default_time_lim | ||
@test get_silent() == default_silent | ||
@test get_it_lim() == default_it_lim | ||
@test get_mip_gap() == default_mip_gap | ||
return | ||
end | ||
end | ||
@test get_time_lim() == default_time_lim | ||
@test get_silent() == default_silent | ||
@test get_it_lim() == default_it_lim | ||
@test get_mip_gap() == default_mip_gap | ||
return | ||
end | ||
register!(unit_tests, "subsolvers", reset_parameters_after_optimize_with_moi) |
Oops, something went wrong.