convert pulp model into matrix formulation for scipy.optimize.milp
Project description
pulp2mat
Convert pulp model into matrix formulation.
It can be easily thrown to scipy.optimize.milp function.
How to install
$ pip install pulp2mat
Without poetry, please look at pyproject.toml and install all dependencies manually.
Quick Example
For example, the binpacking problem can be formulated with pulp as below;
import pulp as pl
import numpy as np
item_sizes = np.array([7, 3, 3, 1, 6, 8, 4, 9, 5, 2])
num_items = len(item_sizes)
num_bins = len(item_sizes)
bin_size = 10
# Variables * must be defined as dictionaries
x = {
(i, j): pl.LpVariable("x_{}_{}".format(i, j), cat=pl.LpBinary)
for i in range(num_items)
for j in range(num_bins)
}
y = {
j: pl.LpVariable("y_{}".format(j), cat=pl.LpBinary)
for j in range(num_bins)
}
problem = pl.LpProblem()
# Bin size constraint for each bin
for j in range(num_bins):
problem += (
pl.lpSum(
x[i, j] * item_sizes[i] for i in range(num_items)
)
<= bin_size * y[j]
)
# One-hot constraint for each item
for i in range(num_items):
problem += pl.lpSum(x[i, j] for j in range(num_bins)) == 1
# Objective: minimize number of bins used.
problem += pl.lpSum(y[j] for j in range(num_bins))
the pulp.LpProblem object and the list of variable dictionaries can be converted to the matrix format for scipy.optimize.milp.
import pulp2mat
from scipy.optimize import milp
c, integrality, constraints, bounds = pulp2mat.convert_all(problem)
result = milp(c, integrality=integrality, constraints=constraints, bounds=bounds)
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
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 pulp2mat-0.1.5.tar.gz.
File metadata
- Download URL: pulp2mat-0.1.5.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f7b3297e878e0874be8c3d3c318d6366593f5d87775a34cd846d16e1180b06d
|
|
| MD5 |
59aa7c5293130e206fdbc50b26f32139
|
|
| BLAKE2b-256 |
97cae3cfb044cc2beea2f58a57d6a566dfde380379bbf309c2392d59ed82a61d
|
Provenance
The following attestation bundles were made for pulp2mat-0.1.5.tar.gz:
Publisher:
python-publish.yml on rtonoue/pulp2mat
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pulp2mat-0.1.5.tar.gz -
Subject digest:
2f7b3297e878e0874be8c3d3c318d6366593f5d87775a34cd846d16e1180b06d - Sigstore transparency entry: 152600525
- Sigstore integration time:
-
Permalink:
rtonoue/pulp2mat@602516e42fc39fcafd0e1bb03fc07e29a27baf24 -
Branch / Tag:
refs/tags/0.1.5 - Owner: https://github.com/rtonoue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@602516e42fc39fcafd0e1bb03fc07e29a27baf24 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pulp2mat-0.1.5-py3-none-any.whl.
File metadata
- Download URL: pulp2mat-0.1.5-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c62af5733a40395574431032a844f7398ae363a3798a5bab50e97548786bc301
|
|
| MD5 |
1c1ff2a1d09917a6a47b893bbd23c411
|
|
| BLAKE2b-256 |
3bd8772deb0c4d120518d9f4d19a37d54b3b90dacfb7d5f557268015a6e7de23
|
Provenance
The following attestation bundles were made for pulp2mat-0.1.5-py3-none-any.whl:
Publisher:
python-publish.yml on rtonoue/pulp2mat
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pulp2mat-0.1.5-py3-none-any.whl -
Subject digest:
c62af5733a40395574431032a844f7398ae363a3798a5bab50e97548786bc301 - Sigstore transparency entry: 152600526
- Sigstore integration time:
-
Permalink:
rtonoue/pulp2mat@602516e42fc39fcafd0e1bb03fc07e29a27baf24 -
Branch / Tag:
refs/tags/0.1.5 - Owner: https://github.com/rtonoue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@602516e42fc39fcafd0e1bb03fc07e29a27baf24 -
Trigger Event:
release
-
Statement type: