.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_numerical_methods/optimization/plot_optimization_highs.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_auto_numerical_methods_optimization_plot_optimization_highs.py: Optimization using HiGHS solver =============================== .. GENERATED FROM PYTHON SOURCE LINES 9-13 In this example we are going to explore mixed-integer non linear problems optimization using the `HiGHS `_ interface. %% .. GENERATED FROM PYTHON SOURCE LINES 13-16 .. code-block:: Python import openturns as ot import openturns.experimental as otexp .. GENERATED FROM PYTHON SOURCE LINES 17-32 The following example will demonstrate the use of HiGHS solver to solve the following problem: .. math:: \max x + y + 2 z subject to: .. math:: \begin{array}{l} x + 2 y + 3 z \leq 4\\ x + y \ge 1\\ x, x, z \in \{0,1\}^3\\ \end{array} .. GENERATED FROM PYTHON SOURCE LINES 35-36 Definition of objective function as a cost vector .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python cost = [1, 1, 2] .. GENERATED FROM PYTHON SOURCE LINES 39-40 Definition of constraints in the form L<=Ax<=U .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python LU = ot.Interval([-1e30, 1], [4, 1e30]) A = ot.Matrix([[1, 2, 3], [1, 1, 0]]) .. GENERATED FROM PYTHON SOURCE LINES 44-45 Definition of variables types .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python BINARY = ot.OptimizationProblemImplementation.BINARY variablesType = [BINARY] * 3 bounds = ot.Interval(3) .. GENERATED FROM PYTHON SOURCE LINES 50-51 Define the linear problem .. GENERATED FROM PYTHON SOURCE LINES 51-55 .. code-block:: Python problem = otexp.LinearProblem(cost, bounds, A, LU) problem.setVariablesType(variablesType) problem.setMinimization(False) .. GENERATED FROM PYTHON SOURCE LINES 56-57 Run the algorithm .. GENERATED FROM PYTHON SOURCE LINES 57-60 .. code-block:: Python algo = otexp.HiGHS(problem) algo.setStartingPoint([0.0] * 3) .. GENERATED FROM PYTHON SOURCE LINES 61-62 Running the solver .. GENERATED FROM PYTHON SOURCE LINES 62-69 .. code-block:: Python algo.run() # Retrieving the results result = algo.getResult() print(" -- Optimal point = " + str(result.getOptimalPoint())) print(" -- Optimal value = " + str(result.getOptimalValue())) print(" -- Evaluation number = " + str(result.getInputSample().getSize())) .. rst-class:: sphx-glr-script-out .. code-block:: none -- Optimal point = [1,0,1] -- Optimal value = [3] -- Evaluation number = 0 .. _sphx_glr_download_auto_numerical_methods_optimization_plot_optimization_highs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_optimization_highs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_optimization_highs.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_optimization_highs.zip `