Secret Santa organiser with MCMC random sampling of arbitrary constraints and email utilities.
Project description
secret-santaclaus
Secret Santa organiser with MCMC random sampling of arbitrary constraints and email utilities.
Usage
secret-santaclaus is a Python package for generating near-uniformly random Secret Santa allocations from a set of participants and a set of arbitrary constraints upon who can be allocated to whom. It also includes a built-in utility for secretly sending emails to participants with their allocated recipients.
This package is published to PyPI for easy installation via pip (or any other package manager), e.g.:
pip install secret-santaclaus
See example.py for a simple walkthrough of using the package to configure a Secret Santa model of participants and constraints, generate a solution by sampling a Markov-chain Monte Carlo (MCMC) method, and email participants their allocations via an SMTP mail server. It also demonstrates how each of these can either be defined directly in the Python API, or loaded to/from YAML files.
Methodology
In Secret Santa, participants are randomly and secretly allocated to give each other a gift. This is not a complicated problem to solve: it's just random selection without replacement. Let's say you wanted to impose arbitrary constraints, however, such as couples not being able to get each other as an allocation (because that would be boring!).
This Python package solves this problem by modelling the set of participants as a directed graph, where every edge in the graph represents a valid allocation. For example, if Alice and Bob are couples, as are Charlie and Dan, and as are Eve and Frank, this model graph, $G_m$, would resemble a complete graph with edges between couples removed (Figure 1).
A valid Secret Santa allocation is therefore a vertex cycle cover on $G_m$. Finding a vertex cycle cover is equivalent to finding a perfect matching on the corresponding factor graph, which we define as a bipartite graph $G_f = (V_L, V_R, E)$ with each node in $G_m$ 'copied' into both sides $V_L$ and $V_R$, and with each edge $(u,v)$ in $G_m$ represented by an edge $(u_L, v_R)$ (Figure 2). A perfect matching can be found in polynomial time, yielding a valid solution (Figures 3 and 4).
| Figure 1: Model graph $G_m$ with no edges between couples. | Figure 2: Bipartite factor graph $G_f$. |
| Figure 3: A valid solution is a vertex cycle cover on the model graph. | Figure 4: A vertex cycle cover on the model graph is a perfect matching on the factor graph. |
However, algorithms for finding a perfect matching are generally designed as optimisation methods, usually to find a minimum/maximum weight/cardinality. In this case, we aren't interested in an optimal solution, but in fact want to generate random solutions.
This package implements near-uniformly random sampling of bipartite perfect matchings by a Markov-chain Monte Carlo (MCMC) method given by Jerrum and Sinclair (1989). The solver by default progresses the MCMC state before yielding a solution by at least the mixing time, which is calculated from the size of the problem instance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secret_santaclaus-1.0.0a2.tar.gz.
File metadata
- Download URL: secret_santaclaus-1.0.0a2.tar.gz
- Upload date:
- Size: 977.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c737312bd4e9a4812f75a21b474c1343558dfad4487e032f2b0241900cce240
|
|
| MD5 |
8015942c3c3d9aad6c25cc74cf93e947
|
|
| BLAKE2b-256 |
74006a3d2ac16906ca0016d8c70dbed26bdf92cd245d3fe2ab72e23c083b6ff9
|
File details
Details for the file secret_santaclaus-1.0.0a2-py3-none-any.whl.
File metadata
- Download URL: secret_santaclaus-1.0.0a2-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.14 {"installer":{"name":"uv","version":"0.9.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db093e91d2aa58e2da6ac199ed60af9268885138744f9a88619ef7c4bf997bee
|
|
| MD5 |
0967d776c584875a40ddf7da0a7232cf
|
|
| BLAKE2b-256 |
9fbdca48ddeb89d992c165d2977e6ba460673766aafcace4da371885886c71fe
|