From 1a2334139e2533a83c84e46e50d50975dd222b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Wed, 13 Dec 2023 22:25:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=201.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Simplex.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Simplex.py b/Simplex.py index 5596b44..42acde3 100644 --- a/Simplex.py +++ b/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}")