0% found this document useful (0 votes)
14 views1 page

Code

Uploaded by

Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Code

Uploaded by

Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import pulp

def solve_lp_problem(problem_type):
# Create LP problem
if problem_type == "bounded":
print("Maximization Problem (Bounded):")
lp_problem = pulp.LpProblem("Maximize_Z_Bounded", pulp.LpMaximize)

x = pulp.LpVariable('x', lowBound=0, cat='Continuous')


y = pulp.LpVariable('y', lowBound=0, cat='Continuous')

lp_problem += 3 * x + 2 * y, "Objective_Function"
lp_problem += x + y <= 4, "Constraint_1"
lp_problem += 2 * x + y <= 5, "Constraint_2"

elif problem_type == "unbounded":


print("Maximization Problem (Unbounded):")
lp_problem = pulp.LpProblem("Maximize_Z_Unbounded", pulp.LpMaximize)

x = pulp.LpVariable('x', lowBound=0, cat='Continuous')


y = pulp.LpVariable('y', lowBound=0, cat='Continuous')

lp_problem += 3 * x + 2 * y, "Objective_Function"
lp_problem += x >= 1, "Constraint_1"

elif problem_type == "no_solution":


print("Maximization Problem (No Solution):")
lp_problem = pulp.LpProblem("Maximize_Z_No_Solution", pulp.LpMaximize)

x = pulp.LpVariable('x', lowBound=0, cat='Continuous')


y = pulp.LpVariable('y', lowBound=0, cat='Continuous')

lp_problem += 3 * x + 2 * y, "Objective_Function"
lp_problem += x + y >= 5, "Constraint_1"
lp_problem += x + y <= 3, "Constraint_2"

else:
print("Invalid problem type specified.")
return

# Solve LP problem
lp_problem.solve()

# Output results
print(f"Status: {pulp.LpStatus[lp_problem.status]}")
print(f"x = {x.varValue}")
print(f"y = {y.varValue}")
print(f"Objective function value: {pulp.value(lp_problem.objective)}\n")

# Test different scenarios


solve_lp_problem("bounded")
# solve_lp_problem("unbounded")
# solve_lp_problem("no_solution")

You might also like