Skip to content

Commit 8097aaf

Browse files
committed
fixed small issues
1 parent 8d0ba8e commit 8097aaf

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed
13 Bytes
Binary file not shown.

linear_programming.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def solve(self, method=SOLVER_SIMPLEX):
227227
x_sol = simplex(lp_slacked.A, lp_slacked.b, lp_slacked.c, lp_slacked.vars_slack_amount)
228228

229229
# Cut slack variables
230-
x_sol = x_sol[:lp_slacked.vars_slack_amount]
230+
x_sol = x_sol[:lp_slacked.c.size - lp_slacked.vars_slack_amount]
231231
print(x_sol)
232232

233233
return x_sol

simplex.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
def simplex(A: np.array, b: np.array, c: np.array, slacks_amt: int) -> np.array:
1616
# https://sdu.itslearning.com/ContentArea/ContentArea.aspx?LocationID=17727&LocationType=1&ElementID=589350
1717
#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
2320

2421
while True:
22+
tableau(A, b, c)
2523
## Choosing a pivot
2624
# Pick a non-negative column TODO
2725
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:
5351
# Remove yy_old from basis and add yy to basis
5452
B.remove(yy_old)
5553
B.append(yy)
56-
N.append(yy_old)
57-
N.remove(yy)
54+
#N.append(yy_old)
55+
#N.remove(yy)
5856

5957
## Pivot: A[xx, yy] - Peform row operations
6058
# 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:
120118
return all(np.isclose(A @ x, b, atol=tol))
121119

122120

121+
def tableau(A: np.array, b: np.array, c: np.array):
122+
print(A, b.T, c.T)
123+
123124
if __name__ == "__main__":
124125
A = np.array([[ 1, 1, 1, 1, 1, 0, 0],
125126
[ 2, 1, -1, -1, 0, -1, 0],

0 commit comments

Comments
 (0)