Solving constrained maximization with SciPy
Question: Function to maximize:

    
    
    x[0] + x[1] + x[2]
    

Constraints:

    
    
    0.2 * x[0] + 0.4 * x[1] - 0.33 * x[2] <= 25
    5 * x[0] + 8.33 * x[2] <= 130
    ...
    x[0] >= 0
    x[1] >= 0
    x[2] >= 0
    

My code looks like:

    
    
    from numpy import *
    from scipy.optimize import minimize
    
    
    cons = ({'type': 'ineq', 'fun': lambda x:  array([25 - 0.2 * x[0] - 0.4 * x[1] - 0.33 * x[2]])},
            {'type': 'ineq', 'fun': lambda x:  array([130 - 5 * x[0] - 8.33 * x[2]])},
            {'type': 'ineq', 'fun': lambda x:  array([16 - 0.6 * x[1] - 0.33 * x[2]])},
            {'type': 'ineq', 'fun': lambda x:  array([7 - 0.2 * x[0] - 0.1 * x[1] - 0.33 * x[2]])},
            {'type': 'ineq', 'fun': lambda x:  array([14 - 0.5 * x[1]])},
            {'type': 'ineq', 'fun': lambda x:  array([x[0]])},
            {'type': 'ineq', 'fun': lambda x:  array([x[1]])},
            {'type': 'ineq', 'fun': lambda x:  array([x[2]])})
    
    
    f = lambda x: -1 * (x[0] + x[1] + x[2])
    
    res = minimize(f, [0, 0, 0], method='SLSQP', constraints=cons, options={'disp': True})
    
    print(res)
    

Unfortunately, result I got is:

    
    
    Positive directional derivative for linesearch    (Exit mode 8)
                Current function value: -18240083542.4
                Iterations: 20
                Function evaluations: 180
                Gradient evaluations: 16
           x: array([  6.05846118e+09,   6.05846118e+09,   6.12316118e+09])
         jac: array([ 0.,  0.,  0.,  0.])
     message: 'Positive directional derivative for linesearch'
         fun: -18240083542.377449
      status: 8
        njev: 16
        nfev: 180
         nit: 20
     success: False
    

I can successfully solve this problem in Excel Solver, so I guess I do
something wrong in Python.


Answer: Bug in SciPy, code works under Python2, but refuses to work under Python3

Issue on GitHub: <https://github.com/scipy/scipy/issues/4240>

