.. 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-45 .. 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 matplotlib import pyplot as plt from numpy import sum as np_sum LOGGER = configure_logger() .. GENERATED FROM PYTHON SOURCE LINES 46-50 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 50-52 .. code-block:: default objective = MDOFunction(np_sum, name="f", expr="sum(x)") .. GENERATED FROM PYTHON SOURCE LINES 53-56 Define the design space ----------------------- Then, we define the :class:`.DesignSpace` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 56-59 .. 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 60-63 Define the optimization problem ------------------------------- Then, we define the :class:`.OptimizationProblem` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 63-66 .. code-block:: default problem = OptimizationProblem(design_space) problem.objective = objective .. GENERATED FROM PYTHON SOURCE LINES 67-72 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 72-74 .. code-block:: default DOEFactory().execute(problem, "fullfact", n_samples=11**2) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 14:47:13: Optimization problem: INFO - 14:47:13: minimize f = sum(x) INFO - 14:47:13: with respect to x INFO - 14:47:13: over the design space: INFO - 14:47:13: +------+-------------+-------+-------------+---------+ INFO - 14:47:13: | name | lower_bound | value | upper_bound | type | INFO - 14:47:13: +------+-------------+-------+-------------+---------+ INFO - 14:47:13: | x[0] | -5 | None | 5 | integer | INFO - 14:47:13: | x[1] | -5 | None | 5 | integer | INFO - 14:47:13: +------+-------------+-------+-------------+---------+ INFO - 14:47:13: Solving optimization problem with algorithm fullfact: INFO - 14:47:13: ... 0%| | 0/121 [00:00` .. 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 `_