Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 4, 2024
1 parent 1c5844a commit 972d453
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions src/macros/@constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -600,18 +600,27 @@ julia> @constraint(model, A * x >= b)
struct Nonnegatives end

"""
GreaterThanMacroSet()
GreaterThanZero()
A struct used to intercept `>=` when used in macros.
A struct used to intercept when `>=` or `≥` is used in a macro via
[`operator_to_set`](@ref).
This is not the same as [`Nonnegatives`](@ref) so that we can disambiguate
This struct is not the same as [`Nonnegatives`](@ref) so that we can disambiguate
`x >= y` and `x - y in Nonnegatives()`.
This struct is not intended for general usage, but it may be useful to some
JuMP extensions.
## Example
```jldoctest
julia> operator_to_set(error, Val(:>=))
GreaterThanZero()
```
"""
struct GreaterThanMacroSet end
struct GreaterThanZero end

function operator_to_set(::Function, ::Union{Val{:(>=)},Val{:(≥)}})
return GreaterThanMacroSet()
end
operator_to_set(::Function, ::Union{Val{:(>=)},Val{:(≥)}}) = GreaterThanZero()

"""
Nonpositives()
Expand Down Expand Up @@ -643,18 +652,27 @@ julia> @constraint(model, A * x <= b)
struct Nonpositives end

"""
LessThanMacroSet()
GreaterThanZero()
A struct used to intercept `<=` when used in macros.
A struct used to intercept when `<=` or `≤` is used in a macro via
[`operator_to_set`](@ref).
This is not the same as [`Nonpositives`](@ref) so that we can disambiguate
This struct is not the same as [`Nonpositives`](@ref) so that we can disambiguate
`x <= y` and `x - y in Nonpositives()`.
This struct is not intended for general usage, but it may be useful to some
JuMP extensions.
## Example
```jldoctest
julia> operator_to_set(error, Val(:<=))
LessThanZero()
```
"""
struct LessThanMacroSet end
struct LessThanZero end

function operator_to_set(::Function, ::Union{Val{:(<=)},Val{:(≤)}})
return LessThanMacroSet()
end
operator_to_set(::Function, ::Union{Val{:(<=)},Val{:(≤)}}) = LessThanZero()

"""
Zeros()
Expand Down Expand Up @@ -819,7 +837,7 @@ end
function build_constraint(
error_fn::Function,
f,
::GreaterThanMacroSet,
::GreaterThanZero,
args...;
kwargs...,
)
Expand All @@ -829,7 +847,7 @@ end
function build_constraint(
error_fn::Function,
::Union{Matrix,LinearAlgebra.Symmetric,LinearAlgebra.Hermitian},
::GreaterThanMacroSet,
::GreaterThanZero,
)
return error_fn(
"""
Expand Down Expand Up @@ -859,7 +877,7 @@ end
function build_constraint(
error_fn::Function,
f,
::LessThanMacroSet,
::LessThanZero,
args...;
kwargs...,
)
Expand All @@ -869,7 +887,7 @@ end
function build_constraint(
error_fn::Function,
::Union{Matrix,LinearAlgebra.Symmetric,LinearAlgebra.Hermitian},
::LessThanMacroSet,
::LessThanZero,
)
return error_fn(
"""
Expand Down

0 comments on commit 972d453

Please sign in to comment.