Skip to main content

Let CVXPY support optimization in leximin order

Project description

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

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

cvxpy_leximin-0.4.4.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

cvxpy_leximin-0.4.4-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file cvxpy_leximin-0.4.4.tar.gz.

File metadata

  • Download URL: cvxpy_leximin-0.4.4.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cvxpy_leximin-0.4.4.tar.gz
Algorithm Hash digest
SHA256 21cd22e900adcbf7bc52c6bce8aee4bb3e4a9c7ccd949234f9462472955208de
MD5 bf145719da917c16ce331d9160b86f1a
BLAKE2b-256 533a4da5c5bb3489a6917eaba297fe7eef5d312c08deb13be6806010fbdf3bca

See more details on using hashes here.

File details

Details for the file cvxpy_leximin-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: cvxpy_leximin-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cvxpy_leximin-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8053685ec38e1f8e00e7051967e6bd9ae402906d2e095ddb38f2f8716e97fe58
MD5 c4a34b01ff7898ae56212a99175353cd
BLAKE2b-256 1381bff88399d46e18841a238ee252c6bb2e84f96785dfcd463987b5c0b0ca14

See more details on using hashes here.

Supported by

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