Skip to content

Commit b74498e

Browse files
Merge pull request #589 from Quantum-Software-Development/FabianaCampanari-patch-1
Update README.md
2 parents 9a0113d + b0503d4 commit b74498e

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

README.md

+29-16
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ Now the most negative coefficient in the Z row is for s₃, but:
697697

698698
<br>
699699

700-
### 🏁 [Final Optimal Solution
700+
### 🏁 [Final Optimal Solution]():
701701

702702
The optimal solution was reached at the end of Iteration 1]():
703703

@@ -709,28 +709,41 @@ Z(max) = 12
709709

710710
<br>
711711

712+
## 🐍 Python Code – Simplex Solver (Basic Version)
712713

714+
```python
715+
from scipy.optimize import linprog
713716

717+
# Coefficients of the objective function (to maximise Z = 4x₁ + 3x₂)
718+
# Convert to minimisation: -Z
719+
c = [-4, -3]
714720

721+
# Coefficients of the inequality constraints (Ax ≤ b)
722+
A = [
723+
[1, 3],
724+
[2, 2],
725+
[1, 1],
726+
[0, 1]
727+
]
715728

729+
b = [7, 8, 3, 2]
716730

731+
# Bounds for x₁ and x₂: both ≥ 0
732+
x_bounds = (0, None)
733+
bounds = [x_bounds, x_bounds]
717734

735+
# Solve the problem
736+
res = linprog(c, A_ub=A, b_ub=b, bounds=bounds, method="simplex")
718737

719-
720-
721-
722-
723-
724-
725-
726-
727-
728-
729-
730-
731-
732-
733-
738+
# Output results
739+
if res.success:
740+
print("Optimal solution found:")
741+
print(f"x₁ = {res.x[0]:.2f}")
742+
print(f"x₂ = {res.x[1]:.2f}")
743+
print(f"Maximum Z = {(-res.fun):.2f}")
744+
else:
745+
print("No solution found:", res.message)
746+
```
734747

735748
<br>
736749

0 commit comments

Comments
 (0)