Add your description here
Project description
polORs - Operation Research with polars
This package is heavily inspired by gurobipy-pandas but uses polars as dataframe backend.
Basic example
import polors.gurobi as pg
import gurobipy as gp
model = gp.Model()
df = pl.DataFrame(
{
"i": [0, 0, 1, 2, 2],
"j": [1, 2, 0, 0, 1],
"u": [0.3, 1.2, 0.7, 0.9, 1.2],
"c": [1.3, 1.7, 1.4, 1.1, 0.9],
"obj": [2.5, 2.7, 1.2, 1.7, 3.9],
}
)
df = (
df
.pipe(pg.add_vars, model, name="x", ub="u", obj = "obj", indices = ["i", "j"], vtype = gp.GRB.CONTINUOUS)
)
# shape: (5, 6)
# ┌─────┬─────┬─────┬─────┬─────┬─────────────────────┐
# │ i ┆ j ┆ u ┆ c ┆ obj ┆ x │
# │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
# │ i64 ┆ i64 ┆ f64 ┆ f64 ┆ f64 ┆ object │
# ╞═════╪═════╪═════╪═════╪═════╪═════════════════════╡
# │ 0 ┆ 1 ┆ 0.3 ┆ 1.3 ┆ 2.5 ┆ <gurobi.Var x[0,1]> │
# │ 0 ┆ 2 ┆ 1.2 ┆ 1.7 ┆ 2.7 ┆ <gurobi.Var x[0,2]> │
# │ 1 ┆ 0 ┆ 0.7 ┆ 1.4 ┆ 1.2 ┆ <gurobi.Var x[1,0]> │
# │ 2 ┆ 0 ┆ 0.9 ┆ 1.1 ┆ 1.7 ┆ <gurobi.Var x[2,0]> │
# │ 2 ┆ 1 ┆ 1.2 ┆ 0.9 ┆ 3.9 ┆ <gurobi.Var x[2,1]> │
# └─────┴─────┴─────┴─────┴─────┴─────────────────────┘
(
df
.pipe(pg.apply_eval, "2 * x - c", name = "y")
.group_by("i").agg(pg.quicksum("y"), pl.col("c").min())
.pipe(pg.add_constrs, model, "y <= c", name="constr")
)
# shape: (3, 4)
# ┌─────┬────────────────────────────────┬─────┬────────────────────────┐
# │ i ┆ y ┆ c ┆ constr │
# │ --- ┆ --- ┆ --- ┆ --- │
# │ i64 ┆ object ┆ f64 ┆ object │
# ╞═════╪════════════════════════════════╪═════╪════════════════════════╡
# │ 1 ┆ -1.4 + 2.0 x[1,0] ┆ 1.4 ┆ <gurobi.Constr constr> │
# │ 0 ┆ -3.0 + 2.0 x[0,1] + 2.0 x[0,2] ┆ 1.3 ┆ <gurobi.Constr constr> │
# │ 2 ┆ -2.0 + 2.0 x[2,0] + 2.0 x[2,1] ┆ 0.9 ┆ <gurobi.Constr constr> │
# └─────┴────────────────────────────────┴─────┴────────────────────────┘
model.optimize()
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
polors-0.2.3.tar.gz
(15.0 kB
view details)
Built Distribution
File details
Details for the file polors-0.2.3.tar.gz
.
File metadata
- Download URL: polors-0.2.3.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a3916735808d51fc05ef90bd3c1ef1b401430e28a790a0a9223b9e3ea57768d |
|
MD5 | 2fe1d4b38757d94a16cb93bd3fd005fc |
|
BLAKE2b-256 | e5abd7f521d286cebd6f27d11b9448e17c98c64dd4c66843d6de32144abe0419 |
File details
Details for the file polors-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: polors-0.2.3-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea2004e857e7ba8a32d3ddb75ed538724ff51c06d013691f68366e3dc2939045 |
|
MD5 | 48547a38ae24abcbdb6aa876bcd715bb |
|
BLAKE2b-256 | 9feb229db3ede4560cbab425cc545d2c080230aa261772d0f2bc9856e136c95c |