Skip to content
Merged
Show file tree
Hide file tree
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
37 changes: 6 additions & 31 deletions src/Bridges/Constraint/zero_one.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ function bridge_constraint(
return ZeroOneBridge{T}(interval_index, integer_index)
end

function MOIB.added_constraint_types(::Type{<:ZeroOneBridge{T}}) where {T}
function MOI.Bridges.added_constraint_types(
::Type{<:ZeroOneBridge{T}},
) where {T}
return Tuple{Type,Type}[
(MOI.VariableIndex, MOI.Interval{T}),
(MOI.VariableIndex, MOI.Integer),
]
end

function MOIB.added_constrained_variable_types(::Type{<:ZeroOneBridge})
function MOI.Bridges.added_constrained_variable_types(::Type{<:ZeroOneBridge})
return Tuple{Type}[]
end

Expand All @@ -49,14 +51,7 @@ function MOI.supports_constraint(
return true
end

# Attributes, Bridge acting as a constraint
function MOI.get(
model::MOI.ModelLike,
attr::MOI.ConstraintSet,
bridge::ZeroOneBridge,
)
return MOI.ZeroOne()
end
MOI.get(::MOI.ModelLike, ::MOI.ConstraintSet, ::ZeroOneBridge) = MOI.ZeroOne()

function MOI.get(
model::MOI.ModelLike,
Expand All @@ -74,32 +69,12 @@ end

function MOI.get(
model::MOI.ModelLike,
attr::Union{MOI.ConstraintPrimal,MOI.ConstraintPrimalStart},
attr::Union{MOI.ConstraintPrimal},
bridge::ZeroOneBridge,
)
return MOI.get(model, attr, bridge.interval_index)
end

function MOI.supports(
::MOI.ModelLike,
::MOI.ConstraintPrimalStart,
::Type{<:ZeroOneBridge},
)
return true
end

function MOI.set(
model::MOI.ModelLike,
attr::MOI.ConstraintPrimalStart,
bridge::ZeroOneBridge{T},
value,
) where {T}
MOI.set(model, attr, bridge.integer_index, value)
MOI.set(model, attr, bridge.interval_index, value)
Copy link
Member Author

Choose a reason for hiding this comment

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

@blegat does ConstraintPrimalStart make sense for a ZeroOne constraint?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, a ConstraintPrimalStart is the starting value of the function. It's well-defined for all constraints

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. But does any solver actually implement it...

Copy link
Member

Choose a reason for hiding this comment

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

Since most solvers only support VariableIndex-in-Integer, and setting the starting value of this is a bit redundant, I don't think so. However, if a solver want to implemented ScalarAffineFunction in Integer, they will need this.

Copy link
Member Author

@odow odow Sep 5, 2021

Choose a reason for hiding this comment

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

To rephrase: in what situation would a solver benefit from being able to set ConstraintPrimalStart of a ZeroOne constraint.

There's a lot of stuff in MOI that is there "just because" without a good reason. Not that we shouldn't add some of the stuff. But if no one is ever going to call it, we shouldn't rush to add code. It's an overhead for everyone.

return
end

# Attributes, Bridge acting as a model
function MOI.get(
::ZeroOneBridge{T},
::MOI.NumberOfConstraints{MOI.VariableIndex,MOI.Interval{T}},
Expand Down
8 changes: 0 additions & 8 deletions test/Bridges/Constraint/zero_one.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ function test_ZeroOne()
MOI.VariableIndex,
MOI.ZeroOne,
) == bridge_type

@test MOI.supports(bridged_mock, MOI.ConstraintPrimalStart(), bridge_type)
MOI.Test.test_basic_VariableIndex_ZeroOne(bridged_mock, config)
MOI.empty!(bridged_mock)
MOI.Utilities.set_mock_optimize!(
Expand Down Expand Up @@ -81,12 +79,6 @@ function test_ZeroOne()
MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.ZeroOne}(),
),
)
for attr in [MOI.ConstraintPrimalStart()]
@test MOI.supports(bridged_mock, attr, typeof(ci))
value = 1.0
MOI.set(bridged_mock, attr, ci, value)
@test MOI.get(bridged_mock, attr, ci) ≈ value
end
s = """
variables: x, y
y == 1.0
Expand Down