Notas para contenedor de docker:

Comando de docker para ejecución de la nota de forma local:

nota: cambiar <ruta a mi directorio> por la ruta de directorio que se desea mapear a /datos dentro del contenedor de docker.

docker run --rm -v <ruta a mi directorio>:/datos --name jupyterlab_numerical -p 8888:8888 -d palmoreck/jupyterlab_numerical:1.1.0

password para jupyterlab: qwerty

Detener el contenedor de docker:

docker stop jupyterlab_numerical

Documentación de la imagen de docker palmoreck/jupyterlab_numerical:1.1.0 en liga.


Nota generada a partir de liga1, liga2.


In [1]:
!pip3 install --user -q cvxpy


  WARNING: The scripts futurize and pasteurize are installed in '/home/miuser/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: You are using pip version 19.3.1; however, version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

In [1]:
import os

In [2]:
cur_directory = os.getcwd()

In [3]:
dir_alg_python = '/algoritmos/Python'

In [4]:
os.chdir(cur_directory + dir_alg_python)

In [5]:
import math

import numpy as np

from utils import compute_error

from algorithms_for_cieco import path_following_method_infeasible_init_point

Está lista la implementación para puntos iniciales no factibles en $Ax=b$ pero no para la parte de las desigualdades $f_i(x) <0 \quad \forall i=1,\dots,m$

Primer ejemplo

$$ \min \quad x_1^2 + x_2^2 + x_3^2 + x_4^2 -2x_1-3x_4$$
$$\text{sujeto a: } $$
$$ \begin{array}{c} 2x_1 + x_2 + x_3 + 4x_4 = 7 \\ x_1 + x_2 + 2x_3 + x_4 = 6 \end{array} $$
$$x_1, x_2, x_3, x_4 \geq 0$$

Infeasible for Ax=b


In [6]:
fo = lambda x: x[0]**2 + x[1]**2 + x[2]**2 + x[3]**2-2*x[0]-3*x[3]

In [7]:
const = {0: lambda x: -x[0],
         1: lambda x: -x[1],
         2: lambda x: -x[2],
         3: lambda x: -x[3]
        }

In [8]:
A= np.array([[2,1,1,4],
             [1,1,2,1]])

In [9]:
b=np.array([7,6])

In [10]:
x_ast=np.array([1.1232876712328763,0.6506849315068493,
                1.8287671232876714,0.5684931506849317])

In [11]:
x_0 = np.array([1,1,1,1],dtype=float)

In [12]:
x_0


Out[12]:
array([1., 1., 1., 1.])

In [13]:
nu_0 = np.array([0,0], dtype=float)

In [14]:
p_ast=fo(x_ast)

In [15]:
p_ast


Out[15]:
1.4006849315068495

In [16]:
tol_outer_iter = 1e-6
tol=1e-8
tol_backtracking=1e-8
maxiter=30
mu=10

In [17]:
[x,iter_barrier,t] = path_following_method_infeasible_init_point(fo, A, b,
                                                                 const,
                                                               x_0, nu_0, tol,
                                                               tol_backtracking, x_ast, p_ast, maxiter,
                                                               mu, tol_outer_iter = tol_outer_iter 
                                                               )


Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
1		-1.67e+00	1.67e+00	2.40e+00
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	1.41e+00	4.36e+00	-2.49e+00	4.34e-01	1.71e+00	---		1.00e+00
1	2.51e-15	3.50e+00	1.02e-01	9.76e-02	3.64e-02	1.00e+00	1.00e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		7.49e+00		1.40e-02	9.76e-02	3.64e-02	---		1.86e+00
1		7.49e+00		4.15e-08	8.44e-02	2.72e-02	1.00e+00	1.86e+00
2		7.49e+00		4.15e-08	8.44e-02	2.72e-02	4.55e-13	1.86e+00
Error of x with respect to x_ast: 8.44e-02
Approximate solution: [1.09285271 0.83055378 1.76037618 0.55584116]
Backtracking value less than tol_backtracking, check approximation
Inner iterations
[1.09285271 0.83055378 1.76037618 0.55584116]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
2		2.39e+01	1.67e+01	2.40e-01
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	1.41e+00	4.90e+01	-2.35e+01	4.34e-01	1.71e+00	---		1.00e+00
1	2.66e-15	6.76e+01	1.64e-03	1.24e-02	5.84e-04	1.00e+00	1.00e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		7.17e+01		1.37e-03	1.24e-02	5.84e-04	---		1.08e+00
1		7.17e+01		5.41e-12	1.19e-02	5.40e-04	1.00e+00	1.08e+00
Error of x with respect to x_ast: 1.19e-02
Approximate solution: [1.11913837 0.67602916 1.81909083 0.56665082]
Inner iterations
[1.11913837 0.67602916 1.81909083 0.56665082]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
3		2.33e+02	1.67e+02	2.40e-02
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	1.41e+00	4.99e+02	-2.32e+02	4.34e-01	1.71e+00	---		1.00e+00
1	1.99e-15	7.14e+02	1.86e-05	1.32e-03	6.64e-06	1.00e+00	1.00e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		7.18e+02		2.40e-04	1.32e-03	6.64e-06	---		1.01e+00
1		7.18e+02		2.87e-11	1.25e-03	6.00e-06	1.00e+00	1.01e+00
Error of x with respect to x_ast: 1.25e-03
Approximate solution: [1.12285298 0.65335516 1.82774694 0.56829799]
Inner iterations
[1.12285298 0.65335516 1.82774694 0.56829799]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
4		2.33e+03	1.67e+03	2.40e-03
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	1.41e+00	5.00e+03	-2.32e+03	4.34e-01	1.71e+00	---		1.00e+00
1	1.26e-15	7.18e+03	4.23e-07	1.99e-04	1.51e-07	1.00e+00	1.00e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		7.19e+03		2.92e-04	1.99e-04	1.51e-07	---		1.00e+00
1		7.19e+03		4.38e-11	1.26e-04	6.06e-08	1.00e+00	1.00e+00
Error of x with respect to x_ast: 1.26e-04
Approximate solution: [1.12324403 0.65095347 1.8286645  0.56847349]
Inner iterations
[1.12324403 0.65095347 1.8286645  0.56847349]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
5		2.33e+04	1.67e+04	2.40e-04
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	1.41e+00	5.00e+04	-2.32e+04	4.34e-01	1.71e+00	---		1.00e+00
1	3.66e-15	7.19e+04	1.28e-07	1.09e-04	4.57e-08	1.00e+00	1.00e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		7.19e+04		1.96e-03	1.09e-04	4.57e-08	---		1.00e+00
1		7.19e+04		8.80e-10	1.26e-05	6.05e-10	1.00e+00	1.00e+00
Error of x with respect to x_ast: 1.26e-05
Approximate solution: [1.12328341 0.65071176 1.82875684 0.56849114]
Inner iterations
[1.12328341 0.65071176 1.82875684 0.56849114]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
6		2.33e+05	1.67e+05	2.40e-05
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	1.41e+00	5.00e+05	-2.32e+05	4.34e-01	1.71e+00	---		1.00e+00
1	1.99e-15	7.19e+05	1.14e-07	1.03e-04	4.06e-08	1.00e+00	1.00e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		7.19e+05		1.88e-02	1.03e-04	4.06e-08	---		1.00e+00
1		7.19e+05		1.18e-09	1.27e-06	6.17e-12	1.00e+00	1.00e+00
Error of x with respect to x_ast: 1.27e-06
Approximate solution: [1.12328723 0.65068764 1.82876609 0.56849295]
Inner iterations
[1.12328723 0.65068764 1.82876609 0.56849295]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
7		2.33e+06	1.67e+06	2.40e-06
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	1.41e+00	5.00e+06	-2.32e+06	4.34e-01	1.71e+00	---		1.00e+00
1	1.99e-15	7.19e+06	1.12e-07	1.03e-04	4.02e-08	1.00e+00	1.00e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		7.19e+06		1.87e-01	1.03e-04	4.02e-08	---		1.00e+00
1		7.19e+06		5.02e-08	7.69e-08	2.06e-14	1.00e+00	1.00e+00
2		7.19e+06		4.79e-08	7.70e-08	2.04e-14	4.88e-04	1.00e+00
3		7.19e+06		3.61e-08	7.70e-08	2.03e-14	2.44e-04	1.00e+00
4		7.19e+06		5.52e-08	7.73e-08	2.01e-14	7.81e-03	1.00e+00
5		7.19e+06		4.55e-08	7.73e-08	2.01e-14	6.10e-05	1.00e+00
6		7.19e+06		4.83e-08	7.73e-08	2.00e-14	2.38e-07	1.00e+00
7		7.19e+06		5.39e-08	7.73e-08	1.95e-14	4.88e-04	1.00e+00
8		7.19e+06		4.02e-08	7.73e-08	1.97e-14	2.44e-04	1.00e+00
9		7.19e+06		4.02e-08	7.73e-08	1.97e-14	3.73e-09	1.00e+00
Error of x with respect to x_ast: 7.73e-08
Approximate solution: [1.12328763 0.6506851  1.82876707 0.56849315]
Backtracking value less than tol_backtracking, check approximation
Inner iterations
[1.12328763 0.6506851  1.82876707 0.56849315]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
8		2.33e+07	1.67e+07	2.40e-07
----------------------------------------------------------------------------------------

In [18]:
[x,iter_barrier,t]


Out[18]:
[array([1.12328763, 0.6506851 , 1.82876707, 0.56849315]),
 261,
 16661911.55492154]

In [19]:
compute_error(x_ast,x)


Out[19]:
7.734328493620186e-08

In [20]:
x_ast


Out[20]:
array([1.12328767, 0.65068493, 1.82876712, 0.56849315])

Comparación con cvxpy


In [21]:
import cvxpy as cp

In [22]:
x1 = cp.Variable()
x2 = cp.Variable()
x3 = cp.Variable()
x4 = cp.Variable()

In [23]:
# Create two constraints.
constraints = [2*x1+x2+x3+4*x4-7 == 0,x1+x2+2*x3+x4-6 == 0,x1>=0,x2>=0,x3>=0,x4>=0]

# Form objective.

obj = cp.Minimize(x1**2+x2**2+x3**2+x4**2-2*x1-3*x4)

In [24]:
# Form and solve problem.
prob = cp.Problem(obj, constraints)
prob.solve()  # Returns the optimal value.


Out[24]:
1.4006849315068515

In [25]:
print("status:", prob.status)
print("optimal value", prob.value)
print("optimal var", x1.value, x2.value, x3.value,x4.value)


status: optimal
optimal value 1.4006849315068515
optimal var 1.1232876712328763 0.6506849315068494 1.8287671232876717 0.5684931506849316

Segundo ejemplo

$$\min 2x_1 + 5x_2$$
$$\text{sujeto a: }$$
$$ \begin{array}{c} 6-x_1-x_2 \leq 0 \\ -18 + x_1 +2x_2 \leq 0\\ x_1, x_2 \geq 0 \end{array} $$

In [26]:
fo = lambda x: 2*x[0] + 5*x[1]

In [27]:
const = {0: lambda x: 6-x[0]-x[1],
         1: lambda x: -18+x[0]+2*x[1],
         2: lambda x: -x[0],
         3: lambda x: -x[1]
        }

In [28]:
A=np.array([0,0],dtype=float)
b = 0

In [29]:
x_ast = np.array([6,0], dtype=float)

In [30]:
x_0 = np.array([4,4], dtype=float)

In [31]:
p_ast=fo(x_ast)

In [32]:
p_ast


Out[32]:
12.0

In [33]:
nu_0 = np.array([0,0], dtype=float)

In [34]:
tol_outer_iter = 1e-3
tol=1e-8
tol_backtracking=1e-8
maxiter=30
mu=10

In [35]:
[x,iter_barrier,t] = path_following_method_infeasible_init_point(fo, A, b,
                                                                 const,
                                                               x_0, nu_0, tol,
                                                               tol_backtracking, x_ast, p_ast, maxiter,
                                                               mu, tol_outer_iter = tol_outer_iter 
                                                               )


Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
1		1.23e+01	2.50e-01	1.60e+01
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	0.00e+00	8.37e-01	5.59e+00	7.45e-01	1.33e+00	---		9.46e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		8.37e-01		5.59e+00	7.45e-01	1.33e+00	---		9.46e+00
1		8.37e-01		2.61e-02	2.15e-01	5.37e-01	5.00e-01	9.46e+00
2		8.37e-01		2.61e-02	2.15e-01	5.37e-01	1.78e-15	9.46e+00
Error of x with respect to x_ast: 2.15e-01
Approximate solution: [6.88318309 0.93672033]
Backtracking value less than tol_backtracking, check approximation
Inner iterations
[6.88318309 0.93672033]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
2		5.08e+01	2.50e+00	1.60e+00
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	0.00e+00	1.29e+01	5.12e+02	7.45e-01	1.33e+00	---		1.00e+01
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		1.29e+01		5.12e+02	7.45e-01	1.33e+00	---		1.00e+01
1		1.29e+01		1.82e+01	1.05e-01	2.66e-01	6.25e-02	1.00e+01
2		1.29e+01		1.39e-01	2.70e-02	6.48e-02	2.50e-01	1.00e+01
3		1.29e+01		9.73e-03	2.30e-02	6.15e-02	1.00e+00	1.00e+01
4		1.29e+01		9.73e-03	2.30e-02	6.15e-02	7.11e-15	1.00e+01
Error of x with respect to x_ast: 2.30e-02
Approximate solution: [6.06671215 0.120975  ]
Backtracking value less than tol_backtracking, check approximation
Inner iterations
[6.06671215 0.120975  ]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
3		3.19e+02	2.50e+01	1.60e-01
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	0.00e+00	1.34e+02	8.98e+04	7.45e-01	1.33e+00	---		3.29e+01
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		1.34e+02		8.98e+04	7.45e-01	1.33e+00	---		3.29e+01
1		1.34e+02		2.34e+04	2.79e-01	7.50e-01	1.95e-03	3.29e+01
2		1.34e+02		9.87e+03	1.84e-01	4.43e-01	3.91e-03	3.29e+01
3		1.34e+02		1.42e+03	7.07e-02	1.83e-01	7.81e-03	3.29e+01
4		1.34e+02		4.19e+01	2.22e-02	2.94e-02	3.12e-02	3.29e+01
5		1.34e+02		2.72e-01	3.45e-03	9.07e-03	1.25e-01	3.29e+01
6		1.34e+02		4.23e-02	2.14e-03	5.76e-03	1.00e+00	3.29e+01
7		1.34e+02		4.23e-02	2.14e-03	5.76e-03	1.14e-13	3.29e+01
Error of x with respect to x_ast: 2.14e-03
Approximate solution: [6.00409637 0.01217541]
Backtracking value less than tol_backtracking, check approximation
Inner iterations
[6.00409637 0.01217541]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
4		3.01e+03	2.50e+02	1.60e-02
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	0.00e+00	1.35e+03	3.48e+06	7.45e-01	1.33e+00	---		1.24e+00
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		1.35e+03		3.48e+06	7.45e-01	1.33e+00	---		1.24e+00
1		1.35e+03		-3.78e+05	5.92e-01	7.67e-01	4.88e-04	1.24e+00
Error of x with respect to x_ast: 5.92e-01
Approximate solution: [3.74466343 2.74382753]
Inner iterations
[3.74466343 2.74382753]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
5		5.30e+04	2.50e+03	1.60e-03
----------------------------------------------------------------------------------------
I	||res_primal||	||res_dual|| 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0	0.00e+00	1.35e+04	3.67e+08	7.45e-01	1.33e+00	---		1.97e+01
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Beginning Newtons method for feasible initial point
I	Norm gfLogBarrier 	Newton Decrement	Error x_ast	Error p_ast	line search	CondHf
0		1.35e+04		3.67e+08	7.45e-01	1.33e+00	---		1.97e+01
1		1.35e+04		2.04e+08	5.01e-01	5.87e-01	6.10e-05	1.97e+01
2		1.35e+04		1.86e+07	1.14e-01	1.71e-01	6.10e-05	1.97e+01
3		1.35e+04		4.90e+06	5.01e-02	9.54e-02	1.22e-04	1.97e+01
4		1.35e+04		1.46e+06	2.29e-02	5.54e-02	2.44e-04	1.97e+01
5		1.35e+04		4.54e+05	1.18e-02	3.17e-02	4.88e-04	1.97e+01
6		1.35e+04		3.91e+03	2.11e-03	2.13e-03	1.95e-03	1.97e+01
7		1.35e+04		7.20e-01	4.35e-05	6.02e-05	1.56e-02	1.97e+01
8		1.35e+04		2.85e-01	1.78e-05	4.27e-05	1.00e+00	1.97e+01
9		1.35e+04		2.85e-01	1.78e-05	4.27e-05	1.82e-12	1.97e+01
Error of x with respect to x_ast: 1.78e-05
Approximate solution: [6.00008070e+00 7.00989697e-05]
Backtracking value less than tol_backtracking, check approximation
Inner iterations
[6.00008070e+00 7.00989697e-05]
----------------------------------------------------------------------------------------
Outer iterations of path following method
Mu value: 1.00e+01
Outer iteration	LogBarrier 	t_log_barrier	Stopping criteria
6		3.00e+05	2.50e+04	1.60e-04
----------------------------------------------------------------------------------------
/datos/MNO_desde_2018/ramas_repo/mno-master/temas/IV.optimizacion_convexa_y_machine_learning/algoritmos/Python/utils.py:55: RuntimeWarning: invalid value encountered in log
  eval_f_const_inequality = np.log(-eval_f_const_inequality)

In [36]:
[x,iter_barrier,t]


Out[36]:
[array([6.00008070e+00, 7.00989697e-05]), 105, 25000.0]

In [37]:
compute_error(x_ast,x)


Out[37]:
1.7815100934691582e-05

Comparación con cvxpy


In [38]:
x1 = cp.Variable()
x2 = cp.Variable()

In [39]:
# Create two constraints.
constraints = [6-x1-x2 <= 0,-18+x1+2*x2<=0,x1>=0,x2>=0]

# Form objective.

obj = cp.Minimize(2*x1+5*x2)

In [40]:
# Form and solve problem.
prob = cp.Problem(obj, constraints)
prob.solve()  # Returns the optimal value.


Out[40]:
12.0000000016275

In [41]:
print("status:", prob.status)
print("optimal value", prob.value)
print("optimal var", x1.value, x2.value)


status: optimal
optimal value 12.0000000016275
optimal var 6.000000000175689 2.552244387851183e-10

Referencias:

  • S. P. Boyd, L. Vandenberghe, Convex Optimization, Cambridge University Press, 2009.