Skip to content

Commit 966a8ab

Browse files
authored
Create another algorithm under Linear Programming dual_simplex.py
Dual-Simplex Algorithm using PULP The prob.solve() function applies the Dual Simplex method indirectly by solving the dual of the primal LP problem. Pulp doesn’t directly expose the option to select the dual simplex solver, but it will use it when necessary if you alter constraints dynamically (reoptimization).
1 parent 40f65e8 commit 966a8ab

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: linear_programming/dual_simplex.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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

Comments
 (0)