@@ -11,6 +11,9 @@ point on the frontier, corresponding to solving each objective in order.
11
11
12
12
## Supported optimizer attributes
13
13
14
+ * `MOI.TimeLimitSec()`: terminate if the time limit is exceeded and return the
15
+ current best solutions.
16
+
14
17
* `MOA.LexicographicAllPermutations()`: Controls whether to return the
15
18
lexicographic solution for all permutations of the scalar objectives (when
16
19
`true`), or only the solution corresponding to the lexicographic solution of
@@ -62,37 +65,54 @@ function MOI.set(alg::Lexicographic, ::LexicographicAllPermutations, val::Bool)
62
65
end
63
66
64
67
function optimize_multiobjective! (algorithm:: Lexicographic , model:: Optimizer )
68
+ start_time = time ()
65
69
sequence = 1 : MOI. output_dimension (model. f)
66
70
if ! MOI. get (algorithm, LexicographicAllPermutations ())
67
- return _solve_in_sequence (algorithm, model, sequence)
71
+ return _solve_in_sequence (algorithm, model, sequence, start_time )
68
72
end
69
73
solutions = SolutionPoint[]
74
+ status = MOI. OPTIMAL
70
75
for sequence in Combinatorics. permutations (sequence)
71
- status, solution = _solve_in_sequence (algorithm, model, sequence)
76
+ status, solution =
77
+ _solve_in_sequence (algorithm, model, sequence, start_time)
78
+ if ! isempty (solution)
79
+ push! (solutions, solution[1 ])
80
+ end
72
81
if ! _is_scalar_status_optimal (status)
73
- return status, nothing
82
+ break
74
83
end
75
- push! (solutions, solution[1 ])
76
84
end
77
85
sense = MOI. get (model. inner, MOI. ObjectiveSense ())
78
- return MOI . OPTIMAL , filter_nondominated (sense, solutions)
86
+ return status , filter_nondominated (sense, solutions)
79
87
end
80
88
81
89
function _solve_in_sequence (
82
90
algorithm:: Lexicographic ,
83
91
model:: Optimizer ,
84
92
sequence:: AbstractVector{Int} ,
93
+ start_time:: Float64 ,
85
94
)
86
95
variables = MOI. get (model. inner, MOI. ListOfVariableIndices ())
87
96
constraints = Any[]
88
97
scalars = MOI. Utilities. eachscalar (model. f)
98
+ solution = SolutionPoint[]
99
+ status = MOI. OPTIMAL
89
100
for i in sequence
101
+ if _time_limit_exceeded (model, start_time)
102
+ status = MOI. TIME_LIMIT
103
+ break
104
+ end
90
105
f = scalars[i]
91
106
MOI. set (model. inner, MOI. ObjectiveFunction {typeof(f)} (), f)
92
107
MOI. optimize! (model. inner)
93
108
status = MOI. get (model. inner, MOI. TerminationStatus ())
109
+ primal_status = MOI. get (model. inner, MOI. PrimalStatus ())
110
+ if _is_scalar_status_feasible_point (primal_status)
111
+ X, Y = _compute_point (model, variables, model. f)
112
+ solution = [SolutionPoint (X, Y)]
113
+ end
94
114
if ! _is_scalar_status_optimal (status)
95
- return status, nothing
115
+ break
96
116
end
97
117
X, Y = _compute_point (model, variables, f)
98
118
rtol = MOI. get (algorithm, ObjectiveRelativeTolerance (i))
@@ -103,9 +123,8 @@ function _solve_in_sequence(
103
123
end
104
124
push! (constraints, MOI. add_constraint (model, f, set))
105
125
end
106
- X, Y = _compute_point (model, variables, model. f)
107
126
for c in constraints
108
127
MOI. delete (model, c)
109
128
end
110
- return MOI . OPTIMAL, [ SolutionPoint (X, Y)]
129
+ return status, solution
111
130
end
0 commit comments