Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC2
maths
simplex
Commits
b575202c
Verified
Commit
b575202c
authored
1 year ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
feat:la personne qui supporte Aliya
parent
b93a87ab
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/simplexe.py
+47
-9
47 additions, 9 deletions
src/simplexe.py
with
47 additions
and
9 deletions
src/simplexe.py
+
47
−
9
View file @
b575202c
...
...
@@ -30,6 +30,10 @@ class Simplexe:
self
.
NumRows
=
self
.
AMatrix
.
shape
[
0
]
self
.
NumCols
=
self
.
AMatrix
.
shape
[
1
]
self
.
hasCycle
=
False
# self.initBasicVariable = self.__basicVariables.copy()
def
SolveProblem
(
self
):
self
.
__start
=
time
.
time
()
self
.
__initTableau
()
...
...
@@ -166,6 +170,9 @@ class Simplexe:
self
.
__tableau
=
np
.
append
(
self
.
__tableau
,
tmpC
,
axis
=
0
)
self
.
__basicVariables
=
np
.
arange
(
self
.
NumCols
,
self
.
NumCols
+
self
.
NumRows
,
1
,
dtype
=
int
)
self
.
__initBasicVariable
=
self
.
__basicVariables
.
copy
()
self
.
TableauRowCount
,
self
.
TableauColCount
=
self
.
__tableau
.
shape
for
rowId
in
range
(
self
.
NumRows
):
if
self
.
__tableau
[
rowId
,
-
1
]
<
-
Constants
.
EPS
:
...
...
@@ -176,6 +183,7 @@ class Simplexe:
# 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)
def
__selectPivot
(
self
):
# print(self.__basicVariables)
colId
=
self
.
__selectEnteringColumn
()
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)
...
...
@@ -188,6 +196,13 @@ class Simplexe:
self
.
OptStatus
=
OptStatus
.
NotBounded
return
None
# 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
]
def
__getBasicVariableValue
(
self
,
rowId
,
baseColId
):
...
...
@@ -249,7 +264,6 @@ class Simplexe:
###################################################################
# returns cheks if the current solution is feasible or not (return True if feasible)
def
__isSolutionFeasible
(
self
):
# we MUST have that all BASIC variables are >= 0 to have a FEASIBLE solution
# to iterate over basic variables do:
...
...
@@ -270,20 +284,25 @@ class Simplexe:
# 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
.
array_equal
(
self
.
__basicVariables
,
self
.
__initBasicVariable
):
self
.
hasCycle
=
True
if
self
.
hasCycle
:
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
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
# return None or -1 if there is pivot (sets optimisation status accoringly before returning)
def
__selectLeavingRow
(
self
,
pivotColId
):
# given the entering column, find the leaving row - return the index of the row or -1 if none is found
# iterate using :
...
...
@@ -305,6 +324,25 @@ class Simplexe:
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
):
if
pivotIDs
is
None
or
pivotIDs
[
0
]
<
0
or
pivotIDs
[
1
]
<
0
:
# no pivot => optimiser status is updated in pivot selection => return!
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment