main.py 509 B

12345678910111213141516171819202122232425262728293031
  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. i, j = 0, 0
  12. while i < len(s) and j < len(d):
  13. q = min(s[i], d[j])
  14. a[i][j] = q
  15. s[i] -= q
  16. d[j] -= q
  17. if s[i] == 0:
  18. i += 1
  19. if d[j] == 0:
  20. j += 1
  21. print("Матрица распределения:")
  22. print(a)
  23. F = np.sum(a * c)
  24. print(f"Целевая функция F = {F}")