|
| 1 | +# Import PuLP library |
| 2 | +from pulp import LpMaximize, LpProblem, LpVariable, LpStatus, value |
| 3 | + |
| 4 | +# Create a Linear Programming Minimization problem |
| 5 | +prob = LpProblem("Dual_Simplex_Example", LpMaximize) |
| 6 | + |
| 7 | +# Create decision variables for the dual problem |
| 8 | +y1 = LpVariable('y1', lowBound=0) # y1 >= 0 |
| 9 | +y2 = LpVariable('y2', lowBound=0) # y2 >= 0 |
| 10 | +y3 = LpVariable('y3', lowBound=0) # y3 >= 0 |
| 11 | + |
| 12 | +# Objective function (minimization in dual corresponds to maximization here) |
| 13 | +prob += 4 * y1 + 2 * y2 + 3 * y3, "Objective" |
| 14 | + |
| 15 | +# Constraints for the dual problem |
| 16 | +prob += y1 + y2 >= 3, "Constraint 1" |
| 17 | +prob += y1 + y3 >= 2, "Constraint 2" |
| 18 | + |
| 19 | +# Solve the problem using the dual simplex method |
| 20 | +prob.solve() |
| 21 | + |
| 22 | +# Print the status of the solution |
| 23 | +print(f"Status: {LpStatus[prob.status]}") |
| 24 | + |
| 25 | +# Print the results (optimal values for y1, y2, and y3) |
| 26 | +print(f"y1 = {value(y1)}") |
| 27 | +print(f"y2 = {value(y2)}") |
| 28 | +print(f"y3 = {value(y3)}") |
| 29 | + |
| 30 | +# Print the objective value (minimized value) |
| 31 | +print(f"Optimal objective value: {value(prob.objective)}") |
| 32 | + |
0 commit comments