📊 Reinforcement Learning in Inventory Optimization using Q-Learning
This repository contains a Python implementation of an inventory optimization model using Q-Learning, a Reinforcement Learning (RL) algorithm. The model is designed to help manage inventory levels by making optimal decisions on order quantities based on forecasted demand, initial stock levels, and inventory capacity.
🚀 Introduction
Efficient inventory management is crucial for reducing costs and avoiding stockouts or overstocking. This project implements a Q-Learning-based optimizer that learns to make optimal inventory decisions over time. It considers factors such as forecasted demand, security stock, and inventory capacity to minimize costs and maintain optimal stock levels.
✨ Features
- 🧠 Q-Learning Algorithm: Implements Q-Learning for decision-making based on temporal difference learning.
- 🔄 Dynamic Inventory Management: Adjusts inventory levels based on forecasted consumption dynamically without traditional rules.
- 🛠️ Customizable Parameters: Adjustable learning rate, discount factor, and exploration rate.
- 📈 Visualizations: Plots inventory levels, forecast, and order amounts to provide insights into the optimization process.
Installation 🚀
You can install the RLInventoryOpt library directly from GitHub. Follow the instructions below to get started!
Install from GitHub 🌟
To install the library directly from GitHub, use the following command:
pip install RLInventoryOpt
🔧 Usage
Initialize the Model
Create an instance of the QLearningOptimizer class.
To create any model for inventory optimization, you have to follow this:
- Create a forecasting model and predict the future consuption.
- You have to know the limitations of your system such as security stock, maximum level of stock, initial stock, lead time, and the minimal order quantity.
- The actions are limited based from 1 to 6 times the minimal order quantity.
from RLInventoryOpt.qlearning import QLearningOptimizer
import numpy as np
# Example forecasted demand for 6 months
forecast = np.array([400, 325, 356, 210, 150, 400])
# Initial conditions of the system
initial_state = {
"stock": 800,
"leadTime": 2,
"minimumOrder": 100,
"securityStock": 200,
"maximalCapacity": 1000
}
# Define the actions
actions = ["no", "m", "2m", "3m", "4m", "5m", "6m"]
# Initialize the optimizer
model = QLearningOptimizer(
forecast=forecast,
initial_stock=initial_state["stock"],
security_stock=initial_state["securityStock"],
capacity=initial_state["maximalCapacity"],
n_actions=actions,
min_order=initial_state["minimumOrder"],
lead_time=initial_state["leadTime"],
alpha=0.1,
gamma=0.6,
epsilon=0.1
)
# Train the model
model.fit(epochs=1000)
# Predict inventory levels and actions
predictions = model.predict()
# Plot the results
model.plot("bar")
A detailed explanation can be found on this article on Medium: https://lnkd.in/gDEvav59
⚙️ Customization
You can customize the behavior of the agent modifying the parameters for training.
- alpha (float): Learning rate (default: 0.1)
- gamma (float): Discount factor (default: 0.6)
- epsilon (float): Exploration rate (default: 0.1)
☕ Support the Project
If you find this inventory optimization tool helpful and would like to support its continued development, consider buying me a coffee. Your support helps maintain and improve this project!
Other Ways to Support
- ⭐ Star this repository
- 🍴 Fork it and contribute
- 📢 Share it with others who might find it useful
- 🐛 Report issues or suggest new features
Your support, in any form, is greatly appreciated! 🙏
Metadata
Release files for RLInventoryOpt 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rlinventoryopt-0.1.6.tar.gz | 10.7 kB | With provenance | Details for rlinventoryopt-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rlinventoryopt-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for rlinventoryopt-0.1.6-py3-none-any.whl |
Total release size: 20.2 kB
Release files / rlinventoryopt-0.1.6.tar.gz
| Download URL | rlinventoryopt-0.1.6.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a1f582fc57347c333355e60abb285e674c3f28940c93426110655d2407433ebd
|
|
BLAKE2b-256 checksum How to use checksums |
a6063fd5fcba7b6ca28e820b49243228a962cef3ad1510575777696bbd5ad7e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 23, 2025.
Transparency logRelease files / rlinventoryopt-0.1.6-py3-none-any.whl
| Download URL | rlinventoryopt-0.1.6-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a76d39679e17e86adb32581c7e7d07d1c6db5667ccd30043163c0078c35d314
|
|
BLAKE2b-256 checksum How to use checksums |
72460ae08c5316f351221e6b2fa314ad96f0542bf09ce949764be124a4fe2d74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 23, 2025.
Transparency logSecurity for RLInventoryOpt 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for rlinventoryopt-0.1.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 23, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.