Skip to content
Permalink
Browse files

[style] re-export build_constraint macro

  • Loading branch information...
odow committed Jan 28, 2019
1 parent 89fea3f commit 2f4c215962d9888517b107bf3122f3388e12e15e
Showing with 14 additions and 14 deletions.
  1. +1 −1 docs/src/constraints.md
  2. +3 −3 src/macros.jl
  3. +10 −10 test/macros.jl
@@ -624,5 +624,5 @@ ConstraintRef
For advanced use cases.

```@docs
JuMP.@_build_constraint
@build_constraint
```
@@ -714,7 +714,7 @@ macro SDconstraint(args...)
end

"""
@_build_constraint(constraint_expr)
@build_constraint(constraint_expr)
Constructs a `ScalarConstraint` or `VectorConstraint` using the same
machinery as [`@constraint`](@ref) but without adding the constraint to a model.
@@ -727,12 +727,12 @@ create arrays of `ScalarConstraint` or `VectorConstraint`.
```jldoctest; setup = :(using JuMP)
model = Model();
@variable(model, x);
@_build_constraint(2x >= 1)
@build_constraint(2x >= 1)
# output
ScalarConstraint{GenericAffExpr{Float64,VariableRef},MathOptInterface.GreaterThan{Float64}}(2 x, MathOptInterface.GreaterThan{Float64}(1.0))
"""
macro _build_constraint(constraint_expr)
macro build_constraint(constraint_expr)
_error(str...) = _macro_error(:_build_constraint, args, str...)

if isa(constraint_expr, Symbol)
@@ -240,29 +240,29 @@ function macros_test(ModelType::Type{<:JuMP.AbstractModel}, VariableRefType::Typ
@test c.set == MOI.Interval(0.0, 1.0)
end

@testset "@_build_constraint (scalar inequality)" begin
@testset "@build_constraint (scalar inequality)" begin
model = ModelType()
@variable(model, x)
con = JuMP.@_build_constraint(3x == 1)
con = @build_constraint(3x == 1)
@test con isa JuMP.ScalarConstraint
@test JuMP.isequal_canonical(con.func, 3x)
@test con.set == MOI.EqualTo(1.0)
end

@testset "@_build_constraint (function-in-set)" begin
@testset "@build_constraint (function-in-set)" begin
model = ModelType()
@variable(model, x[1:2])
con = JuMP.@_build_constraint(x in JuMP.SecondOrderCone())
con = @build_constraint(x in JuMP.SecondOrderCone())
@test con isa JuMP.VectorConstraint
@test con.func == x
@test con.set == MOI.SecondOrderCone(2)
end

@testset "@_build_constraint (broadcast)" begin
@testset "@build_constraint (broadcast)" begin
model = ModelType()
@variable(model, x[1:2])
ub = [1.0, 2.0]
con = JuMP.@_build_constraint(x .<= ub)
con = @build_constraint(x .<= ub)
@test con isa Vector{<:JuMP.ScalarConstraint}
@test JuMP.isequal_canonical(con[1].func, 1.0x[1])
@test JuMP.isequal_canonical(con[2].func, 1.0x[2])
@@ -383,12 +383,12 @@ end
model = Model()
@variable(model, x)
foo() = 2
con1 = JuMP.@_build_constraint(x^(foo()) + x^(foo()-1) +
con1 = @build_constraint(x^(foo()) + x^(foo()-1) +
x^(foo()-2) == 0)
con2 = JuMP.@_build_constraint((x - 1)^(foo()) + (x - 1)^2 + (x - 1)^1 +
con2 = @build_constraint((x - 1)^(foo()) + (x - 1)^2 + (x - 1)^1 +
(x - 1)^0 == 0)
con3 = JuMP.@_build_constraint(sum(x for i in 1:3)^(foo()) == 0)
con4 = JuMP.@_build_constraint(sum(x for i in 1:3)^(foo() - 1) == 0)
con3 = @build_constraint(sum(x for i in 1:3)^(foo()) == 0)
con4 = @build_constraint(sum(x for i in 1:3)^(foo() - 1) == 0)
@test con1.func == x^2 + x
@test con2.func == 2 * x^2 - 3 * x
@test con3.func == 9 * x^2

0 comments on commit 2f4c215

Please sign in to comment.
You can’t perform that action at this time.