Optimizing Supply Chain Decisions with Pyomo
In a dynamic and highly competitive environment, where companies strive to achieve near-utopian levels of efficiency, one of the most…
Optimizing Supply Chain Decisions with Pyomo
In a dynamic and highly competitive environment, where companies strive to achieve near-utopian levels of efficiency, one of the most critical challenges in supply chain management arises: how much and when to place orders? This report addresses this issue through the application of advanced operations research tools and numerical analysis, providing strategic, data-driven solutions to optimize decision-making in the supply chain.

Global trade in action at the Port of Shanghai, the world’s busiest container hub.
The goal of this report is to address the problem of inventory and production planning in a logistical or industrial environment. The aim is to develop a decision-making tool to determine when and how much to order for each input to meet the forecasted demand, also considering logistical constraints and associated costs.
The purpose is to manage inventory to maintain an optimal level of both raw materials and finished products, minimizing storage costs while mitigating the risk of shortages. Regarding the production planning of finished products, it is acknowledged that this exceeds the scope of this work; hence, production is only simulated to understand the demand values of the required inputs. To extend this work, further exploration of the manufacturing or logistical constraints of the addressed company or industry would be needed.

To study this problem, a Mixed-Integer Linear Programming (MILP) optimization model is used. For the model implementation, the Python library Pyomo is utilized, a versatile tool for modeling optimization problems. The model is solved using the Gurobi solver, with a license provided directly by AMPL, allowing the advanced capabilities of this solver to be leveraged for large-scale linear and nonlinear programming problems.
# Importar Bibliotecas
from pyomo.environ import *
import pyomo.opt as opt
from fpdf import FPDF
import pandas as pd
from amplpy import AMPL
ampl = AMPL()
In the next step, we define the appropriate sets, parameters, and variables to formulate the constraints and the objective function. Among these constraints, we consider the truck’s capacity and the requirement that the number of items requested must be a multiple of the pallet quantity specified by the supplier. Such constraints are essential to accurately model real-world conditions and optimize supply chain operations effectively.
# Parameters
pr = parametros['pr']
c = parametros['c']
t = parametros['t']
...
# Define Pyomo Parameters with non-negative domain
model.d = Param(model.PT, model.T, initialize=demand_data, within=NonNegativeReals) # Demand
model.pr = Param(model.I, initialize=lambda model, i: pr[i], within=NonNegativeReals) # Unit price of inputs
model.l = Param(initialize=l, within=NonNegativeReals) # Lead time as scalar
...
# Define Decision Variables
model.q = Var(model.I, model.T, domain=NonNegativeIntegers, initialize=0) # Order quantity
model.x = Var(model.I, model.T, domain=Binary, initialize=0) # Whether an order is placed
...
# Constraint for truck capacity
def capacidad_camion_rule(model, t):
return sum(model.z[i, t] for i in model.I) == model.k * model.cu[t] # Restricted by truck capacity
model.capacidad_camion = Constraint(model.T, rule=capacidad_camion_rule)
The purpose of the model is to minimize the costs associated with the supply chain. To achieve this objective, we define an objective function within the model, which identifies different terms representing various costs associated with the supply chain. The objective function consists of three main terms. The first term considers the general costs associated with the maintenance of inventory, which includes warehouse rent, employee costs (labor), and insurance. These costs are represented in the objective function as a coefficient ‘c’ multiplied by the number of items and goods in inventory.

Maintenance of inventory general cost
Another incurred cost is the financial cost associated with the inventory level. It is represented in the function by another parameter multiplied by the number of products and goods in inventory.

Maintenance of inventory financial cost
The logistics and production costs are also taken into account, along with penalties to weigh certain constraints within the supply chain.

Inventory and Orders of Input I2 over Time
The Python implementation enables the visualization of inventory levels, allowing for the prevention of shortages and excess inventory through timely replenishment decisions.

Cost Components vs. Time
This graph illustrates the evolution of various cost components over time, including total cost, holding cost, shortage cost, production cost, and logistics cost. It highlights periods of peak costs, providing insights into the contribution of each component to the total cost. This visualization enables budgeting areas to offer precise feedback to the planning department, fostering informed decision-making. The model’s capabilities allow for cost optimization, identifying inefficiencies, and improving resource allocation, ultimately supporting a more strategic and data-driven planning process.
Operational Research enables the modeling of specific industry or warehouse operations to optimize various aspects. In this report, we aim to address a small issue in supply chain planning that can be automated and enhanced by analyzing it from a simpler and faster perspective.
You can find the source code and all related documentation at the following link: GitHub Repository: Supply and Inventory Planning Optimization Model
I invite you to explore the repository, test the model, and contribute ideas or improvements. I hope you find this resource helpful for your optimization and decision-making projects!
메타데이터
- post_id
- a65b1c620ff4
- slug
- optimizing-supply-chain-decisions-with-pyomo-a65b1c620ff4
- url
- https://medium.com/@brunoflombardi/optimizing-supply-chain-decisions-with-pyomo-a65b1c620ff4
- canonical_url
- https://medium.com/@brunoflombardi/optimizing-supply-chain-decisions-with-pyomo-a65b1c620ff4
- author_url
- https://medium.com/@brunoflombardi
- status
- ok
- fetched_at
- 2026-06-29 01:02:39