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

MOI test_constraint_* pass #629

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 13 additions & 2 deletions src/Algorithm/basic/solveipform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Parameters:
deactivate_artificial_vars::Bool = true
enforce_integrality::Bool = true
get_dual_bound::Bool = true
get_dual_solution::Bool = false # Used in MOI integration tests.
max_nb_ip_primal_sols::Int = 50
log_level::Int = 2
silent::Bool = true
Expand Down Expand Up @@ -180,14 +181,15 @@ function run!(
max_length_ip_primal_sols = algo.max_nb_ip_primal_sols
)

ip_supported = check_if_optimizer_supports_ip(getoptimizer(form, optimizer_id))
optimizer = getoptimizer(form, optimizer_id)
ip_supported = check_if_optimizer_supports_ip(optimizer)
if !ip_supported
@warn "Optimizer of formulation with id =", getuid(form),
" does not support integer variables. Skip SolveIpForm algorithm."
return OptimizationOutput(result)
end

primal_sols = optimize_ip_form!(algo, getoptimizer(form, optimizer_id), form, result)
primal_sols = optimize_ip_form!(algo, optimizer, form, result)

partial_sol = nothing
partial_sol_value = 0.0
Expand Down Expand Up @@ -223,6 +225,15 @@ function run!(
dual_bound = getvalue(get_ip_primal_bound(result)) + partial_sol_value
set_ip_dual_bound!(result, DualBound(form, dual_bound))
end
if algo.get_dual_solution && getterminationstatus(result) == OPTIMAL
dual_sols = get_dual_solutions(form, optimizer)
if length(dual_sols) > 0
coeff = getobjsense(form) == MinSense ? 1.0 : -1.0
lp_dual_sol_pos = argmax(coeff * getvalue.(dual_sols))
lp_dual_sol = dual_sols[lp_dual_sol_pos]
set_lp_dual_sol!(result, lp_dual_sol)
end
end

return OptimizationOutput(result)
end
Expand Down
26 changes: 13 additions & 13 deletions src/MOIwrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function _add_constraint_on_variable!(
form::Formulation, varinfo::_VarInfo, set::MOI.GreaterThan{Float64}
)
_throw_if_existing_lower(varinfo.lb_type, MOI.GreaterThan{Float64}, varinfo.index)
MathProg._setperenlb!(form, varinfo.var, set.lower)
MathProg.setperenlb!(form, varinfo.var, set.lower)
varinfo.lb_type = _GREATER
return
end
Expand All @@ -212,7 +212,7 @@ function _add_constraint_on_variable!(
form::Formulation, varinfo::_VarInfo, set::MOI.LessThan{Float64}
)
_throw_if_existing_upper(varinfo.ub_type, MOI.LessThan{Float64}, varinfo.index)
MathProg._setperenub!(form, varinfo.var, set.upper)
MathProg.setperenub!(form, varinfo.var, set.upper)
varinfo.ub_type = _LESS
return
end
Expand All @@ -222,8 +222,8 @@ function _add_constraint_on_variable!(
)
_throw_if_existing_lower(varinfo.lb_type, MOI.EqualTo{Float64}, varinfo.index)
_throw_if_existing_upper(varinfo.ub_type, MOI.EqualTo{Float64}, varinfo.index)
MathProg._setperenlb!(form, varinfo.var, set.value)
MathProg._setperenub!(form, varinfo.var, set.value)
MathProg.setperenlb!(form, varinfo.var, set.value)
MathProg.setperenub!(form, varinfo.var, set.value)
varinfo.lb_type = _EQUAL
varinfo.ub_type = _EQUAL
return
Expand All @@ -234,8 +234,8 @@ function _add_constraint_on_variable!(
)
_throw_if_existing_lower(varinfo.lb_type, MOI.Interval{Float64}, varinfo.index)
_throw_if_existing_upper(varinfo.ub_type, MOI.Interval{Float64}, varinfo.index)
MathProg._setperenlb!(form, varinfo.var, set.lower)
MathProg._setperenub!(form, varinfo.var, set.upper)
MathProg.setperenlb!(form, varinfo.var, set.lower)
MathProg.setperenub!(form, varinfo.var, set.upper)
varinfo.lb_type = _INTERVAL
varinfo.ub_type = _INTERVAL
return
Expand Down Expand Up @@ -296,15 +296,15 @@ function _delete_constraint_on_variable!(
form::Formulation, varinfo::_VarInfo, ::Type{<:MOI.GreaterThan{Float64}}
)
varinfo.lb_type = _NONE
MathProg._setperenlb!(form, varinfo.var, -Inf)
MathProg.setperenlb!(form, varinfo.var, -Inf)
return
end

function _delete_constraint_on_variable!(
form::Formulation, varinfo::_VarInfo, ::Type{<:MOI.LessThan{Float64}}
)
varinfo.ub_type = _NONE
MathProg._setperenub!(form, varinfo.var, Inf)
MathProg.setperenub!(form, varinfo.var, Inf)
return
end

Expand All @@ -313,8 +313,8 @@ function _delete_constraint_on_variable!(
)
varinfo.lb_type = _NONE
varinfo.ub_type = _NONE
MathProg._setperenlb!(form, varinfo.var, -Inf)
MathProg._setperenub!(form, varinfo.var, Inf)
MathProg.setperenlb!(form, varinfo.var, -Inf)
MathProg.setperenub!(form, varinfo.var, Inf)
return
end

Expand All @@ -323,8 +323,8 @@ function _delete_constraint_on_variable!(
)
varinfo.lb_type = _NONE
varinfo.ub_type = _NONE
MathProg._setperenlb!(form, varinfo.var, -Inf)
MathProg._setperenub!(form, varinfo.var, Inf)
MathProg.setperenlb!(form, varinfo.var, -Inf)
MathProg.setperenub!(form, varinfo.var, Inf)
return
end

Expand Down Expand Up @@ -989,7 +989,7 @@ function MOI.get(optimizer::Optimizer, ::MOI.PrimalStatus)
return convert_status(getstatus(primal_sol))
end

function MOI.get(optimizer::Optimizer, ::MOI.DualStatus)
function MOI.get(optimizer::Optimizer, ::MOI.DualStatus)
dual_sol = get_best_lp_dual_sol(optimizer.result)
dual_sol === nothing && return MOI.NO_SOLUTION
return convert_status(getstatus(dual_sol))
Expand Down
23 changes: 21 additions & 2 deletions src/MathProg/varconstr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ function setcurcost!(form::Formulation, varid::VarId, cost::Float64)
end

## Lower bound
_setperenlb!(::Formulation, var::Variable, lb) = var.perendata.lb = lb
"""
setperenlb!(formulation, var, rhs)

Set the perennial lower bound of a variable in a formulation.
Change is propagated to the current lower bound of the variable.
"""
function setperenlb!(form::Formulation, var::Variable, lb)
var.perendata.lb = lb
return setcurlb!(form, var, lb)
end

"""
getperenlb(formulation, varid)
getperenlb(formulation, var)
Expand Down Expand Up @@ -106,7 +116,16 @@ end
setcurlb!(form::Formulation, varid::VarId, lb::Float64) = setcurlb!(form, getvar(form, varid), lb)

## Upper bound
_setperenub!(::Formulation, var::Variable, ub) = var.perendata.ub = ub
"""
setperenub!(formulation, var, rhs)

Set the perennial upper bound of a variable in a formulation.
Change is propagated to the current upper bound of the variable.
"""
function setperenub!(form::Formulation, var::Variable, ub)
var.perendata.ub = ub
return setcurub!(form, var, ub)
end

"""
getperenub(formulation, varid)
Expand Down
59 changes: 21 additions & 38 deletions test/MathOptInterface/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ const OPTIMIZER = MOI.instantiate(
MOI.OptimizerWithAttributes(
Coluna.Optimizer,
MOI.RawOptimizerAttribute("default_optimizer") => HiGHS.Optimizer,
MOI.RawOptimizerAttribute("params") => Coluna.Params(solver = Coluna.Algorithm.SolveIpForm())
MOI.RawOptimizerAttribute("params") => Coluna.Params(
solver = Coluna.Algorithm.SolveIpForm(
moi_params = Coluna.Algorithm.MoiOptimize(get_dual_solution = true)
)
)
),
)

const BRIDGED = MOI.instantiate(
MOI.OptimizerWithAttributes(
Coluna.Optimizer,
MOI.RawOptimizerAttribute("default_optimizer") => HiGHS.Optimizer,
MOI.RawOptimizerAttribute("params") => Coluna.Params(solver = Coluna.Algorithm.SolveIpForm())
MOI.RawOptimizerAttribute("params") => Coluna.Params(
solver = Coluna.Algorithm.SolveIpForm(
moi_params = Coluna.Algorithm.MoiOptimize(get_dual_solution = true)
)
)
),
with_bridge_type = Float64,
)
Expand Down Expand Up @@ -66,18 +74,16 @@ function test_runtests()
BRIDGED,
CONFIG,
# include = [
# "test_add_constrained_variables_vector",
# "test_basic_ScalarAffineFunction_EqualTo",
# "test_basic_ScalarAffineFunction_GreaterThan",
# "test_basic_ScalarAffineFunction_LessThan",
# "test_basic_VariableIndex_EqualTo",
# "test_basic_VariableIndex_GreaterThan",
# "test_basic_VariableIndex_Interval",
# "test_basic_VariableIndex_LessThan",
# "test_basic_VariableIndex_ZeroOne",
# "test_basic_VectorOfVariables_Nonnegatives",
# "test_basic_VectorOfVariables_Nonpositives",
# "test_basic_VectorOfVariables_Zeros",
# "test_constraint_ScalarAffineFunction_EqualTo",
# "test_constraint_ScalarAffineFunction_GreaterThan",
# "test_constraint_ScalarAffineFunction_Interval",
# "test_constraint_ScalarAffineFunction_LessThan",
# "test_constraint_ScalarAffineFunction_duplicate",
# "test_constraint_VectorAffineFunction_duplicate",
# "test_constraint_ZeroOne_bounds",
# "test_constraint_ZeroOne_bounds_2",
# "test_constraint_ZeroOne_bounds_3",
# "test_constraint_get_ConstraintIndex"
# ],
exclude = [
"test_attribute_NumberOfThreads",
Expand All @@ -86,30 +92,7 @@ function test_runtests()
"test_attribute_RawStatusString",
"test_attribute_SolveTimeSec",
"test_attribute_SolverVersion",
"test_conic_NormInfinityCone_3",
"test_conic_NormInfinityCone_INFEASIBLE",
"test_conic_NormInfinityCone_VectorAffineFunction",
"test_conic_NormInfinityCone_VectorOfVariables",
"test_conic_NormOneCone",
"test_conic_NormOneCone_INFEASIBLE",
"test_conic_NormOneCone_VectorAffineFunction",
"test_conic_NormOneCone_VectorOfVariables",
"test_conic_linear_INFEASIBLE",
"test_conic_linear_INFEASIBLE_2",
"test_conic_linear_VectorAffineFunction",
"test_conic_linear_VectorAffineFunction_2",
"test_conic_linear_VectorOfVariables",
"test_conic_linear_VectorOfVariables_2",
"test_constraint_ScalarAffineFunction_EqualTo",
"test_constraint_ScalarAffineFunction_GreaterThan",
"test_constraint_ScalarAffineFunction_Interval",
"test_constraint_ScalarAffineFunction_LessThan",
"test_constraint_ScalarAffineFunction_duplicate",
"test_constraint_VectorAffineFunction_duplicate",
"test_constraint_ZeroOne_bounds",
"test_constraint_ZeroOne_bounds_2",
"test_constraint_ZeroOne_bounds_3",
"test_constraint_get_ConstraintIndex",
"test_conic_",
"test_linear_DUAL_INFEASIBLE",
"test_linear_DUAL_INFEASIBLE_2",
"test_linear_FEASIBILITY_SENSE",
Expand Down