| Server IP : 217.160.0.135 / Your IP : 216.73.217.37 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/scipy/optimize/__pycache__/ |
Upload File : |
�
d�c�` � �j � d Z ddlZddlmZ ddlmZmZmZ ddl m
Z
dd �Zdd
�Zdd�Z
dd�Z dd�ZdS )a Simplex method for linear programming
The *simplex* method uses a traditional, full-tableau implementation of
Dantzig's simplex algorithm [1]_, [2]_ (*not* the Nelder-Mead simplex).
This algorithm is included for backwards compatibility and educational
purposes.
.. versionadded:: 0.15.0
Warnings
--------
The simplex method may encounter numerical difficulties when pivot
values are close to the specified tolerance. If encountered try
remove any redundant constraints, change the pivot strategy to Bland's
rule or increase the tolerance value.
Alternatively, more robust methods maybe be used. See
:ref:`'interior-point' <optimize.linprog-interior-point>` and
:ref:`'revised simplex' <optimize.linprog-revised_simplex>`.
References
----------
.. [1] Dantzig, George B., Linear programming and extensions. Rand
Corporation Research Study Princeton Univ. Press, Princeton, NJ,
1963
.. [2] Hillier, S.H. and Lieberman, G.J. (1995), "Introduction to
Mathematical Programming", McGraw-Hill, Chapter 4.
� N)�warn� )�OptimizeResult�OptimizeWarning�_check_unknown_options)�
_postsolve��&�.>Fc �� � t j � | ddd�f | k | ddd�f d�� � }|� � � dk rdt j fS |rKdt j t j t j |j � � � � � � d d fS dt j � ||� � � k � � d d fS )a5
Given a linear programming simplex tableau, determine the column
of the variable to enter the basis.
Parameters
----------
T : 2-D array
A 2-D array representing the simplex tableau, T, corresponding to the
linear programming problem. It should have the form:
[[A[0, 0], A[0, 1], ..., A[0, n_total], b[0]],
[A[1, 0], A[1, 1], ..., A[1, n_total], b[1]],
.
.
.
[A[m, 0], A[m, 1], ..., A[m, n_total], b[m]],
[c[0], c[1], ..., c[n_total], 0]]
for a Phase 2 problem, or the form:
[[A[0, 0], A[0, 1], ..., A[0, n_total], b[0]],
[A[1, 0], A[1, 1], ..., A[1, n_total], b[1]],
.
.
.
[A[m, 0], A[m, 1], ..., A[m, n_total], b[m]],
[c[0], c[1], ..., c[n_total], 0],
[c'[0], c'[1], ..., c'[n_total], 0]]
for a Phase 1 problem (a problem in which a basic feasible solution is
sought prior to maximizing the actual objective. ``T`` is modified in
place by ``_solve_simplex``.
tol : float
Elements in the objective row larger than -tol will not be considered
for pivoting. Nominally this value is zero, but numerical issues
cause a tolerance about zero to be necessary.
bland : bool
If True, use Bland's rule for selection of the column (select the
first column with a negative coefficient in the objective row,
regardless of magnitude).
Returns
-------
status: bool
True if a suitable pivot column was found, otherwise False.
A return of False indicates that the linear programming simplex
algorithm is complete.
col: int
The index of the column of the pivot element.
If status is False, col will be returned as nan.
���NF��copyr T)
�np�ma�masked_where�count�nan�nonzero�logical_not�
atleast_1d�mask�min)�T�tol�blandr s �A/usr/lib/python3/dist-packages/scipy/optimize/_linprog_simplex.py�
_pivot_colr % s� � �h
�� � �A�b�#�2�#�g�J�3�$�.��"�c�r�c�'�
�� � G� G�B� �x�x�z�z�Q����b�f�}��� N��R�Z���r�}�R�W�/E�/E� F� F�G�G��J�1�M�M�M������r�R�V�V�X�X�~�.�.�q�1�!�4�4�4� c �J � |dk rd}nd}t j � | d| �|f |k | d| �|f d�� � }|� � � dk rdt j fS t j � | d| �|f |k | d| �df d�� � }||z } t j � | | � � � k � � d }
|r/d|
t j t j ||
� � � � fS d|
d fS ) a�
Given a linear programming simplex tableau, determine the row for the
pivot operation.
Parameters
----------
T : 2-D array
A 2-D array representing the simplex tableau, T, corresponding to the
linear programming problem. It should have the form:
[[A[0, 0], A[0, 1], ..., A[0, n_total], b[0]],
[A[1, 0], A[1, 1], ..., A[1, n_total], b[1]],
.
.
.
[A[m, 0], A[m, 1], ..., A[m, n_total], b[m]],
[c[0], c[1], ..., c[n_total], 0]]
for a Phase 2 problem, or the form:
[[A[0, 0], A[0, 1], ..., A[0, n_total], b[0]],
[A[1, 0], A[1, 1], ..., A[1, n_total], b[1]],
.
.
.
[A[m, 0], A[m, 1], ..., A[m, n_total], b[m]],
[c[0], c[1], ..., c[n_total], 0],
[c'[0], c'[1], ..., c'[n_total], 0]]
for a Phase 1 problem (a Problem in which a basic feasible solution is
sought prior to maximizing the actual objective. ``T`` is modified in
place by ``_solve_simplex``.
basis : array
A list of the current basic variables.
pivcol : int
The index of the pivot column.
phase : int
The phase of the simplex algorithm (1 or 2).
tol : float
Elements in the pivot column smaller than tol will not be considered
for pivoting. Nominally this value is zero, but numerical issues
cause a tolerance about zero to be necessary.
bland : bool
If True, use Bland's rule for selection of the row (if more than one
row can be used, choose the one with the lowest variable index).
Returns
-------
status: bool
True if a suitable pivot row was found, otherwise False. A return
of False indicates that the linear programming problem is unbounded.
row: int
The index of the row of the pivot element. If status is False, row
will be returned as nan.
r � NFr r r T) r r r r r r r �argmin�take)r �basis�pivcol�phaser r �kr �mb�q�min_rowss r �
_pivot_rowr) b s � �p
��z�z�
���
�� �� � �A�c��r�c�6�k�N�c�1�1�S�q�b�S�&�[�>�� � N� N�B� �x�x�z�z�Q����b�f�}�� �� � �A�c��r�c�6�k�N�c�1�1�S�q�b�S�"�W�:�E� � J� J�B�
�R��A��u�}�}�Q�!�%�%�'�'�\�*�*�1�-�H�� C��X�b�i����x�(@�(@�A�A�B�B�B���!���r c �R � |||<