← Back
Editing: _linprog_ip.cpython-311.pyc
� d�cY� � �& � d Z ddlZddlZddlmZ ddlm Z ddl mZ ddlm Z mZmZ ddlmZ dZdZ ddlZdd lmZ dd lmZ n # e$ r dZY nw xY w ddlZn # e$ r dZY nw xY w dd �Z dd�Zd� Zd� Z d� Z!d� Z"d� Z#d� Z$dd�Z%d� Z& dd�Z'dS ) a Interior-point method for linear programming The *interior-point* method uses the primal-dual path following algorithm outlined in [1]_. This algorithm supports sparse constraint matrices and is typically faster than the simplex methods, especially for large, sparse problems. Note, however, that the solution returned may be slightly less accurate than those of the simplex methods and will not, in general, correspond with a vertex of the polytope defined by the constraints. .. versionadded:: 1.0.0 References ---------- .. [1] Andersen, Erling D., and Knud D. Andersen. "The MOSEK interior point optimizer for linear programming: an implementation of the homogeneous algorithm." High performance optimization. Springer US, 2000. 197-232. � N)�warn)�LinAlgError� )�OptimizeWarning�OptimizeResult�_check_unknown_options)� _postsolveT)�cholesky)�analyzeF� MMD_AT_PLUS_Ac �V � �� |r�|rd� fd� }n�|rv t j � � � � nH# t $ r; t � � � t _ t j � � � � Y nw xY wt j }n�t r"|r t j � � � � }n]t j � � |�� � j }n6|r� fd�}n.|r%t j � � � � ��fd�}n|f� fd� }n# t $ r � t $ r Y dS w xY w|S ) ae Given solver options, return a handle to the appropriate linear system solver. Parameters ---------- M : 2-D array As defined in [4] Equation 8.31 sparse : bool (default = False) True if the system to be solved is sparse. This is typically set True when the original ``A_ub`` and ``A_eq`` arrays are sparse. lstsq : bool (default = False) True if the system is ill-conditioned and/or (nearly) singular and thus a more robust least-squares solver is desired. This is sometimes needed as the solution is approached. sym_pos : bool (default = True) True if the system matrix is symmetric positive definite Sometimes this needs to be set false as the solution is approached, even when the system should be symmetric positive definite, due to numerical difficulties. cholesky : bool (default = True) True if the system is to be solved by Cholesky, rather than LU, decomposition. This is typically faster unless the problem is very small or prone to numerical difficulties. permc_spec : str (default = 'MMD_AT_PLUS_A') Sparsity preservation strategy used by SuperLU. Acceptable values are: - ``NATURAL``: natural ordering. - ``MMD_ATA``: minimum degree ordering on the structure of A^T A. - ``MMD_AT_PLUS_A``: minimum degree ordering on the structure of A^T+A. - ``COLAMD``: approximate minimum degree column ordering. See SuperLU documentation. Returns ------- solve : function Handle to the appropriate solver function Fc �P �� t j � �| � � d S �Nr )�sps�linalg�lsqr��r�sym_pos�Ms ��</usr/lib/python3/dist-packages/scipy/optimize/_linprog_ip.py�solvez_get_solver.<locals>.solveW s �� ��:�?�?�1�a�0�0��3�3� )� permc_specc �P �� t j � �| � � d S r )�spr �lstsq)r r s �r r z_get_solver.<locals>.solvej s �� ��9�?�?�1�a�0�0��3�3r c �D �� t j � �| � � S �N)r r � cho_solve)r �Ls �r r z_get_solver.<locals>.solveo s �� ��9�.�.�q�!�4�4�4r c � �� |r"t j � �| d�� � S t j � �| � � S )N�pos)�assume_a)r r r r s �r r z_get_solver.<locals>.solvet s; �� �� 5�!�y���q�!�e��D�D�D�!�y���q�!�4�4�4r N�F)�_get_solver�cholmod_factor�cholesky_inplace� Exception�cholmod_analyze�has_umfpackr r � factorized�splur r � cho_factor�KeyboardInterrupt)r �sparser r r r r r! s ` @r r&