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