Advertisement
Dmitrey15

Sparse OpenOpt/FuncDesigner NLP with knitro

Jul 13th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. """
  2. Sparse OpenOpt NLP example with knitro
  3. """
  4.  
  5. from openopt import *
  6. from numpy import arange
  7. from FuncDesigner import *
  8. N = 50000
  9. x, y, z = oovars(3)
  10.  
  11. startPoint = {x:0, y:[0]*N, z:[0]*(2*N)}
  12. # thus x from R, y from R^N, z from R^2N
  13. # hence for N = 50000 nVars = 150001
  14.  
  15. objective = x**2 + 2*sum(y**2) + 3*sum(z)
  16.  
  17. cons = [
  18.         x<150, x + 1e-3*abs(x)**2.05<100,  x>-100, y<arange(N),
  19.         y>-10-arange(N), z<arange(2*N), z>-100-arange(2*N),
  20.         x + y > 2-3*arange(N), # N linear constraints
  21.         x**4 + sum(y) + sum(z**2) < 100,
  22.         x+sum(z)>4
  23.         ]
  24.  
  25. p = NLP(objective, startPoint, constraints = cons, iprint=50)
  26. solver = 'knitro'
  27. r = p.minimize(solver)
  28. ''' Intel Pentium 2.8 GHz, 32-bit Ubuntu Linux:
  29. ------------------------- OpenOpt 0.50 -------------------------
  30. solver: knitro   problem: unnamed    type: NLP   goal: minimum
  31. iter   objFunVal   log10(maxResidual)  
  32.    0  0.000e+00               0.60
  33.   50  9.896e+00              -0.39
  34.  100  1.033e+01            -100.00
  35.  150  1.006e+01            -100.00
  36.  200  1.000e+01            -100.00
  37.  232  1.000e+01            -100.00
  38. istop: 1000
  39. Solver:   Time Elapsed = 270.07     CPU Time Elapsed = 270.0
  40. objFunValue: 10.000001 (feasible, MaxResidual = 0)
  41. # Peak memory consumption ~ 400 MB
  42. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement