diff --git a/docs/src/api.md b/docs/src/api.md index a65644eb..b89950ad 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -106,6 +106,10 @@ Metaheuristics.compare Metaheuristics.gen_initial_state ``` +```@docs +set_inital_solutions! +``` + ## Variation ```@docs diff --git a/src/common/set_inital_solutions.jl b/src/common/set_inital_solutions.jl index 0604bf71..3bdfa9cd 100644 --- a/src/common/set_inital_solutions.jl +++ b/src/common/set_inital_solutions.jl @@ -1,5 +1,42 @@ include("gen_initial_state.jl") +""" + set_inital_solutions!(optimizer, x, fx) + +Provide initial solutions to the `optimizer`. +- `x` can be a `Vector` and `fx` a function or `fx = f(x)` +- `x` can be a matrix containing solutions in rows. + +### Example + +```julia-repl +julia> f(x) = abs(x[1]) + x[2] + x[3]^2 # objective function +f (generic function with 1 method) + +julia> algo = ECA(N = 61); # optimizer + +julia> # one solution can be provided + x0 = [0.5, 0.5 0.5]; + +julia> set_inital_solutions!(algo, x0, f); + +julia> # providing multiple solutions + X0 = rand(30, 3); # 30 solutions with dim 3 + +julia> set_inital_solutions!(algo, X0, f); + +julia> optimize(f, [0 0 0; 1 1 1.0], algo) ++=========== RESULT ==========+ + iteration: 413 + minimum: 0 + minimizer: [0.0, 0.0, 0.0] + f calls: 25132 + total time: 0.0856 s +stop reason: Small difference of objective function values. ++============================+ +``` + +""" function set_inital_solutions!(algo::AbstractAlgorithm, solution::AbstractSolution) status = algo.status if !isnothing(status.best_sol) && !isempty(status.population)