Skip to main content

fairpyx

PyTest result PyPI version

fairpyx is a Python library containing various algorithms for fair allocation, with an emphasis on Course allocation. It is designed for three target audiences:

  • Laypeople, who want to use existing fair division algorithms for real-life problems.
  • Researchers, who develop new fair division algorithms and want to quickly implement them and compare to existing algorithms.
  • Students, who want to trace the execution of algorithms to understand how they work.

Installation

For the stable version:

pip install fairpyx

For the latest version:

pip install git+https://github.com/ariel-research/fairpyx.git

To verify that everything was installed correctly, run one of the example programs, e.g.

cd fairpyx
python examples/courses.py
python examples/input_formats.py

or run the tests:

pytest

Usage

To activate a fair division algorithm, first construct a fairpyx.Instance, for example:

import fairpyx
valuations = {"Alice": {"w":11,"x":22,"y":44,"z":0}, "George": {"w":22,"x":11,"y":66,"z":33}}
instance = fairpyx.Instance(valuations=valuations)

An instance can have other fields, such as: agent_capacities, item_capacities, agent_conflicts and item_conflicts. These fields are used by some of the algorithms. See instances.py for details.

Then, use the function fairpyx.divide to run an algorithm on the instance. For example:

allocation = fairpyx.divide(algorithm=fairpyx.algorithms.iterated_maximum_matching, instance=instance)
print(allocation)

Features and Examples

  1. Course allocation algorithms;

  2. Various input formats, to easily use by both researchers and end-users;

  3. A demo of a the simple round-robin algorithm;

Contributing new algorithms

You are welcome to add fair allocation algorithms, including your published algorithms, to fairpyx. Please use the following steps to contribute:

  1. Fork the repository, then install your fork locally as follows:

    clone https://github.com/<your-username>/fairpyx.git
    cd fairpyx
    pip install -e .
    
  2. Read the code at algorithm_examples.py to see how the implementation works.

  • Note that the implementation does not use the Instance variable directly - it uses an AllocationBuilder variable, which tracks both the ongoing allocation and the remaining input (the remaining capacities of agents and items).
  1. Write a function that accepts a parameter of type AllocationBuilder, as well as any custom parameters your algorithm needs.
  • The AllocationBuilder argument sent to your function is already initialized with an empty allocation. Your function has to modify this argument using the methods give or give_bundle, which give an item or a set of items to an agent and update the capacities accordingly.
  • You can easily chain algorithms. For example, if the last phase of your algorithm is dividing the remaining items using round-robin, you can simply call round_robin(alloc) at the end of your function; the AllocationBundle object already tracks the remaining items for you.
  • Your function need not return any value; the allocation is read from the alloc.
  • The divide function is responsible for converting the Instance to an AllocationBuilder before your function starts, and extracting the allocation from the AllocationBuilder after your function ends, so you can focus on writing the algorithm itself.

See allocations.py for more details on the AllocationBuilder object.

See also

  • fairpy is an older library with the same goals. It contains more algorithms for fair item allocation, as well as algorithms for fair cake-cutting. fairpyx was created in order to provide a simpler interface, that also allows capacities and conflicts, which are important for fair course allocation.
  • Other open-source projects related to fairness.

Download files

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

Source Distribution

fairpyx-0.1.tar.gz (201.6 kB view details)

Uploaded Source

Built Distribution

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

fairpyx-0.1-py3-none-any.whl (194.7 kB view details)

Uploaded Python 3

File details

Details for the file fairpyx-0.1.tar.gz.

File metadata

  • Download URL: fairpyx-0.1.tar.gz
  • Upload date:
  • Size: 201.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.9

File hashes

Hashes for fairpyx-0.1.tar.gz
Algorithm Hash digest
SHA256 95b4f4ff5fb4be71184c5a1a7d3a2a0bd645818daceadc40b5fd03816db41196
MD5 b08556750a86dc19e3fd87399c3c3187
BLAKE2b-256 025ab803d27a3dbb024827bd9592a9f00c06bf5d44ff2fc09471551de78fd95c

See more details on using hashes here.

File details

Details for the file fairpyx-0.1-py3-none-any.whl.

File metadata

  • Download URL: fairpyx-0.1-py3-none-any.whl
  • Upload date:
  • Size: 194.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.9

File hashes

Hashes for fairpyx-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 115c482c9dbd415431bf1669a5805ede13c36fa9c5b45aa06128adc7b21ff354
MD5 88ebdd51c2dac70063c39d7080e84bed
BLAKE2b-256 0a0240636bde5d8fb6569a5e4bad9fa5bf02064d5b9a6f981f46d260de038b9f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1 This release

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page