.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/optimization_problem/plot_simple_opt_3.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_optimization_problem_plot_simple_opt_3.py: Analytical test case # 3 ======================== .. GENERATED FROM PYTHON SOURCE LINES 25-31 In this example, we consider a simple optimization problem to illustrate algorithms interfaces and DOE libraries integration. Integer variables are used Imports ------- .. GENERATED FROM PYTHON SOURCE LINES 31-44 .. code-block:: default from __future__ import annotations from gemseo.algos.design_space import DesignSpace from gemseo.algos.doe.doe_factory import DOEFactory from gemseo.algos.opt_problem import OptimizationProblem from gemseo.api import configure_logger from gemseo.api import execute_post from gemseo.core.mdofunctions.mdo_function import MDOFunction from numpy import sum as np_sum LOGGER = configure_logger() .. GENERATED FROM PYTHON SOURCE LINES 45-49 Define the objective function ----------------------------- We define the objective function :math:`f(x)=\sum_{i=1}^dx_i` using a :class:`.MDOFunction`. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: default objective = MDOFunction(np_sum, name="f", expr="sum(x)") .. GENERATED FROM PYTHON SOURCE LINES 52-55 Define the design space ----------------------- Then, we define the :class:`.DesignSpace` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: default design_space = DesignSpace() design_space.add_variable("x", 2, l_b=-5, u_b=5, var_type="integer") .. GENERATED FROM PYTHON SOURCE LINES 59-62 Define the optimization problem ------------------------------- Then, we define the :class:`.OptimizationProblem` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 62-65 .. code-block:: default problem = OptimizationProblem(design_space) problem.objective = objective .. GENERATED FROM PYTHON SOURCE LINES 66-71 Solve the optimization problem using a DOE algorithm ---------------------------------------------------- We can see this optimization problem as a trade-off and solve it by means of a design of experiments (DOE), e.g. full factorial design .. GENERATED FROM PYTHON SOURCE LINES 71-73 .. code-block:: default DOEFactory().execute(problem, "fullfact", n_samples=11**2) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:58:58: Optimization problem: INFO - 16:58:58: minimize f = sum(x) INFO - 16:58:58: with respect to x INFO - 16:58:58: over the design space: INFO - 16:58:58: +------+-------------+-------+-------------+---------+ INFO - 16:58:58: | name | lower_bound | value | upper_bound | type | INFO - 16:58:58: +------+-------------+-------+-------------+---------+ INFO - 16:58:58: | x[0] | -5 | None | 5 | integer | INFO - 16:58:58: | x[1] | -5 | None | 5 | integer | INFO - 16:58:58: +------+-------------+-------+-------------+---------+ INFO - 16:58:58: Solving optimization problem with algorithm fullfact: INFO - 16:58:58: ... 0%| | 0/121 [00:00 .. GENERATED FROM PYTHON SOURCE LINES 85-86 Note that you can get all the optimization algorithms names: .. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: default algo_list = DOEFactory().algorithms print("Available algorithms ", algo_list) .. rst-class:: sphx-glr-script-out .. code-block:: none Available algorithms ['CustomDOE', 'DiagonalDOE', 'OT_SOBOL', 'OT_RANDOM', 'OT_HASELGROVE', 'OT_REVERSE_HALTON', 'OT_HALTON', 'OT_FAURE', 'OT_MONTE_CARLO', 'OT_FACTORIAL', 'OT_COMPOSITE', 'OT_AXIAL', 'OT_OPT_LHS', 'OT_LHS', 'OT_LHSC', 'OT_FULLFACT', 'OT_SOBOL_INDICES', 'fullfact', 'ff2n', 'pbdesign', 'bbdesign', 'ccdesign', 'lhs'] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.634 seconds) .. _sphx_glr_download_examples_optimization_problem_plot_simple_opt_3.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_simple_opt_3.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_simple_opt_3.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_