Giter Club home page Giter Club logo

Comments (9)

odow avatar odow commented on August 16, 2024

Seems similar to #2384 #2396

from mathoptinterface.jl.

odow avatar odow commented on August 16, 2024

Here's a pure MOI

julia> import MathOptInterface as MOI

julia> src = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
MOIU.UniversalFallback{MOIU.Model{Float64}}
fallback for MOIU.Model{Float64}

julia> x = MOI.add_variable(src)
MOI.VariableIndex(1)

julia> MOI.add_constraint(src, x, MOI.GreaterThan(1.0))
MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.GreaterThan{Float64}}(1)

julia> c = MOI.add_constraint(src, 2.0 * x, MOI.EqualTo(3.0))
MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}(1)

julia> MOI.Utilities.@model(
           Model2452,
           (),
           (),
           (MOI.Nonnegatives, MOI.Zeros),
           (),
           (),
           (),
           (MOI.VectorOfVariables,),
           (MOI.VectorAffineFunction,)
       )
MathOptInterface.Utilities.GenericModel{T, MathOptInterface.Utilities.ObjectiveContainer{T}, MathOptInterface.Utilities.VariablesContainer{T}, Model2452FunctionConstraints{T}} where T

julia> function MOI.supports_constraint(
           ::Model2452{T},
           ::Type{MOI.VariableIndex},
           ::Type{
               <:Union{
                   MOI.GreaterThan{T},
                   MOI.LessThan{T},
                   MOI.EqualTo{T},
                   MOI.Interval{T},
                   MOI.ZeroOne,
                   MOI.Integer,
               },
           },
       ) where {T}
           return false
       end

julia> function MOI.supports_constraint(
           ::Model2452{T},
           ::Type{MOI.VectorOfVariables},
           ::Type{MOI.Reals},
       ) where {T}
           return false
       end

julia> dest = MOI.instantiate(Model2452{Float64}; with_bridge_type = Float64)
MOIB.LazyBridgeOptimizer{MOIU.GenericModel{Float64, MOIU.ObjectiveContainer{Float64}, MOIU.VariablesContainer{Float64}, Model2452FunctionConstraints{Float64}}}
with 0 variable bridges
with 0 constraint bridges
with 0 objective bridges
with inner model MOIU.GenericModel{Float64, MOIU.ObjectiveContainer{Float64}, MOIU.VariablesContainer{Float64}, Model2452FunctionConstraints{Float64}}

julia> index_map = MOI.copy_to(dest, src)
MathOptInterface.Utilities.IndexMap with 3 entries:
  MOI.VariableIndex(1)             => MOI.VariableIndex(-1)
  ConstraintIndex{VariableIndex,  => ConstraintIndex{VariableIndex, GreaterThan{Float64}}(-1)
  ConstraintIndex{ScalarAffineFun => ConstraintIndex{ScalarAffineFunction{Float64}, EqualTo{Float64

julia> MOI.get(dest, MOI.ConstraintSet(), index_map[c])
MathOptInterface.EqualTo{Float64}(1.0)

I can't help but think that many Variable bridges were a bad idea, particularly Vectorize ones with a non-zero constant.

from mathoptinterface.jl.

odow avatar odow commented on August 16, 2024

I think the issue is the interaction of the variable and constraint bridges, but it gets pretty complicated following the call_in_context.

from mathoptinterface.jl.

mtanneau avatar mtanneau commented on August 16, 2024

Thanks for following up on that so quick!

What I was missing in trying to build a minimal example was that x should have a non-zero lower bound (I think, based on your example). Namely, I did not encounter any issue when x was declared as @variable(model, x >= 0).
I think this echoes

particularly Vectorize ones with a non-zero constant

from mathoptinterface.jl.

odow avatar odow commented on August 16, 2024

A hacky work-around for now is remove_bridge:

julia> using JuMP, Clarabel

julia> model = Model(Clarabel.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Clarabel

julia> MOI.Bridges.remove_bridge(
           backend(model).optimizer,
           MOI.Bridges.Variable.VectorizeBridge{Float64},
       )

julia> set_silent(model)

julia> @variable(model, x >= 1)
x

julia> @constraint(model, c, 2x == 3)
c : 2 x = 3

julia> optimize!(model)

julia> value(x)
1.4999999999999996

julia> b = normalized_rhs(c)
3.0

julia> set_normalized_rhs(c, b)

julia> optimize!(model)

julia> value(x)
1.4999999999999996

from mathoptinterface.jl.

odow avatar odow commented on August 16, 2024

I need to discuss this with @blegat, but he's a bit busy this week.

from mathoptinterface.jl.

odow avatar odow commented on August 16, 2024

@blegat I think this one is for you. I really don't understand the ins and outs of call_in_context. I poke one bit and some unrelated stuff starts erroring.

from mathoptinterface.jl.

odow avatar odow commented on August 16, 2024

I swear I tested this:

julia> using JuMP, Clarabel

julia> model = Model(Clarabel.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Clarabel

julia> set_silent(model)

julia> @variable(model, x >= 1)
x

julia> @constraint(model, c, 2x == 3)
c : 2 x = 3

julia> optimize!(model)

julia> value(x)
1.4999999999999996

julia> b = normalized_rhs(c)
3.0

julia> set_normalized_rhs(c, b)

julia> optimize!(model)

julia> value(x)
0.9999999995620605

(clarabel) pkg> st
Status `/private/tmp/clarabel/Project.toml`
  [61c947e1] Clarabel v0.7.1
  [4076af6c] JuMP v1.21.0
  [b8f27783] MathOptInterface v1.27.1 `https://github.com/jump-dev/MathOptInterface.jl.git#master`

from mathoptinterface.jl.

odow avatar odow commented on August 16, 2024

Closed by #2472

from mathoptinterface.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.