Skip to content
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

Fix model_convert for BridgeableConstraint #3437

Merged
merged 2 commits into from
Jul 29, 2023
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
3 changes: 2 additions & 1 deletion src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,8 @@ end
function model_convert(model::AbstractModel, con::BridgeableConstraint)
return BridgeableConstraint(
model_convert(model, con.constraint),
con.bridge_type,
con.bridge_type;
con.coefficient_type,
)
end

Expand Down
16 changes: 16 additions & 0 deletions test/nonnegative_bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ struct Nonnegative <: MOI.AbstractScalarSet end

MOI.copy(set::Nonnegative) = set

struct BridgeMe{T,S}
set::S
end

function JuMP.build_constraint(
error::Function,
f,
set::BridgeMe{T,Nonnegative},
) where {T}
return BridgeableConstraint(
JuMP.build_constraint(error, f, set.set),
NonnegativeBridge;
coefficient_type = T,
)
end

"""
NonnegativeBridge{T}
Expand Down
7 changes: 7 additions & 0 deletions test/test_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ function test_bridges_add_bridgeable_con_model_optimizer()
@test 2.0 == @inferred dual(c)
end

function test_macro_bridgeable()
model = Model()
@variable(model, x)
@constraint(model, x in BridgeMe{Int,Nonnegative}(Nonnegative()))
@test NonnegativeBridge{Int} in model.bridge_types
end

function test_bridges_add_bridgeable_con_set_optimizer()
model = Model()
@variable(model, x)
Expand Down
Loading