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

Docs for MOO #823

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ SymbolicAnalysis = "4297ee4d-0239-47d8-ba5d-195ecdf594fe"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
BlackBoxOptim = "a134a8b2-14d6-55f6-9291-3336d3ab0209"
Metaheuristics = "bcdb8e00-2c21-11e9-3065-2b553b22f898"

[compat]
AmplNLWriter = "1"
Expand Down Expand Up @@ -86,3 +88,6 @@ SymbolicAnalysis = "0.3"
Symbolics = "6"
Tracker = ">= 0.2"
Zygote = ">= 0.5"
BlackBoxOptim = "0.6"
Metaheuristics = "3"

18 changes: 18 additions & 0 deletions docs/src/optimization_packages/blackboxoptim.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ prob = Optimization.OptimizationProblem(f, x0, p, lb = [-1.0, -1.0], ub = [1.0,
sol = solve(prob, BBO_adaptive_de_rand_1_bin_radiuslimited(), maxiters = 100000,
maxtime = 1000.0)
```

## Multi-objective optimization
The optimizer for Multi-Objective Optimization is `BBO_borg_moea()`. Your objective function should return a tuple of the objective values and you should indicate the fitness scheme to be (typically) Pareto fitness and specify the number of objectives. Otherwise, the use is similar, here is an example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a tuple? That is not going to scale well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah corrected that mistake to vector, the struct uses a vector of objective functions.


```@example MOO-BBO
using OptimizationBBO, Optimization, BlackBoxOptim
using SciMLBase: MultiObjectiveOptimizationFunction
u0 = [0.25, 0.25]
opt = OptimizationBBO.BBO_borg_moea()
function multi_obj_func(x, p)
f1 = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2 # Rosenbrock function
f2 = -20.0 * exp(-0.2 * sqrt(0.5 * (x[1]^2 + x[2]^2))) - exp(0.5 * (cos(2π * x[1]) + cos(2π * x[2]))) + exp(1) + 20.0 # Ackley function
return (f1, f2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you didn't actually change it though?

end
mof = MultiObjectiveOptimizationFunction(multi_obj_func)
prob = Optimization.OptimizationProblem(mof, u0; lb = [0.0, 0.0], ub = [2.0, 2.0])
sol = solve(prob, opt, NumDimensions=2, FitnessScheme=ParetoFitnessScheme{2}(is_minimizing=true))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NumDimensions, FitnessScheme, those don't match Julia style.

```
17 changes: 17 additions & 0 deletions docs/src/optimization_packages/evolutionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ f = OptimizationFunction(rosenbrock)
prob = Optimization.OptimizationProblem(f, x0, p, lb = [-1.0, -1.0], ub = [1.0, 1.0])
sol = solve(prob, Evolutionary.CMAES(μ = 40, λ = 100))
```

## Multi-objective optimization
The Rosenbrock and Ackley functions can be optimized using the `Evolutionary.NSGA2()` as follows:

```@example MOO-Evolutionary
using Optimization, OptimizationEvolutionary, Evolutionary
function func(x, p=nothing)::Vector{Float64}
f1 = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2 # Rosenbrock function
f2 = -20.0 * exp(-0.2 * sqrt(0.5 * (x[1]^2 + x[2]^2))) - exp(0.5 * (cos(2π * x[1]) + cos(2π * x[2]))) + exp(1) + 20.0 # Ackley function
return [f1, f2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an array now? Is there an in-place form?

end
initial_guess = [1.0, 1.0]
obj_func = MultiObjectiveOptimizationFunction(func)
algorithm = OptimizationEvolutionary.NSGA2()
problem = OptimizationProblem(obj_func, initial_guess)
result = solve(problem, algorithm)
```
51 changes: 51 additions & 0 deletions docs/src/optimization_packages/metaheuristics.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,54 @@ sol = solve(prob, ECA(), use_initial = true, maxiters = 100000, maxtime = 1000.0
### With Constraint Equations

While `Metaheuristics.jl` supports such constraints, `Optimization.jl` currently does not relay these constraints.


## Multi-objective optimization
The zdt1 functions can be optimized using the `Metaheuristics.jl` as follows:

```@example MOO-Metaheuristics
using Optimization, OptimizationEvolutionary,OptimizationMetaheuristics, Metaheuristics
function zdt1(x)
f1 = x[1]
g = 1 + 9 * mean(x[2:end])
h = 1 - sqrt(f1 / g)
f2 = g * h
# In this example, we have no constraints
gx = [0.0] # Inequality constraints (not used)
hx = [0.0] # Equality constraints (not used)
return [f1, f2], gx, hx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now a third API?

end
multi_obj_fun = MultiObjectiveOptimizationFunction((x, p) -> zdt1(x))

# Define the problem bounds
lower_bounds = [0.0, 0.0, 0.0]
upper_bounds = [1.0, 1.0, 1.0]

# Define the initial guess
initial_guess = [0.5, 0.5, 0.5]

# Create the optimization problem
prob = OptimizationProblem(multi_obj_fun, initial_guess; lb = lower_bounds, ub = upper_bounds)

nobjectives = 2
npartitions = 100

# reference points (Das and Dennis's method)
weights = Metaheuristics.gen_ref_dirs(nobjectives, npartitions)

# Choose the algorithm as required.
alg1 = Metaheuristics.NSGA2()
alg2 = Metaheuristics.NSGA3()
alg3 = Metaheuristics.SPEA2()
alg4 = Metaheuristics.CCMO(NSGA2(N=100, p_m=0.001))
alg5 = Metaheuristics.MOEAD_DE(weights, options=Options(debug=false, iterations = 250))
alg6 = Metaheuristics.SMS_EMOA()

# Solve the problem
sol1 = solve(prob, alg1; maxiters = 100, use_initial = true)
sol2 = solve(prob, alg2; maxiters = 100, use_initial = true)
sol3 = solve(prob, alg3; maxiters = 100, use_initial = true)
sol4 = solve(prob, alg4)
sol5 = solve(prob, alg5; maxiters = 100, use_initial = true)
sol6 = solve(prob, alg6; maxiters = 100, use_initial = true)
```
Loading