Add your description here
Project description
xplor - Operation Research with polars
This package is heavily inspired by gurobipy-pandas but uses polars as dataframe backend.
Basic example
import xplor.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
xplor-0.1.0.tar.gz
(15.3 kB
view details)
Built Distribution
xplor-0.1.0-py3-none-any.whl
(2.5 kB
view details)
File details
Details for the file xplor-0.1.0.tar.gz
.
File metadata
- Download URL: xplor-0.1.0.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 | 2a451e67b47277ba04869571ba0ed4166645fc41b7d31d174644050bfc198173 |
|
MD5 | 0a4c25f9a90da5c1b6f817863a74c333 |
|
BLAKE2b-256 | ef981925ebd7e3755069ce12abebb8e013e49ecf0771d77dc7b931bddc113e10 |
File details
Details for the file xplor-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: xplor-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c0d5c8029e02b774c1d1cd5c61ecdda36f1641c361f6f30c16acc156454547f |
|
MD5 | 5a6f3d7c198630698326d9e392c60ab0 |
|
BLAKE2b-256 | a50c6d7220b68e388659e78f09ee6aea34b6e591c5249b547555273f7d984ac2 |