Skip to content

Commit

Permalink
Merge pull request #70 from jmejia8/develop
Browse files Browse the repository at this point in the history
Fix low value from codecov
  • Loading branch information
jmejia8 authored Mar 8, 2023
2 parents 01296d6 + a5e49d8 commit b7c2738
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
12 changes: 4 additions & 8 deletions src/DecisionMaking/ROI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,12 @@ end

function roiarchiving(population, w, parameters::ROIArchiving; verbose=true)

if isempty(population) || isempty(w)
# nothing to do
return Int[]
end
(isempty(population) || isempty(w)) && (return Int[]) # nothing to do

feasible_sols = Metaheuristics.is_feasible.(population)
if !any(feasible_sols)
# we cannot work on infeasible solutions
return Int[]
end

# we cannot work on infeasible solutions
!any(feasible_sols) && (return Int[])

δ_w = parameters.δ_w_transformed

Expand Down
2 changes: 1 addition & 1 deletion src/common/gen_initial_state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function _complete_population!(status,problem,parameters,information,options)
# increase population if necessary
parameters.N = length(status.population)
# TODO: use this options.debug == true to show the message?
@warn("Population size increased to $(parameters.N) due to initial solutions.")
options.debug && @warn("Population size increased to $(parameters.N) due to initial solutions.")
return
end

Expand Down
22 changes: 11 additions & 11 deletions src/common/set_user_solutions.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include("gen_initial_state.jl")

"""
set_user_solutions!(optimizer, x, fx)
set_user_solutions!(optimizer, x, fx;verbose=true)
Provide initial solutions to the `optimizer`.
- `x` can be a `Vector` and `fx` a function or `fx = f(x)`
Expand Down Expand Up @@ -37,7 +37,7 @@ stop reason: Small difference of objective function values.
```
"""
function set_user_solutions!(algo::AbstractAlgorithm, solution::AbstractSolution)
function set_user_solutions!(algo::AbstractAlgorithm, solution::AbstractSolution;kargs...)
status = algo.status
if !isnothing(status.best_sol) && !isempty(status.population)
push!(status.population, solution)
Expand All @@ -48,23 +48,23 @@ function set_user_solutions!(algo::AbstractAlgorithm, solution::AbstractSolution
end


function set_user_solutions!(algo::AbstractAlgorithm, x::AbstractVector, fx)
set_user_solutions!(algo, create_child(x, fx))
function set_user_solutions!(algo::AbstractAlgorithm, x::AbstractVector, fx;kargs...)
set_user_solutions!(algo, create_child(x, fx); kargs...)
end

function set_user_solutions!(algo::AbstractAlgorithm, x::AbstractVector, f::Function)
set_user_solutions!(algo, x, f(x))
function set_user_solutions!(algo::AbstractAlgorithm, x::AbstractVector, f::Function;kargs...)
set_user_solutions!(algo, x, f(x); kargs...)
end


function set_user_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, fX::AbstractVector)
function set_user_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, fX::AbstractVector;verbose=true)
n = size(X, 1)
m = length(fX)

if n != m
@warn "$(n) decision vectors provided but $(m) objective values."
verbose && @warn "$(n) decision vectors provided but $(m) objective values."
n = min(m, n)
println("Taking ", n, " as the number of initial solutions.")
verbose && println("Taking ", n, " as the number of initial solutions.")
end

# nothing to do due to it is necessary the objective value
Expand All @@ -80,7 +80,7 @@ function set_user_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, fX::Abs
algo
end

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)])
function set_user_solutions!(algo::AbstractAlgorithm, X::AbstractMatrix, f::Function;kargs...)
set_user_solutions!(algo, X, [f(X[i,:]) for i in 1:size(X,1)];kargs...)
end

34 changes: 15 additions & 19 deletions src/core/stop_status_codes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
TerminationStatusCode
An Enum of possible return values for [`State`](@ref).
An Enum of possible => values for [`State`](@ref).
Possible values:
- `ITERATION_LIMIT`
Expand Down Expand Up @@ -46,24 +46,20 @@ julia> termination_status_message(ECA())
```
"""
function termination_status_message(status_code::TerminationStatusCode)
if status_code == ITERATION_LIMIT
return "Maximum number of iterations exceeded."
elseif status_code == TIME_LIMIT
return "Maximum time exceeded."
elseif status_code == EVALUATIONS_LIMIT
return "Maximum objective function calls exceeded."
elseif status_code == ACCURACY_LIMIT
return "The desired accuracy was obtained."
elseif status_code == OBJECTIVE_VARIANCE_LIMIT
return "Small variance of the objective function."
elseif status_code == OBJECTIVE_DIFFERENCE_LIMIT
return "Small difference of objective function values."
elseif status_code == OTHER_LIMIT
return "Other stopping criteria."
elseif status_code == UNKNOWN_STOP_REASON
return "Unknown stop reason."
codes = Dict(
ITERATION_LIMIT => "Maximum number of iterations exceeded.",
TIME_LIMIT => "Maximum time exceeded.",
EVALUATIONS_LIMIT => "Maximum objective function calls exceeded.",
ACCURACY_LIMIT => "The desired accuracy was obtained.",
OBJECTIVE_VARIANCE_LIMIT => "Small variance of the objective function.",
OBJECTIVE_DIFFERENCE_LIMIT =>"Small difference of objective function values.",
OTHER_LIMIT => "Other stopping criteria.",
UNKNOWN_STOP_REASON => "Unknown stop reason."
)
try
return codes[status_code]
catch
throw("Illegal value $status_code")
end

throw("Illegal value $status_code")
end

14 changes: 11 additions & 3 deletions test/initial_solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
for method in methods
for N in [5, 10, 20] # vary the population size
algo = method(N = N, options = options, information = information)
# initial solutions
X = rand(10, size(bounds, 2))
X[1,:] = x_optimum #zeros(size(bounds, 2))
# one solution
set_user_solutions!(algo, x_optimum, f)
# multiple solutions
X = rand(5, size(bounds, 2))
set_user_solutions!(algo, X, f)

# check if size of x and f is defferent
X = ones(4, size(bounds, 2))
set_user_solutions!(algo,
X,
f.([ones(size(bounds, 2)) for i in 1:5]),
verbose = false)

res = optimize(f, bounds, algo)

@test length(res.population) == algo.parameters.N
Expand Down

2 comments on commit b7c2738

@jmejia8
Copy link
Owner Author

@jmejia8 jmejia8 commented on b7c2738 Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/79195

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.2.15 -m "<description of version>" b7c27384a2d3bc3c7c3be5dd34efdead45728dbe
git push origin v3.2.15

Please sign in to comment.