From 0587ededc9a824c84c1e769712afacdfc3d35d37 Mon Sep 17 00:00:00 2001 From: sandyspiers Date: Mon, 7 Apr 2025 16:58:56 +0800 Subject: [PATCH 1/4] add time limits to compute ideal points --- src/MultiObjectiveAlgorithms.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/MultiObjectiveAlgorithms.jl b/src/MultiObjectiveAlgorithms.jl index c631bb2..f58997d 100644 --- a/src/MultiObjectiveAlgorithms.jl +++ b/src/MultiObjectiveAlgorithms.jl @@ -559,13 +559,17 @@ function MOI.delete(model::Optimizer, ci::MOI.ConstraintIndex) return end -function _compute_ideal_point(model::Optimizer) +function _compute_ideal_point(model::Optimizer, start_time) objectives = MOI.Utilities.eachscalar(model.f) model.ideal_point = fill(NaN, length(objectives)) if !MOI.get(model, ComputeIdealPoint()) return end for (i, f) in enumerate(objectives) + if _time_limit_exceeded(model, start_time) + status = MOI.TIME_LIMIT + break + end MOI.set(model.inner, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.optimize!(model.inner) status = MOI.get(model.inner, MOI.TerminationStatus()) @@ -584,7 +588,7 @@ function MOI.optimize!(model::Optimizer) model.termination_status = MOI.INVALID_MODEL return end - _compute_ideal_point(model) + _compute_ideal_point(model, start_time) algorithm = something(model.algorithm, default(Algorithm())) status, solutions = optimize_multiobjective!(algorithm, model) model.termination_status = status From ed6f3f7d1d57ea8a39b6a86a8b31291fe6f0d1c8 Mon Sep 17 00:00:00 2001 From: sandyspiers Date: Mon, 7 Apr 2025 17:02:45 +0800 Subject: [PATCH 2/4] add time limits to dichotomy starting solves --- src/algorithms/Dichotomy.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/algorithms/Dichotomy.jl b/src/algorithms/Dichotomy.jl index 6b66054..72e8bb0 100644 --- a/src/algorithms/Dichotomy.jl +++ b/src/algorithms/Dichotomy.jl @@ -81,11 +81,17 @@ function optimize_multiobjective!(algorithm::Dichotomy, model::Optimizer) error("Only scalar or bi-objective problems supported.") end if MOI.output_dimension(model.f) == 1 + if _time_limit_exceeded(model, start_time) + return MOI.TIME_LIMIT, nothing + end status, solution = _solve_weighted_sum(model, algorithm, [1.0]) return status, [solution] end solutions = Dict{Float64,SolutionPoint}() for w in (0.0, 1.0) + if _time_limit_exceeded(model, start_time) + return MOI.TIME_LIMIT, nothing + end status, solution = _solve_weighted_sum(model, algorithm, w) if !_is_scalar_status_optimal(status) return status, nothing From e0ad9516479773a97703632c5c3aa701557e6b32 Mon Sep 17 00:00:00 2001 From: sandyspiers Date: Mon, 7 Apr 2025 17:04:19 +0800 Subject: [PATCH 3/4] update dichotomy time limit unit test logic with 0 timelimit, there should be no solutions as there is no solve. --- test/algorithms/Dichotomy.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/algorithms/Dichotomy.jl b/test/algorithms/Dichotomy.jl index 471f23d..a77bea7 100644 --- a/test/algorithms/Dichotomy.jl +++ b/test/algorithms/Dichotomy.jl @@ -261,7 +261,7 @@ function test_time_limit() ) MOI.optimize!(model) @test MOI.get(model, MOI.TerminationStatus()) == MOI.TIME_LIMIT - @test MOI.get(model, MOI.ResultCount()) > 0 + @test MOI.get(model, MOI.ResultCount()) == 0 return end From 56ae7f8f994e703e7dbf9d7f255f8fa2b501dd28 Mon Sep 17 00:00:00 2001 From: Sandy Spiers <86579677+sandyspiers@users.noreply.github.com> Date: Tue, 8 Apr 2025 07:25:05 +0800 Subject: [PATCH 4/4] Return after timeout instead of break Co-authored-by: Oscar Dowson --- src/MultiObjectiveAlgorithms.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/MultiObjectiveAlgorithms.jl b/src/MultiObjectiveAlgorithms.jl index f58997d..2ea3d42 100644 --- a/src/MultiObjectiveAlgorithms.jl +++ b/src/MultiObjectiveAlgorithms.jl @@ -567,8 +567,7 @@ function _compute_ideal_point(model::Optimizer, start_time) end for (i, f) in enumerate(objectives) if _time_limit_exceeded(model, start_time) - status = MOI.TIME_LIMIT - break + return end MOI.set(model.inner, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.optimize!(model.inner)