Skip to content
Snippets Groups Projects
Verified Commit b93a87ab authored by iliya.saroukha's avatar iliya.saroukha :first_quarter_moon:
Browse files

cleanup: refactored Aliya's ideas

parent f2711b0c
Branches
Tags
No related merge requests found
......@@ -255,19 +255,32 @@ class Simplexe:
# to iterate over basic variables do:
for rowId, baseColId in enumerate(self.__basicVariables):
if self.RHS[rowId] / self.__tableau[rowId][baseColId] < 0:
if self.__getBasicVariableValue(rowId, baseColId) < 0:
return False
# raise Exception(
# 'Not implemented', 'Simplexe.__isSolutionFeasible: missing code to be implemented.')
return True
# returns index of entering col Id
# return None or -1 if there is pivot
def __selectEnteringColumn(self):
# find an entering column for pivot => return -1 if none is found!
raise Exception(
'Not implemented', 'Simplexe.__selectEnteringColumn: missing code to be implemented.')
# print(self.__tableau[0])
# for rowId, baseColId in enumerate(self.__basicVariables):
# print(self.__tableau[rowId, baseColId])
#
# This maybe ain't that dumb but it works half the time which is weird
# if self.__PivotCount > self.AMatrix.shape[1] - 1:
# return -1
#
# return self.__PivotCount
if np.size(self.__tableau[-1, :-1][np.where(self.__tableau[-1, :-1]
< 0)]) == 0:
return -1
return np.argmin(self.__tableau[-1, :-1])
# returns leaving row ID
# return None or -1 if there is pivot (sets optimisation status accoringly before returning)
......@@ -276,8 +289,21 @@ class Simplexe:
# iterate using :
# rowCount = self.TableauRowCount - 2 if self.IsPhaseI else self.TableauRowCount - 1
# for index in range(rowCount):
raise Exception(
'Not implemented', 'Simplexe.__selectLeavingRow: missing code to be implemented.')
rowCount = self.TableauRowCount - 2 if self.IsPhaseI else \
self.TableauRowCount - 1
lhs = self.__tableau[:rowCount, pivotColId]
rhs = self.__tableau[:rowCount, -1]
ratios = rhs / lhs
candidates = np.where(ratios > 0, ratios, np.inf)
if len((np.unique(candidates))) == 0:
return -1
return candidates.argmin()
def __pivotTableau(self, pivotIDs):
if pivotIDs is None or pivotIDs[0] < 0 or pivotIDs[1] < 0:
......@@ -302,8 +328,21 @@ class Simplexe:
# iterate using
# pivotRow = self.__tableau[pivotRowId, :] / pivotVal
# for rowId in range(self.TableauRowCount):
raise Exception(
'Not implemented', 'Simplexe.__pivotTableau: missing code to be implemented.')
# Calculer la ligne du pivot normalisée (avoir la valeur 1 à la colonne du pivot)
pivotRow = self.__tableau[pivotRowId, :] / pivotVal
# Pour chaque ligne autre que le pivot
for rowId in range(self.TableauRowCount):
if rowId != pivotRowId:
# Mettre la colonne du pivot à 0
multiplier = self.__tableau[rowId, pivotColId]
self.__tableau[rowId, :] -= multiplier * pivotRow
self.__tableau[pivotRowId, :] = pivotRow
# raise Exception(
# 'Not implemented', 'Simplexe.__pivotTableau: missing code to be implemented.')
# For a given unfeasible initial problem, this method creates the corresponding Tableau of the Phase I, then launches the optimization of Phase I
def initPhaseI(self, simplexe):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment