# Can't launch a basic example with Evolution.jl

**URL:** <https://discourse.julialang.org/t/cant-launch-a-basic-example-with-evolution-jl/90184>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [November 13, 2022, 8:51am UTC](https://discourse.julialang.org/t/cant-launch-a-basic-example-with-evolution-jl/90184 "2022-11-13T08:51:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![culebron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/culebron/32/44276_2.png) [@culebron](https://discourse.julialang.org/u/culebron)\
**Post date:** [November 13, 2022, 8:51am UTC](https://discourse.julialang.org/t/cant-launch-a-basic-example-with-evolution-jl/90184/1 "2022-11-13T08:51:44Z")

</div>

I’m trying to run a genetic algorithm optimization, and to reuse Evolution.jl package instead of writing the implementation on my own.

The docs don’t show any basic example, so I tried [this code in tests](https://github.com/wildart/Evolutionary.jl/blob/master/test/n-queens.jl#L30) as a pattern, studied the arguments one by one and tried to construct the simplest possible code to run.

I use `import` instead of `using`, because other packages like `GeoDataFrames` redefine `union` and other important funcitons, and they clash in the global scope.

The basic example I’m trying to run is: generate a vector of 20 floats and take a sum of them.

```julia
import StatsBase as sb
import Evolutionary as ev
import StableRNGs as sr

P = 100
G = 20
N = 30

result = ev.optimize(
    (v1) -> -sum(v1),
    () -> [rand(G) for i in 1:P],
        ev.GA(
        populationSize = P,
        selection = (fitness) -> sortperm(fitness, rev=true)[1:N],
        crossover = (v1, v2) -> sb.shuffle(collect(union(v1, v2)))[1:G],
        crossoverRate = 0.8,
        mutation = (v1) -> rand(G),
        mutationRate = 0.06,
    ),
    ev.Options(successive_f_tol=30)
    # another variant: ev.Options(rng=sr.StableRNG(42), successive_f_tol=30)
);

```

As I see, [somewhere deep in the code](https://github.com/wildart/Evolutionary.jl/blob/master/src/api/utilities.jl#L130) it tries to call `zero` with my gene type (`Vector{Float64}`), but fails.

Does anyone have a simplest example of this lib to try out?

```julia
MethodError: no method matching zero(::Type{Vector{Float64}})
Closest candidates are:
  zero(::Union{Type{P}, P}) where P<:Dates.Period at /snap/julia/62/share/julia/stdlib/v1.8/Dates/src/periods.jl:53
  zero(::ForwardDiff.Dual) at ~/.julia/packages/ForwardDiff/pDtsf/src/dual.jl:355
  zero(::LinearAlgebra.Diagonal{T, StaticArraysCore.SVector{N, T}}) where {N, T} at ~/.julia/packages/StaticArrays/PUoe1/src/SDiagonal.jl:41
  ...

Stacktrace:
 [1] default_values(x::Vector{Vector{Float64}})
   @ Evolutionary ~/.julia/packages/Evolutionary/65hL6/src/api/utilities.jl:130
 [2] Evolutionary.EvolutionaryObjective(f::var"#47#53", x::Vector{Vector{Float64}}, F::Vector{Float64}; eval::Symbol)
   @ Evolutionary ~/.julia/packages/Evolutionary/65hL6/src/api/objective.jl:19
 [3] optimize(f::var"#47#53", constraints::Evolutionary.NoConstraints, method::Evolutionary.GA{var"#50#56", var"#51#57", var"#52#58"}, population::Vector{Vector{Vector{Float64}}}, opts::Evolutionary.Options{Nothing, Random.TaskLocalRNG})
   @ Evolutionary ~/.julia/packages/Evolutionary/65hL6/src/api/optimize.jl:54
 [4] optimize(f::var"#47#53", constraints::Evolutionary.NoConstraints, individual::Function, method::Evolutionary.GA{var"#50#56", var"#51#57", var"#52#58"}, opts::Evolutionary.Options{Nothing, Random.TaskLocalRNG})
   @ Evolutionary ~/.julia/packages/Evolutionary/65hL6/src/api/optimize.jl:42
 [5] optimize(f::var"#47#53", individual::Function, method::Evolutionary.GA{var"#50#56", var"#51#57", var"#52#58"}, opts::Evolutionary.Options{Nothing, Random.TaskLocalRNG})
   @ Evolutionary ~/.julia/packages/Evolutionary/65hL6/src/api/optimize.jl:15
 [6] top-level scope
   @ In[16]:6
 [7] eval
   @ ./boot.jl:368 [inlined]
 [8] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1428

```
