Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
49 views

The Problem Can Be Translated Into Python With The

The document describes how to solve a simple linear optimization problem using the Python pulp package. It defines two variables x and y with lower bounds of 0, specifies the objective function and three constraints, and calls the .solve() method to find the optimal solution. It then shows how to print the values of the variables using a for loop and the .variables() and .varValue methods. Finally, it outlines the three possible outcomes of linear programs: a local optimal solution, an infeasible problem, or an unbounded problem.

Uploaded by

hachan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

The Problem Can Be Translated Into Python With The

The document describes how to solve a simple linear optimization problem using the Python pulp package. It defines two variables x and y with lower bounds of 0, specifies the objective function and three constraints, and calls the .solve() method to find the optimal solution. It then shows how to print the values of the variables using a for loop and the .variables() and .varValue methods. Finally, it outlines the three possible outcomes of linear programs: a local optimal solution, an infeasible problem, or an unbounded problem.

Uploaded by

hachan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

The problem can be translated into Python with the pulp package, as follows:

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.

The following output is generated when the code runs:


In [ ]:
print("Maximization Results:")
for variable in problem.variables():
print(variable.name, '=', variable.varValue)
Out[ ]:
Maximization Results:

Outcomes of linear programs


There are three outcomes in linear optimization, as follows:

• 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.

You might also like