Tired of making guesses in your decisions? Want to get the most out of limited resources? Linear programming is the secret weapon businesses use worldwide to optimize everything from production to delivery routes.
In this article, we’ll discuss the simple logic behind linear programming. You’ll learn how to transform complex problems into easy-to-solve mathematical models. We’ll conquer real-world scenarios like:
Linear programming is a fundamental skill for data scientists and analysts. But fear not; even beginners can grasp these powerful concepts. We’ll start with the basics and progress step-by-step, using clear explanations and practical examples.
Note: If you want to learn this in a course format, we have curated this free course for you- Linear Programming for Data Science Professionals
Linear programming is a simple technique that depicts complex relationships through linear functions and then finds the optimum points. The key term here is “depicts.” Real relationships might be much more complex, but we can simplify them to linear relationships.
Moreover, it’s important to note that linear programming is a special case of mathematical programming. It involves finding the optimal solution to a problem that involves linear relationships between the decision variables and the constraints. This method has applications in various industries and fields, from production planning to logistics optimization, and is a powerful tool in making data-driven decisions that can lead to improved efficiency and cost savings.
Applications of linear programming are everywhere around you. You use linear programming at personal and professional fronts. You are using linear programming when you are driving from home to work and want to take the shortest route. Or when you have a project delivery you make strategies to make your team work efficiently for on-time delivery.
Before exploring an example, let’s look at common terminologies used in LP!
Let us define some terminologies used in Linear Programming using the above example.
Let’s say a FedEx delivery man has 6 packages to deliver in a day. The warehouse is located at point A. U, V, W, X, Y, and Z represents the 6 delivery destinations. The numbers on the lines indicate the distance between the cities. To save on fuel and time the delivery person wants to take the shortest route.
The delivery person calculates different routes to all six destinations and then chooses the shortest route. This technique of selecting the shortest route is linear programming.
In this case, the objective of the delivery person is to deliver parcels on time to all six destinations. The process of choosing the best route is operations research, which involves methods to operate a system efficiently. In the above example, the system is the delivery model.
Linear programming is used to obtain the most optimal solution for a problem with given constraints. It formulates real-life problems into a mathematical model involving an objective function and linear inequalities subject to constraints.
Is the linear representation of the six points above representative of the real world? Yes and no. It is an oversimplification since the real route would not be a straight line. It would likely have multiple turns, U-turns, signals, and traffic jams. However, this simple assumption reduces the complexity of the problem drastically and creates a solution that works in most scenarios.
Let’s manufacture some chocolates…
Example: Consider a chocolate manufacturing company that produces only two types of chocolate – A and B. Both the chocolates require Milk and Choco only. To manufacture each unit of A and B, the following quantities are required:
The company kitchen has a total of 5 units of Milk and 12 units of Choco. On each sale, the company makes a profit of
Now, the company wishes to maximize its profit. How many units of A and B should it produce respectively?
The first thing I’m gonna do is represent the problem in a tabular form for better understanding.
Note: Everything taught here has also been taught in a course format in this free course- Linear Programming for Data Science Professionals
R is an open-source tool that is very popular among the data scientists for essential data science tasks. Performing linear programming is very easy and we can attain an optimum solution in very few steps. Come let’s learn.
A toy manufacturing organization manufactures two types of toys A and B. Both the toys are sold at Rs.25 and Rs.20 respectively. There are 2000 resource units available every day from which the toy A requires 20 units while toy B requires 12 units. Both of these toys require a production time of 5 minutes. Total working hours are 9 hours a day. What should be the manufacturing quantity for each of the pipes to maximize the profits?
The objective function is:
Max.Z=25x+20y
where x are the units of pipe A
y are the units of pipe B
For the diet to be optimal we must have minimum cost along with required calories, protein, carbohydrate, and fat.
In cell B7:E7 we take the reference to the number of units. And in cell B8:E8 we put the per-unit cost of each food item.
In cell B10, we want the total cost of the diet. The total cost is given by the sumproduct of the number of units eaten and per-unit cost. Sumproduct is given by = B7*B8+C7*C8+D7*D8+E7*E8. Let’s see this in a spreadsheet.
Column F contains a total of calories, protein, carbohydrate, and fat. The total number of calorie intake in given by sumproduct the number of food items eaten and the calorie consumed per food item. For cell F13= Sumprodcut($B$7:$F$7, B13:F13). Similarly for others. Column G gives the inequality since the problem demands Calories, Protein, Carbohydrate and Fat to be at least 500, 6, 10 and 8 respectively. Column H gives the required nutrient content.
Once you have installed OpenSolver. When you click on the Data tab, on the right you will see Model. Click on the model, then enter the values one by one. First, we will enter the objective function,$B10 i.e in the objective cell. Select minimize because we want to minimize the diet cost.
The first constraint is the F13 ≥ H13. Add all the constraints one by one.
The non-negativity restriction. All the decision variables will be greater than 0.
Once you save the model, it will look something like this.
The optimal solution and values are displayed in the corresponding cells. The optimal minimum cost is US$0.90. Sara should consume 3 units of Food Item 2 and 1 unit of Food Item 3 for the required nutrient content at the minimum cost. This solves our linear program.
Simplex Method is one of the most powerful & popular methods for linear programming. The simplex method is an iterative procedure for getting the most feasible solution. In this method, we keep transforming the value of basic variables to get maximum value for the objective function.
A linear programming function is in its standard form if it seeks to maximize the objective function. subject to constraints,
After adding slack variables, the corresponding system of constraint equation is,
where,
The variables,S1 , S2 ……. Sm are called slack variables. They are non-negative numbers that are added to remove the inequalities from an equation.
The above explanation gives the theoretical explanation of the simplex method. Now, I am gonna explain how to use the simplex method in real life using Excel. But before that, let’s look that the steps of solving LP using simplex method!
The Simplex Method is a systematic way for testing the vertices of the feasible region to find the optimal value of the objective function. Here are the steps:
The advertising alternatives for a company include television, newspaper and radio advertisements. The cost for each medium with its audience coverage is given below.
Television | Newspaper | Radio | |
Cost per advertisement ($) | 2000 | 600 | 300 |
Audience per advertisement | 100,000 | 40,000 | 18,000 |
The local newspaper limits the number of advertisements from a single company to ten. Moreover, in order to balance the advertising among the three types of media, no more than half of the total number of advertisements should occur on the radio. And at least 10% should occur on television. The weekly advertising budget is $18,200. How many advertisements should be run in each of the three types of media to maximize the total audience?
First I am going to formulate my problem for a clear understanding.
Let x1 , x2 , x3 represent the total number of ads for television, newspaper, and radio respectively.
The objective of the company is to maximize the audience. The objective function is given by:
Now, I will mention each constraint one by one.
It is clearly given that we have a budget constraint. The total budget which can be allocated is $18,200. And the individual costs per television, newspaper and radio advertisement is $2000, $600 and $300 respectively. This can be represented by the equation,
For a newspaper advertisement, there is an upper cap on the number of advertisements to 10. My first constraints are,
The next constraint is the number of advertisements on television. The company wants at least 10% of the total advertisements to be on television. So, it can be represented as:
The last constraint is the number of advertisements on the radio cannot be more than half of the total number of advertisements. It can be represented as
Now, I have formulated my linear programming problem. We are using the simplex method to solve this. I will take you through the simplex method one by one.
To reiterate all the constraints are as follows. I have simplified the last two equations to bring them in standard form.
We have a total of 4 equations. To balance out each equation, I am introducing 4 slack variables,S1 , S2 , S3 , S4
So our equations are as follows:
I hope now you are available to make sense of the entire advertising problem. All the above equations are only for your better understanding. Now if you solve these equations, you will get the values for X1= 4, X2= 10 and X3= 14.
On solving the objective function you will get the maximum weekly audience as 1,052,000. You can follow the tutorial here to solve the equation. To solve a linear program in excel, follow this tutorial.
The northwest corner method is a special type of method used for transportation problems in linear programming. It is used to calculate the feasible solution for transporting commodities from one place to another. Whenever you are given a real-world problem, which involves supply and demand from one source or a different source. The data model includes the following:
The model assumes that there is only one commodity. The demand for this can come from different sources. The objective is to fulfill the total demand with minimum transportation costs. The model is based on the hypothesis that the total demand is equal to the total supply, i.e the model is balanced. Let’s understand this with the help of an example.
Consider there are 3 silos which are required to satisfy the demand from 4 mills. (A silo is a storage area of the farm used to store grain and Mill is a grinding factory for grains).
Let’s understand what the above table explains.
The cost of transportation from Silo i to Mill j is given by the cost in each cell corresponding to the supply from each silo 1 and the demand at each Mill. For example, The cost of transporting from Silo 1 to Mill 1 is $10, from Silo 3 to Mill 5 is $18. It is also given the total demand & supply for mill and silos. The objective is to find the minimal transportation cost such that the demand for all the mills is satisfied.
As the name suggests Northwest corner method is a method of allocating the units starting from the top-left cell.
The demand for Mill 1 is 5 and Silo 1 has a total supply of 15. So, 5 units can be allocated to Mill1 at a cost of $10 per unit. The demand for Mill1 is met. then we move to the top-left cell of Mill 2.
The demand for Mill 2 is 15 units, which it can get 10 units from Silo 1 at a cost of $2 per unit and 5 units from Silo 2 at a cost of $7 per unit.
Then we move onto Mill 3, the northwest cell is S2M3. The demand for Mill 3 is 15 units, which it can get from Silo 2 at a cost of $9 per unit.
Moving on to the last Mill, Mill 4 has a demand of 15 units. It will get 5 units from a Silo 2 at a cost of $20 per unit and 10 units from Silo 3 at a cost of $18 per unit.
The total cost of transportation is = 5*10+(2*10+7*5)+9*15+(20*5+18*10) = $520
Least Cost method is another method to calculate the most feasible solution for a linear programming problem. This method derives more accurate results than the Northwest Corner method. It is used for transportation and manufacturing problems.
To keep it simple I am explaining the above transportation problem.
According to the least cost method, you start from the cell containing the least unit cost for transportation. So, for the above problem, I supply 5 units from Silo 3 at a per-unit cost of $4. The demand for Mill1 is met. For Mill 2, we supply 15 units from Silo 1 at a per-unit cost of $2. Then For Mill 3 we supply 15 units from Silo 2 at a per-unit cost of $9. Then for Mill 4 we supply 10 units from Silo 2 at a per unit cost of $20 and 5 units from Silo 3 an $18 per unit. The total transportation costs are $475.
Well, the above method explains we can optimize our costs further with the best method. Let’s check this using Excel Solver. Solver is an in-built add-on in Microsoft Excel. It’s an add-in plug available in Excel. Go to file->options->add-ins->select solver->click on manage->select solver->click Ok. Your solver is now added in excel. You can check it under the Data tab.
The first thing I am gonna do is enter my data in excel. After entering the data in excel, I have calculated the total of C3:F3. Similarly for others. This is done to take the total demand from Silo 1 and others.
After this, I am gonna break my model into two. The first table gives me the units supplied and the second table gives me the unit cost.
Now, I am calculating my total cost which will be given by Sumproduct of unit cost and units supplied.
Now I am gonna use Solver to compute my model. Similar to the above method. Add the objective function, variable cells, constraints.
Now your model is ready to be solved. Click on solve and you will get your optimal cost. The minimum transportation cost is $435.
Linear programming and optimization are utilized across various industries to enhance efficiency and reduce costs. Below are some common applications, each explained in detail:
Manufacturing Industries: Linear programming analyzes supply chain operations to maximize efficiency with minimum operation cost. By reconfiguring storage layouts, adjusting the workforce, and reducing bottlenecks based on recommendations from linear programming models, manufacturers can significantly improve their operations. For instance, Cequent, a US-based company, uses these techniques to optimize their warehouse operations.
Retail Stores: Organized retail chains like Walmart, Hypercity, Reliance, and Big Bazaar use linear programming for shelf space optimization. With an increasing number of products, it is crucial to understand customer preferences. Products are strategically placed in stores considering shopping patterns, limited shelf space, and a variety of products, to make it easier for customers to locate and select items.
Service Industry: Companies like FedEx and Amazon use optimization to determine the best delivery routes. This involves solving the traveling salesman problem using clustering and greedy algorithms. The objective is to minimize operation costs and delivery times by finding the most efficient routes for multiple salesmen traveling to multiple cities.
Machine Learning: Supervised learning in machine learning relies on optimization principles. Training systems fit mathematical models to labeled input data, enabling them to predict values from unknown test data. Linear programming fine-tunes these models for accurate predictions.
Industries: Linear programming is applied to allocate limited resources such as labor, raw materials, and machine hours efficiently. It helps determine the optimal mix of resources to maximize production output while minimizing costs.
I hope you enjoyed reading this article. I have tried to explain all the basic concepts under linear programming. If you have any doubts or questions feel free to post them in the comments section. For easy understanding, we have broken this long article into a shorter course format – Linear Programming for Data Science Professionals
I have explained each concept with a real-life example. I want you to try them at your end and get hands-on experience. Let me know what you think!
A. Linear programming is an optimization technique that optimizes a linear objective function, subject to linear equations or constraints. This mathematical method finds the best possible solution to a problem with multiple objectives and limited resources.
Q2. What is a linear programming problem in simple words?A. Linear programming problem is an optimization problem where the goal is to find the maximum or the minimum value within a number of constraints(such as available resources or limitations) depending upon the type of problem we are solving.
Q3. What is an objective function in LPP (linear programming problem)?A. An objective function in LPP is a linear equation optimized to achieve the best outcome within given constraints.