Skip to content

Commit 616b7c8

Browse files
committed
Add timing information to log footer, including % of time in subproblems
1 parent da4c7cf commit 616b7c8

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/MultiObjectiveAlgorithms.jl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
178178
ideal_point::Vector{Float64}
179179
compute_ideal_point::Bool
180180
subproblem_count::Int
181+
solve_time_inner::Float64
181182
optimizer_factory::Any
182183

183184
function Optimizer(optimizer_factory)
@@ -198,6 +199,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
198199
Float64[],
199200
_default(ComputeIdealPoint()),
200201
0,
202+
0.0,
201203
optimizer_factory,
202204
)
203205
end
@@ -653,7 +655,7 @@ end
653655
optimize_inner!(model::Optimizer)
654656
655657
A function that must be called instead of `MOI.optimize!(model.inner)` because
656-
it also increments the `subproblem_count`.
658+
it also increments `subproblem_count` and `solve_time_inner`.
657659
658660
## Usage
659661
@@ -662,7 +664,9 @@ user-facing code. You may use it when implementing new algorithms in third-party
662664
packages.
663665
"""
664666
function optimize_inner!(model::Optimizer)
667+
start_time = time()
665668
MOI.optimize!(model.inner)
669+
model.solve_time_inner += time() - start_time
666670
model.subproblem_count += 1
667671
return
668672
end
@@ -803,8 +807,19 @@ end
803807
function _print_footer(io::IO, model::Optimizer)
804808
rule = "-"^(7 + 13 * (MOI.output_dimension(model.f) + 1))
805809
println(io, rule)
806-
println(io, "TerminationStatus: ", model.termination_status)
807-
println(io, "ResultCount: ", length(model.solutions))
810+
println(io, "termination_status: ", model.termination_status)
811+
println(io, "result_count: ", length(model.solutions))
812+
println(io)
813+
println(io, "Total solve time: ", _format(model.solve_time))
814+
println(
815+
io,
816+
"Time spent in subproblems:",
817+
_format(model.solve_time_inner),
818+
" (",
819+
round(Int, 100 * (model.solve_time_inner / model.solve_time)),
820+
"%)",
821+
)
822+
println(io, "Number of subproblems: ", model.subproblem_count)
808823
println(io, rule)
809824
return
810825
end
@@ -856,6 +871,7 @@ function _optimize!(model::Optimizer)
856871
empty!(model.solutions)
857872
model.termination_status = MOI.OPTIMIZE_NOT_CALLED
858873
model.subproblem_count = 0
874+
model.solve_time_inner = 0.0
859875
if model.f === nothing
860876
model.termination_status = MOI.INVALID_MODEL
861877
empty!(model.ideal_point)
@@ -874,16 +890,16 @@ function _optimize!(model::Optimizer)
874890
sense = MOI.get(model, MOI.ObjectiveSense())
875891
model.solutions = filter_nondominated(sense, solutions)
876892
end
877-
if !model.silent
878-
_print_footer(stdout, model)
879-
end
880893
if MOI.get(model, ComputeIdealPoint())
881894
_compute_ideal_point(model)
882895
end
883896
if MOI.supports(model.inner, MOI.TimeLimitSec())
884897
MOI.set(model.inner, MOI.TimeLimitSec(), nothing)
885898
end
886899
model.solve_time = time() - model.start_time
900+
if !model.silent
901+
_print_footer(stdout, model)
902+
end
887903
return
888904
end
889905

0 commit comments

Comments
 (0)