Skip to content

Commit

Permalink
Reduced cost method (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
guimarqu authored May 14, 2020
1 parent cf94c8f commit e3300e7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/MathProg/MOIinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,41 @@ function fill_dual_result!(form::Formulation, optimizer::MoiOptimizer,
return
end

function _getreducedcost(form::Formulation, optimizer, var::Variable)
varname = getname(form, var)
opt = typeof(optimizer)
@warn """
Cannot retrieve reduced cost of variable $varname from formulation solved with optimizer of type $opt.
Method returns nothing.
"""
return nothing
end

function _getreducedcost(form::Formulation, optimizer::MoiOptimizer, var::Variable)
sign = getobjsense(form) == MinSense ? 1.0 : -1.0
inner = getinner(optimizer)
if MOI.get(inner, MOI.ResultCount()) < 1
@warn """
No dual solution stored in the optimizer of formulation. Cannot retrieve reduced costs.
Method returns nothing.
"""
return nothing
end
if !iscuractive(form, var) || !iscurexplicit(form, var)
varname = getname(form, var)
@warn """
Cannot retrieve reduced cost of variable $varname because the variable must be active and explicit.
Method returns nothing.
"""
return nothing
end
bounds_interval_idx = getbounds(getmoirecord(var))
dualval = MOI.get(inner, MOI.ConstraintDual(1), bounds_interval_idx)
return sign * dualval
end
getreducedcost(form::Formulation, var::Variable) = _getreducedcost(form, getoptimizer(form), var)
getreducedcost(form::Formulation, varid::VarId) = _getreducedcost(form, getoptimizer(form), getvar(form, varid))

function _show_function(io::IO, moi_model::MOI.ModelLike,
func::MOI.ScalarAffineFunction)
for term in func.terms
Expand Down
2 changes: 1 addition & 1 deletion src/MathProg/MathProg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export Variable, Constraint, VarId, ConstrId, VarMembership, ConstrMembership,
getpereneub, getcurub, setcurub!, getperenerhs, getcurrhs, setcurrhs!, getperenesense,
getcursense, setcursense!, getperenekind, getcurkind, setcurkind!, getpereneincval,
getcurincval, setcurincval!, ispereneactive, iscuractive, activate!, deactivate!,
ispereneexplicit, iscurexplicit, setiscurexplicit!, getname, reset!
ispereneexplicit, iscurexplicit, setiscurexplicit!, getname, reset!, getreducedcost

# Types & methods related to solutions & bounds
# Note : we should export only get methods for MoiResult (the solution is built in MathProg)
Expand Down

0 comments on commit e3300e7

Please sign in to comment.