|
| 1 | +facts("Parallel population optimizer") do |
| 2 | + |
| 3 | +@everywhere using BlackBoxOptim |
| 4 | + |
| 5 | +context("optimizing small problem") do |
| 6 | + rosenbrock2d(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2 |
| 7 | + |
| 8 | + res = bboptimize(rosenbrock2d; Method = :parallel_population_optimizer, |
| 9 | + SearchSpace = [(-5.0, 5.0), (-2.0, 2.0)], MaxTime = 100.0, |
| 10 | + ShowTrace = true, MigrationSize = 2, MigrationPeriod = 100) |
| 11 | + @fact size(best_candidate(res)) => (2,) |
| 12 | + @fact typeof(best_fitness(res)) => Float64 |
| 13 | + @fact best_fitness(res) => less_than(100.0) |
| 14 | + pop = population(res) |
| 15 | + @fact numdims(pop) --> 2 |
| 16 | + @fact popsize(pop) > 0 --> true |
| 17 | +end |
| 18 | + |
| 19 | +context("propagating exceptions from workers to the master") do |
| 20 | + # 0.01 chance to get domain error |
| 21 | + bogus(x) = sqrt(x[1]-0.01) |
| 22 | + # 0.01 chance to raise exception prematurely during bbsetup() |
| 23 | + res = bbsetup(bogus; Method = :parallel_population_optimizer, |
| 24 | + SearchSpace = [(0.0, 1.0)], MaxTime = 100.0, |
| 25 | + ShowTrace = true, MigrationSize = 2, MigrationPeriod = 100) |
| 26 | + @fact_throws RemoteException bboptimize(res) |
| 27 | +end |
| 28 | + |
| 29 | +#= doesn't work with PopulationMatrix |
| 30 | +context("worker method that uses PopulationMatrix") do |
| 31 | + rosenbrock2d(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2 |
| 32 | +
|
| 33 | + res = bboptimize(rosenbrock2d; Method = :parallel_population_optimizer, |
| 34 | + WorkerMethod = :separable_nes, |
| 35 | + SearchSpace = [(-5.0, 5.0), (-2.0, 2.0)], MaxTime = 100.0, |
| 36 | + ShowTrace = true, MigrationSize = 2, MigrationPeriod = 100) |
| 37 | + @fact size(best_candidate(res)) => (2,) |
| 38 | + @fact typeof(best_fitness(res)) => Float64 |
| 39 | + @fact best_fitness(res) => less_than(100.0) |
| 40 | + pop = population(res) |
| 41 | + @fact numdims(pop) --> 2 |
| 42 | + @fact popsize(pop) > 0 --> true |
| 43 | +end |
| 44 | +=# |
| 45 | +end |
0 commit comments