Advertisement
Dmitrey15

OpenOpt stochastic programming demo

Jun 15th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. from FuncDesigner import *
  2. from openopt import NLP
  3.  
  4. x, y, z = oovars('x y z', lb=-1, ub=1)
  5. z.lb = 0
  6.  
  7. # dice distribution
  8. s = discrete(range(1, 7), [1.0/6]*6)
  9. #                  values           probabilities
  10.  
  11. # future plans include:
  12. # common distributions like gauss, uniform, exponential, etc
  13. # possibility to use quantiles, e.g. constraint1 = P(sin(a)<0.3)>0.2 (probability of event sin(a)<0.3 must less than 0.2)
  14.  
  15. f1 = -2*s * z**2
  16. f = f1 + 2*x + 3*y
  17.  
  18. objective = f.M
  19.  
  20. startPoint = {x:0, y:0, z:0.001}
  21. p = NLP(objective, startPoint, constraints = [f.std < 0.15])
  22. r = p.solve('scipy_cobyla')
  23. print(f.std(r))
  24. '''
  25. Solver:   Time Elapsed = 0.33   CPU Time Elapsed = 0.33
  26. objFunValue: -5.3074085 (feasible, MaxResidual = 0)
  27. 0.149999999601
  28. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement