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 piece dimension. Each element along the piece dimension is the chord of one piece: \(m_k \cdot x + c_k\). No auxiliary variables are created.

For most users: prefer add_piecewise_formulation() with a bounded tuple (y, y_pts, "<=") / (y, y_pts, ">=") — 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_piece dimension (one entry per piece).

Warns:

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