linopy.model.Model.reformulate_sos_constraints

linopy.model.Model.reformulate_sos_constraints#

Model.reformulate_sos_constraints(prefix='_sos_reform_')#

Reformulate SOS constraints as binary + linear constraints.

This converts SOS1 and SOS2 constraints into equivalent binary variable formulations using the Big-M method. This allows solving models with SOS constraints using solvers that don’t support them natively (e.g., HiGHS, GLPK).

Big-M values are determined as follows: 1. If custom big_m was specified in add_sos_constraints(), use that 2. Otherwise, use the variable bounds (tightest valid Big-M)

Note: This permanently mutates the model and returns a token the caller owns. For a stateful, reversible API use model.apply_sos_reformulation() / model.undo_sos_reformulation(); for automatic undo around a single solve use model.solve(reformulate_sos=True).

Parameters:
  • model (Model) – Model containing SOS constraints to reformulate.

  • prefix (str, optional) – Prefix for auxiliary variables and constraints. Default: “_sos_reform_”

Returns:

SOSReformulationResult – Tracks what was changed, enabling undo via undo_sos_reformulation.