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.1.tar.gz
(16.4 kB
view details)
Built Distribution
xplor-0.1.1-py3-none-any.whl
(6.0 kB
view details)
File details
Details for the file xplor-0.1.1.tar.gz
.
File metadata
- Download URL: xplor-0.1.1.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bac4c0c3604c3cbe4aee0a3526b13dfaa2fec3f7b22c24ed9891b405126f604 |
|
MD5 | aea1964cf504b0284d754935ce8f7b6a |
|
BLAKE2b-256 | a63bc7f28445a4932736aca2e4d7f5e65baa7496ac13d6d6814c08e23288d79c |
File details
Details for the file xplor-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: xplor-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2184aaaa0bfacfaa41985d54e982086a6ddcbffe8c3cdce7488e930d1ed86809 |
|
MD5 | ebd98c2769c8bea8ddac6747af7742d2 |
|
BLAKE2b-256 | 53e16854f3dc52a5cfa7ccda0d9d3ccb9c941dd8b67fa868f8f0676320aa4bd3 |