From f6d6f4de86708757d3be8cdbfd01b586b66423c8 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Wed, 20 Dec 2023 01:41:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BB=D0=B8?= =?UTF-8?q?=D1=88=D0=BD=D0=B8=D0=B9=20=D1=81=D1=82=D0=BE=D0=BB=D0=B1=D0=B5?= =?UTF-8?q?=D1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simplexImp.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/simplexImp.py b/simplexImp.py index 8905b4d..9acdce1 100644 --- a/simplexImp.py +++ b/simplexImp.py @@ -13,13 +13,13 @@ def find_min_col(table): return m, n = table.shape main_col = 1 - for j in range(n - 2): + for j in range(n - 1): if table[m - 1, j] < table[m - 1, main_col]: main_col = j return main_col -def return_row(table, column): +def find_min_row(table, column): if np.ndim(table) != 2: return m, n = table.shape @@ -39,9 +39,9 @@ class SimplexMethod: def __init__(self, data): m, n = data.shape - self.table = np.zeros((m, n + m)) + self.table = np.zeros((m, n + m - 1)) self.table[:, :n - 1] = data[:, :n - 1] # Копируем значения из data в первые n столбцов table - self.table[:, -2] = data[:, -1] # Копируем последний столбец (вектор правой части) + self.table[:, -1] = data[:, -1] # Копируем последний столбец (вектор правой части) for i in range(m - 1): self.table[i, n - 1 + i] = 1 @@ -54,7 +54,7 @@ class SimplexMethod: def solve(self): while return_status(self.table, self.n): column_with_min_value = find_min_col(self.table) - row_with_min_value = return_row(self.table, column_with_min_value) + row_with_min_value = find_min_row(self.table, column_with_min_value) new_table = np.copy(self.table) @@ -73,7 +73,7 @@ class SimplexMethod: def return_result(self, out_count): result = [] - for j in range(self.n - 2): + for j in range(self.n - 1): if len(result) >= out_count: break @@ -88,11 +88,11 @@ class SimplexMethod: if count == 1: result.append({ "name": "x" + str(index), - "value": self.table[index, self.n - 2] / self.table[index, j] + "value": self.table[index, self.n - 1] / self.table[index, j] }) result.append({ "name": "F", - "value": self.table[self.m - 1, self.n - 2] + "value": self.table[self.m - 1, self.n - 1] }) return result