Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import numpy as np
  2. from gekko import GEKKO
  3.  
  4. class model():
  5. def __init__(self, ab, cd, ef):
  6. self.ab = ab
  7. self.cd = cd
  8. self.ef = ef
  9.  
  10. """Objective Function"""
  11. 'Entry level'
  12. def fun(self,x):
  13. paramA = self.paramA()
  14. return paramA + ((np.pi * x[0] * x[1] * x[2]) * 1e-4)**0.81
  15.  
  16. def paramA(self):
  17. if self.ab >20:
  18. results = self.ab + self.cd ** self.ef
  19. return results
  20. else:
  21. results = self.ab*2 - self.cd ** self.ef
  22. return results
  23.  
  24. 'Process inputs'
  25. ## Here I just define the initial process values. It will be used for pDrop and Q calculations
  26. obj = model(360, 1.20, 300)
  27.  
  28. m = GEKKO()
  29. x = []
  30. x1 = m.Var(value=20,lb=20, ub=6555) #integer=True
  31. x2 = m.Var(value=1,lb=1,ub=10000) #integer=True
  32. x3 = m.sos1([30, 42, 45, 55])
  33. x3.value = 1.0
  34. x = [x1, x2, x3]
  35.  
  36.  
  37. m.Equation((x1 * x2* x3) * 1e-6 >= 50)
  38.  
  39.  
  40. m.Obj(obj.fun(x))
  41.  
  42. # Change to True to initialize with IPOPT
  43. init = False
  44. if init:
  45. m.options.SOLVER=3
  46. m.solve(disp=False) # Solve
  47.  
  48. m.options.SOLVER=1
  49. m.solve(disp=True) # Solve
  50.  
  51. print('Results')
  52. print('x1: ' + str(x1.value))
  53. print('x2: ' + str(x2.value))
  54. print('x3: ' + str(x3.value))
  55. print('Objective: ' + str(m.options.objfcnval))
  56.  
  57. x1 = m.Var(value=20,lb=20, ub=6555) #integer=True
  58. x2 = m.Var(value=1,lb=1,ub=10000) #integer=True
  59. x3 = m.sos1([30, 42, 45, 55])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement