-
Notifications
You must be signed in to change notification settings - Fork 27
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
[feature] Support MOI.VectorAffineFunction #170
Comments
It is already supported through bridges: Line 21 in 3b289dd
full_bridge_optimizer adds many bridges including http://www.juliaopt.org/MathOptInterface.jl/dev/apireference/#MathOptInterface.Bridges.ScalarizeBridge which transforms VectorAffineFunction to ScalarAffineFunction .
|
@blegat Thanks. My problem seems to be that I haven't been able to understand the manual of MOI... To be concrete, consider the linear program max c x s.t. A x <= b, where A = [1 1; -1 0; 0 -1]
b = [1, 0, 0]
c = [1, 0] Let's use T = Float64 # or Rational{BigInt}
optimizer = CDDLib.Optimizer{T}()
x = MOI.add_variables(optimizer, length(c))
MOI.set(optimizer, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
MOI.ScalarAffineFunction{T}(MOI.ScalarAffineTerm{T}.(c, x), 0))
MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MAX_SENSE) I know the following works: for i in 1:size(A, 1)
MOI.add_constraint(
optimizer,
MOI.ScalarAffineFunction{T}(
MOI.ScalarAffineTerm{T}.(A[i, :], x), 0
),
MOI.LessThan{T}(b[i])
)
end MOI.optimize!(optimizer)
But it feels a bit stupid to pass the content of the matrix MOI.add_constraint(
optimizer,
MOI.VectorAffineFunction{T}(A, -b),
MOI.Nonpositives(length(b))
)
|
See this discourse post for how to formulate the constraint with VectorAffineFunction. |
Ah sorry, I should have read that thread carefully. Now the issue seems to be that T = Float64 # or Rational{BigInt}
optimizer = CDDLib.Optimizer{T}()
x = MOI.add_variables(optimizer, length(c))
MOI.set(optimizer, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
MOI.ScalarAffineFunction{T}(MOI.ScalarAffineTerm{T}.(c, x), 0))
MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MAX_SENSE)
terms = MOI.VectorAffineTerm{T}.(
1:size(A, 1), MOI.ScalarAffineTerm{T}.(A, reshape(x, 1, length(x)))
)
f = MOI.VectorAffineFunction{T}(vec(terms), -b)
MOI.add_constraint(optimizer, f, MOI.Nonpositives(size(A, 1)))
|
You should do |
Great, that works now. In PR #171 I added a description of the usage to the documentation. |
Would it be costly to support
MOI.VectorAffineFunction
also?Polyhedra.jl/src/lphrep.jl
Lines 3 to 5 in 3b289dd
The text was updated successfully, but these errors were encountered: