Skip to main content

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.2.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

polors-0.2.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file polors-0.2.2.tar.gz.

File metadata

  • Download URL: polors-0.2.2.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.19

File hashes

Hashes for polors-0.2.2.tar.gz
Algorithm Hash digest
SHA256 45e1581af5b69092943d79f5e12629ebba067ce97820544f82393ab3df25c70d
MD5 d864d9fe39575cbfa5a0e91d36dbf6e2
BLAKE2b-256 6426cc1165f88cfee32aadc45b056b2b16229faec48f44bd8564227a57910fa6

See more details on using hashes here.

File details

Details for the file polors-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: polors-0.2.2-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

Hashes for polors-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 adbad5427c6cb978015bee44b9c3b25e83ace332d62d9c6e711a04120e09e50f
MD5 1e197593fbd47579995b98d1ae81e912
BLAKE2b-256 98a4482d8cb4e3839f34cde4c361e075a68a3780e856699adfdc300ec3af973c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page