Ñò
pXJc           @   sÓ   d  Z  d d g Z d d k l Z d d k l Z l Z l Z l Z l	 Z	 l
 Z
 l Z l Z l Z d d k l Z l Z d Z e e e ƒ i ƒ Z d „  Z g  d g  d g  d d d d d	 d
 d d e d „ Z d S(   sª   This module implements the Sequential Least SQuares Programming optimization
algorithm (SLSQP), orginally developed by Dieter Kraft.

See http://www.netlib.org/toms/733

t   approx_jacobiant
   fmin_slsqpiÿÿÿÿ(   t   slsqp(	   t   zerost   arrayt   linalgt   appendt   asfarrayt   concatenatet   finfot   sqrtt   vstack(   t   approx_fprimet   wrap_functions   restructuredtext enc   	      G   s­   t  |  ƒ } | | f | Œ  } t t | ƒ t | ƒ g ƒ } t t | ƒ ƒ } xQ t t | ƒ ƒ D]= } | | | <| | | f | Œ  | | | | <d | | <qb W| i ƒ  S(   sJ  Approximate the Jacobian matrix of callable function func

       *Parameters*:
         x       - The state vector at which the Jacobian matrix is desired
         func    - A vector-valued function of the form f(x,*args)
         epsilon - The peturbation used to determine the partial derivatives
         *args   - Additional arguments passed to func

       *Returns*:
         An array of dimensions (lenf, lenx) where lenf is the length
         of the outputs of func, and lenx is the number of

       *Notes*:
         The approximation is done using forward differences

    g        (   R   R   t   lent   ranget	   transpose(	   t   xt   funct   epsilont   argst   x0t   f0t   jact   dxt   i(    (    sD   P:\graphics\Tools\Python26\lib\site-packages\scipy\optimize\slsqp.pyR       s     
#id   gíµ ÷Æ°>i   i    c   6   !   C   s7	  h d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6} t  |  |
 ƒ \ } }  | o t  | |
 ƒ \ } } n t  t |  | f ƒ \ } } | oT t  | |
 ƒ \ } } | o t  | |
 ƒ \ } } q}t  t | | f ƒ \ } } n€ g  } xv t t | ƒ ƒ D]b } | i d) ƒ | | oD t  | | |
 ƒ \ } | | <t  t | | | f ƒ \ } | | <qqW| oT t  | |
 ƒ \ } } |	 o t  |	 |
 ƒ \ } }	 qWt  t | | f ƒ \ } }	 n€ g  } xv t t | ƒ ƒ D]b } | i d) ƒ | | oD t  | | |
 ƒ \ } | | <t  t | | | f ƒ \ } | | <qñqñWt | ƒ i ƒ  } | o t | | ƒ ƒ } n t | ƒ } | o t | | ƒ ƒ } n t | ƒ } | | } t	 d | g ƒ i
 ƒ  } t | ƒ } | d } | | | | } d
 | | | d | | d | d d | | | | | d | | | d | d d | d
 | d
 | d } | }  t | ƒ }! t |  ƒ }" t | ƒ d j o+ g  }# t | ƒ D] } |# d* qÁ~# } n„ t | ƒ | j o t d ‚ nd x` t t | ƒ ƒ D]L } | | d | | d j o) t d t | ƒ d t | d ƒ ‚ qqWt	 g  }$ | D] }% |$ |% d ql~$ ƒ }& t	 g  }' | D] }% |' |% d q—~' ƒ }( t	 d t ƒ }) t	 | t ƒ } t	 | t ƒ }* d }+ | d j o d d+ GHn x|) d j p |) d j oG|  | ƒ }, | o | | ƒ }- n8 t	 g  }. t | ƒ D] } |. | | | ƒ qU~. ƒ }- | o | | ƒ }/ n> t	 g  }0 t t | ƒ ƒ D] } |0 | | | ƒ q©~0 ƒ }/ | d j o t | g ƒ }1 qe| d j o | d j o
 |- }1 n | d j o | d j o
 |/ }1 n | d j o  | d j o t |- |/ ƒ }1 qen |) d j p |) d j o}t | | ƒ d! ƒ }2 | o | | ƒ }3 n> t | | g ƒ }3 x( t | ƒ D] } | | | ƒ |3 | <qÊW|	 o |	 | ƒ }4 n> t | | g ƒ }4 x( t | ƒ D] } | | | ƒ |4 | <qW| d j o t | | g ƒ }5 ny | d j o | d j o
 |3 }5 nU | d j o | d j o
 |4 }5 n1 | d j o# | d j o t |3 |4 f ƒ }5 n t |5 t | d g ƒ f d ƒ }5 n t | | | |& |( |, |1 |2 |5 | |* |) |! |" ƒ | d j o3 |* |+ j o& d" |* | d |, t i |2 ƒ f GHn t |) ƒ d j o Pn t |* ƒ }+ q| d j oQ | t |) ƒ d# t |) ƒ d$ GHd% G|, GHd& G|* GHd' G| d GHd( G| d GHn | p | St | ƒ t |, ƒ t |* ƒ t |) ƒ | t |) ƒ g Sd) S(,   s,  
    Minimize a function using Sequential Least SQuares Programming

    Python interface function for the SLSQP Optimization subroutine
    originally implemented by Dieter Kraft.

    *Parameters*:
        func : callable f(x,*args)
            Objective function.
        x0 : ndarray of float
            Initial guess for the independent variable(s).
        eqcons : list
            A list of functions of length n such that
            eqcons[j](x0,*args) == 0.0 in a successfully optimized
            problem.
        f_eqcons : callable f(x,*args)
            Returns an array in which each element must equal 0.0 in a
            successfully optimized problem.  If f_eqcons is specified,
            eqcons is ignored.
        ieqcons : list
            A list of functions of length n such that
            ieqcons[j](x0,*args) >= 0.0 in a successfully optimized
            problem.
        f_ieqcons : callable f(x0,*args)
            Returns an array in which each element must be greater or
            equal to 0.0 in a successfully optimized problem.  If
            f_ieqcons is specified, ieqcons is ignored.
        bounds : list
            A list of tuples specifying the lower and upper bound
            for each independent variable [(xl0, xu0),(xl1, xu1),...]
        fprime : callable f(x,*args)
            A function that evaluates the partial derivatives of func.
        fprime_eqcons : callable f(x,*args)
            A function of the form f(x, *args) that returns the m by n
            array of equality constraint normals.  If not provided,
            the normals will be approximated. The array returned by
            fprime_eqcons should be sized as ( len(eqcons), len(x0) ).
        fprime_ieqcons : callable f(x,*args)
            A function of the form f(x, *args) that returns the m by n
            array of inequality constraint normals.  If not provided,
            the normals will be approximated. The array returned by
            fprime_ieqcons should be sized as ( len(ieqcons), len(x0) ).
        args : sequence
            Additional arguments passed to func and fprime.
        iter : int
            The maximum number of iterations.
        acc : float
            Requested accuracy.
        iprint : int
            The verbosity of fmin_slsqp:
              iprint <= 0 : Silent operation
              iprint == 1 : Print summary upon completion (default)
              iprint >= 2 : Print status of each iterate and summary
        full_output : bool
            If False, return only the minimizer of func (default).
            Otherwise, output final objective function and summary
            information.
        epsilon : float
            The step size for finite-difference derivative estimates.

    *Returns*: ( x, { fx, its, imode, smode })
        x : ndarray of float
            The final minimizer of func.
        fx : ndarray of float
            The final value of the objective function.
        its : int
            The number of iterations.
        imode : int
            The exit mode from the optimizer (see below).
        smode : string
            Message describing the exit mode from the optimizer.

    *Notes*

        Exit modes are defined as follows:
            -1 : Gradient evaluation required (g & a)
             0 : Optimization terminated successfully.
             1 : Function evaluation required (f & c)
             2 : More equality constraints than independent variables
             3 : More than 3*n iterations in LSQ subproblem
             4 : Inequality constraints incompatible
             5 : Singular matrix E in LSQ subproblem
             6 : Singular matrix C in LSQ subproblem
             7 : Rank-deficient equality constraint subproblem HFTI
             8 : Positive directional derivative for linesearch
             9 : Iteration limit exceeded

    s$   Gradient evaluation required (g & a)iÿÿÿÿs%   Optimization terminated successfully.i    s$   Function evaluation required (f & c)i   s4   More equality constraints than independent variablesi   s*   More than 3*n iterations in LSQ subproblemi   s#   Inequality constraints incompatiblei   s#   Singular matrix E in LSQ subproblemi   s#   Singular matrix C in LSQ subproblemi   s2   Rank-deficient equality constraint subproblem HFTIi   s.   Positive directional derivative for linesearchi   s   Iteration limit exceededi	   g   ¢”mÂg   ¢”mBs<   SLSQP Error:  If bounds is specified, len(bounds) == len(x0)s   SLSQP Error: lb > ub in bounds[s   ]  s   %5s %5s %16s %16st   NITt   FCt   OBJFUNt   GNORMg        s   %5i %5i % 16.6E % 16.6Es       (Exit mode t   )s#               Current function value:s               Iterations:s!               Function evaluations:s!               Gradient evaluations:N(   g   ¢”mÂg   ¢”mB(   R   R   R   R   (   R   R   R    R   R   R   t   NoneR   t   flattenR   t   maxR   t
   IndexErrort
   ValueErrort   strt   intt   floatR   R   R   R   t   normt   abst   list(6   R   R   t   eqconst   f_eqconst   ieqconst	   f_ieqconst   boundst   fprimet   fprime_eqconst   fprime_ieqconsR   t   itert   acct   iprintt   full_outputR   t
   exit_modest   fevalt   gevalt   cevalt   eqcons_primeR   t   ieqcons_primeR   t   meqt   mieqt   mt   lat   nt   n1t   mineqt   len_wt   len_jwt   wt   jwt   _[1]t   _[2]t   bt   xlt   _[3]t   xut   modet   majitert   majiter_prevt   fxt   c_eqt   _[4]t   c_ieqt   _[5]t   ct   gt   a_eqt   a_ieqt   a(    (    sD   P:\graphics\Tools\Python26\lib\site-packages\scipy\optimize\slsqp.pyR   1   s   ]

 % %

z+
 *++7=

  

%1!						N(    (   t   __doc__t   __all__t   _slsqpR   t   numpyR   R   R   R   R   R   R	   R
   R   t   optimizeR   R   t   __docformat__R&   t   epst   _epsilonR    R   R   (    (    (    sD   P:\graphics\Tools\Python26\lib\site-packages\scipy\optimize\slsqp.pyt   <module>   s   @		