If you walk into any local provision shop, what you see might just be a masterclass of constraint management. Every single day, those who own shops face a complex puzzle, which is balancing the money (capital) available to run the business, the limited shelf space for displaying the goods or items they want to sell, and how much of these goods should be held so that unnecessary amount is not kept leading to tying down capital that should be used for another purpose or getting spoilt before they are demanded.
For the majority retailers, solving this puzzle is done by guesswork. This guesswork might be based on how they feel the general market for that product is at that moment or the buying patterns they have experienced for some time. Although this method is not completely out of place, however, there is a mathematical approach that we can use to, at least better, solve this puzzle to yield optimal result.
This approach was discovered and used some 80-something years ago, not for business management but for fighting battles. During the Second World War (fought between 1939 and 1945), the field termed "Operations Research" or "Operational Research" began to gain recognition starting with Britain. As at the time, the British military executives started turning to scientists for aid when the German air attack began. Military leaders employed the services of multidisciplinary teams of scientists, such as mathematicians, physicists and engineers to solve logical and tactical problems, like optimizing radar placements, the managing of convoy routing and deployment of anti-submarine both effectively and effieciently. When the war came to an end, some of these Operations Research (OR) experts particularly the British, left the military and brought the knowledge to the commercial sector. From then OR has found itself in the management field and now widely used in most industries.
Among the Techniques in OR is Linear Programming (LP). LP is a powerful optimization technique that can transform a business, in our case a retail shop, into a well calculated and optimized system. LP is made for situations where we want to achieve a specific goal, such as maximizing profit or minimizing costs, while operating within limited resources or budget. You will agree with me that no business has unlimited resources to operate with. Even a philanthropic organization must operate within budgets, else, it risks bursting. This is one of the reasons LP is so important.
Next, we shall proceed to how a business owner can formulate a retail business challenge as a LP problem and identify the tools that can be used to solve it. Let us use a simple but practical example. Before then, we shall consider the three basic components of an LP model.
The three basic components of a Linear Programming model
LP models are generally formulated around three core components.
1. Objective function
This is probably the reason you may have clicked on this article because you either want to learn how to maximize your business profits or minimize your business wastage. You will clearly see how the objective function is formulated with the given example in this article. Next is the Decision Variables.
2. Decision variables
These are the choices you wish to control. For instance, you may want to know the quantities of different items to purchase, such as the number of bags of rice, bags of beans, cartons of milk, and so on. The quantities we choose to purchase are called decision variables because they represent the decisions available to the business owner.
3. Constraints
Do you struggle knowing the right quantities of provisions or other items to purchase for your shop? or the total handling cost to allow for each item? Do you have a challenge with knowing how much shelf space to allocate to each item? all because your capital is limited or your shop is not the size of the universe?
Earlier, we mentioned that the essence of optimization is to achieve our objective while working with limited resources. If resources such as demand, procurement capital, shelf space, and labour were unlimited, then plainly speaking there is no need for the use of an optimization technique.Unfortunately, that is far from reality. Constraints play the role of considering these limitations in our model. These constraints could be financial, physical, labour, or market in nature.
Having understood these three components, we can now formulate our example mathematically.
Formulating a retail business problem as an LP model
Consider a provision shop that sells three products say, rice, beans, and milk. For simplicity, let us assume that rice and beans are purchased in bags, while milk in cartons. Let us also denote the quantities of these products by x, y, and z, respectively.These are our decision variables.
Further, suppose we have a weekly procurement budget of ₦1,000,000, handling ₦20,000, and 40 square feet of storage space available for these products. These becomes our resource limitations, constraints, or boundaries.
Assume that a bag of rice sells for ₦70,000, a bag of beans sells for ₦45,000, and a carton of milk sells for ₦60,000.
At first glance, we might be tempted to write our objective function as
\[
R=70x+45y+60z,
\]
where R represents total sales revenue measured in thousands of naira.
But take note that maximizing sales revenue is not the same as maximizing profit, because a product that may generate high revenue might have a high purchase cost, which will make the spread between these two costs a small profit.
Since our objective or aim is to maximize profit, we must also know the purchase cost of each product.
For this illustration, let's assume the following products purchase costs which is shown in the table below, along side the the selling prices:
| Product | Purchase cost per unit | Selling price per unit | Gross profit per unit |
|---|---|---|---|
| Rice | ₦60,000 | ₦70,000 | ₦10,000 |
| Beans | ₦35,000 | ₦45,000 | ₦10,000 |
| Milk | ₦48,000 | ₦60,000 | ₦12,000 |
1. The objective function
The gross profit per bag of rice is ₦10,000, beans ₦10,000, and milk ₦12,000.
Our total gross profit is then given as
\[
P=10{,}000x+10{,}000y+12{,}000z.
\]
Our objective is to maximize this profit:
\[
\boxed{\text{Maximize }P=10x+10y+12z}
\]
2. The procurement budget constraint
The total amount spent on purchasing the goods cannot exceed ₦1,000,000.
Since a bag of rice costs ₦60,000, beans ₦35,000, and a carton of milk ₦48,000, we have
\[
60{,}000x+35{,}000y+48{,}000z\leq1{,}000{,}000.
\]
Dividing both sides by 1,000 we have
\[
\boxed{60x+35y+48z\leq1000}.
\]
This is our first constraint. It ensures that the total procurement expenditure remains within the available budget.
3. The handling budget constraint
Suppose the handling expense per bag of rice is ₦1,000, beans ₦800, and per carton of milk is ₦500.
The total handling expense must not exceed ₦20,000. Therefore,
\[
1000x+800y+500z\leq20{,}000.
\]
Dividing both sides by 1,000 we have
\[
\boxed{x+0.8y+0.5z\leq20}.
\]
This is our second constraint.
4. The storage space constraint
The shop has only 40 square feet of storage space available.
Suppose each bag of rice requires 4 square feet, each bag of beans requires 3 square feet, and each carton of milk requires 1.5 square feet.
The storage requirement is therefore
\[
\boxed{4x+3y+1.5z\leq40}.
\]
This constraint ensures that the total storage space required by the selected quantities does not exceed the available space.
5. The market demand constraints
We cannot assume that every product purchased will automatically be sold. Purchasing decisions should also reflect the estimated demand for each product.
Suppose the shop can sell at most 10 bags of rice, 12 bags of beans, and 20 cartons of milk during the planning period.
We therefore have
\[
\boxed{x\leq10},
\]
\[
\boxed{y\leq12},
\]
and
\[
\boxed{z\leq20}.
\]
These constraints prevent the model from recommending quantities beyond the assumed market demand.
6. The non-negativity constraints
Finally, it makes no practical sense to purchase negative quantities of goods. We therefore require
\[
\boxed{x,y,z\geq0}.
\]
Since bags and cartons are normally purchased as whole units, we may also require (x), (y), and (z) to be integers. We will return to this when solving the model.
The complete LP model
Putting everything together, our mathematical model becomes
\[
\begin{aligned}
\text{Maximize}\quad
&P=10x+10y+12z\\[5pt]
\text{subject to}\quad
&60x+35y+48z\leq1000,\\
&x+0.8y+0.5z\leq20,\\
&4x+3y+1.5z\leq40,\\
&x\leq10,\\
&y\leq12,\\
&z\leq20,\\
&x,y,z\geq0.
\end{aligned}
\]
This is our Linear Programming model.
If we also require the quantities to be whole numbers, we add the integer restrictions
\[
x,y,z\in\mathbb{Z}_{\geq0}.
\]
The model with these integer restrictions is called an integer linear programming model. It is an extension of ordinary LP that is useful when decisions involve indivisible items, such as bags, cartons, machines, or vehicles.
Now that we have formulated the problem mathematically, how do we solve it?
We can use several methods, including graphical methods for small problems with two decision variables, the Simplex method, and computer-based optimization tools. For this example, we shall use two accessible tools: Microsoft Excel and Python.
Solving the LP model using Microsoft Excel
One advantage of Linear Programming is that we do not necessarily need to write a computer program to solve it. Microsoft Excel provides a tool called Solver, which can find an optimal solution to a properly formulated model.
Let us see how we can use it to solve our retail problem.
Step 1: Prepare your Excel worksheet
Open a new Excel workbook and enter the following information.
| Cell | Description | Rice | Beans | Milk |
|---|---|---|---|---|
| Row 1 | Product | Rice | Beans | Milk |
| Row 2 | Decision variables | 0 | 0 | 0 |
| Row 3 | Profit per unit (₦'000) | 10 | 10 | 12 |
| Row 4 | Purchase cost (₦'000) | 60 | 35 | 48 |
| Row 5 | Handling cost (₦'000) | 1 | 0.8 | 0.5 |
| Row 6 | Storage space (ft²) | 4 | 3 | 1.5 |
The corresponding entries for Rice, Beans, and Milk should be in columns B, C, and D, respectively.
Next, create a section for the objective function and constraints:
| Cell | Description | Formula or value |
|---|---|---|
| A8 | Total profit (₦'000) | =SUMPRODUCT(B2:D2,B3:D3) |
| A9 | Total purchase cost (₦'000) | =SUMPRODUCT(B2:D2,B4:D4) |
| A10 | Total handling cost (₦'000) | =SUMPRODUCT(B2:D2,B5:D5) |
| A11 | Total storage space (ft²) | =SUMPRODUCT(B2:D2,B6:D6) |
| F2 | Procurement budget (₦'000) | 1000 |
| F3 | Handling budget (₦'000) | 20 |
| F4 | Storage capacity (ft²) | 40 |
| F5 | Maximum rice demand | 10 |
| F6 | Maximum beans demand | 12 |
| F7 | Maximum milk demand | 20 |

The decision variables in cells B2 are initially set to zero. These are the cells that Solver will adjust to find the best solution.
The SUMPRODUCT function multiplies corresponding entries in two ranges and adds the products together. For example, the formula in cell A8 calculates the total profit by multiplying the quantity of each product by its profit per unit and adding the results.
Step 2: Enable Solver
If the Solver command is not visible in Excel, you may need to enable the Solver Add-in.
On the Windows desktop version of Excel:
Click File and select Options.
Select Add-ins.
At the bottom of the window, choose Excel Add-ins from the Manage list and click Go.
Tick Solver Add-in and click OK.
You should now find Solver under the Data tab.
The steps may differ slightly across Excel versions. Some mobile versions of Excel do not support the full Solver workflow, so use desktop Excel where possible.
Step 3: Set the objective
Click Data → Solver.
In the Solver Parameters window, enter the following:
Set Objective:
$B$8Select Max, because we want to maximize profit.
By Changing Variable Cells:
$B$2:$D$2
This tells Excel that cell A8 contains the objective function and that the quantities in B2 are the variables it can change.
Step 4: Enter the constraints
Click Add to enter each constraint.
| Cell reference | Relationship | Constraint value |
|---|---|---|
$A$9 | <= | $F$2 |
$A$10 | <= | $F$3 |
$A$11 | <= | $F$4 |
$B$2 | <= | $F$5 |
$C$2 | <= | $F$6 |
$D$2 | <= | $F$7 |
These constraints represent the procurement budget, handling budget, storage capacity, and maximum demand for each product.
You must also ensure that the decision variables are non-negative. You can do this by checking the option that makes unconstrained variables non-negative, if available, or by explicitly adding the constraint
$B$2:$D$2 ≥ 0

If you want whole bags and cartons, add an integer constraint for $B$2:$D$2. This is important because the ordinary continuous LP model may return fractional quantities.

Step 5: Select the solution method
At the bottom of the Solver window, select Simplex LP as the solving method.
Simplex LP is suitable for this model because the objective function and all the constraints are linear.
Before clicking Solve, check that the objective cell, variable cells, and constraints refer to the correct worksheet cells. A small mistake in a cell reference can change the model you are actually solving.
Step 6: Solve the model
Click Solve and allow Excel to find a solution.
For the continuous LP model, an optimal solution is approximately
\[
x=0,\qquad y=4.5902,\qquad z=17.4863.
\]
The corresponding maximum gross profit is approximately
\[
P=255.7377
\]
in thousands of naira, or ₦255,737.70.

This continuous solution uses the full procurement budget and storage capacity. However, it recommends fractional quantities of beans and milk, which may not be practical for a shop purchasing whole bags and cartons.
If we require integer quantities, Solver can instead find an optimal whole-unit solution. For this example, one optimal integer solution is
\[
\boxed{x=0,\qquad y=1,\qquad z=20}.
\]
The total gross profit is
\[
P=10(0)+10(1)+12(20)=250,
\]
in thousands of naira, giving a gross profit of ₦250,000.
The procurement cost is
\[
35(1)+48(20)=995,
\]
in thousands of naira, or ₦995,000. The handling cost is ₦10,800, and the required storage space is 33 square feet.
All the constraints are satisfied.

This example shows why the distinction between an ordinary LP solution and an integer solution matters. The continuous model allows fractional quantities, while the integer model reflects the practical requirement to purchase whole bags and cartons.
Solving the same LP model using Python
Excel is useful for getting started, but Python gives us another way to formulate, solve, and reproduce optimization problems. It is particularly useful when the model becomes larger, when we want to solve many related problems, or when we need to integrate optimization with data analysis.
You do not need to be an experienced programmer to begin. We can solve this particular problem using Python's SciPy library, which provides optimization routines.
Step 1: Install Python and the required library
If you already have Python installed through Miniconda or Anaconda, open your terminal or Anaconda Prompt and run:
python -m pip install scipyIf you are using a Jupyter Notebook, you can run the installation command in a notebook cell by prefixing it with an exclamation mark:
!pip install scipyAfter installation, open a Python script or notebook.
Step 2: Enter the model in Python
The following code solves the continuous LP model.
from scipy.optimize import linprog
# Decision variables:
# x = bags of rice
# y = bags of beans
# z = cartons of milk
# Profit per unit, in thousands of naira
profit = [10, 10, 12]
# linprog minimizes by default.
# Negative coefficients convert profit maximization
# into an equivalent minimization problem.
objective = [-p for p in profit]
# Coefficients of the inequality constraints
A = [
[60, 35, 48], # Procurement budget
[1, 0.8, 0.5], # Handling budget
[4, 3, 1.5], # Storage capacity
[1, 0, 0], # Maximum rice demand
[0, 1, 0], # Maximum beans demand
[0, 0, 1] # Maximum milk demand
]
# Right-hand-side limits
b = [1000, 20, 40, 10, 12, 20]
# Non-negative decision variables
bounds = [(0, None), (0, None), (0, None)]
# Solve the LP
result = linprog(
c=objective,
A_ub=A,
b_ub=b,
bounds=bounds,
method="highs"
)
# Display the results
if result.success:
x, y, z = result.x
maximum_profit = -result.fun
print("Optimal solution found")
print(f"Rice bags: {x:.4f}")
print(f"Beans bags: {y:.4f}")
print(f"Milk cartons: {z:.4f}")
print(
f"Maximum gross profit: "
f"₦{maximum_profit * 1000:,.2f}"
)
else:
print("Solver status:", result.message)Step 3: Understand the code
The first important detail is that linprog solves minimization problems by default. Because we want to maximize profit, we pass the negative of each profit coefficient to the solver.
The A list contains the coefficients on the left-hand side of our constraints. Each row corresponds to one constraint in the mathematical model. The b list contains the corresponding upper limits.
The bounds argument ensures that all quantities are non-negative. Finally, method="highs" selects SciPy's HiGHS optimization solver.
If the solver succeeds, result.x contains the optimal values of the decision variables, while result.fun contains the minimized objective value. We multiply that objective value by (-1) to recover the maximum profit, and by 1,000 to express the answer in naira rather than thousands of naira.
Running this code should give approximately the same continuous solution as Excel:
Rice: 0 bags
Beans: 4.5902 bags
Milk: 17.4863 cartons
Maximum gross profit: ₦255,737.70
Small differences in the last decimal place may occur because of numerical precision.
Step 4: What if the quantities must be whole numbers?
The linprog function solves a continuous LP. It does not impose integer restrictions on the decision variables.
For whole bags and cartons, we can use SciPy's mixed-integer linear optimization function, milp, which is available in modern versions of SciPy.
Use the following code in place of the previous solver section, keeping the same definitions of objective, A, and b.
import numpy as np
from scipy.optimize import milp, LinearConstraint, Bounds
# Convert the constraint data into NumPy arrays
A_array = np.array(A, dtype=float)
b_array = np.array(b, dtype=float)
# Every decision variable must be an integer
integrality = np.ones(3, dtype=int)
# Lower bounds: no negative quantities
bounds = Bounds(
lb=[0, 0, 0],
ub=[np.inf, np.inf, np.inf]
)
# Every constraint is an upper-bound constraint
constraints = LinearConstraint(
A_array,
lb=-np.inf * np.ones(len(b_array)),
ub=b_array
)
# Solve the integer linear optimization model
result = milp(
c=np.array(objective, dtype=float),
integrality=integrality,
bounds=bounds,
constraints=constraints
)
if result.success:
x, y, z = np.rint(result.x).astype(int)
maximum_profit = -result.fun
print("Optimal integer solution found")
print(f"Rice bags: {x}")
print(f"Beans bags: {y}")
print(f"Milk cartons: {z}")
print(
f"Maximum gross profit: "
f"₦{maximum_profit * 1000:,.2f}"
)
else:
print("Solver status:", result.message)The expected optimal integer result for our example is zero bags of rice, one bag of beans, and 20 cartons of milk, with a gross profit of ₦250,000.
Notice that the integer model is not solved simply by rounding the continuous solution. Rounding can violate the constraints or produce a solution that is not optimal. Instead, the integer solver searches for the best feasible whole-number combination.
What does the solution mean for the business owner?
Just because there is a mathematical solution to this example doesn’t mean that all shops should stop selling rice, or just sell milk and beans. It will only apply to the specific case where the prices, profit margins, resource limits, handling costs and demand estimates are the ones mentioned above.
The model provided us with values for our variables which gave us the maximum profit based on the values we inputted. However, if the price of rice changes, or transporting milk becomes more expensive, or customers want more beans, then these values could change.
One of the advantages of using Linear Programming is that you can actually see how different prices, budgets and resource limits will affect your buying decisions, rather than just going off of intuition.
However, there are some limitations to the model. It assumes that you know what the relevant numbers are, and that there is a linear relationship between the number of items bought, the cost and the resource usage. In reality there will be changes in price, uncertainty in demand, spoilage and more which would require a more complex model.
If there are expiry dates on products then the shop owner may need to consider the risk of not selling them. If the shop has a limited amount of shelf space but extra storage elsewhere then this resource limit may need to be split into categories. If the supplier offers discounts for buying in bulk then this may mean that the cost isn’t linear and could require more decision variables or constraints.
Ultimately the quality of the answer you get will depend on the quality of the model and data as well as the solver.
Concluding,
Mathematics can be used within real-life scenarios. For example, a small provision shop can use mathematics to help decide how best to utilise their limited resources.
Using Linear Programming a business can be set up to allow for decision making. An objective function will be formed using the decisions that can be made (variables) and constraints will be created from the limits. Using software such as Excel Solver and Python we can find the optimal solution.
The key thing to note is that this does not replace the business decision making. It instead helps provide a mathematical framework to help the owner make more informed decisions.
Whilst the shop owner may not need to know the details of the Simplex Method or the algorithms used by the Python optimization libraries, knowing how to set up the problem for optimization and how to interpret the results can have a large impact.
This is just one example of how Operations Research can be applied to real-life situations to help improve how efficiently limited resources can be used within a business.
References
1. Dantzig, G. B. (1982). Reminiscences about the origins of linear programming. Operations Research Letters, 1(2), 43–48. https://doi.org/10.1016/0167-6377(82)90043-8
2. Ekoko, P, O. (2016). Operations Research for Sciences And Social Sciences. Mindex Publishing Company Ltd, Benin City, Nigeria.
3. Hillier, F. S., & Lieberman, G. J. (2021). Introduction to operations research (11th ed.). McGraw-Hill Education.
4. INFORMS. (n.d.). The origins of OR. https://www.informs.org/Explore/History-of-O.R.-Excellence/Bibliographies/The-Origins-of-OR
5. Microsoft. (n.d.). Define and solve a problem by using Solver. Microsoft Support. https://support.microsoft.com/en-us/excel/define-and-solve-a-problem-by-using-solver
6. SciPy Developers. (n.d.). scipy.optimize.linprog. SciPy documentation. https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linprog.html
7. SciPy Developers. (n.d.). scipy.optimize.milp. SciPy documentation. https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.milp.html
8. The Operational Research Society. (n.d.). History of the OR Society. https://www.theorsociety.com/ORS/About-Us/The-history-of-the-OR-Society.aspx
📖 ALSO READ: The Art of Business Optimization: Why 'Good Enough' Is Not Enough
📖 ALSO READ: The Mathematics of Ruin: Why Retail Traders Are Destined to Lose Against the House
📖 ALSO READ: The Man Who Knew Infinity: The Enduring Legacy of Srinivasa Ramanujan
