Skip to main content

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.

build pre-commit PyPI - Version

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).

model-graph factor-graph
Figure 1: Model graph $G_m$ with no edges between couples. Figure 2: Bipartite factor graph $G_f$.
model-graph-solution factor-graph
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

secret_santaclaus-1.0.0.tar.gz (977.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

secret_santaclaus-1.0.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file secret_santaclaus-1.0.0.tar.gz.

File metadata

  • Download URL: secret_santaclaus-1.0.0.tar.gz
  • Upload date:
  • Size: 977.1 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

Hashes for secret_santaclaus-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e962dfbede094b883aa50503d4288d6488affcda7a09087265f5447c325357a5
MD5 69a04abcfba366d8a0def7f3e24ed59f
BLAKE2b-256 2c78d2e752adc3b940bec2e23d78cf272e94bc4f775bde29afc509d74643d1ee

See more details on using hashes here.

File details

Details for the file secret_santaclaus-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: secret_santaclaus-1.0.0-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

Hashes for secret_santaclaus-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23ae11843b619da7df042d25113a9117079efc81c1597eb39cfc8b2d1dbb8a45
MD5 6035571b124196bc7fa07c00e23652f2
BLAKE2b-256 2d614d17aa1ff420f6e42f58b3111f0e0ed3dc7e420c4591b97c003460180319

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page