|
15 | 15 | def simplex(A: np.array, b: np.array, c: np.array, slacks_amt: int) -> np.array:
|
16 | 16 | # https://sdu.itslearning.com/ContentArea/ContentArea.aspx?LocationID=17727&LocationType=1&ElementID=589350
|
17 | 17 | #x_current = basic_feasible_solution(A, b, c)
|
18 |
| - N = [i for i in range(c.size - slacks_amt)] # Not In basis |
19 |
| - B = [i for i in range(slacks_amt, c.size)] # In basis |
20 |
| - |
21 |
| - print(A, b, c) |
22 |
| - print(N, B) |
| 18 | + #N = [i for i in range(c.size - slacks_amt)] # Not In basis |
| 19 | + B = [i + (c.size - slacks_amt) for i in range(slacks_amt)] # In basis |
23 | 20 |
|
24 | 21 | while True:
|
| 22 | + tableau(A, b, c) |
25 | 23 | ## Choosing a pivot
|
26 | 24 | # Pick a non-negative column TODO
|
27 | 25 | positives = np.where(c > 0)
|
@@ -53,8 +51,8 @@ def simplex(A: np.array, b: np.array, c: np.array, slacks_amt: int) -> np.array:
|
53 | 51 | # Remove yy_old from basis and add yy to basis
|
54 | 52 | B.remove(yy_old)
|
55 | 53 | B.append(yy)
|
56 |
| - N.append(yy_old) |
57 |
| - N.remove(yy) |
| 54 | + #N.append(yy_old) |
| 55 | + #N.remove(yy) |
58 | 56 |
|
59 | 57 | ## Pivot: A[xx, yy] - Peform row operations
|
60 | 58 | # Set yy row with in column xx to 1
|
@@ -120,6 +118,9 @@ def is_feasible(A: np.array, x: np.array, b: np.array, tol=10e-5) -> bool:
|
120 | 118 | return all(np.isclose(A @ x, b, atol=tol))
|
121 | 119 |
|
122 | 120 |
|
| 121 | +def tableau(A: np.array, b: np.array, c: np.array): |
| 122 | + print(A, b.T, c.T) |
| 123 | + |
123 | 124 | if __name__ == "__main__":
|
124 | 125 | A = np.array([[ 1, 1, 1, 1, 1, 0, 0],
|
125 | 126 | [ 2, 1, -1, -1, 0, -1, 0],
|
|
0 commit comments