jmejia8 / Metaheuristics.jl

High-performance metaheuristics for optimization coded purely in Julia.
https://jmejia8.github.io/Metaheuristics.jl/stable/
Other
253 stars 27 forks source link

Real-valued GA example in documentation #86

Closed jbytecode closed 1 year ago

jbytecode commented 1 year ago

The documentation of the package in

https://jmejia8.github.io/Metaheuristics.jl/dev/algorithms/#GA

includes an example for real-value GA as shown below:

julia> f, bounds, solutions = Metaheuristics.TestProblems.rastrigin();

julia> ga = GA(;mutation=PolynomialMutation(;bounds),
                crossover=SBX(;bounds),
                environmental_selection=GenerationalReplacement()
               );

julia> optimize(f, bounds, ga)

f, bounds, and solutions were successfully extracted, however, GA() part is problematic as I end up with:

julia> ga = GA(;mutation=PolynomialMutation(;bounds),
                       crossover=SBX(;bounds),
                       environmental_selection=GenerationalReplacement()
                      );
ERROR: MethodError: no method matching getdim(::Matrix{Float64})

Closest candidates are:
  getdim(::SearchSpaces.AtomicSearchSpace)
   @ SearchSpaces ~/.julia/packages/SearchSpaces/ZzKXT/src/common.jl:2
  getdim(::SearchSpaces.MixedSpace)
   @ SearchSpaces ~/.julia/packages/SearchSpaces/ZzKXT/src/spaces/mixed/mixed.jl:101
  getdim(::Problem)
   @ Metaheuristics ~/.julia/packages/Metaheuristics/wLOSa/src/core/structures.jl:25

Stacktrace:
 [1] top-level scope
jmejia8 commented 1 year ago

Thank you for reporting. This will be fixed in the next minor update.

For reference, it's no longer necessary to provide parameters to GA:

res = optimize(f, bounds, GA)

The optimize API infers the genetic operators depending on the problem.