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

Printing progress to terminal when running optimization? #78

Closed Yuricst closed 1 year ago

Yuricst commented 1 year ago

Hi, I was wondering if there are any ways to display to the terminal the information during the optimization (something like a verbosity clause, e.g. the message you'd get when running pygmo: https://esa.github.io/pygmo2/tutorials/nlopt_basics.html?highlight=verbosity). It could also maybe be the option to include a user-defined callback function called at each iteration, where the function can access the status of the algorithm or something. Apologies if I just missed it, but I couldn't find it in the documentation/examples... Thanks!

longemen3000 commented 1 year ago

https://jmejia8.github.io/Metaheuristics.jl/stable/api/#Metaheuristics.Options, using debug = true ?

jmejia8 commented 1 year ago

Hi!

Example 1

You can use the debug=true in the Options

f, bounds, _ = Metaheuristics.TestProblems.get_problem(:discus);
# show information on the optimization process when debug=true 
my_options = Options(debug=true)
# optimize and get results
result = optimize(f, bounds, ECA(options=my_options))

Example 2

Besides, you can pass a logger function to optimize.

f, bounds, _ = Metaheuristics.TestProblems.get_problem(:discus);
# logger function is called each iteration
my_logger(status) = println("Iteration: ", status.iteration, "  | f calls: ", nfes(status), " |  Min: ", minimum(status))
result = optimize(f, bounds, ECA(); logger = my_logger)

See State for more information.

Yuricst commented 1 year ago

Awesome, thank you!