#do not forget to instal pulp
#python -m pip install pulp

import gurobipy as gp
from gurobipy import GRB

# Create model
model = gp.Model("ReddyMikks")

# Decision variables (x1 and x2), non-negative
x1 = model.addVar(lb=0, name="x1")
x2 = model.addVar(lb=0, name="x2")

# Set objective: Maximize 5*x1 + 4*x2
model.setObjective(5 * x1 + 4 * x2, GRB.MAXIMIZE)

# Constraints
c1 = model.addConstr(6 * x1 + 4 * x2 <= 24, name="c1")
c2 = model.addConstr(1 * x1 + 2 * x2 <= 6, name="c2")
c3 = model.addConstr(-1 * x1 + 1 * x2 <= 1, name="c3")
c4 = model.addConstr(0 * x1 + 1 * x2 <= 2, name="c4")

# Solve the model
model.optimize()

# Print status
print("\nOptimization Status:", model.Status)
if model.Status == GRB.OPTIMAL:
    print("\n✅ Optimal solution found!\n")

    # Print objective value
    print(f"Objective Value: {model.ObjVal:.2f}\n")

    # Print variable values
    print("Variable Values:")
    for v in model.getVars():
        print(f"  {v.VarName} = {v.X:.2f}")

    # Print slack and shadow prices
    print("\nConstraint Info:")
    for c in model.getConstrs():
        slack = c.Slack
        shadow_price = c.Pi
        print(f"  {c.ConstrName}: Slack = {slack:.2f}, Shadow Price = {shadow_price:.2f}")

    # Sensitivity Analysis: Objective Coefficient Ranges
    print("\nSensitivity Analysis - Objective Coefficient Ranges:")
    for v in model.getVars():
        print(f"  {v.VarName}: Coeff = {v.Obj}, "
              f"Reduced Cost = {v.RC:.2f}, "
              f"Allowable Range = [{v.SAObjLow:.2f}, {v.SAObjUp:.2f}]")

    # Sensitivity Analysis: RHS Ranges
    print("\nSensitivity Analysis - RHS Ranges:")
    for c in model.getConstrs():
        print(f"  {c.ConstrName}: RHS = {c.RHS}, "
              f"Shadow Price = {c.Pi:.2f}, "
              f"Allowable RHS Range = [{c.SARHSLow:.2f}, {c.SARHSUp:.2f}]")
else:
    print("⚠️ No optimal solution found.")
