Basic linear programming terms
- Objective function: The main goal of the problem, either maximize or minimize, is the objective function of linear programming. In the problem below, Z (for minimization) is the objective function.
- Decision Variables: Variables used to define the output as decision variables. These are unknown mathematical programming models. In the task below, we have to define the x and y values to minimize Z. Here x and y are the decision variables.
- Constraints: are the constraints on the decision variables. Constraints on decision variables given in accordance with the constraints in the following problem are constraints of linear programming.
- Constraints of non-negativity: in linear programming, the values of decision variables are always greater than or equal to 0.
Note. For the problem to be a linear programming problem, the objective function, constraints and nonnegativity constraints must be linear.
Example 1. Consider the following problem:
Minimize: Z = 3x + 5y Subject to the constraints : 2x + 3y" = 12 -x + y "= 3 x" = 4 y "= 3 x, y" = 0
Solution of the above linear programming problem in Python:
PuLP — one of the many libraries in the Python ecosystem for solving optimization problems. You can install PuLp in Jupyter notebook like this:
|
Code: To solve the above linear programming problem in Python:
|
Explanation :
Now let’s go through the code step by step:
- Line 1-2: first import the library mass as p.
- Line 4-5: Define the problem by giving a suitable name for your problem, here I am gave the name "Problem". Also, specify your target for the objective function: expand or collapse.
- Line 7-9: Define an LpVariable to store the variables of the objective functions. The next argument sets the lower bound for the specified variable, that is, 0, and the upper bound is zero by default. You can also specify an upper bound.
- Line 11-12: denotes the objective function in terms of defined variables.
- Line 14-18: these are variable restrictions.
- Line 21: this will show you the problem on the output screen.
- Line 23: this is the solution to the problems.
- Line 24: will display the status of the problem.
- Line 27: will print the value for x and y and the minimum value for the objective function.
View the output
|
Exit

|
Exit
Optimal
|
Exit
6.0 0.0 18.0
Optimal values for x and y are 6.0 and 0.0 , respectively. The optimized objective function value is 18.0.