Убрал лишний столбец
This commit is contained in:
parent
613b784274
commit
f6d6f4de86
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user