main2.py 499 B

123456789101112131415161718192021222324252627
  1. import numpy as np
  2. s = [500, 1000, 900, 1500]
  3. d = [1200, 1000, 1000, 1000]
  4. c = np.array([
  5. [4, 6, 8, 10],
  6. [2, 4, 6, 8],
  7. [3, 5, 7, 9],
  8. [5, 7, 9, 11]
  9. ])
  10. a = np.zeros((len(s), len(d)))
  11. while np.any(s) and np.any(d):
  12. i, j = np.unravel_index(np.argmin(c + (a > 0) * np.inf), c.shape)
  13. q = min(s[i], d[j])
  14. a[i][j] = q
  15. s[i] -= q
  16. d[j] -= q
  17. print("Матрица распределения:")
  18. print(a)
  19. F = np.sum(a * c)
  20. print(f"Целевая функция F = {F}")