Skip to content

Add time limits to compute ideal point & dichotomy starting solutions #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/MultiObjectiveAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,16 @@ 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)
return
end
MOI.set(model.inner, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.optimize!(model.inner)
status = MOI.get(model.inner, MOI.TerminationStatus())
Expand All @@ -584,7 +587,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
Expand Down
6 changes: 6 additions & 0 deletions src/algorithms/Dichotomy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@
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

Check warning on line 85 in src/algorithms/Dichotomy.jl

View check run for this annotation

Codecov / codecov/patch

src/algorithms/Dichotomy.jl#L85

Added line #L85 was not covered by tests
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
Expand Down
2 changes: 1 addition & 1 deletion test/algorithms/Dichotomy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading