ó
î&]\c           @` s=  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l	 j
 Z d d l m Z d d l m Z d d l m Z m Z e e e e d „ Z e e e e e e d	 d
 „ Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d d d d d d d e d e e e d e e d	 d „ Z  d S(   s2   
An interior-point method for linear programming.
i    (   t   print_functiont   divisiont   absolute_importN(   t   warn(   t   LinAlgErrori   (   t   OptimizeWarningt   _check_unknown_optionsc         C` se   |  r. | s | r" t  d „ } qa d „  } n3 | r@ d „  } n! | rU t j j } n | d „ } | S(   s;  
    Given solver options, return a handle to the appropriate linear system
    solver.

    Parameters
    ----------
    sparse : bool
        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
        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
        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
        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.

    Returns
    -------
    solve : function
        Handle to the appropriate solver function

    c         S` s   t  j j |  | ƒ d S(   Ni    (   t   spst   linalgt   lsqr(   t   Mt   rt   sym_pos(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   solve/   s    c         S` s   t  j j |  | d d ƒS(   Nt
   permc_spect   MMD_AT_PLUS_A(   R   R   t   spsolve(   R
   R   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR   4   s    c         S` s   t  j j |  | ƒ d S(   Ni    (   t   spR   t   lstsq(   R
   R   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR   9   s    c         S` s   t  j j |  | d | ƒS(   NR   (   R   R   R   (   R
   R   R   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR   @   s    (   t   FalseR   R   t	   cho_solve(   t   sparseR   R   t   choleskyR   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _get_solver   s    R   c   0   
   C` sq  |  j  d d k r4 t t t t f \ }
 } } } n  t |
 | | | ƒ } t | ƒ } | | |  j | ƒ } | | |  j j | ƒ | } | j | ƒ | j ƒ  j | ƒ | } | j | ƒ | | | d } | | } t } |
 rp| rp|  j t j	 | d d d ƒj |  j ƒ ƒ } y% t j
 j | d | ƒj } t } Wq’t k
 rlt } t |
 | | | ƒ } q’Xn" |  j | j d d ƒ |  j ƒ } | rày t j
 j | ƒ } Wqàt k
 rÜt } t |
 | | | ƒ } qàXn  | rìd n d } d } d \ } } } }  }! xN| | k r]|	 | ƒ | }" |	 | ƒ | }# t j |	 | ƒ | ƒ j d ƒ }$ | | | | }% t j | | | | ƒ j d ƒ }& | d k r.| rd | | | | | | d | | }% t j d | | | | | | d |  |! ƒ j d ƒ }& q.|% | | 8}% |& |  |! 8}& n  t }' x%|' s[y© | rL| n | }( t | |( |  | | | | ƒ \ }) }* t | |( |  |# d | |% |" | | ƒ \ }+ }, t j t j |) ƒ ƒ sÖt j t j |* ƒ ƒ rßt ‚ n  t }' Wq7t t f k
 rW}- t } | s<| r&t d t ƒ t } qBt d	 t ƒ t } n |- ‚ t |
 | | ƒ } q7Xq7W|$ d | |& | j |+ ƒ | j |, ƒ d | | | j |) ƒ | j |* ƒ }  |+ |) |  } |, |* |  }. d | |% | | } d | |& | |  }! t | | | | | |  | |! d ƒ	 } | r+d
 } n% d }/ d | d t |/ d | ƒ } | d 7} qW| |. | |  |! f S(   sæ  
    Given standard form problem defined by ``A``, ``b``, and ``c``;
    current variable estimates ``x``, ``y``, ``z``, ``tau``, and ``kappa``;
    algorithmic parameters ``gamma and ``eta;
    and options ``sparse``, ``lstsq``, ``sym_pos``, ``cholesky``, ``pc``
    (predictor-corrector), and ``ip`` (initial point improvement),
    get the search direction for increments to the variable estimates.

    Parameters
    ----------
    As defined in [4], except:
    sparse : bool
        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
        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
        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
        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.
    pc : bool
        True if the predictor-corrector method of Mehrota is to be used. This
        is almost always (if not always) beneficial. Even though it requires
        the solution of an additional linear system, the factorization
        is typically (implicitly) reused so solution is efficient, and the
        number of algorithm iterations is typically reduced.
    ip : bool
        True if the improved initial point suggestion due to [4] section 4.3
        is desired. It's unclear whether this is beneficial.
    permc_spec : str (default = 'MMD_AT_PLUS_A')
        (Has effect only with ``sparse = True``, ``lstsq = False``, ``sym_pos =
        True``.) A matrix is factorized in each iteration of the algorithm.
        This option specifies how to permute the columns of the matrix for
        sparsity preservation. 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.

        This option can impact the convergence of the
        interior point algorithm; test different values to determine which
        performs best for your problem. For more information, refer to
        ``scipy.sparse.linalg.splu``.

    Returns
    -------
    Search directions as defined in [4]

    References
    ----------
    .. [4] 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.

    i    i   t   formatt   cscR   iÿÿÿÿi   sÚ   Solving system with option 'sym_pos':True failed. It is normal for this to happen occasionally, especially as the solution is approached. However, if you see this frequently, consider setting option 'sym_pos' to False.sU  Solving system with option 'sym_pos':False failed. This may happen occasionally, especially as the solution is approached. However, if you see this frequently, your problem may be numerically challenging. If you cannot improve the formulation, consider setting 'lstsq' to True. Consider also setting `presolve` to True, if it is not already.i
   gš™™™™™¹?(   i    i    i    i    i    (   i   (   i   (   i   (   t   shapeR   t   TrueR   t   lent   dott   Tt	   transposeR   t   diagsR   t   spluR   t	   Exceptiont   reshapeR   t
   cho_factort   npt   arrayt
   _sym_solvet   anyt   isnanR   t
   ValueErrorR   R   t	   _get_stept   min(0   t   At   bt   ct   xt   yt   zt   taut   kappat   gammat   etaR   R   R   R   t   pct   ipR   R   t   n_xt   r_Pt   r_Dt   r_Gt   mut   DinvR!   R
   t   Lt   n_correctionst   it   alphat   d_xt   d_zt   d_taut   d_kappat   rhatpt   rhatdt   rhatgt   rhatxst   rhattkt   solvedt
   solve_thist   pt   qt   ut   vt   et   d_yt   beta1(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt
   _get_deltaF   s¢    T!&
-
""$*	$!0	
		**$	c   
      C` s_   | | j  |  | ƒ } | r, | | ƒ } n | | | ƒ } |  | j j  | ƒ | }	 |	 | f S(   sX  
    An implementation of [4] equation 8.31 and 8.32

    References
    ----------
    .. [4] 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.

    (   R   R   (
   R>   R
   R-   t   r1t   r2R   R!   R   RQ   RP   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR'   8  s    c	         C` sæ   | d k  }	 | d k  }
 t  j |	 ƒ rG | t  j |  |	 | |	 ƒ n d } | d k  rh | | | n d } t  j |
 ƒ r | t  j | |
 | |
 ƒ n d } | d k  r¾ | | | n d } t  j d | | | | g ƒ } | S(   sO  
    An implementation of [4] equation 8.21

    References
    ----------
    .. [4] 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.

    i    i   (   R%   R(   R,   (   R0   RC   R2   RD   R3   RE   R4   RF   t   alpha0t   i_xt   i_zt   alpha_xt	   alpha_taut   alpha_zt   alpha_kappaRB   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR+   O  s    5!5!c         C` s   d d d d d g } | |  S(   s  
    Given problem status code, return a more detailed message.

    Parameters
    ----------
    status : int
        An integer representing the exit status of the optimization::

         0 : Optimization terminated successfully
         1 : Iteration limit reached
         2 : Problem appears to be infeasible
         3 : Problem appears to be unbounded
         4 : Serious numerical difficulties encountered

    Returns
    -------
    message : str
        A string descriptor of the exit status of the optimization.

    s%   Optimization terminated successfully.s?   The iteration limit was reached before the algorithm converged.sT   The algorithm terminated successfully and determined that the problem is infeasible.sS   The algorithm terminated successfully and determined that the problem is unbounded.s  Numerical difficulties were encountered before the problem converged. Please check your problem formulation for errors, independence of linear equality constraints, and reasonable scaling and matrix condition numbers. If you continue to encounter this error, please submit a bug report.(    (   t   statust   messages(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _get_messagei  s    	c         C` sY   |  |
 | }  | |
 | } | |
 | } | |
 |	 } | |
 | } |  | | | | f S(   sN  
    An implementation of [4] Equation 8.9

    References
    ----------
    .. [4] 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.

    (    (   R0   R1   R2   R3   R4   RC   RS   RD   RE   RF   RB   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _do_stepŽ  s    c         C` sX   |  \ } } t  j | ƒ } t  j | ƒ } t  j | ƒ } d } d } | | | | | f S(   sO  
    Return the starting point from [4] 4.4

    References
    ----------
    .. [4] 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.

    i   (   R%   t   onest   zeros(   R   t   mt   nt   x0t   y0t   z0t   tau0t   kappa0(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _get_blind_start¢  s    c	         ` s´  t  ˆ  j ƒ \ }	 }
 } } } ‡  ‡ f d †  } ‡  ‡ f d †  } ‡ ‡ f d †  } d „  } ˆ j | | ƒ | } d „  } | |	 | ƒ } | |
 | | ƒ } | |	 |
 | ƒ } | |	 | | | ƒ } | ˆ j j | ƒ ˆ j j | ƒ ƒ | | ˆ j j | ƒ ƒ } | | | | ƒ ƒ t d | | ƒ ƒ } | | | | | ƒ ƒ t d | | ƒ ƒ } | | | | | ƒ ƒ t d | | ƒ ƒ } | | | | | ƒ | } | | | | | | f S(   s‹  
    Implementation of several equations from [4] used as indicators of
    the status of optimization.

    References
    ----------
    .. [4] 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.

    c         ` s   ˆ | ˆ  j  |  ƒ S(   N(   R   (   R0   R3   (   R-   R.   (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   r_pÉ  s    c         ` s   ˆ | ˆ  j  j |  ƒ | S(   N(   R   R   (   R1   R2   R3   (   R-   R/   (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   r_dÌ  s    c         ` s   | ˆ j  |  ƒ ˆ  j  | ƒ S(   N(   R   (   R0   R1   R4   (   R.   R/   (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   r_gÏ  s    c         S` s+   |  j  | ƒ t j  | | ƒ t |  ƒ d S(   Ni   (   R   R%   R   (   R0   R3   R2   R4   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR=   Ó  s    c         S` s   t  j j |  ƒ S(   N(   R%   R   t   norm(   t   a(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyRp   Ø  s    i   (   Rl   R   R   R   t   max(   R-   R.   R/   t   c0R0   R1   R2   R3   R4   Rg   Rh   Ri   Rj   Rk   Rm   Rn   Ro   R=   t   objRp   t   r_p0t   r_d0t   r_g0t   mu_0t   rho_At   rho_pt   rho_dt   rho_gt   rho_mu(    (   R-   R.   R/   s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _indicators·  s"    		B(++c         C` sN   | r" t  d d d d d d ƒ n  d } t  | j |  | | | | | ƒ ƒ d S(	   s\  
    Print indicators of optimization status to the console.

    Parameters
    ----------
    rho_p : float
        The (normalized) primal feasibility, see [4] 4.5
    rho_d : float
        The (normalized) dual feasibility, see [4] 4.5
    rho_g : float
        The (normalized) duality gap, see [4] 4.5
    alpha : float
        The step size, see [4] 4.3
    rho_mu : float
        The (normalized) path parameter, see [4] 4.5
    obj : float
        The objective function value of the current iterate
    header : bool
        True if a header is to be printed

    References
    ----------
    .. [4] 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.

    s   Primal Feasibility s   Dual Feasibility   s   Duality Gap        s   Step            s   Path Parameter     s   Objective          s<   {0:<20.13}{1:<20.13}{2:<20.13}{3:<17.13}{4:<20.13}{5:<20.13}N(   t   printR   (   Rz   R{   R|   RB   R}   Rt   t   headert   fmt(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _display_iterè  s    
	c   *      C` s  d } t  |  j ƒ \ } } } } } | r0 | n t } t |  | | | | | | | | ƒ	 \ } } } } } } | | k p | | k p | | k } | r¸ t | | | d | | d t ƒn  d } d } |	 rë t j |  ƒ }  |  j ƒ  |  _	 n  x| rÿ| d 7} | rd } d „  }  n/ | r"d n | t
 j | | ƒ } | d „ }  y8t |  | | | | | | | | |  |	 |
 | | | | | ƒ \ }! }" }# }$ }% | rd }& t | | | | | |! |" |# |$ |% |& ƒ \ } } } } } d | | d k  <d | | d k  <t d | ƒ } t d | ƒ } t } n] t | |! | |# | |$ | |% | ƒ	 }& t | | | | | |! |" |# |$ |% |& ƒ \ } } } } } Wn0 t t t t f k
 r¯d	 } t | ƒ } Pn Xt |  | | | | | | | | ƒ	 \ } } } } } } | | k p| | k p| | k } | r2t | | | |& t | ƒ | ƒ n  | | k  ol| | k  ol| | k  ol| | t d | ƒ k  }' | | k  o‘| | t d | ƒ k  }( |' s |( rÚ| j ƒ  j | ƒ | k rÄd
 } n d } t | ƒ } Pqî | | k rî d } t | ƒ } Pqî qî W| | }) |) | | | f S(   s  
    Solve a linear programming problem in standard form:

    Minimize::

        c @ x

    Subject to::

        A @ x == b
            x >= 0

    using the interior point method of [4].

    Parameters
    ----------
    A : 2D array
        2D array such that ``A @ x``, gives the values of the equality
        constraints at ``x``.
    b : 1D array
        1D array of values representing the RHS of each equality constraint
        (row) in ``A`` (for standard form problem).
    c : 1D array
        Coefficients of the linear objective function to be minimized (for
        standard form problem).
    c0 : float
        Constant term in objective function due to fixed (and eliminated)
        variables. (Purely for display.)
    alpha0 : float
        The maximal step size for Mehrota's predictor-corrector search
        direction; see :math:`\beta_3`of [4] Table 8.1
    beta : float
        The desired reduction of the path parameter :math:`\mu` (see  [6]_)
    maxiter : int
        The maximum number of iterations of the algorithm.
    disp : bool
        Set to ``True`` if indicators of optimization status are to be printed
        to the console each iteration.
    tol : float
        Termination tolerance; see [4]_ Section 4.5.
    sparse : bool
        Set to ``True`` if the problem is to be treated as sparse. However,
        the inputs ``A_eq`` and ``A_ub`` should nonetheless be provided as
        (dense) arrays rather than sparse matrices.
    lstsq : bool
        Set to ``True`` if the problem is expected to be very poorly
        conditioned. This should always be left as ``False`` unless severe
        numerical difficulties are frequently encountered, and a better option
        would be to improve the formulation of the problem.
    sym_pos : bool
        Leave ``True`` if the problem is expected to yield a well conditioned
        symmetric positive definite normal equation matrix (almost always).
    cholesky : bool
        Set to ``True`` if the normal equations are to be solved by explicit
        Cholesky decomposition followed by explicit forward/backward
        substitution. This is typically faster for moderate, dense problems
        that are numerically well-behaved.
    pc : bool
        Leave ``True`` if the predictor-corrector method of Mehrota is to be
        used. This is almost always (if not always) beneficial.
    ip : bool
        Set to ``True`` if the improved initial point suggestion due to [4]_
        Section 4.3 is desired. It's unclear whether this is beneficial.
    permc_spec : str (default = 'MMD_AT_PLUS_A')
        (Has effect only with ``sparse = True``, ``lstsq = False``, ``sym_pos =
        True``.) A matrix is factorized in each iteration of the algorithm.
        This option specifies how to permute the columns of the matrix for
        sparsity preservation. 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.

        This option can impact the convergence of the
        interior point algorithm; test different values to determine which
        performs best for your problem. For more information, refer to
        ``scipy.sparse.linalg.splu``.

    Returns
    -------
    x_hat : float
        Solution vector (for standard form problem).
    status : int
        An integer representing the exit status of the optimization::

         0 : Optimization terminated successfully
         1 : Iteration limit reached
         2 : Problem appears to be infeasible
         3 : Problem appears to be unbounded
         4 : Serious numerical difficulties encountered

    message : str
        A string descriptor of the exit status of the optimization.
    iteration : int
        The number of iterations taken to solve the problem

    References
    ----------
    .. [4] 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.
    .. [6] Freund, Robert M. "Primal-Dual Interior-Point Methods for Linear
           Programming based on Newton's Method." Unpublished Course Notes,
           March 2004. Available 2/25/2017 at:
           https://ocw.mit.edu/courses/sloan-school-of-management/15-084j-nonlinear-programming-spring-2004/lecture-notes/lec14_int_pt_mthd.pdf

    i    t   -R€   s%   Optimization terminated successfully.i   c         S` s   d S(   Ni   (    (   t   g(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR6   ©  s    c         S` s   d |  S(   Ni   (    (   R„   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyR6   ²  s    g      ð?i   i   i   (   Rl   R   R   R~   R‚   R   R   t
   csc_matrixR   R   R%   t   meanRU   Rb   Rr   R+   R   t   FloatingPointErrorR*   t   ZeroDivisionErrorRa   t   floatR,   R   (*   R-   R.   R/   Rs   RX   t   betat   maxitert   dispt   tolR   R   R   R   R7   R8   R   t	   iterationR0   R1   R2   R3   R4   Rz   R{   Ry   R|   R}   Rt   t   goR_   t   messageR5   R6   RC   RS   RD   RE   RF   RB   t   inf1t   inf2t   x_hat(    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _ip_hsd  s~    p3$"	
#*!	:3$"*%	
gSt$—ÿï?gš™™™™™¹?iè  g:Œ0âŽyE>c         K` so  t  | ƒ | t k	 r% t d ƒ ‚ n  |
 o. | rA t d t ƒ n  |
 oK | r^ t d t ƒ n  |
 og | rz t d t ƒ n  | oƒ | r– t d t ƒ n  d d d d	 f } | j ƒ  | k rÞ t d
 t | ƒ d t ƒ d } n  | oè | rú t d ƒ ‚ n  | t k o| o|
 o| } t | | |  | | | | | |	 |
 | | | | | | ƒ \ } } } } | | | | f S(   sù+  
    Minimize a linear objective function subject to linear
    equality and non-negativity constraints using the interior point method
    of [4]_. Linear programming is intended to solve problems
    of the following form:

    Minimize::

        c @ x

    Subject to::

        A @ x == b
            x >= 0

    Parameters
    ----------
    c : 1D array
        Coefficients of the linear objective function to be minimized.
    c0 : float
        Constant term in objective function due to fixed (and eliminated)
        variables. (Purely for display.)
    A : 2D array
        2D array such that ``A @ x``, gives the values of the equality
        constraints at ``x``.
    b : 1D array
        1D array of values representing the right hand side of each equality
        constraint (row) in ``A``.

    Options
    -------
    maxiter : int (default = 1000)
        The maximum number of iterations of the algorithm.
    disp : bool (default = False)
        Set to ``True`` if indicators of optimization status are to be printed
        to the console each iteration.
    tol : float (default = 1e-8)
        Termination tolerance to be used for all termination criteria;
        see [4]_ Section 4.5.
    alpha0 : float (default = 0.99995)
        The maximal step size for Mehrota's predictor-corrector search
        direction; see :math:`\beta_{3}` of [4]_ Table 8.1.
    beta : float (default = 0.1)
        The desired reduction of the path parameter :math:`\mu` (see [6]_)
        when Mehrota's predictor-corrector is not in use (uncommon).
    sparse : bool (default = False)
        Set to ``True`` if the problem is to be treated as sparse after
        presolve. If either ``A_eq`` or ``A_ub`` is a sparse matrix,
        this option will automatically be set ``True``, and the problem
        will be treated as sparse even during presolve. If your constraint
        matrices contain mostly zeros and the problem is not very small (less
        than about 100 constraints or variables), consider setting ``True``
        or providing ``A_eq`` and ``A_ub`` as sparse matrices.
    lstsq : bool (default = False)
        Set to ``True`` if the problem is expected to be very poorly
        conditioned. This should always be left ``False`` unless severe
        numerical difficulties are encountered. Leave this at the default
        unless you receive a warning message suggesting otherwise.
    sym_pos : bool (default = True)
        Leave ``True`` if the problem is expected to yield a well conditioned
        symmetric positive definite normal equation matrix
        (almost always). Leave this at the default unless you receive
        a warning message suggesting otherwise.
    cholesky : bool (default = True)
        Set to ``True`` if the normal equations are to be solved by explicit
        Cholesky decomposition followed by explicit forward/backward
        substitution. This is typically faster for moderate, dense problems
        that are numerically well-behaved.
    pc : bool (default = True)
        Leave ``True`` if the predictor-corrector method of Mehrota is to be
        used. This is almost always (if not always) beneficial.
    ip : bool (default = False)
        Set to ``True`` if the improved initial point suggestion due to [4]_
        Section 4.3 is desired. Whether this is beneficial or not
        depends on the problem.
    permc_spec : str (default = 'MMD_AT_PLUS_A')
        (Has effect only with ``sparse = True``, ``lstsq = False``, ``sym_pos =
        True``.) A matrix is factorized in each iteration of the algorithm.
        This option specifies how to permute the columns of the matrix for
        sparsity preservation. 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.

        This option can impact the convergence of the
        interior point algorithm; test different values to determine which
        performs best for your problem. For more information, refer to
        ``scipy.sparse.linalg.splu``.

    Returns
    -------
    x : 1D array
        Solution vector.
    status : int
        An integer representing the exit status of the optimization::

         0 : Optimization terminated successfully
         1 : Iteration limit reached
         2 : Problem appears to be infeasible
         3 : Problem appears to be unbounded
         4 : Serious numerical difficulties encountered

    message : str
        A string descriptor of the exit status of the optimization.
    iteration : int
        The number of iterations taken to solve the problem.

    Notes
    -----
    This method implements the algorithm outlined in [4]_ with ideas from [8]_
    and a structure inspired by the simpler methods of [6]_ and [4]_.

    The primal-dual path following method begins with initial 'guesses' of
    the primal and dual variables of the standard form problem and iteratively
    attempts to solve the (nonlinear) Karush-Kuhn-Tucker conditions for the
    problem with a gradually reduced logarithmic barrier term added to the
    objective. This particular implementation uses a homogeneous self-dual
    formulation, which provides certificates of infeasibility or unboundedness
    where applicable.

    The default initial point for the primal and dual variables is that
    defined in [4]_ Section 4.4 Equation 8.22. Optionally (by setting initial
    point option ``ip=True``), an alternate (potentially improved) starting
    point can be calculated according to the additional recommendations of
    [4]_ Section 4.4.

    A search direction is calculated using the predictor-corrector method
    (single correction) proposed by Mehrota and detailed in [4]_ Section 4.1.
    (A potential improvement would be to implement the method of multiple
    corrections described in [4]_ Section 4.2.) In practice, this is
    accomplished by solving the normal equations, [4]_ Section 5.1 Equations
    8.31 and 8.32, derived from the Newton equations [4]_ Section 5 Equations
    8.25 (compare to [4]_ Section 4 Equations 8.6-8.8). The advantage of
    solving the normal equations rather than 8.25 directly is that the
    matrices involved are symmetric positive definite, so Cholesky
    decomposition can be used rather than the more expensive LU factorization.

    With the default ``cholesky=True``, this is accomplished using
    ``scipy.linalg.cho_factor`` followed by forward/backward substitutions
    via ``scipy.linalg.cho_solve``. With ``cholesky=False`` and
    ``sym_pos=True``, Cholesky decomposition is performed instead by
    ``scipy.linalg.solve``. Based on speed tests, this also appears to retain
    the Cholesky decomposition of the matrix for later use, which is beneficial
    as the same system is solved four times with different right hand sides
    in each iteration of the algorithm.

    In problems with redundancy (e.g. if presolve is turned off with option
    ``presolve=False``) or if the matrices become ill-conditioned (e.g. as the
    solution is approached and some decision variables approach zero),
    Cholesky decomposition can fail. Should this occur, successively more
    robust solvers (``scipy.linalg.solve`` with ``sym_pos=False`` then
    ``scipy.linalg.lstsq``) are tried, at the cost of computational efficiency.
    These solvers can be used from the outset by setting the options
    ``sym_pos=False`` and ``lstsq=True``, respectively.

    Note that with the option ``sparse=True``, the normal equations are solved
    using ``scipy.sparse.linalg.spsolve``. Unfortunately, this uses the more
    expensive LU decomposition from the outset, but for large, sparse problems,
    the use of sparse linear algebra techniques improves the solve speed
    despite the use of LU rather than Cholesky decomposition. A simple
    improvement would be to use the sparse Cholesky decomposition of
    ``CHOLMOD`` via ``scikit-sparse`` when available.

    Other potential improvements for combatting issues associated with dense
    columns in otherwise sparse problems are outlined in [4]_ Section 5.3 and
    [10]_ Section 4.1-4.2; the latter also discusses the alleviation of
    accuracy issues associated with the substitution approach to free
    variables.

    After calculating the search direction, the maximum possible step size
    that does not activate the non-negativity constraints is calculated, and
    the smaller of this step size and unity is applied (as in [4]_ Section
    4.1.) [4]_ Section 4.3 suggests improvements for choosing the step size.

    The new point is tested according to the termination conditions of [4]_
    Section 4.5. The same tolerance, which can be set using the ``tol`` option,
    is used for all checks. (A potential improvement would be to expose
    the different tolerances to be set independently.) If optimality,
    unboundedness, or infeasibility is detected, the solve procedure
    terminates; otherwise it repeats.

    The expected problem formulation differs between the top level ``linprog``
    module and the method specific solvers. The method specific solvers expect a
    problem in standard form:

    Minimize::

        c @ x

    Subject to::

        A @ x == b
            x >= 0

    Whereas the top level ``linprog`` module expects a problem of form:

    Minimize::

        c @ x

    Subject to::

        A_ub @ x <= b_ub
        A_eq @ x == b_eq
         lb <= x <= ub

    where ``lb = 0`` and ``ub = None`` unless set in ``bounds``.

    The original problem contains equality, upper-bound and variable constraints
    whereas the method specific solver requires equality constraints and
    variable non-negativity.

    ``linprog`` module converts the original problem to standard form by
    converting the simple bounds to upper bound constraints, introducing
    non-negative slack variables for inequality constraints, and expressing
    unbounded variables as the difference between two non-negative variables.


    References
    ----------
    .. [4] 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.
    .. [6] Freund, Robert M. "Primal-Dual Interior-Point Methods for Linear
           Programming based on Newton's Method." Unpublished Course Notes,
           March 2004. Available 2/25/2017 at
           https://ocw.mit.edu/courses/sloan-school-of-management/15-084j-nonlinear-programming-spring-2004/lecture-notes/lec14_int_pt_mthd.pdf
    .. [8] Andersen, Erling D., and Knud D. Andersen. "Presolving in linear
           programming." Mathematical Programming 71.2 (1995): 221-245.
    .. [9] Bertsimas, Dimitris, and J. Tsitsiklis. "Introduction to linear
           programming." Athena Scientific 1 (1997): 997.
    .. [10] Andersen, Erling D., et al. Implementation of interior point methods
            for large scale linear programming. HEC/Universite de Geneve, 1996.

    s<   method 'interior-point' does not support callback functions.sc   Invalid option combination 'sparse':True and 'lstsq':True; Sparse least squares is not recommended.s‡   Invalid option combination 'sparse':True and 'sym_pos':False; the effect is the same as sparse least squares, which is not recommended.sl   Invalid option combination 'sparse':True and 'cholesky':True; sparse Colesky decomposition is not available.sv   Invalid option combination 'lstsq':True and 'cholesky':True; option 'cholesky' has no effect when 'lstsq' is set True.t   NATURALt   MMD_ATAR   t   COLAMDs   Invalid permc_spec option: 'sc   '. Acceptable values are 'NATURAL', 'MMD_ATA', 'MMD_AT_PLUS_A', and 'COLAMD'. Reverting to default.s‘   Invalid option combination 'sym_pos':False and 'cholesky':True: Cholesky decomposition is only possible for symmetric positive definite matrices.(	   R   t   Nonet   NotImplementedErrorR   R   t   uppert   strR*   R”   (   R/   Rs   R-   R.   t   callbackRX   RŠ   R‹   RŒ   R   R   R   R   R   R7   R8   R   t   unknown_optionst   valid_permc_specR0   R_   R   RŽ   (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   _linprog_ip÷  s<    ÿ 




	 	(!   t   __doc__t
   __future__R    R   R   t   numpyR%   t   scipyR   t   scipy.sparseR   R   t   warningsR   t   scipy.linalgR   t   optimizeR   R   R   R   R   RU   R'   R+   Ra   Rb   Rl   R~   R‚   R”   R˜   RŸ   (    (    (    s9   lib/python2.7/site-packages/scipy/optimize/_linprog_ip.pyt   <module>   sN   Bá		%			10	á