Лабораторная 1.
This commit is contained in:
parent
941542c3f4
commit
1a2334139e
28
Simplex.py
28
Simplex.py
@ -1,16 +1,14 @@
|
||||
# This is a sample Python script.
|
||||
import numpy as np
|
||||
import scipy.optimize as sp
|
||||
|
||||
# Press Shift+F10 to execute it or replace it with your code.
|
||||
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
||||
|
||||
|
||||
def print_hi(name):
|
||||
# Use a breakpoint in the code line below to debug your script.
|
||||
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
||||
|
||||
|
||||
# Press the green button in the gutter to run the script.
|
||||
if __name__ == '__main__':
|
||||
print_hi('PyCharm')
|
||||
|
||||
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
||||
# Целевая функция - коэффициенты 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}")
|
||||
|
Loading…
Reference in New Issue
Block a user