@@ -18,21 +18,7 @@ random weights.
1818
1919At least one of these two limits must be set.
2020"""
21- mutable struct RandomWeighting <: AbstractAlgorithm
22- solution_limit:: Union{Nothing,Int}
23- RandomWeighting () = new (nothing )
24- end
25-
26- MOI. supports (:: RandomWeighting , :: MOI.SolutionLimit ) = true
27-
28- function MOI. set (alg:: RandomWeighting , :: MOI.SolutionLimit , value)
29- alg. solution_limit = value
30- return
31- end
32-
33- function MOI. get (alg:: RandomWeighting , attr:: MOI.SolutionLimit )
34- return something (alg. solution_limit, default (alg, attr))
35- end
21+ mutable struct RandomWeighting <: AbstractAlgorithm end
3622
3723function optimize_multiobjective! (algorithm:: RandomWeighting , model:: Optimizer )
3824 if MOI. get (model, MOI. TimeLimitSec ()) === nothing &&
@@ -42,39 +28,25 @@ function optimize_multiobjective!(algorithm::RandomWeighting, model::Optimizer)
4228 start_time = time ()
4329 solutions = SolutionPoint[]
4430 sense = MOI. get (model, MOI. ObjectiveSense ())
45- P = MOI. output_dimension (model. f)
4631 variables = MOI. get (model. inner, MOI. ListOfVariableIndices ())
47- f = _scalarise (model. f, ones (P))
48- MOI. set (model. inner, MOI. ObjectiveFunction {typeof(f)} (), f)
49- optimize_inner! (model)
50- status = MOI. get (model. inner, MOI. TerminationStatus ())
51- if _is_scalar_status_optimal (status)
52- X, Y = _compute_point (model, variables, model. f)
53- push! (solutions, SolutionPoint (X, Y))
54- else
55- return status, nothing
56- end
57- # This double loop is a bit weird:
58- # * the inner loop fills up SolutionLimit number of solutions. Then we cut
59- # it back to nondominated.
60- # * then the outer loop goes again
61- while length (solutions) < MOI. get (algorithm, SolutionLimit ())
62- while length (solutions) < MOI. get (algorithm, SolutionLimit ())
63- ret = _check_premature_termination (model, start_time)
64- if ret != = nothing
65- return ret, filter_nondominated (sense, solutions)
66- end
67- weights = rand (P)
68- f = _scalarise (model. f, weights)
69- MOI. set (model. inner, MOI. ObjectiveFunction {typeof(f)} (), f)
70- optimize_inner! (model)
71- status = MOI. get (model. inner, MOI. TerminationStatus ())
72- if _is_scalar_status_optimal (status)
73- X, Y = _compute_point (model, variables, model. f)
74- push! (solutions, SolutionPoint (X, Y))
75- end
32+ limit = something (MOI. get (model, MOI. SolutionLimit ()), typemax (Int))
33+ status = MOI. OPTIMAL
34+ while length (solutions) < limit
35+ if (ret = _check_premature_termination (model, start_time)) != = nothing
36+ status = ret
37+ break
38+ end
39+ weights = rand (MOI. output_dimension (model. f))
40+ f = _scalarise (model. f, weights)
41+ MOI. set (model. inner, MOI. ObjectiveFunction {typeof(f)} (), f)
42+ optimize_inner! (model)
43+ if _is_scalar_status_optimal (model)
44+ X, Y = _compute_point (model, variables, model. f)
45+ push! (solutions, SolutionPoint (X, Y))
46+ end
47+ if length (solutions) == limit
48+ solutions = filter_nondominated (sense, solutions)
7649 end
77- solutions = filter_nondominated (sense, solutions)
7850 end
79- return MOI . OPTIMAL , filter_nondominated (sense, solutions)
51+ return status , filter_nondominated (sense, solutions)
8052end
0 commit comments