Using Evolutionary Algorithms in DESDEO (Functional)¶
Here, we will show multiple ways of using Evolutionary Algorithms (EAs) in DESDEO, depending on the user's needs. Be sure to read the explanation on how these algorithms are structured. We will showcase three different ways of using EAs in DESDEO:
- Using inbuilt algorithms in DESDEO for to calculate a representative set of solutions for multi-objective optimization problems.
- Using inbuilt algorithms in DESDEO for to interactive evolutionary multi-objective optimization.
- Using components implemented in DESDEO to build custom EAs (interactive or not).
Using inbuilt algorithms in DESDEO¶
First, let's import the necessary classes and functions from DESDEO.
import warnings
# Suppress Userwarnings from not having solvers installed
# This is not a problem, as we are not using any solvers in this example.
warnings.filterwarnings("ignore", category=UserWarning)
import plotly.graph_objects as go
from desdeo.emo.hooks.archivers import NonDominatedArchive
from desdeo.emo.methods.EAs import ReferenceVectorOptions, nsga3
from desdeo.problem.testproblems import dtlz2
First, we instantiate the problem we want to solve. We will use the DTLZ2 problem from the desdeo.problems module.
Then, we will pass the problem to the nsga3 method from the desdeo.emo module. This method creates a solver and a publisher object. The solver object can be run to solve the problem using NSGA-III, while the publisher object can be used to append additional components to the algorithm. We will see the usage of publisher further down.
problem = dtlz2(n_variables=10, n_objectives=3)
solver, publisher = nsga3(problem=problem)
result = solver()
Running the solver object will return a EMOResult object, which contains the final population of solutions.
print(result.optimal_variables.head()) # Contains the decision variables values
print(result.optimal_outputs.head())
# Contains the objective values, target values (values that are minimized), and constraints, and extra functions.
shape: (5, 10) ┌──────────┬──────────┬──────────┬──────────┬───┬──────────┬──────────┬──────────┬──────────┐ │ x_1 ┆ x_2 ┆ x_3 ┆ x_4 ┆ … ┆ x_7 ┆ x_8 ┆ x_9 ┆ x_10 │ │ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │ │ f64 ┆ f64 ┆ f64 ┆ f64 ┆ ┆ f64 ┆ f64 ┆ f64 ┆ f64 │ ╞══════════╪══════════╪══════════╪══════════╪═══╪══════════╪══════════╪══════════╪══════════╡ │ 0.159948 ┆ 0.77809 ┆ 0.474853 ┆ 0.482729 ┆ … ┆ 0.495864 ┆ 0.48108 ┆ 0.535351 ┆ 0.48465 │ │ 0.05178 ┆ 0.388254 ┆ 0.509597 ┆ 0.482102 ┆ … ┆ 0.502939 ┆ 0.488673 ┆ 0.474891 ┆ 0.505252 │ │ 0.85863 ┆ 0.810954 ┆ 0.504916 ┆ 0.505759 ┆ … ┆ 0.494227 ┆ 0.481803 ┆ 0.46666 ┆ 0.524865 │ │ 0.268906 ┆ 0.115783 ┆ 0.518448 ┆ 0.449515 ┆ … ┆ 0.542335 ┆ 0.481133 ┆ 0.510302 ┆ 0.505532 │ │ 0.043808 ┆ 0.132723 ┆ 0.511168 ┆ 0.512178 ┆ … ┆ 0.49821 ┆ 0.521688 ┆ 0.514324 ┆ 0.512196 │ └──────────┴──────────┴──────────┴──────────┴───┴──────────┴──────────┴──────────┴──────────┘ shape: (5, 7) ┌──────────┬──────────┬──────────┬──────────┬──────────┬──────────┬──────────┐ │ g ┆ f_1 ┆ f_2 ┆ f_3 ┆ f_1_min ┆ f_2_min ┆ f_3_min │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 │ ╞══════════╪══════════╪══════════╪══════════╪══════════╪══════════╪══════════╡ │ 1.003388 ┆ 0.331957 ┆ 0.913436 ┆ 0.249454 ┆ 0.331957 ┆ 0.913436 ┆ 0.249454 │ │ 1.001771 ┆ 0.81846 ┆ 0.571877 ┆ 0.08139 ┆ 0.81846 ┆ 0.571877 ┆ 0.08139 │ │ 1.004485 ┆ 0.064734 ┆ 0.211548 ┆ 0.97982 ┆ 0.064734 ┆ 0.211548 ┆ 0.97982 │ │ 1.005801 ┆ 0.902269 ┆ 0.16593 ┆ 0.412326 ┆ 0.902269 ┆ 0.16593 ┆ 0.412326 │ │ 1.002052 ┆ 0.978034 ┆ 0.206908 ┆ 0.068901 ┆ 0.978034 ┆ 0.206908 ┆ 0.068901 │ └──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘
go.Figure(
go.Scatter3d(
x=result.optimal_outputs["f_1"],
y=result.optimal_outputs["f_2"],
z=result.optimal_outputs["f_3"],
mode="markers",
marker=dict(size=2),
)
).show(renderer="notebook", include_plotlyjs="cdn")