.. 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 :ref:`Go to the end ` 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 26-32 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 32-44 .. code-block:: Python from __future__ import annotations from numpy import sum as np_sum from gemseo import execute_algo from gemseo import execute_post from gemseo import get_available_doe_algorithms from gemseo import get_available_opt_algorithms from gemseo.algos.design_space import DesignSpace from gemseo.algos.optimization_problem import OptimizationProblem from gemseo.core.mdo_functions.mdo_function import MDOFunction .. 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 an :class:`.MDOFunction`. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python 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:: Python design_space = DesignSpace() design_space.add_variable("x", 2, lower_bound=-5, upper_bound=5, 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:: Python 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:: Python execute_algo(problem, algo_name="PYDOE_FULLFACT", n_samples=11**2, algo_type="doe") .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 16:25:01: Optimization problem: INFO - 16:25:01: minimize f = sum(x) INFO - 16:25:01: with respect to x INFO - 16:25:01: over the design space: INFO - 16:25:01: +------+-------------+-------+-------------+---------+ INFO - 16:25:01: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:25:01: +------+-------------+-------+-------------+---------+ INFO - 16:25:01: | x[0] | -5 | None | 5 | integer | INFO - 16:25:01: | x[1] | -5 | None | 5 | integer | INFO - 16:25:01: +------+-------------+-------+-------------+---------+ INFO - 16:25:01: Solving optimization problem with algorithm PYDOE_FULLFACT: INFO - 16:25:01: 1%| | 1/121 [00:00<00:00, 5146.39 it/sec, feas=True, obj=-10] INFO - 16:25:01: 2%|▏ | 2/121 [00:00<00:00, 4655.17 it/sec, feas=True, obj=-9] INFO - 16:25:01: 2%|▏ | 3/121 [00:00<00:00, 5007.13 it/sec, feas=True, obj=-8] INFO - 16:25:01: 3%|▎ | 4/121 [00:00<00:00, 5324.41 it/sec, feas=True, obj=-7] INFO - 16:25:01: 4%|▍ | 5/121 [00:00<00:00, 5567.17 it/sec, feas=True, obj=-6] INFO - 16:25:01: 5%|▍ | 6/121 [00:00<00:00, 5762.73 it/sec, feas=True, obj=-5] INFO - 16:25:01: 6%|▌ | 7/121 [00:00<00:00, 5933.74 it/sec, feas=True, obj=-4] INFO - 16:25:01: 7%|▋ | 8/121 [00:00<00:00, 5952.53 it/sec, feas=True, obj=-3] INFO - 16:25:01: 7%|▋ | 9/121 [00:00<00:00, 6013.82 it/sec, feas=True, obj=-2] INFO - 16:25:01: 8%|▊ | 10/121 [00:00<00:00, 6108.80 it/sec, feas=True, obj=-1] INFO - 16:25:01: 9%|▉ | 11/121 [00:00<00:00, 6201.26 it/sec, feas=True, obj=0] INFO - 16:25:01: 10%|▉ | 12/121 [00:00<00:00, 6266.39 it/sec, feas=True, obj=-9] INFO - 16:25:01: 11%|█ | 13/121 [00:00<00:00, 6331.39 it/sec, feas=True, obj=-8] INFO - 16:25:01: 12%|█▏ | 14/121 [00:00<00:00, 6400.73 it/sec, feas=True, obj=-7] INFO - 16:25:01: 12%|█▏ | 15/121 [00:00<00:00, 6397.66 it/sec, feas=True, obj=-6] INFO - 16:25:01: 13%|█▎ | 16/121 [00:00<00:00, 6431.75 it/sec, feas=True, obj=-5] INFO - 16:25:01: 14%|█▍ | 17/121 [00:00<00:00, 6479.75 it/sec, feas=True, obj=-4] INFO - 16:25:01: 15%|█▍ | 18/121 [00:00<00:00, 6524.15 it/sec, feas=True, obj=-3] INFO - 16:25:01: 16%|█▌ | 19/121 [00:00<00:00, 6546.60 it/sec, feas=True, obj=-2] INFO - 16:25:01: 17%|█▋ | 20/121 [00:00<00:00, 6578.27 it/sec, feas=True, obj=-1] INFO - 16:25:01: 17%|█▋ | 21/121 [00:00<00:00, 6617.61 it/sec, feas=True, obj=0] INFO - 16:25:01: 18%|█▊ | 22/121 [00:00<00:00, 6624.65 it/sec, feas=True, obj=1] INFO - 16:25:01: 19%|█▉ | 23/121 [00:00<00:00, 6640.21 it/sec, feas=True, obj=-8] INFO - 16:25:01: 20%|█▉ | 24/121 [00:00<00:00, 6673.07 it/sec, feas=True, obj=-7] INFO - 16:25:01: 21%|██ | 25/121 [00:00<00:00, 6704.45 it/sec, feas=True, obj=-6] INFO - 16:25:01: 21%|██▏ | 26/121 [00:00<00:00, 6739.92 it/sec, feas=True, obj=-5] INFO - 16:25:01: 22%|██▏ | 27/121 [00:00<00:00, 6773.10 it/sec, feas=True, obj=-4] INFO - 16:25:01: 23%|██▎ | 28/121 [00:00<00:00, 6801.84 it/sec, feas=True, obj=-3] INFO - 16:25:01: 24%|██▍ | 29/121 [00:00<00:00, 6829.58 it/sec, feas=True, obj=-2] INFO - 16:25:01: 25%|██▍ | 30/121 [00:00<00:00, 6814.47 it/sec, feas=True, obj=-1] INFO - 16:25:01: 26%|██▌ | 31/121 [00:00<00:00, 6828.96 it/sec, feas=True, obj=0] INFO - 16:25:01: 26%|██▋ | 32/121 [00:00<00:00, 6846.80 it/sec, feas=True, obj=1] INFO - 16:25:01: 27%|██▋ | 33/121 [00:00<00:00, 6865.34 it/sec, feas=True, obj=2] INFO - 16:25:01: 28%|██▊ | 34/121 [00:00<00:00, 6879.56 it/sec, feas=True, obj=-7] INFO - 16:25:01: 29%|██▉ | 35/121 [00:00<00:00, 6894.96 it/sec, feas=True, obj=-6] INFO - 16:25:01: 30%|██▉ | 36/121 [00:00<00:00, 6908.63 it/sec, feas=True, obj=-5] INFO - 16:25:01: 31%|███ | 37/121 [00:00<00:00, 6900.06 it/sec, feas=True, obj=-4] INFO - 16:25:01: 31%|███▏ | 38/121 [00:00<00:00, 6907.50 it/sec, feas=True, obj=-3] INFO - 16:25:01: 32%|███▏ | 39/121 [00:00<00:00, 6923.93 it/sec, feas=True, obj=-2] INFO - 16:25:01: 33%|███▎ | 40/121 [00:00<00:00, 6937.89 it/sec, feas=True, obj=-1] INFO - 16:25:01: 34%|███▍ | 41/121 [00:00<00:00, 6951.23 it/sec, feas=True, obj=0] INFO - 16:25:01: 35%|███▍ | 42/121 [00:00<00:00, 6966.46 it/sec, feas=True, obj=1] INFO - 16:25:01: 36%|███▌ | 43/121 [00:00<00:00, 6978.88 it/sec, feas=True, obj=2] INFO - 16:25:01: 36%|███▋ | 44/121 [00:00<00:00, 6970.97 it/sec, feas=True, obj=3] INFO - 16:25:01: 37%|███▋ | 45/121 [00:00<00:00, 6967.54 it/sec, feas=True, obj=-6] INFO - 16:25:01: 38%|███▊ | 46/121 [00:00<00:00, 6976.86 it/sec, feas=True, obj=-5] INFO - 16:25:01: 39%|███▉ | 47/121 [00:00<00:00, 6987.29 it/sec, feas=True, obj=-4] INFO - 16:25:01: 40%|███▉ | 48/121 [00:00<00:00, 6991.23 it/sec, feas=True, obj=-3] INFO - 16:25:01: 40%|████ | 49/121 [00:00<00:00, 7001.46 it/sec, feas=True, obj=-2] INFO - 16:25:01: 41%|████▏ | 50/121 [00:00<00:00, 7013.18 it/sec, feas=True, obj=-1] INFO - 16:25:01: 42%|████▏ | 51/121 [00:00<00:00, 7027.25 it/sec, feas=True, obj=0] INFO - 16:25:01: 43%|████▎ | 52/121 [00:00<00:00, 7016.37 it/sec, feas=True, obj=1] INFO - 16:25:01: 44%|████▍ | 53/121 [00:00<00:00, 7024.08 it/sec, feas=True, obj=2] INFO - 16:25:01: 45%|████▍ | 54/121 [00:00<00:00, 7036.33 it/sec, feas=True, obj=3] INFO - 16:25:01: 45%|████▌ | 55/121 [00:00<00:00, 7046.45 it/sec, feas=True, obj=4] INFO - 16:25:01: 46%|████▋ | 56/121 [00:00<00:00, 7057.30 it/sec, feas=True, obj=-5] INFO - 16:25:01: 47%|████▋ | 57/121 [00:00<00:00, 7069.68 it/sec, feas=True, obj=-4] INFO - 16:25:01: 48%|████▊ | 58/121 [00:00<00:00, 7081.05 it/sec, feas=True, obj=-3] INFO - 16:25:01: 49%|████▉ | 59/121 [00:00<00:00, 7075.05 it/sec, feas=True, obj=-2] INFO - 16:25:01: 50%|████▉ | 60/121 [00:00<00:00, 7077.40 it/sec, feas=True, obj=-1] INFO - 16:25:01: 50%|█████ | 61/121 [00:00<00:00, 7085.76 it/sec, feas=True, obj=0] INFO - 16:25:01: 51%|█████ | 62/121 [00:00<00:00, 7094.44 it/sec, feas=True, obj=1] INFO - 16:25:01: 52%|█████▏ | 63/121 [00:00<00:00, 7017.43 it/sec, feas=True, obj=2] INFO - 16:25:01: 53%|█████▎ | 64/121 [00:00<00:00, 7020.12 it/sec, feas=True, obj=3] INFO - 16:25:01: 54%|█████▎ | 65/121 [00:00<00:00, 7018.94 it/sec, feas=True, obj=4] INFO - 16:25:01: 55%|█████▍ | 66/121 [00:00<00:00, 7001.65 it/sec, feas=True, obj=5] INFO - 16:25:01: 55%|█████▌ | 67/121 [00:00<00:00, 6999.74 it/sec, feas=True, obj=-4] INFO - 16:25:01: 56%|█████▌ | 68/121 [00:00<00:00, 6997.71 it/sec, feas=True, obj=-3] INFO - 16:25:01: 57%|█████▋ | 69/121 [00:00<00:00, 6998.96 it/sec, feas=True, obj=-2] INFO - 16:25:01: 58%|█████▊ | 70/121 [00:00<00:00, 6997.67 it/sec, feas=True, obj=-1] INFO - 16:25:01: 59%|█████▊ | 71/121 [00:00<00:00, 6996.58 it/sec, feas=True, obj=0] INFO - 16:25:01: 60%|█████▉ | 72/121 [00:00<00:00, 6982.59 it/sec, feas=True, obj=1] INFO - 16:25:01: 60%|██████ | 73/121 [00:00<00:00, 6976.81 it/sec, feas=True, obj=2] INFO - 16:25:01: 61%|██████ | 74/121 [00:00<00:00, 6978.72 it/sec, feas=True, obj=3] INFO - 16:25:01: 62%|██████▏ | 75/121 [00:00<00:00, 6983.06 it/sec, feas=True, obj=4] INFO - 16:25:01: 63%|██████▎ | 76/121 [00:00<00:00, 6978.72 it/sec, feas=True, obj=5] INFO - 16:25:01: 64%|██████▎ | 77/121 [00:00<00:00, 6978.88 it/sec, feas=True, obj=6] INFO - 16:25:01: 64%|██████▍ | 78/121 [00:00<00:00, 6980.36 it/sec, feas=True, obj=-3] INFO - 16:25:01: 65%|██████▌ | 79/121 [00:00<00:00, 6971.83 it/sec, feas=True, obj=-2] INFO - 16:25:01: 66%|██████▌ | 80/121 [00:00<00:00, 6968.73 it/sec, feas=True, obj=-1] INFO - 16:25:01: 67%|██████▋ | 81/121 [00:00<00:00, 6968.71 it/sec, feas=True, obj=0] INFO - 16:25:01: 68%|██████▊ | 82/121 [00:00<00:00, 6970.39 it/sec, feas=True, obj=1] INFO - 16:25:01: 69%|██████▊ | 83/121 [00:00<00:00, 6972.86 it/sec, feas=True, obj=2] INFO - 16:25:01: 69%|██████▉ | 84/121 [00:00<00:00, 6974.32 it/sec, feas=True, obj=3] INFO - 16:25:01: 70%|███████ | 85/121 [00:00<00:00, 6978.33 it/sec, feas=True, obj=4] INFO - 16:25:01: 71%|███████ | 86/121 [00:00<00:00, 6966.61 it/sec, feas=True, obj=5] INFO - 16:25:01: 72%|███████▏ | 87/121 [00:00<00:00, 6960.64 it/sec, feas=True, obj=6] INFO - 16:25:01: 73%|███████▎ | 88/121 [00:00<00:00, 6960.98 it/sec, feas=True, obj=7] INFO - 16:25:01: 74%|███████▎ | 89/121 [00:00<00:00, 6963.38 it/sec, feas=True, obj=-2] INFO - 16:25:01: 74%|███████▍ | 90/121 [00:00<00:00, 6965.61 it/sec, feas=True, obj=-1] INFO - 16:25:01: 75%|███████▌ | 91/121 [00:00<00:00, 6969.06 it/sec, feas=True, obj=0] INFO - 16:25:01: 76%|███████▌ | 92/121 [00:00<00:00, 6971.18 it/sec, feas=True, obj=1] INFO - 16:25:01: 77%|███████▋ | 93/121 [00:00<00:00, 6963.68 it/sec, feas=True, obj=2] INFO - 16:25:01: 78%|███████▊ | 94/121 [00:00<00:00, 6962.61 it/sec, feas=True, obj=3] INFO - 16:25:01: 79%|███████▊ | 95/121 [00:00<00:00, 6963.75 it/sec, feas=True, obj=4] INFO - 16:25:01: 79%|███████▉ | 96/121 [00:00<00:00, 6964.75 it/sec, feas=True, obj=5] INFO - 16:25:01: 80%|████████ | 97/121 [00:00<00:00, 6965.49 it/sec, feas=True, obj=6] INFO - 16:25:01: 81%|████████ | 98/121 [00:00<00:00, 6967.16 it/sec, feas=True, obj=7] INFO - 16:25:01: 82%|████████▏ | 99/121 [00:00<00:00, 6969.15 it/sec, feas=True, obj=8] INFO - 16:25:01: 83%|████████▎ | 100/121 [00:00<00:00, 6950.66 it/sec, feas=True, obj=-1] INFO - 16:25:01: 83%|████████▎ | 101/121 [00:00<00:00, 6946.72 it/sec, feas=True, obj=0] INFO - 16:25:01: 84%|████████▍ | 102/121 [00:00<00:00, 6946.81 it/sec, feas=True, obj=1] INFO - 16:25:01: 85%|████████▌ | 103/121 [00:00<00:00, 6941.53 it/sec, feas=True, obj=2] INFO - 16:25:01: 86%|████████▌ | 104/121 [00:00<00:00, 6939.57 it/sec, feas=True, obj=3] INFO - 16:25:01: 87%|████████▋ | 105/121 [00:00<00:00, 6939.51 it/sec, feas=True, obj=4] INFO - 16:25:01: 88%|████████▊ | 106/121 [00:00<00:00, 6940.31 it/sec, feas=True, obj=5] INFO - 16:25:01: 88%|████████▊ | 107/121 [00:00<00:00, 6930.81 it/sec, feas=True, obj=6] INFO - 16:25:01: 89%|████████▉ | 108/121 [00:00<00:00, 6931.04 it/sec, feas=True, obj=7] INFO - 16:25:01: 90%|█████████ | 109/121 [00:00<00:00, 6932.00 it/sec, feas=True, obj=8] INFO - 16:25:01: 91%|█████████ | 110/121 [00:00<00:00, 6933.15 it/sec, feas=True, obj=9] INFO - 16:25:01: 92%|█████████▏| 111/121 [00:00<00:00, 6933.56 it/sec, feas=True, obj=0] INFO - 16:25:01: 93%|█████████▎| 112/121 [00:00<00:00, 6934.06 it/sec, feas=True, obj=1] INFO - 16:25:01: 93%|█████████▎| 113/121 [00:00<00:00, 6926.25 it/sec, feas=True, obj=2] INFO - 16:25:01: 94%|█████████▍| 114/121 [00:00<00:00, 6926.21 it/sec, feas=True, obj=3] INFO - 16:25:01: 95%|█████████▌| 115/121 [00:00<00:00, 6930.84 it/sec, feas=True, obj=4] INFO - 16:25:01: 96%|█████████▌| 116/121 [00:00<00:00, 6934.31 it/sec, feas=True, obj=5] INFO - 16:25:01: 97%|█████████▋| 117/121 [00:00<00:00, 6939.20 it/sec, feas=True, obj=6] INFO - 16:25:01: 98%|█████████▊| 118/121 [00:00<00:00, 6943.63 it/sec, feas=True, obj=7] INFO - 16:25:01: 98%|█████████▊| 119/121 [00:00<00:00, 6947.79 it/sec, feas=True, obj=8] INFO - 16:25:01: 99%|█████████▉| 120/121 [00:00<00:00, 6952.27 it/sec, feas=True, obj=9] INFO - 16:25:01: 100%|██████████| 121/121 [00:00<00:00, 6845.86 it/sec, feas=True, obj=10] INFO - 16:25:01: Optimization result: INFO - 16:25:01: Optimizer info: INFO - 16:25:01: Status: None INFO - 16:25:01: Message: None INFO - 16:25:01: Solution: INFO - 16:25:01: Objective: -10.0 INFO - 16:25:01: Design space: INFO - 16:25:01: +------+-------------+-------+-------------+---------+ INFO - 16:25:01: | Name | Lower bound | Value | Upper bound | Type | INFO - 16:25:01: +------+-------------+-------+-------------+---------+ INFO - 16:25:01: | x[0] | -5 | -5 | 5 | integer | INFO - 16:25:01: | x[1] | -5 | -5 | 5 | integer | INFO - 16:25:01: +------+-------------+-------+-------------+---------+ .. raw:: html
Optimization result:
  • Design variables: [-5. -5.]
  • Objective function: -10.0
  • Feasible solution: True


.. GENERATED FROM PYTHON SOURCE LINES 74-76 Post-process the results ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 76-84 .. code-block:: Python execute_post( problem, post_name="ScatterPlotMatrix", variable_names=["x", "f"], save=False, show=True, ) .. image-sg:: /examples/optimization_problem/images/sphx_glr_plot_simple_opt_3_001.png :alt: plot simple opt 3 :srcset: /examples/optimization_problem/images/sphx_glr_plot_simple_opt_3_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 85-86 Note that you can get all the optimization algorithms names: .. GENERATED FROM PYTHON SOURCE LINES 86-87 .. code-block:: Python get_available_opt_algorithms() .. rst-class:: sphx-glr-script-out .. code-block:: none ['Augmented_Lagrangian_order_0', 'Augmented_Lagrangian_order_1', 'Scipy_MILP', 'HEXALY', 'MMA', 'MNBI', 'MultiStart', 'NLOPT_MMA', 'NLOPT_COBYLA', 'NLOPT_SLSQP', 'NLOPT_BOBYQA', 'NLOPT_BFGS', 'NLOPT_NEWUOA', 'PDFO_COBYLA', 'PDFO_BOBYQA', 'PDFO_NEWUOA', 'PYOPTSPARSE_SLSQP', 'PYOPTSPARSE_SNOPT', 'PYMOO_GA', 'PYMOO_NSGA2', 'PYMOO_NSGA3', 'PYMOO_UNSGA3', 'PYMOO_RNSGA3', 'SMT_EGO', 'DUAL_ANNEALING', 'SHGO', 'DIFFERENTIAL_EVOLUTION', 'INTERIOR_POINT', 'DUAL_SIMPLEX', 'SLSQP', 'L-BFGS-B', 'TNC', 'NELDER-MEAD', 'COBYQA'] .. GENERATED FROM PYTHON SOURCE LINES 88-89 and all the DOE algorithms names: .. GENERATED FROM PYTHON SOURCE LINES 89-90 .. code-block:: Python get_available_doe_algorithms() .. rst-class:: sphx-glr-script-out .. code-block:: none ['CustomDOE', 'DiagonalDOE', 'MorrisDOE', 'OATDOE', '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', 'PYDOE_BBDESIGN', 'PYDOE_CCDESIGN', 'PYDOE_FF2N', 'PYDOE_FULLFACT', 'PYDOE_LHS', 'PYDOE_PBDESIGN', 'Halton', 'LHS', 'MC', 'PoissonDisk', 'Sobol'] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.307 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-jupyter :download:`Download Jupyter notebook: plot_simple_opt_3.ipynb ` .. 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-zip :download:`Download zipped: plot_simple_opt_3.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_