Skip to content

Commit 36ed96f

Browse files
committed
Update
1 parent 90b109c commit 36ed96f

File tree

10 files changed

+47
-71
lines changed

10 files changed

+47
-71
lines changed

ext/MultiObjectiveAlgorithmsPolyhedraExt.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ function MOA.minimize_multiobjective!(
101101
H = _halfspaces(IPS)
102102
count = 0
103103
while !isempty(H)
104-
if MOA._time_limit_exceeded(model, start_time)
105-
status = MOI.TIME_LIMIT
104+
ret = MOA._check_premature_termination(model, start_time)
105+
if ret !== nothing
106+
status = ret
106107
break
107108
end
108109
count += 1

src/MultiObjectiveAlgorithms.jl

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,6 @@ function MOI.set(model::Optimizer, ::MOI.TimeLimitSec, ::Nothing)
185185
return
186186
end
187187

188-
function _time_limit_exceeded(model::Optimizer, start_time::Float64)
189-
time_limit = MOI.get(model, MOI.TimeLimitSec())
190-
if time_limit === nothing
191-
return false
192-
end
193-
time_remaining = time_limit - (time() - start_time)
194-
if time_remaining <= 0
195-
return true
196-
end
197-
if MOI.supports(model.inner, MOI.TimeLimitSec())
198-
MOI.set(model.inner, MOI.TimeLimitSec(), time_remaining)
199-
end
200-
return false
201-
end
202-
203188
### SolveTimeSec
204189

205190
function MOI.get(model::Optimizer, ::MOI.SolveTimeSec)
@@ -604,7 +589,7 @@ end
604589

605590
function _compute_ideal_point(model::Optimizer, start_time)
606591
for (i, f) in enumerate(MOI.Utilities.eachscalar(model.f))
607-
if _time_limit_exceeded(model, start_time)
592+
if _check_premature_termination(model, start_time) !== nothing
608593
return
609594
end
610595
if !isnan(model.ideal_point[i])
@@ -644,16 +629,29 @@ function optimize_multiobjective!(
644629
return minimize_multiobjective!(algorithm, model)
645630
end
646631

647-
function _check_interrupt()
632+
function _check_premature_termination(model::Optimizer, start_time::Float64)
648633
try
649-
reenable_sigint(() -> nothing)
634+
return reenable_sigint() do
635+
time_limit = MOI.get(model, MOI.TimeLimitSec())
636+
if time_limit === nothing
637+
return
638+
end
639+
time_remaining = time_limit - (time() - start_time)
640+
if time_remaining <= 0
641+
return MOI.TIME_LIMIT
642+
end
643+
if MOI.supports(model.inner, MOI.TimeLimitSec())
644+
MOI.set(model.inner, MOI.TimeLimitSec(), time_remaining)
645+
end
646+
return
647+
end
650648
catch ex
651649
if ex isa InterruptException
652-
return true
650+
return MOI.INTERRUPTED
653651
end
654652
rethrow(ex)
655653
end
656-
return false
654+
return nothing # no termination
657655
end
658656

659657
function MOI.optimize!(model::Optimizer)

src/algorithms/Chalmet.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ function minimize_multiobjective!(algorithm::Chalmet, model::Optimizer)
100100
push!(solutions, SolutionPoint(x2, y2))
101101
push!(Q, (1, 2))
102102
t = 3
103+
status = MOI.OPTIMAL
103104
while !isempty(Q)
104-
if _time_limit_exceeded(model, start_time)
105-
return MOI.TIME_LIMIT, solutions
106-
elseif _check_interrupt()
107-
return MOI.INTERRUPTED, solutions
105+
if (ret = _check_premature_termination(model, start_time)) !== nothing
106+
status = ret
107+
break
108108
end
109109
r, s = pop!(Q)
110110
yr, ys = solutions[r].y, solutions[s].y
@@ -118,5 +118,5 @@ function minimize_multiobjective!(algorithm::Chalmet, model::Optimizer)
118118
append!(Q, [(r, t), (t, s)])
119119
t += 1
120120
end
121-
return MOI.OPTIMAL, solutions
121+
return status, solutions
122122
end

src/algorithms/Dichotomy.jl

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,16 @@ function optimize_multiobjective!(algorithm::Dichotomy, model::Optimizer)
7777
error("Only scalar or bi-objective problems supported.")
7878
end
7979
if MOI.output_dimension(model.f) == 1
80-
if _time_limit_exceeded(model, start_time)
81-
return MOI.TIME_LIMIT, nothing
82-
elseif _check_interrupt()
83-
return MOI.INTERRUPTED, nothing
80+
if (ret = _check_premature_termination(model, start_time)) !== nothing
81+
return ret, nothing
8482
end
8583
status, solution = _solve_weighted_sum(model, algorithm, [1.0])
8684
return status, [solution]
8785
end
8886
solutions = Dict{Float64,SolutionPoint}()
8987
for (i, w) in (1 => 1.0, 2 => 0.0)
90-
if _time_limit_exceeded(model, start_time)
91-
return MOI.TIME_LIMIT, nothing
92-
elseif _check_interrupt()
93-
return MOI.INTERRUPTED, nothing
88+
if (ret = _check_premature_termination(model, start_time)) !== nothing
89+
return ret, nothing
9490
end
9591
status, solution = _solve_weighted_sum(model, algorithm, [w, 1.0 - w])
9692
if !_is_scalar_status_optimal(status)
@@ -107,11 +103,8 @@ function optimize_multiobjective!(algorithm::Dichotomy, model::Optimizer)
107103
limit = MOI.get(algorithm, SolutionLimit())
108104
status = MOI.OPTIMAL
109105
while length(queue) > 0 && length(solutions) < limit
110-
if _time_limit_exceeded(model, start_time)
111-
status = MOI.TIME_LIMIT
112-
break
113-
elseif _check_interrupt()
114-
status = MOI.INTERRUPTED
106+
if (ret = _check_premature_termination(model, start_time)) !== nothing
107+
status = ret
115108
break
116109
end
117110
(a, b) = popfirst!(queue)

src/algorithms/DominguezRios.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ function _p_partition(
5757
= max.(z, B.l)
5858
ret = _DominguezRiosBox[]
5959
for i in 1:length(z)
60-
new_l = vcat(B.l[1:i], ẑ[i+1:end])
61-
new_u = vcat(B.u[1:i-1], ẑ[i], B.u[i+1:end])
60+
new_l = vcat(B.l[1:i], ẑ[(i+1):end])
61+
new_u = vcat(B.u[1:(i-1)], ẑ[i], B.u[(i+1):end])
6262
new_priority = _reduced_scaled_priority(new_l, new_u, i, ẑ, yI, yN)
6363
push!(ret, _DominguezRiosBox(new_l, new_u, new_priority))
6464
end
@@ -183,11 +183,8 @@ function minimize_multiobjective!(algorithm::DominguezRios, model::Optimizer)
183183
k = 0
184184
status = MOI.OPTIMAL
185185
while any(!isempty(l) for l in L)
186-
if _time_limit_exceeded(model, start_time)
187-
status = MOI.TIME_LIMIT
188-
break
189-
elseif _check_interrupt()
190-
status = MOI.INTERRUPTED
186+
if (ret = _check_premature_termination(model, start_time)) !== nothing
187+
status = ret
191188
break
192189
end
193190
i, k = _select_next_box(L, k)

src/algorithms/EpsilonConstraint.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,8 @@ function minimize_multiobjective!(
111111
bound -= constant
112112
status = MOI.OPTIMAL
113113
for _ in 3:n_points
114-
if _time_limit_exceeded(model, start_time)
115-
status = MOI.TIME_LIMIT
116-
break
117-
elseif _check_interrupt()
118-
status = MOI.INTERRUPTED
114+
if (ret = _check_premature_termination(model, start_time)) !== nothing
115+
status = ret
119116
break
120117
end
121118
MOI.set(model, MOI.ConstraintSet(), ci, MOI.LessThan{Float64}(bound))

src/algorithms/KirlikSayin.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,8 @@ function minimize_multiobjective!(algorithm::KirlikSayin, model::Optimizer)
117117
L = [_Rectangle(_project(yI, k), _project(yN, k))]
118118
status = MOI.OPTIMAL
119119
while !isempty(L)
120-
if _time_limit_exceeded(model, start_time)
121-
status = MOI.TIME_LIMIT
122-
break
123-
elseif _check_interrupt()
124-
status = MOI.INTERRUPTED
120+
if (ret = _check_premature_termination(model, start_time)) !== nothing
121+
status = ret
125122
break
126123
end
127124
max_volume_index = argmax([_volume(Rᵢ, _project(yI, k)) for Rᵢ in L])

src/algorithms/Lexicographic.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,8 @@ function _solve_in_sequence(
124124
solution = SolutionPoint[]
125125
status = MOI.OPTIMAL
126126
for i in sequence
127-
if _time_limit_exceeded(model, start_time)
128-
status = MOI.TIME_LIMIT
129-
break
130-
elseif _check_interrupt()
131-
status = MOI.INTERRUPTED
127+
if (ret = _check_premature_termination(model, start_time)) !== nothing
128+
status = ret
132129
break
133130
end
134131
f = scalars[i]

src/algorithms/RandomWeighting.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ function optimize_multiobjective!(algorithm::RandomWeighting, model::Optimizer)
6060
# * then the outer loop goes again
6161
while length(solutions) < MOI.get(algorithm, SolutionLimit())
6262
while length(solutions) < MOI.get(algorithm, SolutionLimit())
63-
if _time_limit_exceeded(model, start_time)
64-
return MOI.TIME_LIMIT, filter_nondominated(sense, solutions)
65-
elseif _check_interrupt()
66-
return MOI.INTERRUPTED, filter_nondominated(sense, solutions)
63+
ret = _check_premature_termination(model, start_time)
64+
if ret !== nothing
65+
return ret, filter_nondominated(sense, solutions)
6766
end
6867
weights = rand(P)
6968
f = _scalarise(model.f, weights)

src/algorithms/TambyVanderpooten.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,8 @@ function minimize_multiobjective!(
123123
U_N[yN] = [[_get_child(yN, yI, k)] for k in 1:n]
124124
status = MOI.OPTIMAL
125125
while !isempty(U_N)
126-
if _time_limit_exceeded(model, start_time)
127-
status = MOI.TIME_LIMIT
128-
break
129-
elseif _check_interrupt()
130-
status = MOI.INTERRUPTED
126+
if (ret = _check_premature_termination(model, start_time)) !== nothing
127+
status = ret
131128
break
132129
end
133130
k, u = _select_search_zone(U_N, yI, yN)

0 commit comments

Comments
 (0)