-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRevised_Simplex.py
More file actions
25 lines (24 loc) · 884 Bytes
/
Revised_Simplex.py
File metadata and controls
25 lines (24 loc) · 884 Bytes
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
import numpy as np
import RS_Phase1
import RS_Phase2
import time
def RevisedSimplex(A, b, Cost):
start = time.time()
n, m = A.shape
A, b, NewIndexB, NewIndexN, New_b_bar, count1 = RS_Phase1.AuxiliarySolver(A, b, Cost)
A = A[:m]
NewIndexN = NewIndexN[NewIndexN < m]
print('Phase1: Output')
print('Basis: ', NewIndexB)
print('---------------------------')
NewIndexB, b_bar, count2 = RS_Phase2.Phase2(A, b, Cost, NewIndexB, NewIndexN)
OptimalSolution = np.zeros(m)
for i in range(len(NewIndexB)):
OptimalSolution[NewIndexB[i]] = b_bar[i]
end = time.time()
print('We are done!')
print('Basis: ', NewIndexB)
print('Optimal Solution: ', OptimalSolution)
print('Optimal Value: %.2f ' % OptimalSolution.dot(Cost))
print('Number of Pivoting: ', str(count1+count2))
print('Total Running Times: ', str(end-start))