Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Linear Optimization
- # Juhani Kaukoranta 1.3.2021
- # "Advanced Engineering Mathematics", Sec 21.4 probl 5,s 1129,
- from pulp import LpMaximize, LpProblem, LpStatus, LpVariable
- # Create the model, LpMaximize or LpMinimize
- model = LpProblem(name="small-problem", sense=LpMaximize)
- # Initialize variables
- # lamps type I, II, III
- x1 = LpVariable(name="x1", lowBound=0)
- x2 = LpVariable(name="x2", lowBound=0)
- x3 = LpVariable(name="x3", lowBound=0)
- # Add the constraints to the model
- model += (3 * x1 + x2 <= 450,"metal supply")
- model += (2*x2 + 3 * x3 <= 900,"plastic supply")
- model += (2*x1 + x2 <= 350, "glass supply")
- # Add the objective function to the model (object of optimization)
- # object : total profit ( profit per lamp 10,8,5 USD)
- model += 10*x1 + 8 * x2 + 5*x3
- # Solve the problem
- status = model.solve()
- print(model) # show model
- print(f"status: {model.status}, {LpStatus[model.status]}")
- print(f"objective: {model.objective.value()}")
- for var in model.variables():
- print(f"{var.name}: {var.value()}")
Advertisement
Add Comment
Please, Sign In to add comment