Skip to content

Commit

Permalink
Merge 93cf4c7 into b7b865a
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 3, 2020
2 parents b7b865a + 93cf4c7 commit ba73249
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
33 changes: 15 additions & 18 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function test_hygiene_variable()
model_y = Model()
@variable(model_y, y)
err = JuMP.VariableNotOwned(y)

@test_throws err @constraint(model_x, y in MOI.EqualTo(1.0))
@test_throws err @constraint(model_x, [x, y] in MOI.Zeros(2))
@test_throws err @objective(model_x, Min, y)
Expand Down Expand Up @@ -152,7 +152,7 @@ function test_hygiene_attribute()

cy = @constraint(model_y, y in MOI.EqualTo(1.0))
cerr = JuMP.ConstraintNotOwned(cy)

@test_throws err MOI.get(model_x, MOI.VariablePrimalStart(), y)
@test_throws cerr MOI.get(model_x, MOI.ConstraintPrimalStart(), cy)
@test_throws err MOI.set(model_x, MOI.VariablePrimalStart(), y, 1.0)
Expand Down Expand Up @@ -277,24 +277,21 @@ function test_bridges_add_before_con_set_optimizer()
end

function test_bridges_add_after_con_model_optimizer()
error_string = """
Constrained variables in `Nonnegative` are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `Nonnegative` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because:
(1) `MOI.SingleVariable`-in-`Nonnegative` constraints are not supported
(1) `MOI.SingleVariable`-in-`Nonnegative` constraints are not supported because:
Cannot use `MOIB.Constraint.ScalarFunctionizeBridge{Float64,Nonnegative}` because:
(2) `MOI.ScalarAffineFunction{Float64}`-in-`Nonnegative` constraints are not supported
(2) `MOI.ScalarAffineFunction{Float64}`-in-`Nonnegative` constraints are not supported because:
Cannot use `MOIB.Constraint.ScalarSlackBridge{Float64,MOI.ScalarAffineFunction{Float64},Nonnegative}` because:
[1] constrained variables in `Nonnegative` are not supported
"""
error_string = replace(error_string, "Nonnegative" => "Main.TestModels.Nonnegative")
err = ErrorException(error_string)

model = Model(mock_factory)
@variable(model, x)
@test_throws err @constraint(model, x in Nonnegative())
flag = true
try
@constraint(model, x in Nonnegative())
flag = false
catch err
@test err isa ErrorException
# Rather than test a particular bridging error, just check that the
# bridge explanation has been called. The sequence of errors could vary
# between MOI versions.
@test occursin("Nonnegative", err.msg)
@test occursin("are not supported and cannot be bridged", err.msg)
end
@test flag
JuMP.add_bridge(model, NonnegativeBridge)
c = @constraint(model, x in Nonnegative())
JuMP.optimize!(model)
Expand Down
2 changes: 2 additions & 0 deletions test/nonnegative_bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Scalar set of nonnegative numbers.
"""
struct Nonnegative <: MOI.AbstractScalarSet end

MOI.copy(set::Nonnegative) = set

"""
NonnegativeBridge{T}
Expand Down
6 changes: 3 additions & 3 deletions test/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ function model_printing_test(ModelType::Type{<:JuMP.AbstractModel})
@variable(model_1, u[1:3], Bin)
@variable(model_1, fi == 9)
@objective(model_1, Max, a - b + 2a1 - 10x)
@constraint(model_1, con, a + b - 10c - 2x + c1 <= 1)
@constraint(model_1, con, a + b - 10c + c1 - 2x <= 1)
@constraint(model_1, a*b <= 2)
@constraint(model_1, soc, [1 - a; u] in SecondOrderCone())
@constraint(model_1, [a b; c x] in PSDCone())
Expand All @@ -403,7 +403,7 @@ function model_printing_test(ModelType::Type{<:JuMP.AbstractModel})
io_test(REPLMode, model_1, """
Max a - b + 2 a1 - 10 x
Subject to
con : a + b - 10 c - 2 x + c1 $le 1.0
con : a + b - 10 c + c1 - 2 x $le 1.0
a*b $le 2.0
[a b;
b x] $inset PSDCone()
Expand Down Expand Up @@ -453,7 +453,7 @@ function model_printing_test(ModelType::Type{<:JuMP.AbstractModel})

io_test(IJuliaMode, model_1, """
\\begin{alignat*}{1}\\max\\quad & a - b + 2 a1 - 10 x\\\\
\\text{Subject to} \\quad & a + b - 10 c - 2 x + c1 \\leq 1.0\\\\
\\text{Subject to} \\quad & a + b - 10 c + c1 - 2 x \\leq 1.0\\\\
& a\\times b \\leq 2.0\\\\
& \\begin{bmatrix}
a & b\\\\
Expand Down

0 comments on commit ba73249

Please sign in to comment.