Skip to content

Conversation

odow
Copy link
Member

@odow odow commented May 14, 2021

This fixes a TODO in Bridges and closes #967.

One point is up for debate: can you initialize a zero-dimensional set? What do we do in cases like

  • Nonnegatives(0) => ??
  • SecondOrderCone(1) => t <= 0?

@odow odow mentioned this pull request May 14, 2021
10 tasks
@odow
Copy link
Member Author

odow commented May 14, 2021

Tests are failing because of the following, which neatly summarizes my question:

# Can come from a SOC of dimension 2 which makes more sense
# FIXME should it be moved to contconic or is RSOC of dimension 2 too exotic ?
@testset "RSOC of dimension 2" begin
MOI.empty!(bridged_mock)
xy, cxy = MOI.add_constrained_variables(
bridged_mock,
MOI.RotatedSecondOrderCone(2),
)
x, y = xy
fx = MOI.SingleVariable(x)
fy = MOI.SingleVariable(y)
c = MOI.add_constraint(bridged_mock, 1.0fx + 1.0fy, MOI.LessThan(1.0))
obj = 1.0fy
MOI.set(bridged_mock, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.set(bridged_mock, MOI.ObjectiveFunction{typeof(obj)}(), obj)
mock.optimize! =
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(
mock,
[0.0, 2.0],
#(MOI.VectorOfVariables) => [0.0, 1.0],
(MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) =>
[-1.0],
)
MOI.optimize!(bridged_mock)
@test MOI.get(bridged_mock, MOI.ObjectiveValue()) == 1.0
@test MOI.get(bridged_mock, MOI.DualObjectiveValue()) == 1.0
@test MOI.get(bridged_mock, MOI.VariablePrimal(), xy) == [0.0, 1.0]
@test MOI.get(bridged_mock, MOI.ConstraintPrimal(), cxy) == [0.0, 1.0]
@test MOI.get(bridged_mock, MOI.ConstraintDual(), cxy) == [1.0, 0.0]
@test MOI.get(bridged_mock, MOI.ConstraintPrimal(), c) == 1.0
@test MOI.get(bridged_mock, MOI.ConstraintDual(), c) == -1.0
MOI.set(mock, MOI.ConstraintName(), c, "c")
@testset "Test mock model" begin
var_names = ["a", "b"]
MOI.set(
mock,
MOI.VariableName(),
MOI.get(mock, MOI.ListOfVariableIndices()),
var_names,
)
nonneg = MOI.get(
mock,
MOI.ListOfConstraintIndices{
MOI.VectorOfVariables,
MOI.Nonnegatives,
}(),
)
@test length(nonneg) == 1
MOI.set(mock, MOI.ConstraintName(), nonneg[1], "cab")
s = """
variables: a, b
cab: [a, b] in MathOptInterface.Nonnegatives(2)
c: a + 0.5b <= 1.0
maxobjective: 0.5b
"""
model = MOIU.Model{Float64}()
MOIU.loadfromstring!(model, s)
MOIU.test_models_equal(mock, model, var_names, ["cab", "c"])
end
@testset "Test bridged model" begin
var_names = ["x", "y"]
MOI.set(
bridged_mock,
MOI.VariableName(),
MOI.get(bridged_mock, MOI.ListOfVariableIndices()),
var_names,
)
MOI.set(bridged_mock, MOI.ConstraintName(), cxy, "cxy")
s = """
variables: x, y
cxy: [x, y] in MathOptInterface.RotatedSecondOrderCone(2)
c: x + y <= 1.0
maxobjective: 1.0y
"""
model = MOIU.Model{Float64}()
MOIU.loadfromstring!(model, s)
MOIU.test_models_equal(bridged_mock, model, var_names, ["cxy", "c"])
end
test_delete_bridged_variables(
bridged_mock,
xy,
MOI.RotatedSecondOrderCone,
2,
(
(MOI.VectorOfVariables, MOI.Nonnegatives, 0),
(MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle, 0),
(MOI.SingleVariable, MOI.EqualTo{Float64}, 0),
(MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}, 0),
(MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}, 1),
),
)
end

@odow
Copy link
Member Author

odow commented May 17, 2021

I've relaxed the restriction on the sets where it makes sense. So you can have RotatedSecondOrderCone(2) and NormOneCone(1). But you can't have matrix cones with zero dimensional matrices. And you can't have a 1-dimensional GeometricMeanCone (0th root of zero?).

Thoughts?

@odow odow requested a review from blegat June 10, 2021 03:01
@odow
Copy link
Member Author

odow commented Jun 10, 2021

@blegat how's this? Do they make sense?

@odow
Copy link
Member Author

odow commented Jun 18, 2021

Bump @blegat

@odow odow merged commit 1e2687c into master Jun 20, 2021
@odow odow deleted the od/fix_geomean_error branch June 20, 2021 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add a new error for situation where cone is not defined for the specified dimension
2 participants