Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in GA Implementation? #75

Closed
davidreihs opened this issue Mar 21, 2023 · 2 comments
Closed

Bug in GA Implementation? #75

davidreihs opened this issue Mar 21, 2023 · 2 comments

Comments

@davidreihs
Copy link

davidreihs commented Mar 21, 2023

I have noticed that every other run using the GA implementation fails on a MethodError when using it to optimize the Rosenbrock function.

I noticed it when completing the example included with Optimization.jl/(OptimizationMetaheuristics.jl) package.
The following code snippet sometimes leads to the Error in question. The other times I will run into the max number of iterations.
Would be great to get some insight into where this error is coming from and whether it is reproducible on other machines.

using Metaheuristics

h(x) = (1.0 - x[1])^2 + 100. * (x[2] - x[1]^2)^2

D = 2
bounds = [-ones(D) ones(D)]'

result = Metaheuristics.optimize(h, bounds, Metaheuristics.GA())

The Error I get is the following:

ERROR: MethodError: no method matching !(::Float64)
Closest candidates are:
!(::Function) at operators.jl:1077
!(::Bool) at bool.jl:35
!(::Missing) at missing.jl:101
...
Stacktrace:
[1] _broadcast_getindex_evalf
@ .\broadcast.jl:670 [inlined]
[2] _broadcast_getindex
@ .\broadcast.jl:643 [inlined]
[3] getindex
@ .\broadcast.jl:597 [inlined]
[4] copy
@ .\broadcast.jl:899 [inlined]
[5] materialize
@ .\broadcast.jl:860 [inlined]
[6] mutation!(Q::Matrix{Float64}, parameters::BitFlipMutation)
@ Metaheuristics C:\Users\ReihsD.julia\packages\Metaheuristics\qh0JB\src\operators\mutation.jl:13
[7] update_state!(::State{Metaheuristics.xf_solution{Vector{Float64}}}, ::GA{RandomInBounds, TournamentSelection, UniformCrossover, BitFlipMutation, ElitistReplacement}, ::Problem{Float64}, ::Information, ::Options; kargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Metaheuristics C:\Users\ReihsD.julia\packages\Metaheuristics\qh0JB\src\algorithms\GA\GA.jl:198
[8] update_state!(::State{Metaheuristics.xf_solution{Vector{Float64}}}, ::GA{RandomInBounds, TournamentSelection, UniformCrossover, BitFlipMutation, ElitistReplacement}, ::Problem{Float64}, ::Information, ::Options)
@ Metaheuristics C:\Users\ReihsD.julia\packages\Metaheuristics\qh0JB\src\algorithms\GA\GA.jl:182
[9] optimize(f::Function, bounds::LinearAlgebra.Adjoint{Float64, Matrix{Float64}}, method::Metaheuristics.Algorithm{GA{RandomInBounds, TournamentSelection, UniformCrossover, BitFlipMutation, ElitistReplacement}}; logger::Metaheuristics.var"#119#121")
@ Metaheuristics C:\Users\ReihsD.julia\packages\Metaheuristics\qh0JB\src\optimize.jl:91

@jmejia8
Copy link
Owner

jmejia8 commented Mar 21, 2023

Read the documentation on GA for real encoding.

@davidreihs
Copy link
Author

Ah, thank you very much, I didn't notice that the default encoding for GA is binary.
With the hints from the documentation for real encoding everything works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants