{"id":23402598,"url":"https://github.com/martincastroalvarez/supply-chain-optimization","last_synced_at":"2025-09-12T10:41:02.285Z","repository":{"id":106553516,"uuid":"605584623","full_name":"MartinCastroAlvarez/supply-chain-optimization","owner":"MartinCastroAlvarez","description":"Supply chain optimization algorithms using python","archived":false,"fork":false,"pushed_at":"2023-02-25T20:45:23.000Z","size":6602,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T11:11:44.242Z","etag":null,"topics":["keras","machine-learning","optimization","python","supply-chain"],"latest_commit_sha":null,"homepage":"https://martincastroalvarez.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MartinCastroAlvarez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-23T13:23:10.000Z","updated_at":"2024-06-19T14:13:05.000Z","dependencies_parsed_at":"2023-07-16T02:15:22.037Z","dependency_job_id":null,"html_url":"https://github.com/MartinCastroAlvarez/supply-chain-optimization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MartinCastroAlvarez/supply-chain-optimization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinCastroAlvarez%2Fsupply-chain-optimization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinCastroAlvarez%2Fsupply-chain-optimization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinCastroAlvarez%2Fsupply-chain-optimization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinCastroAlvarez%2Fsupply-chain-optimization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MartinCastroAlvarez","download_url":"https://codeload.github.com/MartinCastroAlvarez/supply-chain-optimization/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MartinCastroAlvarez%2Fsupply-chain-optimization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274799754,"owners_count":25352171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["keras","machine-learning","optimization","python","supply-chain"],"created_at":"2024-12-22T12:29:37.353Z","updated_at":"2025-09-12T10:41:02.227Z","avatar_url":"https://github.com/MartinCastroAlvarez.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# supply-chain-optimization\nSupply chain optimization algorithms using python.\n\n![wallpaper.jpg](./wallpaper.jpg)\n\n# 1 References\n\n- [Economic Order Quantity](https://en.wikipedia.org/wiki/Economic_order_quantity)\n\n# 2 Architecture\n\n## 2.1 Overview\n\nIn a modular architecture, a software system is designed and implemented as a collection of\nindividual components or modules that can function independently. Each module is self-contained,\nand has a well-defined interface that allows it to interact with other modules. These interfaces\nspecify the inputs and outputs of each module, as well as any restrictions or requirements for\nusing the module.\n\nThe advantage of a modular architecture is that it allows developers to create complex systems\nby combining small, well-defined components. This approach promotes code reuse, simplifies\nmaintenance and debugging, and makes it easier to add new functionality to the system.\n\n|File|Description|\n|---|---|\n|[v1/simulator.py](./v1/simulator.py)|Monte-Carlo simulator.|\n|[v1/center.py](./v1/center.py)|Cost center class.|\n|[v1/cost.py](./v1/cost.py)|A data structure for storing variable and fixed costs.|\n|[v1/product.py](./v1/product.py)|A data structure for storing products and variable costs.|\n\n## 2.2 Data Model\n\n#### [Cost](./v1/cost.py)\n\n|Attribute|Type|Description|\n|---|---|---|\n|name|String|Cost name|\n|value|Decimal|Cost value|\n\n#### [PurchasedProduct](./v1/product.py)\n\n|Attribute|Type|Description|\n|---|---|---|\n|name|String|Product name|\n|price|Decimal|Market price|\n|demand|Decimal|Annual demand|\n|inventory|Decimal|Annual demand|\n|storage_costs|Array\u003cCost\u003e|Holding cost per unit|\n|purchase_costs|Array\u003cCost\u003e|Purchase costs per unit|\n\n#### [ProducedProduct](./v1/product.py)\n\n|Attribute|Type|Description|\n|---|---|---|\n|name|String|Product name|\n|price|Decimal|Market price|\n|demand|Decimal|Annual demand|\n|inventory|Decimal|Annual demand|\n|storage_costs|Array\u003cCost\u003e|Holding cost per unit|\n|production_costs|Array\u003cCost\u003e|Production costs per unit|\n\n#### [Center](./v1/center.py)\n\n|Attribute|Type|Description|\n|---|---|---|\n|Name|String|Cost center name identification|\n|address|String|Cost center address|\n|costs|Array\u003cCost\u003e|Cost center fixed costs|\n\n# 3 Instructions\n\n## 3.1 Monte-Carlo Simulation\n\n![Monte Carlo](./montecarlo.png)\n\nMonte Carlo simulation is a computational technique used in probability theory and statistics to model\nand analyze complex systems or processes that involve uncertainty. It involves using random sampling and\nstatistical analysis to generate a range of possible outcomes for a given system or process.\n\n```python3\nfrom v1.simulator import Simulator\n\nwith Simulator(times=10, title='Example') as simulator:\n\n    @simulator.simulate()\n    def main() -\u003e Decimal:\n        \"\"\"\n        Sample simulator case.\n        \"\"\"\n        return simulator.normal(mean=3, std=1, upper=10, lower=1)\n```\n```bash\n--------------------------------------------------\nExample Sumary:\n- Simulated: 10 times\n- Average: 3.149073238815085229447277015\n- Maximum: 5.0041348650403794096064302721060812473297119140625\n- Minimum: 1.884182643119448385959913139231503009796142578125\n--------------------------------------------------\n```\n\n## 3.2 Fitting empirical data to a theoretical distribution\n\nFitting an array of empirical data points to a theoritcal distribution using NumPy and SciPy:\n\n```python3\nimport numpy as np\nimport scipy.stats as stats\n\ndata: np.array = np.array([10, 20, 30, 20, 10, 20, 30, 10, 20, 10, 20, 10, 20, 10])\n\nmaximum: int = max(data)\nminimum: int = min(data)\n\ndistributions_by_pvalue: dict = {}\nfor name in (\n    'beta',\n    'cauchy',\n    'chi2',\n    'expon',\n    'gamma',\n    'laplace',\n    'lognorm',\n    'norm',\n    'pareto',\n    'rayleigh',\n    't',\n    'uniform',\n    'weibull_min',\n    'weibull_max',\n    'pareto',\n    'exponweib',\n    'genextreme',\n):\n    distribution: 'scipy.stats._continuous_distns' = getattr(stats, name)\n    params: tuple = distribution.fit(data)\n    kstest: 'KstestResult' = stats.kstest(data, name, params)\n    distributions_by_pvalue[kstest.pvalue] = {\n        'distribution': distribution,\n        'params': params,\n    }\n\nbest_p_value: float = max(distributions_by_pvalue)\nprint('Best Distribution:')\nprint('Distribution:', distributions_by_pvalue[best_p_value]['distribution'])\nprint('Params:', distributions_by_pvalue[best_p_value]['params'])\n```\n```bash\nBest Distribution:\n- Distribution: \u003cscipy.stats._continuous_distns.cauchy_gen object at 0x1322914c0\u003e\n- Params: (18.46152767675262, 4.550807537639908)\n```\n\n## 3.3 Fixed Cost Forecasting\n\nCost forecasting in supply chain is the process of estimating the future costs associated with\na company's supply chain activities. This involves analyzing historical data, current trends,\nand other relevant information to predict how supply chain costs may change over time.\n\n```python3\nfrom v1.simulator import Simulator\nfrom v1.center import Center\nfrom v1.cost import Cost\n\nwith Simulator(title='Total Fixed Cost', times=100) as simulator:\n\n    @simulator.simulate()\n    def main() -\u003e Decimal:\n\n        center: Center = Center()\n        center.name = 'My Center I'\n        center.address = '450 Hawk St.'\n        print('Center identifier:', center)\n\n        center.costs.add(Cost('Quality Control Costs', simulator.normal(mean=100, std=20, upper=3000, lower=50)))\n        center.costs.add(Cost('Labor Costs', simulator.normal(mean=500, std=100, upper=1000, lower=0)))\n        center.costs.add(Cost('Energy Costs', simulator.normal(mean=150, std=180, upper=1000, lower=100)))\n        center.costs.add(Cost('Equipment Costs', simulator.normal(mean=200, std=40, upper=320, lower=160)))\n        center.costs.add(Cost('Overhead Costs', simulator.normal(mean=30, std=20, upper=300, lower=0)))\n        center.costs.add(Cost('Warehouse Rent', simulator.normal(mean=300, std=50, upper=400, lower=200)))\n        center.costs.add(Cost('Inventory Management Software', simulator.normal(mean=10, std=5, upper=80, lower=0)))\n\n        return center.total_fixed_cost\n```\n```bash\n--------------------------------------------------\nTotal Fixed Cost Summary:\n- Simulated: 100 times\n- Average: 1408.849098985442841192039508\n- Maximum: 1806.456092848386123961290651\n- Minimum: 1076.932611251075061709059355\n--------------------------------------------------\n```\n\n## 3.4 Variable Cost Forecasting\n\nA variable cost is a cost that changes in proportion to the level of output or production.\nIn other words, as the level of production increases, variable costs also increase, and as\nthe level of production decreases, variable costs also decrease.\n\nIn a supply chain context, examples of variable costs include the cost of raw materials,\nlabor, and shipping or transportation costs. These costs are directly related to the\nproduction and delivery of goods or services and vary depending on the level of output\nor production.\n\n```python3\nfrom v1.simulator import Simulator\nfrom v1.product import Product, ProducedProduct\nfrom v1.cost import Cost\n\nwith Simulator(title='Product Variable Cost', times=100) as simulator:\n\n    @simulator.simulate()\n    def main() -\u003e Decimal:\n\n        product: Product = ProducedProduct(name='Product I', inventory=100)\n        product.production_costs.add(Cost('Energy Costs', simulator.normal(mean=2, std=1, upper=5, lower=0)))\n        product.production_costs.add(Cost('Labor Costs', simulator.normal(mean=7, std=2, upper=10, lower=5)))\n\n        return product.total_variable_cost\n```\n```bash\n--------------------------------------------------\nOptimum Inventory Size Summary:\n- Simulated: 100 times\n- Average: 9.384934045397640103303160686\n- Maximum: 13.39878319216576141315044879\n- Minimum: 5.753336277825196631852122664\n--------------------------------------------------\n```\n\n## 3.5 Storage Cost Forecasting\n\nThere are several costs associated with maintaining stock in the inventory in supply chain management.\n\n```python3\nfrom v1.simulator import Simulator\nfrom v1.product import Product, PurchasedProduct\nfrom v1.cost import Cost\n\nwith Simulator(title='Product Storage Cost', times=100) as simulator:\n\n    @simulator.simulate()\n    def main() -\u003e Decimal:\n\n        product: Product = PurchasedProduct(name='Product II', inventory=100)\n\n        product.storage_costs.add(Cost('Warehousing', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Utilities', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Insurance', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Taxes', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Freight', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Placement', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Ordering', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Obsolescence', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n\n        return product.total_storage_cost\n```\n```bash\n--------------------------------------------------\nProduct Storage Cost Summary:\n- Simulated: 100 times\n- Average: 1.009046847258865544985639851\n- Maximum: 1.470608471608333550628699981\n- Minimum: 0.4727466627521519915156034130\n--------------------------------------------------\n```\n\n## 3.6 Optimum Inventory Level\n\n![EOQ](./eoq.png)\n\nThis app calculates the optimum inventory level using the Economic Order Quantity (EOQ) formula,\nwhich balances the holding cost of inventory against the ordering cost and the stockout cost.\nThe formula assumes that demand for the product is constant and that lead time for replenishing\ninventory is known.\n\n```python3\nfrom v1.simulator import Simulator\nfrom v1.product import Product, PurchasedProduct\nfrom v1.cost import Cost\n\nwith Simulator(title='Product Optimum Inventory Level', times=100) as simulator:\n\n    @simulator.simulate()\n    def main() -\u003e Decimal:\n\n        product: Product = ProducedProduct(\n            name='Product III',\n            invetory=100,\n            demand=simulator.normal(mean=1000, std=1000, upper=3000, lower=0),\n        )   \n\n        product.production_costs.add(Cost('Energy Costs', simulator.normal(mean=2, std=1, upper=5, lower=0)))\n        product.production_costs.add(Cost('Labor Costs', simulator.normal(mean=7, std=2, upper=10, lower=5)))\n\n        product.storage_costs.add(Cost('Warehousing', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Utilities', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Insurance', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Taxes', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Freight', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Placement', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Ordering', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Obsolescence', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n        product.storage_costs.add(Cost('Refrigeration', simulator.normal(mean=0.1, std=0.1, upper=0.5, lower=0)))\n\n        return product.optimum_inventory_level\n```\n```bash\n--------------------------------------------------\nProduct Optimum Inventory Level Summary:\n- Simulated: 100 times\n- Average: 133.2271375988943578505541154\n- Maximum: 320.56641376094574980015750043094158172607421875\n- Minimum: 22.1323400761799149449871038086712360382080078125\n--------------------------------------------------\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartincastroalvarez%2Fsupply-chain-optimization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartincastroalvarez%2Fsupply-chain-optimization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartincastroalvarez%2Fsupply-chain-optimization/lists"}