-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplexe_solve.py
More file actions
executable file
·121 lines (98 loc) · 2.89 KB
/
simplexe_solve.py
File metadata and controls
executable file
·121 lines (98 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/python3.6
#Test Comment
import re
phase1=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0]
phase2=[-3,-10,-1,-15, -8,-50,-62,-40, 0, 0, 0, 0, 0, 0, 0]
Z=phase1
varIn=[0]
varOut=[0]
simplex_table=[
[20, 5, 7, 3, 9, 0.5, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 5],
[1, 2, 0, 15, 5, 10, 0, 20, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 3],
[1, 2, 0, 18, 2, 9, 25, 12, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 12, 3, 0, 2, 15, 15, 25, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 2],
[0, 6, 0, 5, 1, 20, 25, 25, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 6.66],
[5, 13, 10, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2],
[1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]#Z Indicatrice
Base=['A1', 'S1', 'A2', 'A3', 'A4', 'S2', 'A5']
Vars=['l', 't', 'r', 'y', 'd', 'm', 'i', 'h', 'E1', 'E2', 'E3', 'E4', 'S1', 'S2', 'A1', 'A2', 'A3', 'A4', 'A5']
def removeCol(i):
for row in simplex_table:
row.pop(i)
def removeA():
p = re.compile("A.*");
for i in Vars:
if p.match(i) != None :
removeCol(Vars.index(i))
Vars.pop(Vars.index(i))
def rezZ():
for i in range(0,len(simplex_table[len(simplex_table)-1])):
simplex_table[len(simplex_table)-1][i]=0
def comptZ():
for i in range(0,len(Z)):
simplex_table[len(simplex_table)-1][i]-=Z[i]
for i in range(0, len(simplex_table)-1):
coef=Z[Vars.index(Base[i])]
for j in range(0,len(Z)) :
simplex_table[len(simplex_table)-1][j]+=coef*simplex_table[i][j]
def Stop():
cont = False
cur=0
for i in simplex_table[len(simplex_table)-1]:
if i < 0 and cur != len(simplex_table[len(simplex_table)-1])-1 :
cont = True
break
return cont
def findIN():
tmp=0
cur=0
for i in simplex_table[len(simplex_table)-1] :
if i < tmp and cur != len(simplex_table[len(simplex_table)-1])-1 :
tmp=i
varIn[0]=cur
cur+=1
def findOUT():
rve=0
cur=0
#Init tmp un peu sale mais sa feras l'affaire
tmp = 10**100
for row in simplex_table:
if cur != len(simplex_table)-1:
try :
rve=row[len(row)-1]/row[varIn[0]]
if rve<tmp and rve > 0:
tmp = rve
varOut[0] = cur
except :
pass
cur+=1
def MajTab():
coef=0
r_cur=0
pivot=simplex_table[varOut[0]][varIn[0]]
for row in simplex_table :
coef=-row[varIn[0]]/simplex_table[varOut[0]][varIn[0]]
for i in range(0,len(row)) :
if r_cur != varOut[0] :
row[i]+=simplex_table[varOut[0]][i]*coef
r_cur+=1
for i in range(len(simplex_table[varOut[0]])):
simplex_table[varOut[0]][i]/=pivot
def simplexe():
while Stop():
findIN()
findOUT()
Base[varOut[0]] = Vars[varIn[0]]
MajTab()
##### MAIN
comptZ()
simplexe()
removeA()
rezZ()
Z=phase2
comptZ()
simplexe()
for i in range(len(Base)):
print(Base[i],' : ',simplex_table[i][len(simplex_table[i])-1])