# Error in initial\_population of Evolutionary.jl

**URL:** <https://discourse.julialang.org/t/error-in-initial-population-of-evolutionary-jl/55610>\
**Category:** General Usage\
**Tags:** optimization\
**Created:** [February 19, 2021, 10:17am UTC](https://discourse.julialang.org/t/error-in-initial-population-of-evolutionary-jl/55610 "2021-02-19T10:17:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![umbe](https://avatars.discourse-cdn.com/v4/letter/u/f19dbf/32.png) [@umbe](https://discourse.julialang.org/u/umbe)\
**Post date:** [February 19, 2021, 10:17am UTC](https://discourse.julialang.org/t/error-in-initial-population-of-evolutionary-jl/55610/1 "2021-02-19T10:17:05Z")

</div>

Hello everybody,  
I’m having a weird issue using the package Evolutionary.jl.  
I tried to write a minimal example of my problem but unluckily, being too much simplified, the issue does not appear. Anyway, I’ll try to explain you the question.  
I wrote my optimization problem following the examples reported in the Evolutionary package, in particular [this one](https://github.com/wildart/Evolutionary.jl/blob/master/examples/beam.jl).  
Being relatively long and structured, many parts of the code (such as the objective function) are wrote in external functions that are included at the beginning of the script, anyway, this shouldn’t be a problem for the solver.  
I defined my objective function (OF in the code below) and tested it with many random values of the variables to optimize and it always provided correct results (i.e. it never returned NaN or errors).  
I only have boundary constraints, therefore I defined them with `lb` and `ub` and then I wrote

```julia
c = WorstFitnessConstraints(Evolutionary.ConstraintBounds(lb, ub, [], []), [])
mthd = GA(populationSize = 20, ɛ = 0.03, crossoverRate = 0.8, mutationRate = 0.1, selection = rouletteinv, crossover = singlepoint, mutation = scramble)
opts = Evolutionary.Options(iterations = 40)
opt_res = Evolutionary.optimize(OF, c, mthd, opts)

```

Now, when the last line is executed, Julia provides this error:

```julia
ERROR: MethodError: no method matching zero(::Type{Any})
Closest candidates are:
  zero(::Type{Union{Missing, T}}) where T at missing.jl:105
  zero(::Type{Missing}) at missing.jl:103
  zero(::Type{LibGit2.GitHash}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\LibGit2\src\oid.jl:220
  ...
Stacktrace:
 [1] zero(::Type{Any}) at .\missing.jl:105
 [2] zeros(::Type{Any}, ::Tuple{Int64}) at .\array.jl:505
 [3] zeros(::Type{Any}, ::Int64) at .\array.jl:500
 [4] (::Evolutionary.var"#13#14"{DataType})(::Int64) at .\none:0
 [5] iterate at .\generator.jl:47 [inlined]
 [6] _all(::Base.var"#239#241", ::Base.Generator{Array{Int64,1},Evolutionary.var"#13#14"{DataType}}, ::Colon) at .\reduce.jl:819
 [7] all at .\reduce.jl:815 [inlined]
 [8] Dict(::Base.Generator{Array{Int64,1},Evolutionary.var"#13#14"{DataType}}) at .\dict.jl:130
 [9] initial_population(::GA, ::NLSolversBase.ConstraintBounds{Any}) at C:\Users\umber\.julia\packages\Evolutionary\Ub02D\src\api\utilities.jl:132     
 [10] optimize(::Function, ::WorstFitnessConstraints{Any,Array{Any,1}}, ::NLSolversBase.ConstraintBounds{Any}, ::GA, ::Evolutionary.Options{Nothing}) at C:\Users\user1\.julia\packages\Evolutionary\Ub02D\src\api\optimize.jl:33
 [11] optimize(::Function, ::WorstFitnessConstraints{Any,Array{Any,1}}, ::GA, ::Evolutionary.Options{Nothing}) at C:\Users\user1\.julia\packages\Evolutionary\Ub02D\src\api\optimize.jl:28

```

I’m not very sure about what is going wrong, I’d say that someting fails in the creation of the initial population but I can’t figure how to solve the issue.  
Does anyone have any idea of what is happening?

---

<div class="post-metadata">

**Author:** ![umbe](https://avatars.discourse-cdn.com/v4/letter/u/f19dbf/32.png) [@umbe](https://discourse.julialang.org/u/umbe)\
**Post date:** [February 19, 2021, 1:45pm UTC](https://discourse.julialang.org/t/error-in-initial-population-of-evolutionary-jl/55610/2 "2021-02-19T13:45:11Z")

</div>

**Update** : error has been solved, the issue was that `lb` and `ub` vectors were provided as Type Any. Changed to Float64.  
In case it colud be useful to anyone, Evolutionary seems to not work with

```julia
c = WorstFitnessConstraints(Evolutionary.ConstraintBounds(lb, ub, [], []), [])

```

Changed with

```julia
const_calc(vars) = [0.0]
lc = [-Inf]
uc = [Inf]
c = WorstFitnessConstraints(Evolutionary.ConstraintBounds(lb, ub, lc, uc), const_calc)

```

and a complete run has been successfully performed.

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [February 19, 2021, 4:59pm UTC](https://discourse.julialang.org/t/error-in-initial-population-of-evolutionary-jl/55610/3 "2021-02-19T16:59:44Z")

</div>

Shameless plug: try [CMAEvolutionStrategy.jl](https://github.com/jbrea/CMAEvolutionStrategy.jl) in case you are unhappy with the simplified version of CMA-ES in Evolutionary.jl 🙂

---

<div class="post-metadata">

**Author:** ![umbe](https://avatars.discourse-cdn.com/v4/letter/u/f19dbf/32.png) [@umbe](https://discourse.julialang.org/u/umbe)\
**Post date:** [February 21, 2021, 9:34am UTC](https://discourse.julialang.org/t/error-in-initial-population-of-evolutionary-jl/55610/4 "2021-02-21T09:34:01Z")

</div>

Thanks a lot for the advice! Any suggestion for evolutionary algorithm packages in Julia is very appreciated, I’ll try it for sure.
