Skip to content

Commit

Permalink
Fix model_convert for BridgeableConstraint (#3437)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 29, 2023
1 parent 72b91d7 commit 0ba286e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/macros.jl
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
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
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

0 comments on commit 0ba286e

Please sign in to comment.