<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Stefan,</div>
<div style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thank you once again for your invaluable assistance.</div>
<div style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I can confirm that using <code>SCIPfreeExprQuadratic()</code> indeed allows the coefficients to be correctly modified! However, I'm still struggling with one final issue: how to properly add or remove terms from a quadratic constraint. I've tried several approaches,
but none seem to work. Is this even possible? Or is it that the constraint handler
<code>cons_nonlinear</code> doesn’t support such modifications?</div>
<div class="elementToProof" style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regarding the addition of new coefficients (e.g., a simple term like <code>x^2</code>), I attempted to create a new expression using
<code>SCIPcreateExprQuadratic</code> with the new term, and then add it using <code>
SCIPappendExprChild(scip, qexpr, new_term)</code>, where <code>qexpr</code> is the existing quadratic expression obtained via
<code>SCIPgetExprNonlinear</code> and <code>new_term</code> represents the term I want to add. However, when I follow this procedure and attempt to solve, I encounter the following error:</div>
<pre><div style="direction: ltr; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><code>/scipoptsuite-8.0.3/scip/src/scip/solve.c:4920: SCIPsolveCIP: Assertion `BMSgetNUsedBufferMemory(mem->buffer) == 0' failed.
</code></div></pre>
<div class="elementToProof" style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I also tried using <code>SCIPaddExprNonlinear(scip, q_con, new_term, 1)</code>, where
<code>q_con</code> is the initial quadratic constraint. In this case, I receive this error:</div>
<pre><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><button class="flex gap-1 items-center elementToProof"><div></div></button><code>scip/src/scip/cons_nonlinear.c:12632: SCIPaddExprNonlinear: Assertion `consdata->nvarexprs == 0' failed.
</code></div></pre>
<div class="elementToProof" style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
On the other hand, I'm unsure how to go about removing terms. Setting a coefficient to zero results in the following error:</div>
<pre><div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><button class="flex gap-1 items-center elementToProof"><div></div></button><code>scipoptsuite-8.0.3/scip/src/scip/expr.c:3425: SCIPexprCheckQuadratic: Assertion `coef != 0.0' failed.
</code></div></pre>
<div style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Could you provide any additional guidance on this?</div>
<div style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thank you,</div>
<div style="margin-top: 1em; margin-bottom: 1em; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Enrico</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Da:</b> Stefan Vigerske <svigerske@gams.com><br>
<b>Inviato:</b> venerdì 16 agosto 2024 05:01<br>
<b>A:</b> Enrico Calandrini <e.calandrini@studenti.unipi.it>; scip@zib.de <scip@zib.de><br>
<b>Oggetto:</b> Re: R: R: [SCIP] Quadratic Constraint Modification</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi,<br>
<br>
make sure you run SCIPfreeTransform() after the first solve.<br>
<br>
You could also try calling SCIPfreeExprQuadratic() on the expression <br>
after you did the modifications. That would free a datastructure that <br>
stores a representation of the expression as quadratic form. But I don't <br>
remember why SCIP would do this on the constraints in the original problem.<br>
<br>
Stefan<br>
<br>
On 15/08/2024 16:59, Enrico Calandrini wrote:<br>
> Hi Stefan,<br>
> <br>
> I hope you're doing well.<br>
> <br>
> I recently had the opportunity to work on and test the functionalities you described. The process of retrieving and changing the coefficients works perfectly. However, these changes are not reflected when calling SCIPsolve again. To confirm this, I printed
the model using SCIPwriteOrigProblem. Although other parts of the model (such as bounds and objective function coefficients) are updating correctly, the coefficients modified through the previous procedure remain unchanged.<br>
> <br>
> For further context, I store a pointer to the NonLinear constraint during the construction phase. After calling SCIPsolve, I retrieve the expression using SCIPgetExprNonlinear and the coefficients with SCIPgetCoefsExprSum. I then directly modify the vector
of these coefficients. I'm confident the changes are being made correctly because when I repeat the same procedure after the new call to SCIPsolve, the coefficients are updated. It seems as though I'm not prompting SCIP to internally update its version of
the constraint. Could you please let me know if I'm missing something?<br>
> <br>
> Thank you very much.<br>
> <br>
> Best regards,<br>
> Enrico<br>
> ________________________________<br>
> Da: Stefan Vigerske <svigerske@gams.com><br>
> Inviato: martedì 16 luglio 2024 15:57<br>
> A: Enrico Calandrini <e.calandrini@studenti.unipi.it>; scip@zib.de <scip@zib.de><br>
> Oggetto: Re: R: [SCIP] Quadratic Constraint Modification<br>
> <br>
> Hi,<br>
> <br>
> On 16/07/2024 15:41, Enrico Calandrini wrote:<br>
>> Hi Stefan,<br>
>> Thank you very much for your reply! That is exactly what I was looking for!<br>
>> 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?<br>
> <br>
> You may want to inspect the expression in each child to see whether it<br>
> is x, xy, or y^2. Use functions like SCIPisExprVar(),<br>
> SCIPisExprProduct(), and SCIPisExprPower(). Then use SCIPgetVarExprVar()<br>
> to get the variable in a var-expression or SCIPgetExponentExprPow() to<br>
> get the exponent in a power expression. For a product, use<br>
> SCIPexprGetNChildren() to get the number of children and check that each<br>
> is a var-expression.<br>
> <br>
>> 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?<br>
> <br>
> Modifying the values in SCIPgetCoefsExprSum() should be sufficient, as<br>
> the array returned is a pointer to internal data. It is not so clean to<br>
> do this, but there is currently no elegant way (as far as I remember).<br>
> <br>
> Stefan<br>
> <br>
>> Thank you very much for your time!<br>
>> Enrico<br>
>> ________________________________<br>
>> Da: Stefan Vigerske <svigerske@gams.com><br>
>> Inviato: martedì 16 luglio 2024 15:24<br>
>> A: Enrico Calandrini <e.calandrini@studenti.unipi.it>; scip@zib.de <scip@zib.de><br>
>> Oggetto: Re: [SCIP] Quadratic Constraint Modification<br>
>><br>
>> Hi,<br>
>><br>
>> SCIPcreateConsBasicQuadraticNonlinear() is correct. This is a wrapper<br>
>> around SCIPcreateConsBasicNonlinear(), which makes it easier to create<br>
>> nonlinear constraints that are quadratic.<br>
>><br>
>> There is no SCIPchgLinearCoefQuadratic() in current SCIP versions anymore.<br>
>><br>
>> Since SCIP 8, quadratic constraints are no longer distinguished from<br>
>> other nonlinear constraints. The function of a quadratic constraint is<br>
>> stored as an expression that is a sum of variables, squares of<br>
>> variables, and products of two variables, each term in the sum can have<br>
>> a coefficient. If you just want to change a coefficient in the sum, then<br>
>> you can get the expression of the constraint (SCIPgetExprNonlinear()),<br>
>> check with SCIPisExprSum() that it is indeed a sum, and use<br>
>> SCIPgetCoefsExprSum() to get the coefficients vector. I think it should<br>
>> be ok to change this vector when SCIP is in problem stage. To get the<br>
>> expressions that make up the terms of sum, use SCIPexprGetChildren().<br>
>> For the number of terms, use SCIPexprGetNChildren().<br>
>><br>
>> To change the problem after a solve, call SCIPfreeTransform(). That<br>
>> should bring SCIP back into problem stage.<br>
>><br>
>> Hope that helps,<br>
>> Stefan<br>
>><br>
>> On 15/07/2024 14:59, Enrico Calandrini wrote:<br>
>>> Hi everyone,<br>
>>> First of all, thank you all for your amazing work!<br>
>>> 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.<br>
>>> 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?<br>
>>> I'm a little bit confused, so thank you in advance for your support!<br>
>>> Enrico Calandrini<br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> Scip mailing list<br>
>>> Scip@zib.de<br>
>>> <a href="https://listserv.zib.de/mailman/listinfo/scip">https://listserv.zib.de/mailman/listinfo/scip</a><br>
>><br>
>><br>
> <br>
> <br>
<br>
</div>
</span></font></div>
</body>
</html>