Убрал лишний столбец

This commit is contained in:
maxnes3 2023-12-20 01:41:26 +04:00
parent 613b784274
commit f6d6f4de86

View File

@ -13,13 +13,13 @@ def find_min_col(table):
return return
m, n = table.shape m, n = table.shape
main_col = 1 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]: if table[m - 1, j] < table[m - 1, main_col]:
main_col = j main_col = j
return main_col return main_col
def return_row(table, column): def find_min_row(table, column):
if np.ndim(table) != 2: if np.ndim(table) != 2:
return return
m, n = table.shape m, n = table.shape
@ -39,9 +39,9 @@ class SimplexMethod:
def __init__(self, data): def __init__(self, data):
m, n = data.shape 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[:, :n - 1] = data[:, :n - 1] # Копируем значения из data в первые n столбцов table
self.table[:, -2] = data[:, -1] # Копируем последний столбец (вектор правой части) self.table[:, -1] = data[:, -1] # Копируем последний столбец (вектор правой части)
for i in range(m - 1): for i in range(m - 1):
self.table[i, n - 1 + i] = 1 self.table[i, n - 1 + i] = 1
@ -54,7 +54,7 @@ class SimplexMethod:
def solve(self): def solve(self):
while return_status(self.table, self.n): while return_status(self.table, self.n):
column_with_min_value = find_min_col(self.table) 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) new_table = np.copy(self.table)
@ -73,7 +73,7 @@ class SimplexMethod:
def return_result(self, out_count): def return_result(self, out_count):
result = [] result = []
for j in range(self.n - 2): for j in range(self.n - 1):
if len(result) >= out_count: if len(result) >= out_count:
break break
@ -88,11 +88,11 @@ class SimplexMethod:
if count == 1: if count == 1:
result.append({ result.append({
"name": "x" + str(index), "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({ result.append({
"name": "F", "name": "F",
"value": self.table[self.m - 1, self.n - 2] "value": self.table[self.m - 1, self.n - 1]
}) })
return result return result