title: Solving constrained maximization with SciPy
body: <p>Function to maximize:</p>
  
  <pre><code>x[0] + x[1] + x[2]
  </code></pre>
  
  <p>Constraints:</p>
  
  <pre><code>0.2 * x[0] + 0.4 * x[1] - 0.33 * x[2] &lt;= 25
  5 * x[0] + 8.33 * x[2] &lt;= 130
  ...
  x[0] &gt;= 0
  x[1] &gt;= 0
  x[2] &gt;= 0
  </code></pre>
  
  <p>My code looks like:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Unfortunately, result I got is:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I can successfully solve this problem in Excel Solver, so I guess I do something wrong in Python.</p>