DSA (Recursive Programming) in Real World: Material Requirements Planning

Uday Rao
3 min readOct 24, 2023

--

Material Requirements Planning (MRP)

Material Requirements Planning (MRP) is a crucial aspect of modern manufacturing, ensuring that the right materials are available at the right time to meet production demands efficiently. MRP begins with the determination of what needs to be produced based on the demand forecast, customer orders, and the production schedule. MRP uses the Bill of Materials (BOM) to calculate the materials needed for production. In this article, we’ll explore how recursive programming can be applied to calculate MRP using a BOM, offering a clear and efficient solution to this complex problem.

Understanding the Challenge with Bill of Materials (BOM)

The BOM is a hierarchical list of components and sub-assemblies required to manufacture a specific product. Each item in the BOM is identified by a part number and includes the quantity needed for one unit of the product. The challenge in MRP is to calculate the net requirements for each item in the BOM, considering current inventory levels, lead times for procurement or production, and the demand forecast. This process can be complex, as sub-assemblies might themselves have their own BOMs, creating a nested, recursive structure.

Recursive Programming and BOM

Recursive programming is an elegant approach to solving problems that can be broken down into smaller, similar subproblems. The structure of the BOM naturally lends itself to a recursive solution. The main idea is to traverse the BOM tree, starting from the finished product and working backward to its constituent components.
Components of BOM can be classified as:
1. Finished goods
2. Semi-finished goods
3. Raw Materials.
Let's understand the problem statement with the help of data.

BOM sample Data

Column A indicates the quantity to produce, and the Product Name is the Name of goods for which we are calculating the requirement, component part number, and component Name needed to produce Column B at the given Quantity as indicated by Column E.

Let's Consider we have demand in demand.csv for Final Product A of 10 Quantity. By looking at the BOM data we can see there is the CHM001, CHM002, CHM003, Intermediate X, in which Intermediate X is dependent on CHM002, CHM003, CHM005, and so on.
We will be using recursive programming to generate the MRP for a specified demand using the above BOM.

#Importing the required modules
import pandas as pd
import numpy as np

Reading the BOM and demand file

bom_df  = pd.read_csv('./bom.csv')
bom_df.head()

demand_df = pd.read_csv('./demand.csv')
demand_df.head()

mrp_dict = {}

Below is the recursive function that calculates the requirement of the passed product in the function at argument quantity.

def calulate_requirement(product_name, qty, bom_df:pd.DataFrame):
df_tmp = bom_df[bom_df['Product Name']==product_name]
for i, r in df_tmp.iterrows():
qty_add = (qty*r['Quantity'])/r['Production Qty']
bom_qty = mrp_dict.get(r['Component Name'],0)
mrp_dict[r['Component Name']] = bom_qty+qty_add
calulate_requirement(r['Component Name'],qty_add,bom_df)
for i,r in demand_df.iterrows():
calulate_requirement(r['Product Name'],r['Demand Quantity'], bom_df)

we are iterating through the demand file to generate the requirements and store them in the mrp_dict with their name and the required quantity.
After that, we can write the result of full MPR run.

mrp_df = pd.DataFrame(list(mrp_dict.items()), columns=['Component Name','Quantity'])
mrp_df
mrp_df.to_csv('./mrp_result.csv',index=False)

You can find the complete code here at Github.

Thank You!!!

Keep Learning…Keep Exploring

Related Articles:
1. https://raouday79.medium.com/0-1-knapsack-problem-integer-programming-7cd8a610972f
2. https://raouday79.medium.com/optimization-in-real-world-maximize-the-profit-python-dd7f71c3c162
3. https://raouday79.medium.com/wpi-forecasting-b247b8111207

--

--

Uday Rao
Uday Rao

Written by Uday Rao

Data Scientist | Operation Research Scientist | Software Engineer

No responses yet