The Problem Can Be Translated Into Python With The
The Problem Can Be Translated Into Python With The
In [ ]:
"""
A simple linear optimization problem with 2 variables
"""
import pulp
x = pulp.LpVariable('x', lowBound=0)
y = pulp.LpVariable('y', lowBound=0)
problem = pulp.LpProblem(
'A simple maximization objective',
pulp.LpMaximize)
problem += 3*x + 2*y, 'The objective function'
problem += 2*x + y <= 100, '1st constraint'
problem += x + y <= 80, '2nd constraint'
problem += x <= 40, '3rd constraint'
problem.solve()
The LpVariable function declares a variable to be solved. The LpProblem function initializes
the problem with a text description of the problem and the type of optimization, which in
this case is the maximization method. The += operation allows an arbitrary number of
constraints to be added, along with a text description. Finally, the .solve() method is called
to begin performing linear optimization. To show the values solved by the optimizer, use
the .variables()method to loop through each variable and print out its varValue.
• A local optimal solution to a linear program is a feasible solution with a closer objective
function value than all other feasible solutions close to it. It may or may not be the global
optimal solution, a solution that is better than every feasible solution.
• A linear program is infeasible if a solution cannot be found.
• A linear program is unbounded if the optimal solution is unbounded or is infinite.