io_mappers
Defines various methods for mapping a variable or constraint to its string representation.
Base36Mapper(cls)
Bases: Mapper
, ABC
Source code in pyoframe/io_mappers.py
Base36VarMapper(*args, **kwargs)
Bases: Base36Mapper
Examples:
>>> import polars as pl
>>> from pyoframe import Model, Variable
>>> from pyoframe.constants import VAR_KEY
>>> m = Model("min")
>>> m.x = Variable(pl.DataFrame({"t": range(1,63)}))
>>> (m.x.filter(t=11)+1).to_str()
'[11]: 1 + x[11]'
>>> (m.x.filter(t=11)+1).to_str(var_map=Base36VarMapper(Variable))
'[11]: 1 + xb'
>>> Base36VarMapper(Variable).apply(pl.DataFrame({VAR_KEY: []}))
shape: (0, 1)
┌───────────────┐
│ __variable_id │
│ --- │
│ null │
╞═══════════════╡
└───────────────┘
Source code in pyoframe/io_mappers.py
NamedMapper(cls)
Bases: Mapper
Maps constraints or variables to a string representation using the object's name and dimensions.
Examples:
>>> import polars as pl
>>> import pyoframe as pf
>>> m = pf.Model("min")
>>> m.foo = pf.Variable(pl.DataFrame({"t": range(4)}))
>>> pf.sum(m.foo)
<Expression size=1 dimensions={} terms=4>
foo[0] + foo[1] + foo[2] + foo[3]