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
14 changes: 12 additions & 2 deletions src/Bridges/Constraint/geomean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,19 @@ function MOI.get(
if 2j <= bridge.d
func = MOI.get(model, attr, bridge.rsoc_constraints[offset+j])
func_scalars = MOIU.eachscalar(func)
f_scalars[2j] = func_scalars[1]
# Numerical issues can arise when a VectorOfVariables function
# is turned into a VectorAffineFunction, because the RSOC
# constraints might return something like `0.999999999x` instead
# of exactly `1.0x`. To counteract this, use `convert_approx`.
f_scalars[2j] = MOI.Utilities.convert_approx(
MOI.Utilities.scalar_type(H),
func_scalars[1],
)
if 2j + 1 <= bridge.d
f_scalars[2j+1] = func_scalars[2]
f_scalars[2j+1] = MOI.Utilities.convert_approx(
MOI.Utilities.scalar_type(H),
func_scalars[2],
)
end
end
end
Expand Down
11 changes: 8 additions & 3 deletions src/Test/test_basic_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ function _basic_constraint_test_helper(
### Test MOI.ConstraintFunction
###
if _supports(config, MOI.ConstraintFunction)
@test MOI.get(model, MOI.ConstraintFunction(), c) ≈ constraint_function
@test MOI.get(model, MOI.CanonicalConstraintFunction(), c) ≈
constraint_function
# Don't compare directly, because `f` might not be canonicalized.
f = MOI.get(model, MOI.ConstraintFunction(), c)
@test isapprox(MOI.Utilities.canonical(f), constraint_function, config)
Copy link
Member

Choose a reason for hiding this comment

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

I thought isapprox was canonicalizing already

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. It might have been the isapprox(0 thing then.

@test isapprox(
MOI.get(model, MOI.CanonicalConstraintFunction(), c),
constraint_function,
config,
)
_test_attribute_value_type(model, MOI.ConstraintFunction(), c)
_test_attribute_value_type(model, MOI.CanonicalConstraintFunction(), c)
end
Expand Down