replenishment 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- replenishment-0.1.0/.github/ISSUE_TEMPLATE/release_checklist.yml +52 -0
- replenishment-0.1.0/.github/workflows/ci.yml +31 -0
- replenishment-0.1.0/.github/workflows/release.yml +74 -0
- replenishment-0.1.0/.gitignore +210 -0
- replenishment-0.1.0/.python-version +1 -0
- replenishment-0.1.0/PKG-INFO +259 -0
- replenishment-0.1.0/README.md +233 -0
- replenishment-0.1.0/docs/plots/mean_forecast_safety_stock.png +0 -0
- replenishment-0.1.0/docs/plots/percentile_optimization.png +0 -0
- replenishment-0.1.0/notebooks/generated_data_example.ipynb +1929 -0
- replenishment-0.1.0/notebooks/mean_forecast_fill_rate_example copy.ipynb +1475 -0
- replenishment-0.1.0/notebooks/mean_forecast_policy_variants_example.ipynb +1686 -0
- replenishment-0.1.0/notebooks/mean_forecast_safety_stock_example.ipynb +2002 -0
- replenishment-0.1.0/notebooks/mean_forecast_service_level_probability_example.ipynb +2039 -0
- replenishment-0.1.0/notebooks/percentile_optimization_example.ipynb +2314 -0
- replenishment-0.1.0/notebooks/stock_replenishment_example.ipynb +233 -0
- replenishment-0.1.0/notebooks/stress_test_example.ipynb +1198 -0
- replenishment-0.1.0/pyproject.toml +45 -0
- replenishment-0.1.0/replenishment_policy_summary.pdf +0 -0
- replenishment-0.1.0/setup.cfg +4 -0
- replenishment-0.1.0/src/replenishment/__init__.py +167 -0
- replenishment-0.1.0/src/replenishment/_version.py +34 -0
- replenishment-0.1.0/src/replenishment/aggregation.py +213 -0
- replenishment-0.1.0/src/replenishment/io.py +1964 -0
- replenishment-0.1.0/src/replenishment/optimization.py +1191 -0
- replenishment-0.1.0/src/replenishment/plotting.py +1170 -0
- replenishment-0.1.0/src/replenishment/policies.py +1167 -0
- replenishment-0.1.0/src/replenishment/service_levels.py +166 -0
- replenishment-0.1.0/src/replenishment/simulation.py +219 -0
- replenishment-0.1.0/src/replenishment.egg-info/PKG-INFO +259 -0
- replenishment-0.1.0/src/replenishment.egg-info/SOURCES.txt +35 -0
- replenishment-0.1.0/src/replenishment.egg-info/dependency_links.txt +1 -0
- replenishment-0.1.0/src/replenishment.egg-info/requires.txt +9 -0
- replenishment-0.1.0/src/replenishment.egg-info/top_level.txt +1 -0
- replenishment-0.1.0/tests/conftest.py +4 -0
- replenishment-0.1.0/tests/test_io.py +1185 -0
- replenishment-0.1.0/tests/test_simulation.py +700 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Release checklist
|
|
2
|
+
description: Track tasks for publishing a new version to GitHub Releases and PyPI.
|
|
3
|
+
title: "Release vX.Y.Z"
|
|
4
|
+
labels:
|
|
5
|
+
- release
|
|
6
|
+
body:
|
|
7
|
+
- type: markdown
|
|
8
|
+
attributes:
|
|
9
|
+
value: |
|
|
10
|
+
Use this checklist for each production release.
|
|
11
|
+
|
|
12
|
+
- type: input
|
|
13
|
+
id: version
|
|
14
|
+
attributes:
|
|
15
|
+
label: Version
|
|
16
|
+
description: Semantic version without `v` prefix (example `0.2.0`).
|
|
17
|
+
placeholder: 0.2.0
|
|
18
|
+
validations:
|
|
19
|
+
required: true
|
|
20
|
+
|
|
21
|
+
- type: checkboxes
|
|
22
|
+
id: preflight
|
|
23
|
+
attributes:
|
|
24
|
+
label: Pre-flight
|
|
25
|
+
options:
|
|
26
|
+
- label: CI is green on main.
|
|
27
|
+
- label: Release notes are prepared.
|
|
28
|
+
- label: PyPI trusted publisher is configured for this repo.
|
|
29
|
+
|
|
30
|
+
- type: checkboxes
|
|
31
|
+
id: tag_release
|
|
32
|
+
attributes:
|
|
33
|
+
label: Tag and GitHub release
|
|
34
|
+
options:
|
|
35
|
+
- label: I created and pushed the tag `vX.Y.Z` from main.
|
|
36
|
+
- label: I published a GitHub Release for `vX.Y.Z`.
|
|
37
|
+
- label: Release workflow completed successfully.
|
|
38
|
+
|
|
39
|
+
- type: checkboxes
|
|
40
|
+
id: post_release
|
|
41
|
+
attributes:
|
|
42
|
+
label: Post-release verification
|
|
43
|
+
options:
|
|
44
|
+
- label: Dist artifacts are attached to the GitHub Release.
|
|
45
|
+
- label: Package `replenishment==X.Y.Z` is visible on PyPI.
|
|
46
|
+
- label: I installed from PyPI in a clean environment and smoke-tested import.
|
|
47
|
+
|
|
48
|
+
- type: textarea
|
|
49
|
+
id: notes
|
|
50
|
+
attributes:
|
|
51
|
+
label: Notes
|
|
52
|
+
description: Optional links or follow-ups.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
tests:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.10", "3.12"]
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
|
|
25
|
+
- name: Install package and test dependencies
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip
|
|
28
|
+
python -m pip install -e ".[dev]"
|
|
29
|
+
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: pytest
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
inputs:
|
|
8
|
+
git_ref:
|
|
9
|
+
description: "Tag or commit to publish (example: v0.2.0)"
|
|
10
|
+
required: true
|
|
11
|
+
type: string
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
with:
|
|
20
|
+
fetch-depth: 0
|
|
21
|
+
ref: ${{ github.event.inputs.git_ref || github.ref }}
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.12"
|
|
27
|
+
|
|
28
|
+
- name: Build distribution artifacts
|
|
29
|
+
run: |
|
|
30
|
+
python -m pip install --upgrade pip
|
|
31
|
+
python -m pip install build
|
|
32
|
+
python -m build
|
|
33
|
+
|
|
34
|
+
- name: Upload dist artifacts
|
|
35
|
+
uses: actions/upload-artifact@v4
|
|
36
|
+
with:
|
|
37
|
+
name: dist
|
|
38
|
+
path: dist/*
|
|
39
|
+
|
|
40
|
+
github-release-assets:
|
|
41
|
+
if: github.event_name == 'release'
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
permissions:
|
|
45
|
+
contents: write
|
|
46
|
+
steps:
|
|
47
|
+
- name: Download dist artifacts
|
|
48
|
+
uses: actions/download-artifact@v4
|
|
49
|
+
with:
|
|
50
|
+
name: dist
|
|
51
|
+
path: dist
|
|
52
|
+
|
|
53
|
+
- name: Upload artifacts to GitHub release
|
|
54
|
+
uses: softprops/action-gh-release@v2
|
|
55
|
+
with:
|
|
56
|
+
files: dist/*
|
|
57
|
+
|
|
58
|
+
pypi-publish:
|
|
59
|
+
needs: build
|
|
60
|
+
runs-on: ubuntu-latest
|
|
61
|
+
permissions:
|
|
62
|
+
id-token: write
|
|
63
|
+
environment:
|
|
64
|
+
name: pypi
|
|
65
|
+
url: https://pypi.org/p/replenishment
|
|
66
|
+
steps:
|
|
67
|
+
- name: Download dist artifacts
|
|
68
|
+
uses: actions/download-artifact@v4
|
|
69
|
+
with:
|
|
70
|
+
name: dist
|
|
71
|
+
path: dist
|
|
72
|
+
|
|
73
|
+
- name: Publish package distributions to PyPI
|
|
74
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
# setuptools-scm generated version file
|
|
210
|
+
src/replenishment/_version.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: replenishment
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Stock replenishment simulation library.
|
|
5
|
+
Project-URL: Homepage, https://github.com/janrth/replenishment
|
|
6
|
+
Project-URL: Repository, https://github.com/janrth/replenishment
|
|
7
|
+
Project-URL: Issues, https://github.com/janrth/replenishment/issues
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: ipykernel>=6.31.0
|
|
19
|
+
Requires-Dist: matplotlib>=3.8
|
|
20
|
+
Requires-Dist: pandas>=2.0
|
|
21
|
+
Requires-Dist: polars>=1.36.1
|
|
22
|
+
Requires-Dist: pyarrow>=21.0.0
|
|
23
|
+
Requires-Dist: scienceplots>=2.1.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
|
|
27
|
+
# replenishment
|
|
28
|
+
|
|
29
|
+
Stock replenishment simulation utilities.
|
|
30
|
+
|
|
31
|
+
## Environment (uv + Python 3.12)
|
|
32
|
+
|
|
33
|
+
This repo is set up to use Python 3.12 via `uv`.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
uv python install 3.12
|
|
37
|
+
uv venv --python 3.12
|
|
38
|
+
source .venv/bin/activate
|
|
39
|
+
uv pip install -e ".[dev]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Run checks with:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
uv run pytest
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Release and PyPI publishing
|
|
49
|
+
|
|
50
|
+
This repository is configured so that publishing on PyPI is done from GitHub
|
|
51
|
+
Actions (`.github/workflows/release.yml`), not from local `twine upload`.
|
|
52
|
+
|
|
53
|
+
### One-time setup
|
|
54
|
+
|
|
55
|
+
1. Create a PyPI project named `replenishment` (or let the first publish create it).
|
|
56
|
+
2. In PyPI, configure a trusted publisher for this repository and workflow:
|
|
57
|
+
- Owner: `janrth`
|
|
58
|
+
- Repository: `replenishment`
|
|
59
|
+
- Workflow: `release.yml`
|
|
60
|
+
- Environment: `pypi`
|
|
61
|
+
3. In GitHub, create an environment named `pypi` in repo settings.
|
|
62
|
+
|
|
63
|
+
### Versioning
|
|
64
|
+
|
|
65
|
+
Package versions are derived from git tags via `setuptools-scm`. Use semantic
|
|
66
|
+
tags such as `v0.1.0`, `v0.2.0`, etc.
|
|
67
|
+
|
|
68
|
+
### Release flow (GitHub-first)
|
|
69
|
+
|
|
70
|
+
1. Push a version tag:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
git tag v0.1.0
|
|
74
|
+
git push origin v0.1.0
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
2. In GitHub, create/publish a release for that tag.
|
|
78
|
+
3. The `Release` workflow will:
|
|
79
|
+
- build `sdist` and wheel artifacts,
|
|
80
|
+
- attach them to the GitHub release,
|
|
81
|
+
- publish them to PyPI automatically.
|
|
82
|
+
|
|
83
|
+
You can also run the workflow manually from the Actions tab using `workflow_dispatch`
|
|
84
|
+
and pass `git_ref` (for example `v0.1.0`).
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
## Plot-first usage
|
|
88
|
+
|
|
89
|
+
This README focuses on two visual workflows:
|
|
90
|
+
|
|
91
|
+
- Mean forecast + safety stock optimization.
|
|
92
|
+
- Percentile target optimization.
|
|
93
|
+
|
|
94
|
+
## Example 1: mean forecast + safety stock
|
|
95
|
+
|
|
96
|
+
This example optimizes the safety stock factor on a backtest window, then
|
|
97
|
+
applies the learned policy to the evaluation horizon.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from replenishment import (
|
|
101
|
+
generate_standard_simulation_rows,
|
|
102
|
+
optimize_point_forecast_policy_and_simulate_actuals,
|
|
103
|
+
plot_replenishment_decisions,
|
|
104
|
+
replenishment_decision_rows_to_dataframe,
|
|
105
|
+
split_standard_simulation_rows,
|
|
106
|
+
standard_simulation_rows_to_dataframe,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
rows = generate_standard_simulation_rows(
|
|
110
|
+
n_unique_ids=1,
|
|
111
|
+
periods=18,
|
|
112
|
+
start_date="2031-01-01",
|
|
113
|
+
frequency_days=30,
|
|
114
|
+
forecast_start_period=10,
|
|
115
|
+
history_mean=52,
|
|
116
|
+
history_std=6,
|
|
117
|
+
forecast_mean=48,
|
|
118
|
+
forecast_std=5,
|
|
119
|
+
lead_time=2,
|
|
120
|
+
initial_on_hand=30,
|
|
121
|
+
current_stock=30,
|
|
122
|
+
seed=7,
|
|
123
|
+
)
|
|
124
|
+
backtest_rows, eval_rows = split_standard_simulation_rows(rows)
|
|
125
|
+
|
|
126
|
+
optimized, _, decision_rows = optimize_point_forecast_policy_and_simulate_actuals(
|
|
127
|
+
backtest_rows,
|
|
128
|
+
eval_rows,
|
|
129
|
+
candidate_factors=[0.8, 0.9, 1.0],
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
rows_df = standard_simulation_rows_to_dataframe(rows, library="pandas")
|
|
133
|
+
decision_df = replenishment_decision_rows_to_dataframe(decision_rows, library="pandas")
|
|
134
|
+
|
|
135
|
+
example_id = decision_df["unique_id"].iloc[0]
|
|
136
|
+
plot_replenishment_decisions(
|
|
137
|
+
rows_df,
|
|
138
|
+
decision_df,
|
|
139
|
+
unique_id=example_id,
|
|
140
|
+
title="Mean forecast + safety stock (optimized)",
|
|
141
|
+
decision_style="line",
|
|
142
|
+
)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+

|
|
146
|
+
|
|
147
|
+
## Example 2: optimize percentile targets
|
|
148
|
+
|
|
149
|
+
This example learns the best percentile target on backtest rows and then plots
|
|
150
|
+
replenishment decisions on forecast rows.
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
from replenishment import (
|
|
154
|
+
PercentileForecastOptimizationPolicy,
|
|
155
|
+
build_percentile_forecast_candidates_from_standard_rows,
|
|
156
|
+
build_replenishment_decisions_from_simulations,
|
|
157
|
+
generate_standard_simulation_rows,
|
|
158
|
+
optimize_forecast_targets,
|
|
159
|
+
plot_replenishment_decisions,
|
|
160
|
+
replenishment_decision_rows_to_dataframe,
|
|
161
|
+
simulate_replenishment_with_aggregation,
|
|
162
|
+
split_standard_simulation_rows,
|
|
163
|
+
standard_simulation_rows_to_dataframe,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
rows = generate_standard_simulation_rows(
|
|
167
|
+
n_unique_ids=1,
|
|
168
|
+
periods=24,
|
|
169
|
+
start_date="2031-01-01",
|
|
170
|
+
frequency_days=30,
|
|
171
|
+
forecast_start_period=14,
|
|
172
|
+
history_mean=42,
|
|
173
|
+
history_std=7,
|
|
174
|
+
forecast_mean=40,
|
|
175
|
+
forecast_std=5,
|
|
176
|
+
lead_time=2,
|
|
177
|
+
initial_on_hand=25,
|
|
178
|
+
current_stock=25,
|
|
179
|
+
seed=11,
|
|
180
|
+
percentile_multipliers={"p50": 1.0, "p80": 1.2, "p95": 1.35},
|
|
181
|
+
)
|
|
182
|
+
backtest_rows, forecast_rows = split_standard_simulation_rows(rows)
|
|
183
|
+
|
|
184
|
+
percentile_configs = build_percentile_forecast_candidates_from_standard_rows(
|
|
185
|
+
backtest_rows,
|
|
186
|
+
include_mean=True,
|
|
187
|
+
review_period=1,
|
|
188
|
+
forecast_horizon=1,
|
|
189
|
+
)
|
|
190
|
+
optimized = optimize_forecast_targets(percentile_configs)
|
|
191
|
+
|
|
192
|
+
forecast_configs = build_percentile_forecast_candidates_from_standard_rows(
|
|
193
|
+
forecast_rows,
|
|
194
|
+
include_mean=True,
|
|
195
|
+
review_period=1,
|
|
196
|
+
forecast_horizon=1,
|
|
197
|
+
)
|
|
198
|
+
simulations = {}
|
|
199
|
+
for unique_id, config in forecast_configs.items():
|
|
200
|
+
target = optimized[unique_id].target
|
|
201
|
+
policy = PercentileForecastOptimizationPolicy(
|
|
202
|
+
forecast=config.forecast_candidates[target],
|
|
203
|
+
lead_time=config.lead_time,
|
|
204
|
+
)
|
|
205
|
+
simulations[unique_id] = simulate_replenishment_with_aggregation(
|
|
206
|
+
periods=config.periods,
|
|
207
|
+
demand=config.demand,
|
|
208
|
+
initial_on_hand=config.initial_on_hand,
|
|
209
|
+
lead_time=config.lead_time,
|
|
210
|
+
policy=policy,
|
|
211
|
+
aggregation_window=1,
|
|
212
|
+
holding_cost_per_unit=config.holding_cost_per_unit,
|
|
213
|
+
stockout_cost_per_unit=config.stockout_cost_per_unit,
|
|
214
|
+
order_cost_per_order=config.order_cost_per_order,
|
|
215
|
+
order_cost_per_unit=config.order_cost_per_unit,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
decision_rows = build_replenishment_decisions_from_simulations(
|
|
219
|
+
forecast_rows,
|
|
220
|
+
simulations,
|
|
221
|
+
percentile_target={uid: optimized[uid].target for uid in simulations},
|
|
222
|
+
review_period=1,
|
|
223
|
+
forecast_horizon=1,
|
|
224
|
+
rmse_window=1,
|
|
225
|
+
)
|
|
226
|
+
rows_df = standard_simulation_rows_to_dataframe(rows, library="pandas")
|
|
227
|
+
decision_df = replenishment_decision_rows_to_dataframe(decision_rows, library="pandas")
|
|
228
|
+
|
|
229
|
+
example_id = decision_df["unique_id"].iloc[0]
|
|
230
|
+
plot_replenishment_decisions(
|
|
231
|
+
rows_df,
|
|
232
|
+
decision_df,
|
|
233
|
+
unique_id=example_id,
|
|
234
|
+
title="Percentile forecast target (optimized)",
|
|
235
|
+
decision_style="line",
|
|
236
|
+
)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+

|
|
240
|
+
|
|
241
|
+
## Notebooks
|
|
242
|
+
|
|
243
|
+
For full runnable walkthroughs (including additional variants):
|
|
244
|
+
|
|
245
|
+
- `notebooks/mean_forecast_safety_stock_example.ipynb`
|
|
246
|
+
- `notebooks/percentile_optimization_example.ipynb`
|
|
247
|
+
- `notebooks/generated_data_example.ipynb`
|
|
248
|
+
|
|
249
|
+
For data-loading and table-oriented flows (without plots), see:
|
|
250
|
+
|
|
251
|
+
- `notebooks/stock_replenishment_example.ipynb`
|
|
252
|
+
|
|
253
|
+
## Standard schema helpers
|
|
254
|
+
|
|
255
|
+
If you need CSV/DataFrame conversion helpers:
|
|
256
|
+
|
|
257
|
+
- `iter_standard_simulation_rows_from_csv`
|
|
258
|
+
- `standard_simulation_rows_from_dataframe`
|
|
259
|
+
- `build_point_forecast_article_configs_from_standard_rows`
|