[ANN] Metaheuristics.jl

After several years of development, I share with you Metaheuristics.jl

This package implements state-of-the-art metaheuristic algorithms for single and multi-objective optimization. The aim of this package is to provide easy to use (and fast) metaheuristics for numerical global optimization.

Metaheuristics.jl includes:

  • Popular algorithms such as Differential Evolution, PSO, NSGA-II, NSGA-III, and more…
  • Performance Indicators such as IGD, hypervolume, among others.
  • Test Problems for single and multi-objective optimization.
  • Some visualization features in terminal via UnicodePlots.jl

Example 1

Objective function:

julia> f(x) = 10length(x) + sum( x.^2 - 10cos.(2Ο€*x)  )
f (generic function with 1 method)

Bounds for x∈ [-5,5]⁡ :

julia> bounds = [-5ones(5) 5ones(5)]
5Γ—2 Matrix{Float64}:
 -5.0  5.0
 -5.0  5.0
 -5.0  5.0
 -5.0  5.0
 -5.0  5.0

Optimize:

julia> result = optimize(f, bounds)
+=========== RESULT ==========+
  iteration: 1429
    minimum: 0
  minimizer: [1.8792427588475406e-10, 1.6562253377998926e-9, -2.2532566630145983e-9, 1.649414863704028e-9, 4.005275371381464e-9]
    f calls: 49981
 total time: 0.2483 s
+============================+

Example 2

julia> f, bounds, front = Metaheuristics.TestProblems.ZDT3();

julia> optimize(f, bounds, NSGA2())
+=========== RESULT ==========+
  iteration: 500
...
non-dominated solution(s):
                           F space
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” 
        2 β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β‘€β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β’£β’€β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β €β ˜β ²β €β €β €β €β €β‘„β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
   f_2    β”‚β €β €β €β €β €β €β €β €β ˆβ’†β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β €β €β €β €β €β €β €β €β €β ˆβ ’β‘„β €β €β €β €β €β €β‘€β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β’±β‘€β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          │⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠻⠍⠉⠉⠉⠉⠉⠉⒭⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉│ 
          β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β ˜β‘„β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β ™β €β €β €β €β €β €β €β’°β €β €β €β”‚ 
          β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β ˆβ’‡β €β €β”‚ 
       -1 β”‚β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β”‚ 
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 
          0                                      0.9
                             f_1
    f calls: 50000
  feasibles: 100 / 100 in final population
 total time: 1.4626 s
+============================+

Comments and suggestions are welcome.

31 Likes

Congratulations on the package! I see you have some constraint handling in some of the algorithms. I think this might be the first Julia package for metaheuristics that can handle equality and inequality constraints natively. Would be great to create a wrapper for Metaheuristics in Nonconvex.jl.

8 Likes

Thanks for your comment. Good suggestion!

2 Likes

Looks like a great package!

Very often I need to optimize expensive black-box functions, and having an optimizer that offers multi-threaded, simultaneous evaluation of multiple candidate solutions significantly reduces execution time. Please consider adding this option to your population-based optimizers.

4 Likes

That is a great suggestion. The evaluation of multiple solutions will be included in future versions.

3 Likes

For the reference, parallel evaluation is now available (since?) in Metaheuristics.jl:

3 Likes

Parallel evaluation is available since v3.2.x (released mid-2022). BTW, v3.3 is coming with some new features:

3 Likes

Say, I am only an occasional user to this interesting package.

After working fine earlier, now it seems that it does not regocnize β€˜BitArraySpace’

UndefVarError: `BitArraySpace` not defined

I have tried Metaheuristics.BitArraySpace, etc and looked all over, but cannot figure out why the same code which worked earlier now does not work
Thanks for any hints

Which version are you using?

Hi! Thank you for the package - it is absolutely great.
I have just one question:
How does Metaheuristics.jl β€œpenalize” the objective function for not satisfying the constraints? From what I gather, it doesn’t use penalty method. Does it use something along the lines f^{\prime}(x) = f(x) (1 + \sum |g(x)|)?

Good question.

Looking at the list of algorithms Algorithms Β· Metaheuristics.jl, I would say that the question shouldn’t be asked at the higher level of Metaheuristics.jl, but at the lower level of each algo, since some of them don’t support constraint.

Looking at the classical DE algo, I see no discussion of constraints in the doc. I looked at the DE code, but found nothing about constraints in DE.jl. However, there is a epsilonDE.jl which seems to be specialized for constrainted problem. But is this epsilonDE documented? Or is there an automatic switch to epsilonDE when calling DE solver on a constrained problem?

It seems to be documented here.

Ah yes, my mistake. Since DE and epsilonDE are siblings in the source tree, I was expecting them side-by-side in the table.

But now back to @AkchurinDA question: how are constraints implemented? Actually, to make things tidier, I suggest @AkchurinDA could create a dedicated thread .

Opened a new thread on this topic at Constraints in the Genetic Algorithm implemented in `Metaheuristics.jl`.