Giter VIP home page Giter VIP logo

Comments (6)

odow avatar odow commented on July 18, 2024

ConstraintDualStart for VariableIndex are handled here:

Ipopt.jl/src/MOI_wrapper.jl

Lines 339 to 425 in 4ae7ae9

_dual_start(::Optimizer, ::Nothing, ::Int = 1) = 0.0
function _dual_start(model::Optimizer, value::Real, scale::Int = 1)
return _dual_multiplier(model) * value * scale
end
function MOI.supports(
::Optimizer,
::MOI.ConstraintDualStart,
::Type{MOI.ConstraintIndex{MOI.VariableIndex,<:_SETS}},
)
return true
end
function MOI.set(
model::Optimizer,
::MOI.ConstraintDualStart,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.GreaterThan{Float64}},
value::Union{Real,Nothing},
)
MOI.throw_if_not_valid(model, ci)
model.mult_x_L[ci.value] = value
# No need to reset model.inner, because this gets handled in optimize!.
return
end
function MOI.get(
model::Optimizer,
::MOI.ConstraintDualStart,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.GreaterThan{Float64}},
)
MOI.throw_if_not_valid(model, ci)
return model.mult_x_L[ci.value]
end
function MOI.set(
model::Optimizer,
::MOI.ConstraintDualStart,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.LessThan{Float64}},
value::Union{Real,Nothing},
)
MOI.throw_if_not_valid(model, ci)
model.mult_x_U[ci.value] = value
# No need to reset model.inner, because this gets handled in optimize!.
return
end
function MOI.get(
model::Optimizer,
::MOI.ConstraintDualStart,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.LessThan{Float64}},
)
MOI.throw_if_not_valid(model, ci)
return model.mult_x_U[ci.value]
end
function MOI.set(
model::Optimizer,
::MOI.ConstraintDualStart,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.EqualTo{Float64}},
value::Union{Real,Nothing},
)
MOI.throw_if_not_valid(model, ci)
if value === nothing
model.mult_x_L[ci.value] = nothing
model.mult_x_U[ci.value] = nothing
elseif value >= 0.0
model.mult_x_L[ci.value] = value
model.mult_x_U[ci.value] = 0.0
else
model.mult_x_L[ci.value] = 0.0
model.mult_x_U[ci.value] = value
end
# No need to reset model.inner, because this gets handled in optimize!.
return
end
function MOI.get(
model::Optimizer,
::MOI.ConstraintDualStart,
ci::MOI.ConstraintIndex{MOI.VariableIndex,MOI.EqualTo{Float64}},
)
MOI.throw_if_not_valid(model, ci)
l = model.mult_x_L[ci.value]
u = model.mult_x_U[ci.value]
return (l === u === nothing) ? nothing : (l + u)
end

Do you have an example where you can show they aren't being copied?

from ipopt.jl.

LukasBarner avatar LukasBarner commented on July 18, 2024

In general, setting dual starts works. It is just that the information is lost during copy_to, since MOI.supports() from Ipopt.jl returns the default false if a constraint of type VariableIndex-in-S is passed.
Here is a very ugly example, but it shows the problem

using MathOptInterface,Ipopt
MOIU = MathOptInterface.Utilities 
MOI = MathOptInterface

model = MOIU.CachingOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}()), MOIU.AUTOMATIC)
varidx = MOI.add_variable(model)
MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(),varidx)
MOI.set(model, MOI.ObjectiveSense(),MOI.MIN_SENSE)
ctridx = MOI.add_constraint(model, varidx, MOI.GreaterThan(0.0))

MOI.set(model, MOI.ConstraintDualStart(), ctridx, 2.0)
@assert MOI.get(model, MOI.ConstraintDualStart(), ctridx)==2

solver = MOI.instantiate(Ipopt.Optimizer)
idxmap = MOI.copy_to(solver,model)

@assert MOI.get(solver, MOI.ConstraintDualStart(), idxmap[ctridx])==nothing
# That duals to bounds are not correctly set is visible from the log
MOI.set(solver, MOI.RawOptimizerAttribute("warm_start_init_point"), "yes")
MOI.set(solver, MOI.RawOptimizerAttribute("print_level"), 8)
MOI.optimize!(solver)

# But setting the constraint dual start in general works:
MOI.set(solver, MOI.ConstraintDualStart(), idxmap[ctridx], 2)
@assert MOI.get(solver, MOI.ConstraintDualStart(), idxmap[ctridx]) == 2
MOI.optimize!(solver)

The only attributes that can get ignored during copy without an error/warning are MOI.ConstraintName(), MOI.ConstraintPrimalStart() and MOI.ConstraintDualStart() (as defined by pass_attributes) .
Setting these in the Ipopt.copy_to() function after the default_copy_to() call might be an easy workaround.

from ipopt.jl.

odow avatar odow commented on July 18, 2024

Ooops. We need ::Type{<:MOI.ConstraintIndex{MOI.VariableIndex,<:_SETS}}. I'll make a PR.

from ipopt.jl.

odow avatar odow commented on July 18, 2024

This should fix it: #334

from ipopt.jl.

LukasBarner avatar LukasBarner commented on July 18, 2024

Thanks for the quick action. I tried that as well, but (on my end), it resulted in different problems. Please see the following slightly edited example from above:

using MathOptInterface, Ipopt
MOIU = MathOptInterface.Utilities 
MOI = MathOptInterface

model = MOIU.CachingOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}()), MOIU.AUTOMATIC)
varidx = MOI.add_variable(model)
MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(),varidx)
MOI.set(model, MOI.ObjectiveSense(),MOI.MIN_SENSE)
ctridx = MOI.add_constraint(model, varidx, MOI.GreaterThan(0.0))

MOI.set(model, MOI.ConstraintDualStart(), ctridx, 2.0)
@assert MOI.get(model, MOI.ConstraintDualStart(), ctridx)==2

solver = MathOptInterface.instantiate(Ipopt.Optimizer; with_bridge_type=Float64)
idxmap = MOI.copy_to(solver,model)

This was working fine prior to fixing the type issue, but threw an error after (at least on my end :D)
Edit: If I'm not mistaken, #334 should break for example BilevelJuMP

from ipopt.jl.

odow avatar odow commented on July 18, 2024

Hmm. I'll take a deeper look.

from ipopt.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.