linopy.piecewise.tangent_lines

Contents

linopy.piecewise.tangent_lines#

linopy.piecewise.tangent_lines(x, x_points, y_points)#

Compute tangent-line (chord) expressions for a piecewise linear function.

Low-level helper returning a LinearExpression with an extra segment dimension. Each element along the segment dimension is the chord of one segment: \(m_k \cdot x + c_k\). No auxiliary variables are created.

For most users: prefer add_piecewise_formulation() with sign="<=" / ">=" — it builds on this helper and adds the x [x_min, x_max] domain bound plus a curvature-vs-sign check that catches the “wrong region” case. Use tangent_lines directly only when you need to compose the chord expressions manually (e.g. with other linear terms, or without the domain bound).

t = tangent_lines(power, x_pts, y_pts)
m.add_constraints(fuel <= t)  # upper bound (concave f)
m.add_constraints(fuel >= t)  # lower bound (convex f)
Parameters:
  • x (Variable or LinearExpression) – The input expression.

  • x_points (BreaksLike) – Breakpoint x-coordinates (must be strictly monotonic; both ascending and descending are accepted).

  • y_points (BreaksLike) – Breakpoint y-coordinates.

Returns:

LinearExpression – Expression with an additional _breakpoint_seg dimension (one entry per segment).

Warns:

EvolvingAPIWarningtangent_lines is part of the newly-added piecewise API; the returned expression shape and segment-dim name may be refined. Silence with warnings.filterwarnings("ignore", category=linopy.EvolvingAPIWarning).