Skip to content

Commit b5ff8f2

Browse files
authored
Pass time limit to inner solver (#55)
1 parent 1e3032c commit b5ff8f2

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/MultiObjectiveAlgorithms.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ function _time_limit_exceeded(model::Optimizer, start_time::Float64)
166166
if time_limit === nothing
167167
return false
168168
end
169-
return time() - start_time >= time_limit
169+
time_remaining = time_limit - (time() - start_time)
170+
if time_remaining <= 0
171+
return true
172+
end
173+
if MOI.supports(model.inner, MOI.TimeLimitSec())
174+
MOI.set(model.inner, MOI.TimeLimitSec(), time_remaining)
175+
end
176+
return false
170177
end
171178

172179
### ObjectiveFunction
@@ -498,6 +505,9 @@ function MOI.optimize!(model::Optimizer)
498505
if solutions !== nothing
499506
model.solutions = solutions
500507
end
508+
if MOI.supports(model.inner, MOI.TimeLimitSec())
509+
MOI.set(model.inner, MOI.TimeLimitSec(), nothing)
510+
end
501511
return
502512
end
503513

test/algorithms/EpsilonConstraint.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,33 @@ function test_time_limit()
390390
return
391391
end
392392

393+
function test_time_limit_large()
394+
p1 = [77, 94, 71, 63, 96, 82, 85, 75, 72, 91, 99, 63, 84, 87, 79, 94, 90]
395+
p2 = [65, 90, 90, 77, 95, 84, 70, 94, 66, 92, 74, 97, 60, 60, 65, 97, 93]
396+
w = [80, 87, 68, 72, 66, 77, 99, 85, 70, 93, 98, 72, 100, 89, 67, 86, 91]
397+
model = MOA.Optimizer(HiGHS.Optimizer)
398+
MOI.set(model, MOA.Algorithm(), MOA.EpsilonConstraint())
399+
MOI.set(model, MOI.TimeLimitSec(), 1.0)
400+
MOI.set(model, MOI.Silent(), true)
401+
x = MOI.add_variables(model, length(w))
402+
MOI.add_constraint.(model, x, MOI.ZeroOne())
403+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
404+
f = MOI.Utilities.operate(
405+
vcat,
406+
Float64,
407+
[sum(1.0 * p[i] * x[i] for i in 1:length(w)) for p in [p1, p2]]...,
408+
)
409+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
410+
MOI.add_constraint(
411+
model,
412+
sum(1.0 * w[i] * x[i] for i in 1:length(w)),
413+
MOI.LessThan(900.0),
414+
)
415+
MOI.optimize!(model)
416+
@test MOI.get(model, MOI.ResultCount()) >= 0
417+
return
418+
end
419+
393420
end
394421

395422
TestEpsilonConstraint.run_tests()

0 commit comments

Comments
 (0)