Skip to content

Commit bd29c19

Browse files
committed
Change MOA.SolutionLimit to be an alias for MOA.SolutionLimit
1 parent eee9a90 commit bd29c19

File tree

10 files changed

+54
-53
lines changed

10 files changed

+54
-53
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Combinatorics = "1"
1818
HiGHS = "1"
1919
Ipopt = "1"
2020
JSON = "0.21"
21-
MathOptInterface = "1.19"
21+
MathOptInterface = "1.21"
2222
Polyhedra = "0.8"
2323
Test = "1"
2424
julia = "1.10"
@@ -27,8 +27,8 @@ julia = "1.10"
2727
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
2828
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
2929
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
30-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3130
Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
31+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3232

3333
[targets]
34-
test = ["HiGHS", "Ipopt", "JSON", "Test", "Polyhedra"]
34+
test = ["HiGHS", "Ipopt", "JSON", "Polyhedra", "Test"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import HiGHS
3737
import MultiObjectiveAlgorithms as MOA
3838
model = JuMP.Model(() -> MOA.Optimizer(HiGHS.Optimizer))
3939
set_attribute(model, MOA.Algorithm(), MOA.Dichotomy())
40-
set_attribute(model, MOA.SolutionLimit(), 4)
40+
set_attribute(model, MOI.SolutionLimit(), 4)
4141
```
4242

4343
For worked examples, see the [Simple multi-objective examples](https://jump.dev/JuMP.jl/stable/tutorials/linear/multi_objective_examples/)
@@ -82,7 +82,7 @@ the solution process.
8282
* `MOA.ObjectivePriority(index::Int)`
8383
* `MOA.ObjectiveRelativeTolerance(index::Int)`
8484
* `MOA.ObjectiveWeight(index::Int)`
85-
* `MOA.SolutionLimit()`
85+
* `MOI.SolutionLimit()`
8686
* `MOI.TimeLimitSec()`
8787

8888
Query the number of scalar subproblems that were solved using

src/MultiObjectiveAlgorithms.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,9 @@ function MOI.get(model::Optimizer, attr::AbstractAlgorithmAttribute)
263263
return MOI.get(model.algorithm, attr)
264264
end
265265

266-
"""
267-
SolutionLimit <: AbstractAlgorithmAttribute -> Int
268-
269-
Terminate the algorithm once the set number of solutions have been found.
270-
271-
Defaults to `typemax(Int)`.
272-
"""
273-
struct SolutionLimit <: AbstractAlgorithmAttribute end
266+
const SolutionLimit = MOI.SolutionLimit
274267

275-
default(::SolutionLimit) = typemax(Int)
268+
default(::MOI.SolutionLimit) = typemax(Int)
276269

277270
"""
278271
ObjectivePriority(index::Int) <: AbstractAlgorithmAttribute -> Int

src/algorithms/Dichotomy.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Science 25(1), 73-78.
1616
* `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
1717
list of current solutions.
1818
19-
* `MOA.SolutionLimit()`: terminate once this many solutions have been found.
19+
* `MOI.SolutionLimit()`: terminate once this many solutions have been found.
2020
"""
2121
mutable struct Dichotomy <: AbstractAlgorithm
2222
solution_limit::Union{Nothing,Int}
@@ -39,18 +39,18 @@ trade‐offs: An algorithm for bicriterion problems. Water Resources Research,
3939
4040
## Supported optimizer attributes
4141
42-
* `MOA.SolutionLimit()`
42+
* `MOI.SolutionLimit()`
4343
"""
4444
NISE() = Dichotomy()
4545

46-
MOI.supports(::Dichotomy, ::SolutionLimit) = true
46+
MOI.supports(::Dichotomy, ::MOI.SolutionLimit) = true
4747

48-
function MOI.set(alg::Dichotomy, ::SolutionLimit, value)
48+
function MOI.set(alg::Dichotomy, ::MOI.SolutionLimit, value)
4949
alg.solution_limit = value
5050
return
5151
end
5252

53-
function MOI.get(alg::Dichotomy, attr::SolutionLimit)
53+
function MOI.get(alg::Dichotomy, attr::MOI.SolutionLimit)
5454
return something(alg.solution_limit, default(alg, attr))
5555
end
5656

@@ -100,7 +100,7 @@ function optimize_multiobjective!(algorithm::Dichotomy, model::Optimizer)
100100
if !(solutions[0.0] solutions[1.0])
101101
push!(queue, (0.0, 1.0))
102102
end
103-
limit = MOI.get(algorithm, SolutionLimit())
103+
limit = MOI.get(algorithm, MOI.SolutionLimit())
104104
status = MOI.OPTIMAL
105105
while length(queue) > 0 && length(solutions) < limit
106106
if (ret = _check_premature_termination(model, start_time)) !== nothing

src/algorithms/EpsilonConstraint.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ bi-objective programs.
1616
default is `1`, so that for a pure integer program this algorithm will
1717
enumerate all non-dominated solutions.
1818
19-
* `MOA.SolutionLimit()`: if this attribute is set then, instead of using the
19+
* `MOI.SolutionLimit()`: if this attribute is set then, instead of using the
2020
`MOA.EpsilonConstraintStep`, with a slight abuse of notation,
2121
`EpsilonConstraint` divides the width of the first-objective's domain in
22-
objective space by `SolutionLimit` to obtain the epsilon to use when
23-
iterating. Thus, there can be at most `SolutionLimit` solutions returned, but
24-
there may be fewer.
22+
objective space by `MOI.SolutionLimit` to obtain the epsilon to use when
23+
iterating. Thus, there can be at most `MOI.SolutionLimit` solutions returned,
24+
but there may be fewer.
25+
26+
* `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
27+
list of current solutions.
2528
"""
2629
mutable struct EpsilonConstraint <: AbstractAlgorithm
2730
solution_limit::Union{Nothing,Int}
@@ -30,14 +33,14 @@ mutable struct EpsilonConstraint <: AbstractAlgorithm
3033
EpsilonConstraint() = new(nothing, nothing)
3134
end
3235

33-
MOI.supports(::EpsilonConstraint, ::SolutionLimit) = true
36+
MOI.supports(::EpsilonConstraint, ::MOI.SolutionLimit) = true
3437

35-
function MOI.set(alg::EpsilonConstraint, ::SolutionLimit, value)
38+
function MOI.set(alg::EpsilonConstraint, ::MOI.SolutionLimit, value)
3639
alg.solution_limit = value
3740
return
3841
end
3942

40-
function MOI.get(alg::EpsilonConstraint, attr::SolutionLimit)
43+
function MOI.get(alg::EpsilonConstraint, attr::MOI.SolutionLimit)
4144
return something(alg.solution_limit, default(alg, attr))
4245
end
4346

@@ -91,8 +94,8 @@ function minimize_multiobjective!(
9194
model.ideal_point .= min.(solution_1[1].y, solution_2[1].y)
9295
# Compute the epsilon that we will be incrementing by each iteration
9396
ε = MOI.get(algorithm, EpsilonConstraintStep())
94-
n_points = MOI.get(algorithm, SolutionLimit())
95-
if n_points != default(algorithm, SolutionLimit())
97+
n_points = MOI.get(algorithm, MOI.SolutionLimit())
98+
if n_points != default(algorithm, MOI.SolutionLimit())
9699
ε = abs(right - left) / (n_points - 1)
97100
end
98101
solutions = SolutionPoint[only(solution_1), only(solution_2)]

src/algorithms/RandomWeighting.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ random weights.
1414
* `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
1515
list of current solutions.
1616
17-
* `MOA.SolutionLimit()`: terminate once this many solutions have been found.
17+
* `MOI.SolutionLimit()`: terminate once this many solutions have been found.
1818
1919
At least one of these two limits must be set.
2020
"""
@@ -23,21 +23,21 @@ mutable struct RandomWeighting <: AbstractAlgorithm
2323
RandomWeighting() = new(nothing)
2424
end
2525

26-
MOI.supports(::RandomWeighting, ::SolutionLimit) = true
26+
MOI.supports(::RandomWeighting, ::MOI.SolutionLimit) = true
2727

28-
function MOI.set(alg::RandomWeighting, ::SolutionLimit, value)
28+
function MOI.set(alg::RandomWeighting, ::MOI.SolutionLimit, value)
2929
alg.solution_limit = value
3030
return
3131
end
3232

33-
function MOI.get(alg::RandomWeighting, attr::SolutionLimit)
33+
function MOI.get(alg::RandomWeighting, attr::MOI.SolutionLimit)
3434
return something(alg.solution_limit, default(alg, attr))
3535
end
3636

3737
function optimize_multiobjective!(algorithm::RandomWeighting, model::Optimizer)
3838
if MOI.get(model, MOI.TimeLimitSec()) === nothing &&
3939
algorithm.solution_limit === nothing
40-
error("At least `MOI.TimeLimitSec` or `MOA.SolutionLimit` must be set")
40+
error("At least `MOI.TimeLimitSec` or `MOI.SolutionLimit` must be set")
4141
end
4242
start_time = time()
4343
solutions = SolutionPoint[]

test/algorithms/Dichotomy.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ end
2828
function test_Dichotomy_SolutionLimit()
2929
model = MOA.Optimizer(HiGHS.Optimizer)
3030
MOI.set(model, MOA.Algorithm(), MOA.Dichotomy())
31-
@test MOI.supports(MOA.Dichotomy(), MOA.SolutionLimit())
32-
@test MOI.supports(model, MOA.SolutionLimit())
33-
@test MOI.get(model, MOA.SolutionLimit()) ==
34-
MOA.default(MOA.SolutionLimit())
35-
MOI.set(model, MOA.SolutionLimit(), 1)
36-
@test MOI.get(model, MOA.SolutionLimit()) == 1
31+
@test MOI.supports(MOA.Dichotomy(), MOI.SolutionLimit())
32+
@test MOI.supports(model, MOI.SolutionLimit())
33+
@test MOI.get(model, MOI.SolutionLimit()) ==
34+
MOA.default(MOI.SolutionLimit())
35+
MOI.set(model, MOI.SolutionLimit(), 1)
36+
@test MOI.get(model, MOI.SolutionLimit()) == 1
3737
return
3838
end
3939

@@ -371,7 +371,7 @@ function test_quadratic()
371371
N = 2
372372
model = MOA.Optimizer(Ipopt.Optimizer)
373373
MOI.set(model, MOA.Algorithm(), MOA.Dichotomy())
374-
MOI.set(model, MOA.SolutionLimit(), 10)
374+
MOI.set(model, MOI.SolutionLimit(), 10)
375375
MOI.set(model, MOI.Silent(), true)
376376
w = MOI.add_variables(model, N)
377377
MOI.add_constraint.(model, w, MOI.GreaterThan(0.0))

test/algorithms/EpsilonConstraint.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function test_biobjective_knapsack()
4040
w = [80, 87, 68, 72, 66, 77, 99, 85, 70, 93, 98, 72, 100, 89, 67, 86, 91]
4141
model = MOA.Optimizer(HiGHS.Optimizer)
4242
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
43-
MOI.set(model, MOA.SolutionLimit(), 100)
43+
MOI.set(model, MOI.SolutionLimit(), 100)
4444
MOI.set(model, MOI.Silent(), true)
4545
x = MOI.add_variables(model, length(w))
4646
MOI.add_constraint.(model, x, MOI.ZeroOne())
@@ -170,7 +170,7 @@ function test_biobjective_knapsack_min()
170170
w = [80, 87, 68, 72, 66, 77, 99, 85, 70, 93, 98, 72, 100, 89, 67, 86, 91]
171171
model = MOA.Optimizer(HiGHS.Optimizer)
172172
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
173-
MOI.set(model, MOA.SolutionLimit(), 100)
173+
MOI.set(model, MOI.SolutionLimit(), 100)
174174
MOI.set(model, MOI.Silent(), true)
175175
x = MOI.add_variables(model, length(w))
176176
MOI.add_constraint.(model, x, MOI.ZeroOne())
@@ -215,8 +215,8 @@ function test_biobjective_knapsack_min_solution_limit()
215215
w = [80, 87, 68, 72, 66, 77, 99, 85, 70, 93, 98, 72, 100, 89, 67, 86, 91]
216216
model = MOA.Optimizer(HiGHS.Optimizer)
217217
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
218-
@test MOI.supports(model, MOA.SolutionLimit())
219-
MOI.set(model, MOA.SolutionLimit(), 3)
218+
@test MOI.supports(model, MOI.SolutionLimit())
219+
MOI.set(model, MOI.SolutionLimit(), 3)
220220
MOI.set(model, MOI.Silent(), true)
221221
x = MOI.add_variables(model, length(w))
222222
MOI.add_constraint.(model, x, MOI.ZeroOne())
@@ -315,7 +315,7 @@ function test_quadratic()
315315
N = 2
316316
model = MOA.Optimizer(Ipopt.Optimizer)
317317
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
318-
MOI.set(model, MOA.SolutionLimit(), 10)
318+
MOI.set(model, MOI.SolutionLimit(), 10)
319319
MOI.set(model, MOI.Silent(), true)
320320
w = MOI.add_variables(model, N)
321321
MOI.add_constraint.(model, w, MOI.GreaterThan(0.0))
@@ -343,7 +343,7 @@ function test_poor_numerics()
343343
N = 2
344344
model = MOA.Optimizer(Ipopt.Optimizer)
345345
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
346-
MOI.set(model, MOA.SolutionLimit(), 10)
346+
MOI.set(model, MOI.SolutionLimit(), 10)
347347
MOI.set(model, MOI.Silent(), true)
348348
w = MOI.add_variables(model, N)
349349
sharpe = MOI.add_variable(model)
@@ -387,7 +387,7 @@ function test_vectornonlinearfunction()
387387
N = 2
388388
model = MOA.Optimizer(Ipopt.Optimizer)
389389
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
390-
MOI.set(model, MOA.SolutionLimit(), 10)
390+
MOI.set(model, MOI.SolutionLimit(), 10)
391391
MOI.set(model, MOI.Silent(), true)
392392
w = MOI.add_variables(model, N)
393393
MOI.add_constraint.(model, w, MOI.GreaterThan(0.0))

test/algorithms/RandomWeighting.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function test_error_attribute()
3333
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
3434
@test_throws(
3535
ErrorException(
36-
"At least `MOI.TimeLimitSec` or `MOA.SolutionLimit` must be set",
36+
"At least `MOI.TimeLimitSec` or `MOI.SolutionLimit` must be set",
3737
),
3838
MOI.optimize!(model),
3939
)
@@ -50,7 +50,7 @@ function test_knapsack_min()
5050
w = Float64[557, 898, 148, 63, 78, 964, 246, 662, 386, 272]
5151
model = MOA.Optimizer(HiGHS.Optimizer)
5252
MOI.set(model, MOA.Algorithm(), MOA.RandomWeighting())
53-
MOI.set(model, MOA.SolutionLimit(), 3)
53+
MOI.set(model, MOI.SolutionLimit(), 3)
5454
MOI.set(model, MOI.Silent(), true)
5555
x = MOI.add_variables(model, n)
5656
MOI.add_constraint.(model, x, MOI.ZeroOne())
@@ -97,7 +97,7 @@ function test_knapsack_max()
9797
w = Float64[557, 898, 148, 63, 78, 964, 246, 662, 386, 272]
9898
model = MOA.Optimizer(HiGHS.Optimizer)
9999
MOI.set(model, MOA.Algorithm(), MOA.RandomWeighting())
100-
MOI.set(model, MOA.SolutionLimit(), 3)
100+
MOI.set(model, MOI.SolutionLimit(), 3)
101101
MOI.set(model, MOI.Silent(), true)
102102
x = MOI.add_variables(model, n)
103103
MOI.add_constraint.(model, x, MOI.ZeroOne())
@@ -174,8 +174,8 @@ function test_unbounded()
174174
model = MOA.Optimizer(HiGHS.Optimizer)
175175
MOI.set(model, MOA.Algorithm(), MOA.RandomWeighting())
176176
MOI.set(model, MOI.Silent(), true)
177-
@test MOI.supports(model, MOA.SolutionLimit())
178-
MOI.set(model, MOA.SolutionLimit(), 10)
177+
@test MOI.supports(model, MOI.SolutionLimit())
178+
MOI.set(model, MOI.SolutionLimit(), 10)
179179
x = MOI.add_variables(model, 2)
180180
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
181181
f = MOI.Utilities.operate(vcat, Float64, 1.0 .* x...)

test/test_model.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ function test_check_interrupt()
234234
return
235235
end
236236

237+
function test_SolutionLimit()
238+
@test MOI.SolutionLimit === MOA.SolutionLimit
239+
return
240+
end
241+
237242
end # module
238243

239244
TestModel.run_tests()

0 commit comments

Comments
 (0)