Kharlamov_ComputedMath_v5/Simplex.py

15 lines
740 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
import scipy.optimize as sp
# Целевая функция - коэффициенты y1, y2, y3 , y4 соответственно
obj = [18, 16, 5, 21]
# Левая сторона неравенств т.к. библитека не умеет работать со знаком >=, то умножаем неравенства на -1.
A = [[-1, -2, 0, -3], [-3, -1, -1, 0]]
B = [-2, -3]
# Границы y
bnd = [(0, None), (0, None), (0, None), (0, None)]
# Результат
res = sp.linprog(obj, A_ub=A, b_ub=B, bounds=bnd, method='highs', options={"disp": True})
print(f"Оптимальное значние целевой функции L* = {res.fun}")
print(f"Оптимальный план X* = {res.x}")