Friday, May 20, 2022
HomeArtificial IntelligenceIntroduction to Linear Programming for Knowledge Science

Introduction to Linear Programming for Knowledge Science

linear programming

Contributed by: Sarita Upadhya
LinkedIn Profile:


Knowledge Science helps companies to make knowledgeable and data-driven choices. Present enterprise conditions or enterprise situations could be explored additional utilizing accessible knowledge, and higher insights could be drawn utilizing Descriptive Analytics. Utilizing previous knowledge, we will predict the long run. Additionally, the trigger and impact relationship between predictors and response variables could be extracted utilizing Predictive Analytics. Predictive fashions are additionally used to simulate a future possible end result by altering and assigning values of the predictors. As part of Prescriptive Analytics, enterprise begins trying on the totally different alternate options accessible to finalise the choice. Together with the accessible insights, useful resource constraints are taken into consideration to get an optimum resolution.

Linear Programming (LP) in Operations Analysis is among the scientific methods that’s used to get an optimum resolution to the given enterprise downside by taking useful resource shortage and constraints into consideration. When resolution making pertains to a steady variable like gross sales, revenue, value and many others. which has a linear relationship with a number of enter variables, Linear Programming is utilized to bear in mind the constraints or constraints related, and arrive at the perfect resolution. For e.g. if a enterprise desires to maximise gross sales, there could also be a constraint when it comes to the quantum of product accessible on the market; the enterprise could need to maximise the revenue by growing the manufacturing nevertheless could have a constraint when it comes to the capability of machines and many others. LP offers an strategy to the above issues to get an optimum resolution by contemplating the constraints.

Learn Extra – What’s Knowledge Science?

LP Utility Necessities

In an effort to apply Linear Programming for Knowledge Science, the beneath necessities need to be met:

  1. We must always have the ability to outline the target or the intention clearly in mathematical phrases. 
  2. The enter variables that decide the target must be distinct and quantitative. 
  3. Limitations or constraints that need to be thought of must be quantitative and measurable.
  4. Relationship between the target and the enter variables needs to be linear in nature.

Formulation of LP Issues

Under are the steps to be adopted to formulate LP Drawback:

  1. Determine the choice variables which might be used to formulate and obtain the target perform
  2. Outline the target perform: It defines the enterprise goal in mathematical kind
  3. Record out the constraints or limitations utilizing the choice variables in mathematical kind
  4. Determine and record out the non-negative constraints 

Let’s perceive this with a number of examples. Additionally, we are going to have a look at the three instruments (Graphical technique, Excel Solver, R) which can be utilized to unravel LP issues.


Drawback Assertion 1

The XYZ firm through the pageant season combines two components A and B to kind a present pack which should weigh 5 kg. Not less than 2 kg of A and no more than 4 kg of B must be used. The web revenue contribution to the corporate is Rs. 5 per kg for A and Rs. 6 per kg for B. Formulate LP Mannequin to search out the optimum issue combine.

LP Formulation:

Step 1: Goal Operate

Within the above downside, the target of the corporate is to maximise the revenue. We’re given the online revenue contribution for issue A and B.

  • Let x kg of issue A be used
  • Let y kg of issue B be used
  • Goal Operate ⬄ maximise z = 5x + 6y

Be aware: x, y are resolution variables and z is the target perform

Step 2: Formulate the constraints

Weight of present pack needs to be 5 kg

Not less than 2 kg of A and no more than 4 kg of B needs to be used

Step 3: Non-negative constraints

The amount used for A and B needs to be optimistic

Summarise the LP Drawback:

Goal: Maximise z = 5x+6y given the constraints

  1. x + y = 5
  2. x >= 2
  3. y <= 4
  4. x, y >= 0

Let’s try to remedy the above LP downside graphically

Graphical Answer:

Allow us to contemplate a 2-dimension graph with x and y-axis:

Linear Programming
Fig 1: Graphical Answer for LP downside
  • Plot the constraints formulated within the above downside.
    • x + y = 5 is a line that cuts x-axis at (5,0) and y-axis at (0,5). As we’ve a “=” constraint, the possible area lies on this line.
    • x >= 2 is the road that cuts the x-axis at (2,0). As we’ve a “>=” constraint, the possible area lies to the appropriate of this line
    • y <= 4 is the road that cuts the y-axis at (0,4). As we’ve a “<=” constraint, the possible area lies to the underside of this line
    • As x, y >= 0 we’ve thought of solely the optimistic facet of the x and y-axis.
  • Combining all of the above constraints, from the above graph the road marked in yellow is the ultimate possible area the place all constraints are happy. 
  • The two excessive factors on this line are the doable choices for consideration to maximise the revenue i.e. level A (2,3) and level B (5,0). 
  • Allow us to substitute these values within the goal perform to search out out which possibility offers larger revenue.
    • Choice A (2,3): z = 5x + 6y ⬄ z = (5*2) +(6*3) = 28
    • Choice B (5,0): z = 5x + 6y ⬄ z = (5*5) +(6*0) = 25
  • Therefore, the optimum resolution is Choice A i.e. 2kg of issue A and 3kg of issue B to be thought of for the present pack.

Drawback Assertion 2

A name centre requires a unique variety of full-time staff on totally different days of the week. The variety of full-time staff required every day is given within the desk beneath. Employment guidelines state that every full-time worker should work 5 days consecutively after which obtain two days off. The decision centre desires to satisfy its each day necessities utilizing solely full-time staff. Formulate an LP that the decision centre can use to minimise the variety of full-time staff who have to be employed.

Days of the Week # of full-time staff required
1=Monday 17
2=Tuesday 13
3=Wednesday 15
4=Thursday 19
5=Friday 14
6=Saturday 16
7=Sunday 11

LP Formulation:

Step 1: Goal Operate

Within the above downside, the target is to minimise the variety of full-time staff to rent.

  • Let x1 be variety of staff starting shifts from Monday
  • Let x2 be variety of staff starting shifts from Tuesday
  • Let x3 be variety of staff starting shifts from Wednesday
  • Let x4 be variety of staff starting shifts from Thursday
  • Let x5 be variety of staff starting shifts from Friday
  • Let x6 be variety of staff starting shifts from Saturday
  • Let x7 be variety of staff starting shifts from Sunday
  • Goal Operate ⬄ minimise z = x1+x2+x3+x4+x5+x6+x7

Be aware: x1, x2…x7 are resolution variables and z is the target perform

Step 2: Formulate the constraints

From the above desk, we all know the variety of full-time staff required every day. Constraint to be thought of is {that a} full-time worker ought to work for five consecutive days and have 2 days off. 

  • x1+x4+x5+x6+x7 >=17 (On Monday, staff engaged on Tuesday & Wednesday get off)
  • x1+x2+x5+x6+x7 >=13 (On Tuesday, staff engaged on Wednesday & Thursday get off)
  • x1+x2+x3+x6+x7 >=15 (On Wednesday, staff engaged on Thursday & Friday get off)
  • x1+x2+x3+x4+x7 >=19 (On Thursday, staff engaged on Friday & Saturday get off)
  • x1+x2+x3+x4+x5 >=14 (On Friday, staff engaged on Saturday & Sunday get off)
  • x2+x3+x4+x5+x6 >=16 (On Saturday, staff engaged on Sunday & Monday get off)
  • x3+x4+x5+x6+x7 <=11 (On Sunday, staff engaged on Monday & Tuesday get off)

Step 3: Non-negative constraints

Variety of staff working every day needs to be 0 or higher than 0, therefore 

  • x1, x2, x3, x4, x5, x6, x7 >= 0

Summarise the LP Drawback:

Goal: Minimise z = x1+x2+x3+x4+x5+x6+x7 topic to constraints

  1. x1+x4+x5+x6+x7 >=17 
  2. x1+x2+x5+x6+x7 >=13 
  3. x1+x2+x3+x6+x7 >=15 
  4. x1+x2+x3+x4+x7 >=19 
  5. x1+x2+x3+x4+x5 >=14 
  6. x2+x3+x4+x5+x6 >=16 
  7. x3+x4+x5+x6+x7 >=11
  8. x1, x2, x3, x4, x5, x6, x7 >= 0

As we’ve a number of resolution variables, fixing this graphically will probably be a tedious job. Allow us to attempt to remedy the above downside utilizing Excel Solver

Answer utilizing Excel Solver:

The solver is a mathematical program or software program that takes required enter, applies the chosen algorithm and offers a mathematical resolution to the issue.

Guarantee you have got Solver add-in accessible within the Knowledge tab of your Excel Workbook as proven within the determine beneath:

Linear Programming
Fig 2: Solver Add-in in Excel

Step 1: Record Constraints in Excel Sheet 

Linear Programming
Fig 3: Constraints in Excel
  • Fig 3 reveals how the primary 7 constraints need to be up to date within the excel
  • The coefficients of every constraint are up to date beneath the respective variables

Step 2: Embrace the Goal Operate

Linear Programming
Fig 4: Goal Operate
  • Fig 4 reveals how the target perform needs to be included
  • Much like the constraints embrace the coefficients of the target perform beneath the respective variables

Step 3: Embrace a row to get the perfect estimate for our resolution variables

Linear Programming
Fig 5: Row to get optimum worth for variables
  • Row 11 within the above figures is the row which can give us the perfect estimate 
  • Initialise it to 0
  • As soon as the solver finds the answer the row will probably be up to date with finest estimates

Step 4: Embrace sumproduct() of every constraint with output row (Row 11) to formulate constraints 

Linear Programming
Fig 6: Sumproduct() perform to outline the constraints
  • Observe the “fx” cell on the high in Fig6
  • Column H has the sumproduct() of every row with the perfect estimate row i.e. row 11
  • Cells marked in inexperienced will show the values of every constraint after solver finds an answer
  • The cell marked in pink is the output of the target perform i.e. the optimum output will probably be displayed as soon as the answer is discovered

Step 5: Invoke Solver and add the constraints

Linear Programming
Fig 7: Invoke Solver and supply the inputs
  • From the determine above, observe the cell inputs to be given to the Solver
  • Choose “Simplex LP” because the “Fixing Methodology”
  • Click on “Remedy”

Step 6: Get the optimum resolution

Click on on ‘Remedy’ to get the optimum resolution

Linear Programming
Fig 8: Answer
  • From the above picture, we see that the optimum resolution is to get 23 full-time staff for the job contemplating the given constraints (cell H10)
  • Values in Row 11 that are marked in yellow are the perfect estimates for every resolution variable
  • Values in inexperienced affirm to us that the constraints have been happy

Drawback Assertion 3

John has a weight-reduction plan chart which provides energy, protein, carbohydrate and fats content material for 4 meals objects. John desires a weight-reduction plan with minimal value. The weight-reduction plan chart is as follows:

Item1 Item2 Item3 Item4 Required
Energy (gms) 400 200 150 500 500
Proteins (gms) 3 2 0 0 6
Carbohydrates (gms) 2 2 4 4 10
Fats (gms) 2 4 1 5 8
Price  0.5$ 0.2$ 0.3$ 0.8$

LP Formulation:

Step 1: Goal Operate

Within the above downside, the target is to purchase meals objects at minimal value however assembly the dietary wants.

  • Let x1 be variety of Item1 to be purchased
  • Let x2 be variety of Item2 to be purchased
  • Let x3 be variety of Item3 to be purchased
  • Let x4 be variety of Item4 to be purchased
  • Goal Operate ⬄ minimise z = 0.5×1+0.2×2+0.3×3+0.8×4

Be aware: x1, x2, x3, x4 are resolution variables and z is the target perform

Step 2: Formulate the constraints

Energy required 500

  • 400×1 + 200×2+ 150×3+ 500×4 >= 500

Proteins required 6

Carbohydrates required 10

  • 2×1 + 2×2 +4×3 + 4×4 >= 10

Fats required 8

  • 2×1 + 4×2 +x3 + 5×4 >= 8

Step 3: Non unfavorable constraints

Objects purchased need to be optimistic

Summarise the LP Drawback:

Goal: Minimise z = 0.5×1+0.2×2+0.3×3+0.8×4 given the constraints

  1. 400×1 + 200×2+ 150×3+ 500×4 >= 500
  2. 3×1 + 2×2 >= 6
  3. 2×1 + 2×2 +4×3 + 4×4 >= 10
  4. 2×1 + 4×2 +x3 + 5×4 >= 8
  5. x1, x2, x3, x4 >= 0

Answer utilizing R: 

R is a programming language which has a bundle and related perform outlined to unravel the LP downside. The bundle identify is ‘lpSolve’ and this system to unravel the above downside is given beneath:

Linear Programming


Linear Programming

From the above we’ve bought the perfect estimates, 3 – Item2 and 1- Item3 needs to be purchased to get required vitamins at a minimal value of 0.9$

Benefits of Linear Programming

  • LP is beneficial for the enterprise because the decision-maker can acquire an optimum resolution by contemplating the efficient use of scarce sources
  • It’s a structured method and helps in making knowledgeable data-driven choices
  • It offers alternate options which the decision-maker can analyse additional and finalise based mostly on subjective issues that additionally must be thought of
  • LP may also be used for altering conditions. Modified constraints or further constraints could be included within the mannequin to get revised output.

Utility of Linear Programming

  • LP is extensively utilized in Manufacturing to resolve on Manufacturing combine, in Manufacturing Planning, Meeting line balancing and many others.
  • Oil industries use LP to get optimum high quality of oil by mixing the appropriate proportion of various crude oils, octane and many others.
  • In finance, choices need to be taken on the place the cash must be spent and from the place the corporate must get the cash from to make sure that they maximise the returns preserving the dangers below acceptable management. Shopping for and promoting bonds, managing company funds, making monetary choices.
  • Media choice, plant location, lowering travelling salesman’s value are a number of the areas the place LP is used within the gross sales and advertising area.
  • In call-centres and hospitals, LP is used for scheduling the shifts for workers.
  • Defence makes use of LP to resolve on the optimum degree of power deployment to a selected place contemplating the totally different conditions and constraints.

Should you want to be taught extra ideas in Knowledge Science for a profitable profession within the area, join Nice Studying’s PGP Knowledge Science Programs.

Reference Books

  • ‘Quantitative Methods for Determination Making in Enterprise’ by Trueman, R.E. Half Saunders, New York, 1981 
  • ‘Quantitative Methods for Determination Making’ by Anand Sharma (IIT Delhi)



Most Popular

Recent Comments