Введение в оптимизацию на Python
Jasmin Ludolf
Content Developer
Спрос:
Производство платья:


$C$: стоимость ткани + зарплата г-на С. + альтернативные издержки г-жи Т.
Альтернативные издержки: стоимость выбора пошива вместо других обязанностей
$C=110g+240g+105g+75t+160t+35t$
$C=455g+270t$
| Затраты | Ткань | Г-н С. | Г-жа Т. |
|---|---|---|---|
| Платье | $\$110$ | $\$40/ч \times 6ч = \$240$ | $\$35/ч \times 3ч = \$105$ |
| Смокинг | $\$75$ | $\$40/ч \times 4ч = \$160$ | $\$35/ч \times 1ч = \$35$ |
Ограничения:
Спрос: $g\leq20$, $t\leq12$
Предложение: $6g+4t\leq40$, $3g+t\leq20$
from scipy.optimize import milp, Bounds, LinearConstraintresult = milp([-545, -330],integrality=[1, 1],bounds=Bounds([0, 0], [20, 12]),constraints=LinearConstraint([[6, 4], [3, 1]], ub=[40, 20]))
print(result.message)
print(f'The optimal number of gowns produced is: {result.x[0]:.2f}')
print(f'The optimal number of tuxedos produced is: {result.x[1]:.2f}')
Optimization terminated successfully. (HiGHS Status 7: Optimal)
The optimal number of gowns produced is: 6.00
The optimal number of tuxedos produced is: 1.00
result = milp([-545, -330],
bounds=Bounds([0, 0], [20, 12]),
constraints=LinearConstraint([[6, 4], [3, 1]], ub=[40, 20]))
...
The optimal number of gowns produced is: 6.67
The optimal number of tuxedos produced is: 0.00
Предложенное решение: 6,67 платья и 0,00 смокингов $\rightarrow$
Округление до 7 платьев и 0 смокингов
Усечение до 6 платьев и 0 смокингов
Введение в оптимизацию на Python