.. 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-43 .. code-block:: default 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 44-48 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 48-50 .. code-block:: default objective = MDOFunction(np_sum, name="f", expr="sum(x)") .. GENERATED FROM PYTHON SOURCE LINES 51-54 Define the design space ----------------------- Then, we define the :class:`.DesignSpace` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. 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 58-61 Define the optimization problem ------------------------------- Then, we define the :class:`.OptimizationProblem` with |g|. .. GENERATED FROM PYTHON SOURCE LINES 61-64 .. code-block:: default problem = OptimizationProblem(design_space) problem.objective = objective .. GENERATED FROM PYTHON SOURCE LINES 65-70 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 70-72 .. code-block:: default DOEFactory().execute(problem, "fullfact", n_samples=11**2) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none INFO - 10:06:11: Optimization problem: INFO - 10:06:11: minimize f = sum(x) INFO - 10:06:11: with respect to x INFO - 10:06:11: over the design space: INFO - 10:06:11: +------+-------------+-------+-------------+---------+ INFO - 10:06:11: | name | lower_bound | value | upper_bound | type | INFO - 10:06:11: +------+-------------+-------+-------------+---------+ INFO - 10:06:11: | x | -5 | None | 5 | integer | INFO - 10:06:11: | x | -5 | None | 5 | integer | INFO - 10:06:11: +------+-------------+-------+-------------+---------+ INFO - 10:06:11: Solving optimization problem with algorithm fullfact: INFO - 10:06:11: Full factorial design required. Number of samples along each direction for a design vector of size 2 with 121 samples: 11 INFO - 10:06:11: Final number of samples for DOE = 121 vs 121 requested INFO - 10:06:11: ... 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 `_