-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassical_Simplex.py
More file actions
25 lines (24 loc) · 852 Bytes
/
Copy pathClassical_Simplex.py
File metadata and controls
25 lines (24 loc) · 852 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 CS_Phase1
import CS_Phase2
import time
def ClassicalSimplex(A, b, Cost):
start = time.time()
np.set_printoptions(precision=2, suppress=True)
m, n = A.shape
Ab, IndexB, count1 = CS_Phase1.AuxSolver(A, b, Cost)
print('Phase1: Output A_b without r')
print(Ab)
print('Basis: ', IndexB)
print('---------------------------')
b_bar, IndexB, count2 = CS_Phase2.NormalSolver(Ab, Cost, IndexB)
OptimalSolution = np.zeros(n)
for i in range(len(IndexB)):
OptimalSolution[IndexB[i]] = b_bar[i]
end = time.time()
print('We are done!')
print('Basis: ', IndexB)
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))