Skip to content

Commit

Permalink
dostring for #68
Browse files Browse the repository at this point in the history
  • Loading branch information
jmejia8 committed Mar 8, 2023
1 parent a01dbfd commit e657910
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ Metaheuristics.compare
Metaheuristics.gen_initial_state
```

```@docs
set_inital_solutions!
```

## Variation

```@docs
Expand Down
37 changes: 37 additions & 0 deletions src/common/set_inital_solutions.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit e657910

Please sign in to comment.