IntegOR
IntegOR is a framework based on scipy.optimize that aims to traduce an Operation Research problem that can be linearized to a binary integer linear problem, to solve it.
The interest is the ability to easily define your variables as strings and to, from here, create easily constraints and cost vector.
Installation
To install the package, you can use pip:
pip install integor
Usage
Suppose you want to solve the following linear problem:
import numpy as np
def J(x):
"""Function to minimize"""
return x[0] + 2 * x[1] + 3 * x[2] + 4 * x[3]
def f(x):
"""Inequality constraint. f(x) must be positive"""
return np.array([
x[0] + x[1] - 1,
x[2] + x[3] - 1,
x[0] + x[2] - 1,
])
def g(x):
"""Equality constraint. g(x) must be zero"""
return np.array([
x[1] + x[3] - 1,
])
Import
from integor import set_variable_names, Variable, get_cost_matrix, solve_ilp, get_solution
Set variable names
set_variable_names(["x0", "x1", "x2", "x3"])
Define variables as python objects
x0 = Variable("x0")
x1 = Variable("x1")
x2 = Variable("x2")
x3 = Variable("x3")
Define the constraints from the variables
constraint1 = x0 + x1 >= 1
constraint2 = x2 + x3 >= 1
constraint3 = x0 + x2 >= 1
constraint4 = x1 + x3 == 1
constraints = [constraint1, constraint2, constraint3, constraint4]
Define the cost from the variables
cost_matrix = get_cost_matrix(x0 + 2 * x1 + 3 * x2 + 4 * x3)
Specify integrality ie type of the solution : 0 for continuous, 1 for integer-bounded
integrality = np.ones(len(cost_matrix)) * 1 # You can let this as it is
Solve the problem
# Solve
res = solve_ilp(cost_matrix=cost_matrix, constraints=constraints, integrality=integrality)
solution_vector = res.x
print(res)
print("\nSolution vector: ", solution_vector)
print("\nVerify that the solution satisfies the constraints:")
verify(res.x)
print("\nGet the solution as a dictionary:")
print(get_solution(res.x))
Metadata
Release files for integor 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| integor-1.2.tar.gz | 5.2 kB | Without provenance | Details for integor-1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| integor-1.2-py3-none-any.whl | Python 3 | none | any | Details for integor-1.2-py3-none-any.whl |
Total release size: 11.7 kB
Release files / integor-1.2.tar.gz
| Download URL | integor-1.2.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9223da4c7d547dec800579305401bb862f5075899ec1a24f159693c28d7bdf6
|
|
BLAKE2b-256 checksum How to use checksums |
ebf7f2033be87db98972a99fcc0da13c42ada6da1369f7fd522e059bd85ba11f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.7
|
Release files / integor-1.2-py3-none-any.whl
| Download URL | integor-1.2-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0db843912782b0f06b453221bff5a26ad1ec52227a36c78db986a94855a3ab75
|
|
BLAKE2b-256 checksum How to use checksums |
05c55c9c6375298b76702f50f8aba69bd0b094410e924584a51a1d84a1c8995b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.7
|
Security for integor 1.2
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.