Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. import numpy as np
  2. from scipy.optimize import minimize
  3. from scipy.optimize import Bounds
  4.  
  5. bnds = Bounds([0, 0, 0, 0, 0, 85, 90, 3, 1.2, 145], [2000, 16000, 120, 5000, 2000, 93, 95, 12, 4, 162])  # Задаю нижние и верхние ограничения из таблицы статьи.
  6.  
  7. eq_cons = {'type': 'eq',
  8.            'fun': lambda x: np.array([1.22 * x[3] - x[0] - x[4], ((98000 * x[2]) / x[3] * x[8] + 1000 * x[2]) - x[5], ((x[1] + x[4]) / x[0]) - x[7]]),
  9.            'jac': lambda x: np.array([[1.22, -1, -1], [98000, 1, 1, 1000, -1], [1, 1, 1, -1]])
  10.            }
  11. ineq_cons = {'type': 'ineq',
  12.             'fun': lambda x: np.array([x[0] * (1.12 + 0.13167 * x[7] - 0.0067 * x[7] ** 2) - 0.99 * x[3],
  13.                                        -(x[0] * (1.12 + 0.13167 * x[7] - 0.0067 * x[7] ** 2) - (100 / 99) * x[3]),
  14.                                        (86.35 + 1.098 * x[7] - 0.038 * x[7] ** 2 + 0.325 * (x[5] - 89)) - 0.99 * x[6],
  15.                                        -(86.35 + 1.098 * x[7] - 0.038 * x[7] ** 2 + 0.325 * (x[5] - 89)) + (100 / 99) *
  16.                                        x[6],
  17.                                        (35.82 - 0.222 * x[9]) - 0.9 * x[8],
  18.                                        -(35.82 - 0.222 * x[9]) - (10 / 9) * x[8],
  19.                                        (-133 + 3 * x[6]) - 0.99 * x[9],
  20.                                         -(133 + 3 * x[6]) + (100 / 99) * x[9]]),
  21.              'jac': lambda x: np.array([[1, 0.13167, -0.0134, -0.99],
  22.                                         [-1, -0.13167, 0.0134, -(100 / 99)],
  23.                                         [1.098, -0.076, 0.325, -0.99],
  24.                                         [-1.098, 0.076, -0.325, + (100 / 99)],
  25.                                         [-0.222, -0.9],
  26.                                         [0.222, -(10 / 9)],
  27.                                         [3, -0.99],
  28.                                         [-3, (100 / 99)]])
  29.               }
  30.  
  31. x0 = np.array([2000, 0])
  32.  
  33.  
  34. def f(x):
  35.     return 0.063 * x[3] * x[6] - 5.04 * x[0] - 0.035 * x[1] - 10 * x[2] - 3.36 * x[4]
  36.  
  37.  
  38. res = minimize(f, x0, method='SLSQP', constraints=[eq_cons, ineq_cons], bounds=bnds, options={'ftol': 1e-9, 'disp': True})
  39. print(res.x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement