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

Modify a metaheuristic #76

Open
jmejia8 opened this issue Mar 21, 2023 · 3 comments
Open

Modify a metaheuristic #76

jmejia8 opened this issue Mar 21, 2023 · 3 comments

Comments

@jmejia8
Copy link
Owner

jmejia8 commented Mar 21, 2023

A modified metaheuristic can extend the capability of an implemented algorithm.
The idea is to define custom components (initialization, termination criterion, etc) without overwriting default methods.

For instance:

eca = ECA(N = 100)
eca_modified = modify(eca, termination = RelativeTolerance())
optimize(f, bounds, eca_modified)
@aplavin
Copy link

aplavin commented Apr 22, 2023

May I suggest ConstructionBase/Accessors as the interface? So that

using ConstructionBase
eca_modified = setproperties(eca, termination = RelativeTolerance())

or

using Accessors
eca_modified = @set eca.termination = RelativeTolerance()

I think both already work, aside from RelativeTolerance() not existing :)

@jmejia8
Copy link
Owner Author

jmejia8 commented Apr 22, 2023

Thank you for the suggestion. The idea is to modify a Julia method for a specific metaheuristic without overwriting the implemented methods (avoid type piracy). For example, I wanted to modify ECA in order to implement o re-use some termination criteria, but the following is a problem.

julia> algo = ECA()

julia> Metaheuristics.stop_criteria!(st, params::ECA, info, opt, args...; kargs...) = error("I modified all ECA instances")

julia> optimize(sum, [-5; 5;;], algo)
ERROR: I modified all ECA instances
...

julia> optimize(sum, [-5; 5;;], ECA)
ERROR: I modified all ECA instances

Therefore, we must find a way (simple to use for the user) to modify only one instance of the algorithm.
However, I can't figure out how to do it. The following is a utopian implementation:

eca_modified = modify(ECA(), some_method = SomeParams())
Metaheuristics.some_method(params::SomeParams) = println("I'm not ECA")
# original implementation
# Metaheuristics.some_method(params::ECA) = println("I'm ECA")
optimize(sum, [5;5;;], eca_modified)
# I'm not ECA
optimize(sum, [5;5;;], ECA)
# I'm ECA

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

No branches or pull requests

3 participants
@aplavin @jmejia8 and others