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, "y = 2 * x - c")
.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.4.tar.gz
(15.3 kB
view details)
Built Distribution
File details
Details for the file polors-0.2.4.tar.gz
.
File metadata
- Download URL: polors-0.2.4.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a63dd039960f8789158d5c1d98d60a7f24b5fb37f1d13fe5fb80cf08ff3471e0 |
|
MD5 | e6813a3df4eb07bd0c34af987a97bac3 |
|
BLAKE2b-256 | cf804fdeb7a52ba4ba1bbce54386ac576cee42fa36840ae7db1b17311f5ea6dd |
File details
Details for the file polors-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: polors-0.2.4-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a38bb28883cca9598e535078e1f065fcb954a3b9e3a575b764229198464543d |
|
MD5 | 58e6d8129ad8e23a82d66f2edb82bd90 |
|
BLAKE2b-256 | fa7e7ea9684406797a54ad366ea06ba824c54f42caa0cd4fb614bbc6b2989414 |