Skip to main content

CVXPY + Leximin

Tox result PyPI version

The cvxpy_leximin package extends cvxpy by adding two objectives: Leximin and Leximax. Each of these objectives takes as an argument a list of expressions. Solving a problem with the Leximin objective follows the leximin order, that is:

  • Find the solutions in which the smallest expression is as large as possible (subject to the constraints).
  • If there are two or more such solutions, then among all these solutions, find the ones in which the next-smallest expression is as large as possible.
  • If there are two or more such solutions, then among all these solutions, find the ones in which the third-smallest expression is as large as possible. And so on.

The Leximax objective is solved in the opposite way: find the solutions that minimize the largest expression (subject to the constraints); among them, minimize the next-largest expression; and so on.

Note that the current implementation works only when domain (as defined by the constraints) is convex. In particular, it does not work for integer programming.

Installation

pip install cvxpy_leximin

Usage example

Leximin optimization can be used to find an egalitarian allocation of resources among people (see Egalitarian item allocation.)

import cvxpy, logging
from cvxpy_leximin import Problem, Leximin

# There are four resources to allocate among two people: Alice and George.
# The variables a[0], a[1], a[2], a[3] denote the fraction of each resource given to Alice:
a = cvxpy.Variable(4)

# The following constraint represents the fact that the allocation is feasible:
feasible_allocation = [x >= 0 for x in a] + [x <= 1 for x in a]

# Alice values the resources at 5, 3, 0, 0:
utility_Alice = a[0] * 5 + a[1] * 3 + a[2] * 0

# George values the resources at 2, 4, 9, 0:
utility_George = (1 - a[0]) * 2 + (1 - a[1]) * 4 + (1 - a[2]) * 9

# The leximin objective is: maximize the smallest utility, and subject to that, the next-smallest utility.
objective = Leximin([utility_Alice, utility_George])

# A problem is defined and solved like any cvxpy problem:
problem = Problem(objective, constraints=feasible_allocation)
problem.solve()
print("Problem status: ", problem.status)   # Should be optimal
print("Objective value: ", objective.value)  
   # It is (8, 9). It maximizes the smallest utility (8), and subject to that, the next-smallest one (9).
print("Allocation: ", a.value)
   # It is [1, 1, 0, 0]: Alice gets resources 0 and 1 (utility=8) and George resources 2 and 3 (utility=9).

For more examples, see the examples folder.

Credits

The ordered outcomes and ordered values algorithms are based on

Ogryczak and Sliwinski (2006), "On Direct Methods for Lexicographic Min-Max Optimization". Programmed by Moshe Ofer.

The saturation algorithm is based on:

Stephen J. Willson, "Fair Division Using Linear Programming" (1998). Part 6, pages 20--27. I am grateful to Sylvain Bouveret for his help with the algorithm. All remaining errors and bugs are my own.

Status

The functionality was tested only on fair allocation problems, only on objectives with linear expressions, and only on the default solver (SCIPY).

If you would like to contribute, it could be great to test leximin optimization on other kinds of problems, expressions and solvers.

Metadata

Release files for cvxpy-leximin 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cvxpy-leximin 0.5
File Size Uploaded Provenance Actions
cvxpy_leximin-0.5.tar.gz 16.0 kB Without provenance Details for cvxpy_leximin-0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cvxpy-leximin 0.5
File Interpreter ABI Platform Actions
cvxpy_leximin-0.5-py3-none-any.whl Python 3 none any Details for cvxpy_leximin-0.5-py3-none-any.whl

Total release size: 31.1 kB

Release files / cvxpy_leximin-0.5.tar.gz

Download URL cvxpy_leximin-0.5.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bb4b03446d877b97ee3393b471de92bd4e52f9dece09a4c360c00d07cb7958f4
BLAKE2b-256 checksum
How to use checksums
a3bf9e8ab98efe08a91cec967db7f4079e3bc395fe828d55368596af82b87a0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / cvxpy_leximin-0.5-py3-none-any.whl

Download URL cvxpy_leximin-0.5-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03fad438bd08f3f03437fddcdf6296607ea18429f61e875d633ee3eab48a12f2
BLAKE2b-256 checksum
How to use checksums
191fdc24c8635ed5544fa0a2dfce943d0626f737ad735ec2694d2c8ad1f6d7de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Security for cvxpy-leximin 0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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