.. 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 28-34 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 34-48 .. code-block:: default from __future__ import division, unicode_literals from numpy import sum as np_sum 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, execute_post from gemseo.core.function import MDOFunction LOGGER = configure_logger() .. GENERATED FROM PYTHON SOURCE LINES 49-53 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 53-55 .. code-block:: default objective = MDOFunction(np_sum, name="f", expr="sum(x)") .. GENERATED FROM PYTHON SOURCE LINES 56-59 Define the design space ----------------------- Then, we define the :class:`.DesignSpace` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. 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 63-66 Define the optimization problem ------------------------------- Then, we define the :class:`.OptimizationProblem` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 66-69 .. code-block:: default problem = OptimizationProblem(design_space) problem.objective = objective .. GENERATED FROM PYTHON SOURCE LINES 70-75 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 75-77 .. code-block:: default DOEFactory().execute(problem, "fullfact", n_samples=11 ** 2) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none INFO - 09:25:55: Optimization problem: INFO - 09:25:55: Minimize: f = sum(x) INFO - 09:25:55: With respect to: x INFO - 09:25:55: Full factorial design required. Number of samples along each direction for a design vector of size 2 with 121 samples: 11 INFO - 09:25:55: Final number of samples for DOE = 121 vs 121 requested INFO - 09:25:55: DOE sampling: 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 Out: .. code-block:: none Available algorithms ['CustomDOE', 'DiagonalDOE', 'OT_SOBOL', 'OT_HASELGROVE', 'OT_REVERSE_HALTON', 'OT_HALTON', 'OT_FAURE', 'OT_AXIAL', 'OT_FACTORIAL', 'OT_MONTE_CARLO', 'OT_LHS', 'OT_LHSC', 'OT_OPT_LHS', 'OT_RANDOM', 'OT_FULLFACT', 'OT_COMPOSITE', 'OT_SOBOL_INDICES', 'fullfact', 'ff2n', 'pbdesign', 'bbdesign', 'ccdesign', 'lhs'] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.682 seconds) .. _sphx_glr_download_examples_optimization_problem_plot_simple_opt_3.py: .. only :: html .. container:: sphx-glr-footer :class: 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 `_