Skip to content

Instantly share code, notes, and snippets.

View tommyod's full-sized avatar

Tommy tommyod

View GitHub Profile
@tommyod
tommyod / mealplanner.py
Last active August 8, 2022 22:58
Automatic planning of cheap, varied, nutritional meals
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MEAL PLANNER - Automatic planning of cheap, varied, nutritional meals
---------------------------------------------------------------------
Summary
-------
This Python module uses optimization (Linear Programming) and stochastic methods to
@tommyod
tommyod / canonical_coin_systems.py
Last active November 14, 2021 12:30
Canonical coin systems - where greedy algorithms are optimal for the coin-change problem
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 5 09:28:57 2020
@author: tommyod (https://github.com/tommyod)
"""
import numbers
@tommyod
tommyod / wagner_whitin.py
Last active March 1, 2022 12:27
Python 3.7 implementation of the Wagner-Whitin algorithm for the dynamic lot size problem
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
The Wagner-Whitin algorithm for the dynamic lot size problem
--------------------------------------------------------------
@author: tommyod (https://github.com/tommyod)
An implementation of the Wagner-Whitin O(n^2) algorithm for the dynamic lot
size problem, also called the single-item uncapacitated lot-sizing problem.
Although the algorithm is O(n^2) in theory, it scales linearily with input
@tommyod
tommyod / wagelmans.py
Last active November 14, 2021 12:30
Python 3.7 implementation of the Wagelmans algorithm for the dynamic lot size problem
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
The linear-time Wagelmans algorithm for the dynamic lot size problem
--------------------------------------------------------------------
@author: tommyod (https://github.com/tommyod)
An implementation of the Wagelmans O(n) algorithm for the dynamic lot
size problem, also called the single-item uncapacitated lot-sizing problem.
@tommyod
tommyod / shapley_value.py
Last active November 14, 2021 12:29
Python 3.7 implementation of the Shapley value for distributioning a total surplus to players in a game.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Shapley value (Python implementation)
-------------------------------------
@author: tommyod (https://github.com/tommyod)
A coalition of players cooperates, and obtains an overall gain from cooperation.
Since some players may contribute more to the coalition than others,
or may possess different bargaining power, what final distribution of
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
For more detailed information about these algorithms and their purpose, see:
https://tommyodland.com/articles/2022/sampling-a-discrete-distributing-with-a-markov-chain
"""
import numbers
import itertools