pyepo.dsl.expression¶
Symbolic expression nodes and algebra for the PyEPO DSL.
Variables and Parameters compose through numpy-style operators into linear
(Affine) and quadratic (Quadratic) nodes; comparisons produce a
Constraint; a single Parameter multiplies a Variable (or slice) into a
ParametricObjective objective. Each linear node carries per-Variable
coefficient blocks (dict[Variable, csr_matrix]) plus a constant offset;
Problem finalizes them into one global sparse matrix (see
pyepo.dsl.problem).
Classes¶
A decision variable of a given shape and per-entry type. |
|
Linear expression |
|
Scalar quadratic expression |
|
The runtime-bound predicted cost symbol (exactly one per Problem). |
|
A predicted cost coefficient with a known base, |
|
The elementwise product |
|
The objective: |
|
A relation |
Module Contents¶
- class pyepo.dsl.expression.Variable(shape, *, vtype=EPO.CONTINUOUS, lb=None, ub=None, name=None)¶
A decision variable of a given shape and per-entry type.
vtypeis a scalarEPO.VarType(uniform) or a per-entry array; binary entries are forced to bounds[0, 1].- Variables:
- shape¶
- size¶
- vtype¶
- lb¶
- ub¶
- name = None¶
- sum(axis=None)¶
- class pyepo.dsl.expression.Affine(blocks, const, shape)¶
Linear expression
Σ_v A_v @ vec(v) + bof logicalshape.- Variables:
- shape¶
- size¶
- const¶
- blocks¶
- sum(axis=None)¶
- finalize(flat_slice, num_vars)¶
- class pyepo.dsl.expression.Quadratic(quad, affine)¶
Scalar quadratic expression
xᵀ Q x + (linear) + const.- Variables:
- quad¶
- affine¶
- finalize_Q(flat_slice, num_vars)¶
- class pyepo.dsl.expression.Parameter(shape, *, name=None)¶
The runtime-bound predicted cost symbol (exactly one per Problem).
The inner product
c @ x(orc @ x[:k]) pairs the predicted cost with a Variable (or a plain slice / index of one) into a scalar objective term. The elementwise productc * xis a vector of predicted terms; reduce it to the scalar objective with(c * x).sum(). A known base may be added first:(d + c) @ xpredictsd + con x. Any other use raisesTypeError.- shape¶
- size¶
- name = None¶
- class pyepo.dsl.expression.ParametricCoef(param, base)¶
A predicted cost coefficient with a known base,
base + param— the transient result ofc + d/d + c/c - d. Pairs with a Variable or selection like a Parameter:(d + c) @ x(scalar) or(d + c) * x(elementwise vector, reduce with.sum()).- param¶
- base¶
- class pyepo.dsl.expression.ParametricVector(param, base, sel)¶
The elementwise product
c * x(optionally with a known base): a vector of predicted terms, one per selected position. It is not yet a scalar objective; reduce it with.sum()to form the objective term(c * x).sum().- Variables:
- param¶
- base¶
- sel¶
- sum(axis=None)¶
- class pyepo.dsl.expression.ParametricObjective(cost_param, cost_var, local_idx=None, base=None, fixed=None, quad=None)¶
The objective:
cost_parampredicts the cost atcost_var’s selected positions (with an optional knownbase), plus optional known fixed linear (fixed) and parameter-free quadratic (quad) terms.- Variables:
cost_param (Parameter) – the predicted cost (size == num_cost)
cost_var (Variable) – the Variable the prediction lands on
local_idx (np.ndarray | None) – predicted indices within cost_var (None = all)
base (np.ndarray | None) – known cost added at the predicted positions
fixed (Affine | None) – known linear term on other / overlapping positions
quad (Quadratic | None) – parameter-free quadratic term
- cost_param¶
- cost_var¶
- local_idx = None¶
- base = None¶
- fixed = None¶
- quad = None¶
- sum(axis=None)¶