jukaukor

LinOptimointi.py

Mar 1st, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. # Linear Optimization
  2. # Juhani Kaukoranta 1.3.2021
  3. # "Advanced Engineering Mathematics", Sec 21.4 probl 5,s 1129,
  4. from pulp import LpMaximize, LpProblem, LpStatus, LpVariable
  5. # Create the model, LpMaximize or LpMinimize
  6. model = LpProblem(name="small-problem", sense=LpMaximize)
  7. # Initialize variables
  8. # lamps type I, II, III
  9. x1 = LpVariable(name="x1", lowBound=0)
  10. x2 = LpVariable(name="x2", lowBound=0)
  11. x3 = LpVariable(name="x3", lowBound=0)
  12. # Add the constraints to the model
  13. model += (3 * x1 + x2 <= 450,"metal supply")
  14. model += (2*x2 + 3 * x3 <= 900,"plastic supply")
  15. model += (2*x1 + x2 <= 350, "glass supply")
  16. # Add the objective function to the model (object of optimization)
  17. # object : total profit ( profit per lamp 10,8,5 USD)
  18. model += 10*x1 + 8 * x2 + 5*x3
  19. # Solve the problem
  20. status = model.solve()
  21. print(model) # show model
  22. print(f"status: {model.status}, {LpStatus[model.status]}")
  23. print(f"objective: {model.objective.value()}")
  24. for var in model.variables():
  25. print(f"{var.name}: {var.value()}")
  26.  
Advertisement
Add Comment
Please, Sign In to add comment