Skip to content

Instantly share code, notes, and snippets.

View tommyod's full-sized avatar

Tommy tommyod

View GitHub Profile
#!/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
@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
@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 / 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 / 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