Skip to content
Closed
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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
- version: '1' # The latest point-release (Windows)
os: windows-latest
arch: x64
- version: '1.10' # 1.10 LTS (64-bit Linux)
os: ubuntu-latest
arch: x64
- version: '1.10' # 1.10 LTS (32-bit Linux)
os: ubuntu-latest
arch: x86
# - version: '1.10' # 1.10 LTS (64-bit Linux)
# os: ubuntu-latest
# arch: x64
# - version: '1.10' # 1.10 LTS (32-bit Linux)
# os: ubuntu-latest
# arch: x86
- version: 'nightly'
os: ubuntu-latest
arch: x64
Expand Down
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DimensionalData", "ParallelTestRunner", "Test"]

[sources]
MathOptInterface = {url = "https://github.com/jump-dev/MathOptInterface.jl", rev = "od/lazy-scalar-set"}
5 changes: 4 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ LinearOperatorCollection = "2.4.1"
Literate = "2.21.0"
MarkdownAST = "0.1.3"
MathOptChordalDecomposition = "=0.2.0"
MathOptInterface = "=1.49.0"
MathOptInterface = "1"
MultiObjectiveAlgorithms = "=1.9.0"
PATHSolver = "=1.7.9"
ParametricOptInterface = "0.15.0"
Expand All @@ -86,3 +86,6 @@ SpecialFunctions = "2.7.1"
StatsPlots = "0.15.8"
Tables = "1.12.1"
Wavelets = "0.10.1"

[sources]
MathOptInterface = {url = "https://github.com/jump-dev/MathOptInterface.jl", rev = "od/lazy-scalar-set"}
34 changes: 34 additions & 0 deletions src/macros/@constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1171,3 +1171,37 @@ function build_constraint(
MOI.SOS2{value_type(variable_ref_type(T))}(set.weights),
)
end

"""
Lazy()

A constraint tag to indicate that the constraint should be treated as a lazy
constraint by the solver.

## Example

```julia
julia> model = Model();

julia> @variable(model, x);

julia> @constraint(model, 2x >= 0, Lazy())
2 x ≥ 0 [lazy]
```
"""
struct Lazy end

Base.broadcastable(::Lazy) = Ref(Lazy())

function build_constraint(
error_fn::Function,
f::AbstractJuMPScalar,
s::MOI.AbstractScalarSet,
::Lazy,
)
return build_constraint(error_fn, f, MOI.LazyScalarSet(s))
end

function model_convert(model::AbstractModel, set::MOI.LazyScalarSet)
return MOI.LazyScalarSet(model_convert(model, set.set))
end
8 changes: 8 additions & 0 deletions src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,14 @@ function in_set_string(
end
end

function in_set_string(mime::MIME"text/plain", set::MOI.LazyScalarSet)
return in_set_string(mime, set.set) * " [lazy]"
end

function in_set_string(mime::MIME"text/latex", set::MOI.LazyScalarSet)
return in_set_string(mime, set.set) * "\\quad[lazy]"
end

"""
in_set_string(mode::MIME, constraint::AbstractConstraint)

Expand Down
15 changes: 15 additions & 0 deletions test/test_constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2246,4 +2246,19 @@ function test_reshape_vector_nothing()
return
end

function test_lazy_constraint_tag()
model = GenericModel{Float32}()
@variable(model, x)
c = @constraint(model, x >= 0, Lazy())
o = constraint_object(c)
@test o.set == MOI.LazyScalarSet(MOI.GreaterThan{Float32}(0.0))
@variable(model, y[1:3])
d = @constraint(model, y .>= (1:3), Lazy())
o = constraint_object.(d)
for i in 1:3
@test o[i].set == MOI.LazyScalarSet(MOI.GreaterThan{Float32}(i))
end
return
end

end # module
11 changes: 11 additions & 0 deletions test/test_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1186,4 +1186,15 @@ function test_solver_name_not_implemented()
return
end

function test_print_lazy_scalar_set()
model = Model()
@variable(model, x)
c = @constraint(model, 2x >= 0, Lazy())
ge = JuMP._math_symbol(MIME("text/plain"), :geq)
@test sprint(show, c) == "2 x $ge 0 [lazy]"
@test sprint(io -> show(io, MIME("text/latex"), c)) ==
"\$\$ 2 x \\geq 0\\quad[lazy] \$\$"
return
end

end # TestPrint
Loading