[SCIP] R: Quadratic Constraint Modification

Enrico Calandrini e.calandrini at studenti.unipi.it
Tue Jul 16 15:41:46 CEST 2024


Hi Stefan,
Thank you very much for your reply! That is exactly what I was looking for!
I just have a quick follow-up question on what you mentioned. Let's say I have an expression like x + 2xy + 3y². Following your procedure, I should be able to retrieve all the terms of the sum (x, xy, y²) using SCIPexprGetChildren(). However, I'm now wondering how I can directly access the individual expressions to determine which variables are active within each one. Is there a method to retrieve the indices of the active variables in the expression?
Assuming this is possible, if I retrieve the vector of coefficients with SCIPgetCoefsExprSum() and modify it, is it sufficient to make the change active in SCIP? Do I need to "provide back" the new vector to SCIP in any way?
Thank you very much for your time!
Enrico
________________________________
Da: Stefan Vigerske <svigerske at gams.com>
Inviato: martedì 16 luglio 2024 15:24
A: Enrico Calandrini <e.calandrini at studenti.unipi.it>; scip at zib.de <scip at zib.de>
Oggetto: Re: [SCIP] Quadratic Constraint Modification

Hi,

SCIPcreateConsBasicQuadraticNonlinear() is correct. This is a wrapper
around SCIPcreateConsBasicNonlinear(), which makes it easier to create
nonlinear constraints that are quadratic.

There is no SCIPchgLinearCoefQuadratic() in current SCIP versions anymore.

Since SCIP 8, quadratic constraints are no longer distinguished from
other nonlinear constraints. The function of a quadratic constraint is
stored as an expression that is a sum of variables, squares of
variables, and products of two variables, each term in the sum can have
a coefficient. If you just want to change a coefficient in the sum, then
you can get the expression of the constraint (SCIPgetExprNonlinear()),
check with SCIPisExprSum() that it is indeed a sum, and use
SCIPgetCoefsExprSum() to get the coefficients vector. I think it should
be ok to change this vector when SCIP is in problem stage. To get the
expressions that make up the terms of sum, use SCIPexprGetChildren().
For the number of terms, use SCIPexprGetNChildren().

To change the problem after a solve, call SCIPfreeTransform(). That
should bring SCIP back into problem stage.

Hope that helps,
Stefan

On 15/07/2024 14:59, Enrico Calandrini wrote:
> Hi everyone,
> First of all, thank you all for your amazing work!
> I was wondering if someone could help me understand how to properly modify a quadratic constraint, if this is possible. Specifically, I'm adding a quadratic constraint using the function SCIPcreateConsBasicQuadraticNonlinear. Firstly, is this method the correct one in the current version of SCIP? Additionally, it is possible that after the model has been solved, I may need to modify that constraint.
> I have noticed that in the constraint handler for quadratic constraints (cons_quadratic.h), there are functions like SCIPchgLinearCoefQuadratic() to modify both linear and quadratic coefficients. However, I'm unsure whether these methods can be used for a constraint created as described above. Moreover, I have seen in the documentation that these changes are allowed only in the problem creation stage, meaning that after a call to SCIPsolve, this constraint can't be modified anymore?
> I'm a little bit confused, so thank you in advance for your support!
> Enrico Calandrini
>
>
> _______________________________________________
> Scip mailing list
> Scip at zib.de
> https://listserv.zib.de/mailman/listinfo/scip

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.zib.de/pipermail/scip/attachments/20240716/8e999a13/attachment.html>


More information about the Scip mailing list