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

New features coming in next release #79

Open jmejia8 opened 1 year ago

jmejia8 commented 1 year ago

Install the unstable version hosted in the develop branch.

 pkg> add Metaheuristics#develop

Optimizers with default parameters

f, bounds, pareto_solutions = Metaheuristics.TestProblems.get_problem(:sphere);
optimize(f, bounds, ECA)

Pass parameters and Options via as kargs...

optimize(f, bounds, ECA, N = 20, iterations = 10, seed = 1)

is similar to

optimize(f, bounds, ECA(N = 20, options=Options(iterations = 10, seed = 1))

Using the SearchSpaces module to define search spaces.

fn(x) = abs(sum(diff(x)))
space = boxconstraints(zeros(10), 100ones(10)) # float
optimize(fn, space, ECA)

# bounds
space = boxconstraints(zeros(10), 100ones(10), rigid = false) # float
optimize(fn, space, ECA)

space = boxconstraints(zeros(Int, 10), 100ones(Int, 10)) # integers
optimize(fn, space, ECA)

# discrete
space = BitArraySpace(10) # 10D array of booleans
optimize(fn, space, GA)

space = PermutationSpace(10) # 10-permutation
optimize(fn, space, GA)

Termination criteria based on convergence

Other performance improvements

Clear message errors (https://github.com/jmejia8/Metaheuristics.jl/issues/65)

ff(x) = "abcd"
optimize(ff, [zeros(2) ones(2)] , ECA )

output:

ERROR: Objective function should return either a numerical value or a Tuple depending on the problem.
Current output:  abcd of type String
Examples at https://jmejia8.github.io/Metaheuristics.jl/stable/examples
Stacktrace:
  [1] error(s::String)
jmejia8 commented 1 year ago

New verbose field in Options

f(x) = sum(x.^2)
optimize(f, [zeros(3) ones(3)], ECA, iterations=5, seed=1, verbose=true)

output

+-----------+------------+------------+------------+------------+
| Iteration | Num. Evals |   Minimum  |    Time    | Converged  |
+-----------+------------+------------+------------+------------+
|         1 |         21 | 2.3077e-01 |   0.0441 s |         No | 
|         2 |         42 | 3.0642e-02 |   0.0442 s |         No | 
|         3 |         63 | 3.0642e-02 |   0.0443 s |         No | 
|         4 |         84 | 1.0031e-02 |   0.0444 s |         No | 
|         5 |        105 | 2.4834e-03 |   0.0444 s |         No | 

Due to https://github.com/jmejia8/Metaheuristics.jl/issues/78

jmejia8 commented 1 year ago

User-defined RNG (https://github.com/jmejia8/Metaheuristics.jl/issues/24):

f(x) = sum(x.^2)
optimize(f, [zeros(3) ones(3)], ECA, rng = Random.Xoshiro(9))

output:

Optimization Result
===================
  Iteration:       137
  Minimum:         3.60251e-49
  Minimizer:       [5.43105e-25, 2.00561e-25, 1.58314e-25]
  Function calls:  2877
  Total time:      0.0808 s
  Stop reason:     Due to Convergence Termination criterion.
optimize(f, [zeros(3) ones(3)], ECA, rng = Random.MersenneTwister(9))
Optimization Result
===================
  Iteration:       142
  Minimum:         2.72803e-49
  Minimizer:       [4.09988e-25, 2.84557e-25, 1.54078e-25]
  Function calls:  2982
  Total time:      0.0115 s
  Stop reason:     Due to Convergence Termination criterion.
jmejia8 commented 1 year ago

User defined termination criteria:

algo = ECA(termination = Metaheuristics.AbsoluteFunctionConvergence(ftol=1e-4) )
optimize(f, [zeros(3) ones(3)], algo)

Output:

Optimization Result
===================
  Iteration:       14
  Minimum:         9.07196e-06
  Minimizer:       [8.84653e-5, 0.000478301, 0.00297243]
  Function calls:  294
  Total time:      0.0010 s
  Stop reason:     Due to Convergence Termination criterion.