.. 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-50 .. code-block:: default from __future__ import absolute_import, division, print_function, unicode_literals from future import standard_library 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 standard_library.install_aliases() LOGGER = configure_logger() .. GENERATED FROM PYTHON SOURCE LINES 51-55 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 55-57 .. code-block:: default objective = MDOFunction(np_sum, name="f", expr="sum(x)") .. GENERATED FROM PYTHON SOURCE LINES 58-61 Define the design space ----------------------- Then, we define the :class:`.DesignSpace` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 61-64 .. 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 65-68 Define the optimization problem ------------------------------- Then, we define the :class:`.OptimizationProblem` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 68-71 .. code-block:: default problem = OptimizationProblem(design_space) problem.objective = objective .. GENERATED FROM PYTHON SOURCE LINES 72-77 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 77-79 .. code-block:: default DOEFactory().execute(problem, "fullfact", n_samples=11 ** 2) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Optimization result: |_ Design variables: [-5. -5.] |_ Objective function: -10.0 |_ Feasible solution: True .. GENERATED FROM PYTHON SOURCE LINES 80-82 Post-process the results ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 82-86 .. code-block:: default execute_post( problem, "ScatterPlotMatrix", variables_list=["x", "f"], save=False, show=True ) .. image:: /examples/optimization_problem/images/sphx_glr_plot_simple_opt_3_001.png :alt: plot simple opt 3 :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 87-88 Note that you can get all the optimization algorithms names: .. GENERATED FROM PYTHON SOURCE LINES 88-90 .. 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_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.382 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 `_