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