Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python35
/
lib64
/
python3.5
/
site-packages
/
scipy
/
optimize
/
__pycache__
/
File Content:
_linprog.cpython-35.opt-1.pyc
�B�W�� � @ s d Z d d l m Z m Z m Z d d l Z d d l m Z m Z d d d g Z d Z d d � Z d d � Z d d d d � Z d d d � Z d d d d d d d d � Z d d d d d d d d d d d d � Z d d d d d d d d d d � Z d S)a" A top-level linear programming interface. Currently this interface only solves linear programming problems via the Simplex Method. .. versionadded:: 0.15.0 Functions --------- .. autosummary:: :toctree: generated/ linprog linprog_verbose_callback linprog_terse_callback � )�division�print_function�absolute_importN� )�OptimizeResult�_check_unknown_options�linprog�linprog_verbose_callback�linprog_terse_callbackzrestructuredtext enc K s~ | d } | d } | d \ } } | d } | d } | d } t j � } t j d d d d d d � i � | r� t d j | � � t d � nB | d k r� t d j | � � n t d j | | � � t d � | d k rmt d t | � d � | st d j | | � � t d | � t � t d � t d | � t � t d � t d | d � t � t j | � d S)a] A sample callback function demonstrating the linprog callback interface. This callback produces detailed output to sys.stdout before each iteration and after the final iteration of the simplex algorithm. Parameters ---------- xk : array_like The current solution vector. **kwargs : dict A dictionary containing the following parameters: tableau : array_like The current tableau of the simplex algorithm. Its structure is defined in _solve_simplex. phase : int The current Phase of the simplex algorithm (1 or 2) nit : int The current iteration number. pivot : tuple(int, int) The index of the tableau selected as the next pivot, or nan if no pivot exists basis : array(int) A list of the current basic variables. Each element contains the name of a basic variable and its value. complete : bool True if the simplex algorithm has completed (and this is the final call to callback), otherwise False. �tableau�nit�pivot�phase�basis�completeZ linewidthi� � formatter�floatc S s d j | � S)Nz {0: 12.4f})�format)�x� r �/_linprog.py�<lambda>C s z*linprog_verbose_callback.<locals>.<lambda>z3--------- Iteration Complete - Phase {0:d} ------- zTableau:r z3--------- Initial Tableau - Phase {0:d} ---------- z2--------- Iteration {0:d} - Phase {1:d} -------- � � z#Pivot Element: T[{0:.0f}, {1:.0f}] zBasic Variables:zCurrent Solution:zx = zCurrent Objective Value:zf = r N���r )r r )�npZget_printoptionsZset_printoptions�printr �str) �xk�kwargsr r �pivrow�pivcolr r r Zsaved_printoptionsr r r r s: c K sG | d } | d k r t d � t d j | � d d �t | � d S)az A sample callback function demonstrating the linprog callback interface. This callback produces brief output to sys.stdout before each iteration and after the final iteration of the simplex algorithm. Parameters ---------- xk : array_like The current solution vector. **kwargs : dict A dictionary containing the following parameters: tableau : array_like The current tableau of the simplex algorithm. Its structure is defined in _solve_simplex. vars : tuple(str, ...) Column headers for each column in tableau. "x[i]" for actual variables, "s[i]" for slack surplus variables, "a[i]" for artificial variables, and "RHS" for the constraint RHS vector. phase : int The current Phase of the simplex algorithm (1 or 2) nit : int The current iteration number. pivot : tuple(int, int) The index of the tableau selected as the next pivot, or nan if no pivot exists basics : list[tuple(int, float)] A list of the current basic variables. Each element contains the index of a basic variable and its value. complete : bool True if the simplex algorithm has completed (and this is the final call to callback), otherwise False. r r z Iter: X:z{0: <5d} �endr N)r r )r r r r r r r ] s $ g�-���q=Fc C s� t j j | d d d � f | k | d d d � f d d �} | j � d k ra d t j f S| r� d t j | j d k � d d f Sd t j j | | j � k � d d f S)a� Given a linear programming simplex tableau, determine the column of the variable to enter the basis. Parameters ---------- T : 2D ndarray The simplex tableau. 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. r N�copyFr Tr r r r )r �ma�masked_where�count�nan�where�mask�min)�T�tol�blandr$ r r r � _pivot_col� s B $r. c C s� | d k r d } n d } t j j | d | � | f | k | d | � | f d d �} | j � d k r} d t j f St j j | d | � | f | k | d | � d f d d �} | | } d t j j | | j � k � d d f S) aI Given a linear programming simplex tableau, determine the row for the pivot operation. Parameters ---------- T : 2D ndarray The simplex tableau. 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. 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 � Nr# Fr Tr )r r$ r% r&