|
1 | | -abstract type AbstractOptimizationSolution end #experimental; comments welcome |
2 | | -mutable struct OptimizationSolution{O, Tx, Tf, Tls, Tsb} <: AbstractOptimizationSolution |
3 | | - method::O |
4 | | - initial_x::Tx |
5 | | - minimizer::Tx |
| 1 | +abstract type AbstractOptimizationSolution{T, N} <: AbstractNoTimeSolution{T, N} end |
| 2 | + |
| 3 | +struct OptimizationSolution{T, N, uType, P, A, Tf} <: AbstractOptimizationSolution{T, N} |
| 4 | + u::uType # minimizer |
| 5 | + prob::P # optimization problem |
| 6 | + alg::A # algorithm |
6 | 7 | minimum::Tf |
7 | | - iterations::Int |
8 | | - iteration_converged::Bool |
9 | | - ls_success::Tls |
10 | | - time_run::Float64 |
11 | | - stopped_by::Tsb |
| 8 | + initial_x::Array{Float64,1} |
| 9 | + retcode::Symbol |
| 10 | + original::String # original output of the optimizer |
12 | 11 | end |
13 | 12 |
|
14 | | -function Base.show(io::IO, r::AbstractOptimizationSolution) |
15 | | - take = Iterators.take |
16 | | - failure_string = "failure" |
17 | | - if isa(r.ls_success, Bool) && !r.ls_success |
18 | | - failure_string *= " (line search failed)" |
19 | | - end |
| 13 | +function build_solution(prob::AbstractNonlinearProblem, |
| 14 | + alg, u, minimum; |
| 15 | + initial_x = prob.u0, |
| 16 | + retcode = :Default, |
| 17 | + original = nothing, |
| 18 | + kwargs...) |
| 19 | + |
| 20 | + T = eltype(eltype(u)) |
| 21 | + N = ndims(u) |
| 22 | + |
| 23 | + OptimizationSolution{T, N, typeof(u), typeof(prob), typeof(alg), |
| 24 | + typeof(minimum)} |
| 25 | + (u, prob, alg, minimum, initial_x, |
| 26 | + retcode, original) |
| 27 | +end |
| 28 | + |
| 29 | +function Base.show(io::IO, A::AbstractNoTimeSolution) |
20 | 30 |
|
21 | | - @printf io " * Status: %s\n\n" r.iteration_converged ? "success" : failure_string |
| 31 | + @printf io "\n * Status: %s\n\n" A.retcode === :Success ? "success" : "failure" |
22 | 32 | @printf io " * Candidate solution\n" |
23 | | - fmt = " Final objective value: %e "*repeat(", %e ",length(r.minimum)-1)*"\n" |
24 | | - @eval @printf($io, $fmt, $r.minimum...) |
25 | | - #@printf io " Final objective value: %e\n" r.minimum |
| 33 | + @printf io " Final objective value: %e\n" A.minimum |
26 | 34 | @printf io "\n" |
27 | 35 | @printf io " * Found with\n" |
28 | | - @printf io " Algorithm: %s\n" r.method |
| 36 | + @printf io " Algorithm: %s\n" A.alg |
29 | 37 | return |
30 | 38 | end |
31 | 39 |
|
@@ -159,15 +167,7 @@ function __solve(prob::OptimizationProblem, opt, data = DEFAULT_DATA; |
159 | 167 |
|
160 | 168 | _time = time() |
161 | 169 |
|
162 | | - OptimizationSolution(opt, |
163 | | - prob.u0,# initial_x, |
164 | | - θ, #pick_best_x(f_incr_pick, state), |
165 | | - save_best ? first(min_err) : first(x), # pick_best_f(f_incr_pick, state, d), |
166 | | - maxiters, #iteration, |
167 | | - maxiters >= maxiters, #iteration == options.iterations, |
168 | | - true, |
169 | | - _time-t0, |
170 | | - NamedTuple()) |
| 170 | + # here should be build_solution to create the output message |
171 | 171 | end |
172 | 172 |
|
173 | 173 |
|
@@ -447,7 +447,7 @@ function __init__() |
447 | 447 | end |
448 | 448 |
|
449 | 449 | _loss = function(θ) |
450 | | - x = ntuple(i->first(prob.prob[i].f(θ, prob.prob[i].p, cur...)),length(prob.prob)) |
| 450 | + x = ntuple(i->first(prob.prob[i].f(θ, prob.prob[i].p, cur...)),length(prob.prob)) |
451 | 451 | return x |
452 | 452 | end |
453 | 453 |
|
|
0 commit comments