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

Edits related to the reoptimization feature #258

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
29 changes: 19 additions & 10 deletions src/MOI_wrapper/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ MOI.supports(::Optimizer, ::MOI.ObjectiveFunction{SAF}) = true
function MOI.set(o::Optimizer, ::MOI.ObjectiveFunction{SAF}, obj::SAF)
allow_modification(o)

# reset objective coefficient of all variables first
for v in values(o.inner.vars)
@SCIP_CALL SCIPchgVarObj(o, v[], 0.0)
end
if haskey(o.params, "reoptimization/enable") && o.params["reoptimization/enable"] == 1
Copy link
Member

Choose a reason for hiding this comment

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

in Julia you can also do

    if get(o.params, "reoptimization/enable", 0) == 1

to get an element with a default value (here 0)

vars = [var(o.inner, vr) for vr in keys(o.inner.vars)]
obj_coefs = [t.coefficient for t in obj.terms]
@assert length(vars) == length(obj_coefs)
scip_obj_sense = SCIPgetObjsense(o.inner)
@SCIP_CALL SCIPchgReoptObjective(o, scip_obj_sense, vars,
obj_coefs, length(vars))
Comment on lines +18 to +19
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@SCIP_CALL SCIPchgReoptObjective(o, scip_obj_sense, vars,
obj_coefs, length(vars))
@SCIP_CALL SCIPchgReoptObjective(
o, scip_obj_sense, vars,
obj_coefs, length(vars),
)

clearer indentation

Copy link
Member

Choose a reason for hiding this comment

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

ping @sbolusani

else
# reset objective coefficient of all variables first
for v in values(o.inner.vars)
@SCIP_CALL SCIPchgVarObj(o, v[], 0.0)
end

# set new objective coefficients, summing coefficients
for t in obj.terms
v = var(o, t.variable)
oldcoef = SCIPvarGetObj(v)
newcoef = oldcoef + t.coefficient
@SCIP_CALL SCIPchgVarObj(o, v, newcoef)
# set new objective coefficients, summing coefficients
for t in obj.terms
v = var(o, t.variable)
oldcoef = SCIPvarGetObj(v)
newcoef = oldcoef + t.coefficient
@SCIP_CALL SCIPchgVarObj(o, v, newcoef)
end
end

@SCIP_CALL SCIPaddOrigObjoffset(o, obj.constant - SCIPgetOrigObjoffset(o))
Expand Down