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

feat:la personne qui supporte Aliya

parent b93a87ab
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,10 @@ class Simplexe: ...@@ -30,6 +30,10 @@ class Simplexe:
self.NumRows = self.AMatrix.shape[0] self.NumRows = self.AMatrix.shape[0]
self.NumCols = self.AMatrix.shape[1] self.NumCols = self.AMatrix.shape[1]
self.hasCycle = False
# self.initBasicVariable = self.__basicVariables.copy()
def SolveProblem(self): def SolveProblem(self):
self.__start = time.time() self.__start = time.time()
self.__initTableau() self.__initTableau()
...@@ -166,6 +170,9 @@ class Simplexe: ...@@ -166,6 +170,9 @@ class Simplexe:
self.__tableau = np.append(self.__tableau, tmpC, axis=0) self.__tableau = np.append(self.__tableau, tmpC, axis=0)
self.__basicVariables = np.arange( self.__basicVariables = np.arange(
self.NumCols, self.NumCols + self.NumRows, 1, dtype=int) self.NumCols, self.NumCols + self.NumRows, 1, dtype=int)
self.__initBasicVariable = self.__basicVariables.copy()
self.TableauRowCount, self.TableauColCount = self.__tableau.shape self.TableauRowCount, self.TableauColCount = self.__tableau.shape
for rowId in range(self.NumRows): for rowId in range(self.NumRows):
if self.__tableau[rowId, -1] < -Constants.EPS: if self.__tableau[rowId, -1] < -Constants.EPS:
...@@ -176,6 +183,7 @@ class Simplexe: ...@@ -176,6 +183,7 @@ class Simplexe:
# returns next pivot as an array of leaving row id and entering col Id # returns next pivot as an array of leaving row id and entering col Id
# return None if there is pivot (sets optimisation status accoringly before returning) # return None if there is pivot (sets optimisation status accoringly before returning)
def __selectPivot(self): def __selectPivot(self):
# print(self.__basicVariables)
colId = self.__selectEnteringColumn() colId = self.__selectEnteringColumn()
if ((not colId) | colId < 0): if ((not colId) | colId < 0):
# no more entering column => optimiser status is OPTIMAL (must be - we never select a pivot if the tableau is unfeasible) # no more entering column => optimiser status is OPTIMAL (must be - we never select a pivot if the tableau is unfeasible)
...@@ -188,6 +196,13 @@ class Simplexe: ...@@ -188,6 +196,13 @@ class Simplexe:
self.OptStatus = OptStatus.NotBounded self.OptStatus = OptStatus.NotBounded
return None return None
# normal case : we do have a standard pivot! # normal case : we do have a standard pivot!
# print(f"Before : {self.__basicVariables}")
# print(f"RowID = {rowId}")
# idx_to_replace = np.argwhere(self.__basicVariables == rowId)[0][0]
self.__basicVariables[rowId] = colId
# print(f"After : {self.__basicVariables}")
# print(idx_to_replace)
return [rowId, colId] return [rowId, colId]
def __getBasicVariableValue(self, rowId, baseColId): def __getBasicVariableValue(self, rowId, baseColId):
...@@ -249,7 +264,6 @@ class Simplexe: ...@@ -249,7 +264,6 @@ class Simplexe:
################################################################### ###################################################################
# returns cheks if the current solution is feasible or not (return True if feasible) # returns cheks if the current solution is feasible or not (return True if feasible)
def __isSolutionFeasible(self): def __isSolutionFeasible(self):
# we MUST have that all BASIC variables are >= 0 to have a FEASIBLE solution # we MUST have that all BASIC variables are >= 0 to have a FEASIBLE solution
# to iterate over basic variables do: # to iterate over basic variables do:
...@@ -270,20 +284,25 @@ class Simplexe: ...@@ -270,20 +284,25 @@ class Simplexe:
# print(self.__tableau[rowId, baseColId]) # print(self.__tableau[rowId, baseColId])
# #
# This maybe ain't that dumb but it works half the time which is weird if np.array_equal(self.__basicVariables, self.__initBasicVariable):
# if self.__PivotCount > self.AMatrix.shape[1] - 1: self.hasCycle = True
# return -1
# if self.hasCycle:
# return self.__PivotCount for idx, val in enumerate(self.__tableau[-1, :-1]):
if val < 0:
return idx
if np.size(self.__tableau[-1, :-1][np.where(self.__tableau[-1, :-1]
< 0)]) == 0:
return -1 return -1
else:
if np.size(self.__tableau[-1, :-1][np.where(self.__tableau[-1, :-1]
< 0)]) == 0:
return -1
return np.argmin(self.__tableau[-1, :-1]) return np.argmin(self.__tableau[-1, :-1])
# returns leaving row ID # returns leaving row ID
# return None or -1 if there is pivot (sets optimisation status accoringly before returning) # return None or -1 if there is pivot (sets optimisation status accoringly before returning)
def __selectLeavingRow(self, pivotColId): def __selectLeavingRow(self, pivotColId):
# given the entering column, find the leaving row - return the index of the row or -1 if none is found # given the entering column, find the leaving row - return the index of the row or -1 if none is found
# iterate using : # iterate using :
...@@ -305,6 +324,25 @@ class Simplexe: ...@@ -305,6 +324,25 @@ class Simplexe:
return candidates.argmin() return candidates.argmin()
# minRatio = float('inf')
# leavingRow = -1
#
# rowCount = self.TableauRowCount - 2 if self.IsPhaseI else \
# self.TableauRowCount - 1
#
# for index in range(rowCount):
# # Si le ration est positif
# if self.__tableau[index][pivotColId] > 0:
# ratio = self.__tableau[index][-1] / \
# self.__tableau[index][pivotColId]
# if ratio < minRatio:
# minRatio = ratio
# leavingRow = index
#
# print("leaving row :", leavingRow) # vérification ok
#
# return leavingRow
def __pivotTableau(self, pivotIDs): def __pivotTableau(self, pivotIDs):
if pivotIDs is None or pivotIDs[0] < 0 or pivotIDs[1] < 0: if pivotIDs is None or pivotIDs[0] < 0 or pivotIDs[1] < 0:
# no pivot => optimiser status is updated in pivot selection => return! # no pivot => optimiser status is updated in pivot selection => return!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment