From dcf87a4e92786a1ae385501743bd049bdc960e4a Mon Sep 17 00:00:00 2001 From: Jesus Mejia Date: Wed, 8 Mar 2023 09:57:51 -0600 Subject: [PATCH] rename method set_user_solutions --- docs/src/api.md | 2 +- src/Metaheuristics.jl | 4 ++-- ...tal_solutions.jl => set_user_solutions.jl} | 24 +++++++++---------- test/initial_solution.jl | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) rename src/common/{set_inital_solutions.jl => set_user_solutions.jl} (65%) diff --git a/docs/src/api.md b/docs/src/api.md index b89950ad..5a0ef53b 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -107,7 +107,7 @@ Metaheuristics.gen_initial_state ``` ```@docs -set_inital_solutions! +set_user_solutions! ``` ## Variation diff --git a/src/Metaheuristics.jl b/src/Metaheuristics.jl index deb34698..4da88a80 100644 --- a/src/Metaheuristics.jl +++ b/src/Metaheuristics.jl @@ -26,7 +26,7 @@ export GenerationalReplacement, ElitistReplacement export sample, LatinHypercubeSampling, Grid export εDE, Restart export optimize! -export set_inital_solutions! +export set_user_solutions! include("externals.jl") @@ -52,7 +52,7 @@ include("common/repair.jl") include("common/stop.jl") include("common/compare.jl") include("common/non-dominated-sorting.jl") -include("common/set_inital_solutions.jl") +include("common/set_user_solutions.jl") diff --git a/src/common/set_inital_solutions.jl b/src/common/set_user_solutions.jl similarity index 65% rename from src/common/set_inital_solutions.jl rename to src/common/set_user_solutions.jl index 3bdfa9cd..b1c3f123 100644 --- a/src/common/set_inital_solutions.jl +++ b/src/common/set_user_solutions.jl @@ -1,7 +1,7 @@ include("gen_initial_state.jl") """ - set_inital_solutions!(optimizer, x, fx) + set_user_solutions!(optimizer, x, fx) Provide initial solutions to the `optimizer`. - `x` can be a `Vector` and `fx` a function or `fx = f(x)` @@ -18,12 +18,12 @@ 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> set_user_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> set_user_solutions!(algo, X0, f); julia> optimize(f, [0 0 0; 1 1 1.0], algo) +=========== RESULT ==========+ @@ -37,7 +37,7 @@ stop reason: Small difference of objective function values. ``` """ -function set_inital_solutions!(algo::AbstractAlgorithm, solution::AbstractSolution) +function set_user_solutions!(algo::AbstractAlgorithm, solution::AbstractSolution) status = algo.status if !isnothing(status.best_sol) && !isempty(status.population) push!(status.population, solution) @@ -48,16 +48,16 @@ function set_inital_solutions!(algo::AbstractAlgorithm, solution::AbstractSoluti end -function set_inital_solutions!(algo::AbstractAlgorithm, x::AbstractVector, fx) - set_inital_solutions!(algo, create_child(x, fx)) +function set_user_solutions!(algo::AbstractAlgorithm, x::AbstractVector, fx) + set_user_solutions!(algo, create_child(x, fx)) end -function set_inital_solutions!(algo::AbstractAlgorithm, x::AbstractVector, f::Function) - set_inital_solutions!(algo, x, f(x)) +function set_user_solutions!(algo::AbstractAlgorithm, x::AbstractVector, f::Function) + set_user_solutions!(algo, x, f(x)) end -function set_inital_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, fX::AbstractVector) +function set_user_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, fX::AbstractVector) n = size(X, 1) m = length(fX) @@ -72,7 +72,7 @@ function set_inital_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, fX::A # TODO: this part can be parallelized for i in 1:n - set_inital_solutions!(algo, X[i,:], fX[i]) + set_user_solutions!(algo, X[i,:], fX[i]) end # TODO check population size provided in algo.parameters.N @@ -80,7 +80,7 @@ function set_inital_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, fX::A algo end -function set_inital_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, f::Function) - set_inital_solutions!(algo, X, [f(X[i,:]) for i in 1:size(X,1)]) +function set_user_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, f::Function) + set_user_solutions!(algo, X, [f(X[i,:]) for i in 1:size(X,1)]) end diff --git a/test/initial_solution.jl b/test/initial_solution.jl index 067342d7..6ceab1ed 100644 --- a/test/initial_solution.jl +++ b/test/initial_solution.jl @@ -23,7 +23,7 @@ # initial solutions X = rand(10, size(bounds, 2)) X[1,:] = x_optimum #zeros(size(bounds, 2)) - set_inital_solutions!(algo, X, f) + set_user_solutions!(algo, X, f) res = optimize(f, bounds, algo) @@ -59,7 +59,7 @@ # initial solutions X = rand(10, size(bounds, 2)) X[1,:] = x_optimum - set_inital_solutions!(algo, X, f) + set_user_solutions!(algo, X, f) res = optimize(f, bounds, algo) @test length(res.population) == algo.parameters.N