Does Model.addGenConstrPWL() (Gurobi 9.0+) use SOS2?
回答済みHello Gurobi Community,
I am writing a model that heavily utilizes piecewise linear constraints using the newer Model.addGenConstrPWL() interface.
I understand from the documentation that:
- Gurobi versions 9.0 and later provide the specialized
addGenConstrPWL()interface. - In versions 8.1 and earlier, one had to manually implement these constraints using the Special Ordered Set of Type 2 (SOS2) formulation.
My primary question is regarding the implementation in Gurobi 9.0 and later:
Does the Model.addGenConstrPWL() function internally rely on and automatically generate the standard SOS2 formulation (i.e., the "lambda" formulation with a $\lambda_i \in \text{SOS2}$ constraint)?
Thank you very much!
-
Hi Yuhan,
Does the
Model.addGenConstrPWL()function internally rely on and automatically generate the standard SOS2 formulation (i.e., the "lambda" formulation with a $\lambda_i \in \text{SOS2}$ constraint)?Yes, it does. To approximate the function \(y = f(x)\), the Gurobi Optimizer uses the following set of constraints, where \((x_i, y_i)\) represents the \(i\)-th break point.
\[ \begin{align} x = \sum_i \lambda_i x_i & \notag \\ y = \sum_i \lambda_i y_i & \notag \\ \sum_i \lambda_i = 1 & \notag \\ \lambda_i \geq 0 ~~\text{and}~~ \text{SOS2} & \notag \end{align} \]The first two constraints define the \(x\)- and the \(y\)- coordinates of the piecewise linear function. The third constraint ensures that \((x, y)\) is a convex combination of the breakpoint values. The SOS2 constraint ensures that the only two adjacent \(\lambda_i\) variables can be positive, which enforces that the solution lies on a single segment of the piecewise-linear function.
If the function \(f(x)\) is convex, the SOS2 constraints are redundant.
Best regards,
Maliheh
0 -
Thank you so much, Maliheh!
0
サインインしてコメントを残してください。
コメント
2件のコメント