Skip to content

Commit 532e45a

Browse files
committed
Merge remote-tracking branch 'origin/v9-minor'
2 parents 2165263 + 17bdbde commit 532e45a

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

src/scip/cons_nonlinear.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,15 @@ SCIP_RETCODE createCons(
13751375
return SCIP_INVALIDCALL;
13761376
}
13771377

1378+
1379+
if( isnan(lhs) || isnan(rhs) )
1380+
{
1381+
SCIPerrorMessage("%s hand side of nonlinear constraint <%s> is nan\n",
1382+
isnan(lhs) ? "left" : "right", name);
1383+
return SCIP_INVALIDDATA;
1384+
}
1385+
1386+
13781387
/* create constraint data */
13791388
SCIP_CALL( SCIPallocClearBlockMemory(scip, &consdata) );
13801389

@@ -12856,10 +12865,30 @@ SCIP_RETCODE SCIPcreateConsQuadraticNonlinear(
1285612865
{
1285712866
SCIP_CONSHDLR* conshdlr;
1285812867
SCIP_EXPR* expr;
12868+
int i;
1285912869

1286012870
assert(nlinvars == 0 || (linvars != NULL && lincoefs != NULL));
1286112871
assert(nquadterms == 0 || (quadvars1 != NULL && quadvars2 != NULL && quadcoefs != NULL));
1286212872

12873+
/* check data for infinity or nan values */
12874+
for( i = 0; i < nlinvars; ++i )
12875+
{
12876+
if( !SCIPisFinite(lincoefs[i]) || SCIPisInfinity(scip, lincoefs[i]) )
12877+
{
12878+
SCIPerrorMessage("Infinite or nan coefficient of variable %s in quadratic constraint %s\n", SCIPvarGetName(linvars[i]), name);
12879+
return SCIP_INVALIDDATA;
12880+
}
12881+
}
12882+
for( i = 0; i < nquadterms; ++i )
12883+
{
12884+
if( !SCIPisFinite(quadcoefs[i]) || SCIPisInfinity(scip, quadcoefs[i]) )
12885+
{
12886+
SCIPerrorMessage("Infinite or nan coefficient of term %s*%s in quadratic constraint %s\n", SCIPvarGetName(quadvars1[i]), SCIPvarGetName(quadvars2[i]), name);
12887+
return SCIP_INVALIDDATA;
12888+
}
12889+
}
12890+
/* lhs and rhs will be checked in createCons */
12891+
1286312892
/* get nonlinear constraint handler */
1286412893
conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
1286512894
if( conshdlr == NULL )
@@ -12939,6 +12968,37 @@ SCIP_RETCODE SCIPcreateConsBasicSOCNonlinear(
1293912968

1294012969
assert(vars != NULL || nvars == 0);
1294112970

12971+
/* check values for infinity or nan */
12972+
for( i = 0; i < nvars; ++i )
12973+
{
12974+
if( !SCIPisFinite(coefs[i]) || SCIPisInfinity(scip, coefs[i]) )
12975+
{
12976+
SCIPerrorMessage("Second-order cone term with infinite or nan coefficient of variable %s in nonlinear constraint %s\n", SCIPvarGetName(vars[i]), name);
12977+
return SCIP_INVALIDDATA;
12978+
}
12979+
if( offsets != NULL && (!SCIPisFinite(offsets[i]) || SCIPisInfinity(scip, coefs[i])) )
12980+
{
12981+
SCIPerrorMessage("Second-order cone term with infinite or nan offset for variable %s in nonlinear constraint %s\n", SCIPvarGetName(vars[i]), name);
12982+
return SCIP_INVALIDDATA;
12983+
}
12984+
}
12985+
if( !SCIPisFinite(constant) || SCIPisInfinity(scip, constant) )
12986+
{
12987+
SCIPerrorMessage("Second-order cone constant with infinite or nan value in nonlinear constraint %s\n", name);
12988+
return SCIP_INVALIDDATA;
12989+
}
12990+
if( !SCIPisFinite(rhscoeff) || SCIPisInfinity(scip, rhscoeff) )
12991+
{
12992+
SCIPerrorMessage("Infinite or nan coefficient of right hand side variable in second-order cone constraint %s\n", name);
12993+
return SCIP_INVALIDDATA;
12994+
}
12995+
if( !SCIPisFinite(rhsoffset) || SCIPisInfinity(scip, rhsoffset) )
12996+
{
12997+
SCIPerrorMessage("Infinite or nan right hand side offset in second-order cone constraint %s\n", name);
12998+
return SCIP_INVALIDDATA;
12999+
}
13000+
/* lhs and rhs will be checked in createCons */
13001+
1294213002
SCIP_CALL( SCIPcreateExprSum(scip, &lhssum, 0, NULL, NULL, constant, NULL, NULL) ); /* gamma */
1294313003
for( i = 0; i < nvars; ++i )
1294413004
{
@@ -13009,6 +13069,24 @@ SCIP_RETCODE SCIPcreateConsBasicSignpowerNonlinear(
1300913069
assert(x != NULL);
1301013070
assert(z != NULL);
1301113071

13072+
if( !SCIPisFinite(exponent) )
13073+
{
13074+
SCIPerrorMessage("exponent in nonlinear signpower constraint <%s> is infinite or nan\n", name);
13075+
return SCIP_INVALIDDATA;
13076+
}
13077+
13078+
if( !SCIPisFinite(xoffset) )
13079+
{
13080+
SCIPerrorMessage("argument offset in nonlinear signpower constraint <%s> is infinite or nan\n", name);
13081+
return SCIP_INVALIDDATA;
13082+
}
13083+
13084+
if( !SCIPisFinite(zcoef) )
13085+
{
13086+
SCIPerrorMessage("coefficient of linear variable in nonlinear signpower constraint <%s> is infinite or nan\n", name);
13087+
return SCIP_INVALIDDATA;
13088+
}
13089+
1301213090
SCIP_CALL( SCIPcreateExprVar(scip, &xexpr, x, NULL, NULL) );
1301313091
if( xoffset != 0.0 )
1301413092
{

src/scip/expr_pow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ SCIP_DECL_EXPRPARSE(parseSignpower)
27192719
return SCIP_READERROR;
27202720
}
27212721

2722-
if( exponent <= 1.0 || SCIPisInfinity(scip, exponent) )
2722+
if( exponent <= 1.0 || !SCIPisFinite(exponent) || SCIPisInfinity(scip, exponent) )
27232723
{
27242724
SCIPerrorMessage("Expected finite exponent >= 1.0 for signpower().\n");
27252725
return SCIP_READERROR;

src/scip/expr_xyz.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ SCIP_DECL_EXPRPARSE(parseXyz)
149149
{ /*lint --e{715}*/
150150
assert(expr != NULL);
151151

152+
/* check values for nan and infinity if needed */
153+
152154
SCIPerrorMessage("method of xyz expression handler not implemented yet\n");
153155
SCIPABORT(); /*lint --e{527}*/
154156

src/scip/scip_expr.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ SCIP_RETCODE parseBase(
241241
return SCIP_READERROR;
242242
}
243243
debugParse("Parsed value %g, creating a value-expression.\n", value);
244+
if( !SCIPisFinite(value) || SCIPisInfinity(scip, value) )
245+
{
246+
SCIPerrorMessage("Infinite or nan term value expression within nonlinear expression %s\n", expr);
247+
return SCIP_INVALIDDATA;
248+
}
244249
SCIP_CALL( SCIPcreateExprValue(scip, basetree, value, ownercreate, ownercreatedata) );
245250
}
246251
else if( isalpha(*expr) )
@@ -403,6 +408,13 @@ SCIP_RETCODE parseFactor(
403408
}
404409
}
405410

411+
if( !SCIPisFinite(exponent) || SCIPisInfinity(scip, exponent) )
412+
{
413+
SCIPerrorMessage("Infinite or nan term exponent in nonlinear expression %s\n", expr);
414+
SCIP_CALL( SCIPreleaseExpr(scip, &basetree) );
415+
return SCIP_INVALIDDATA;
416+
}
417+
406418
debugParse("parsed the exponent %g\n", exponent); /*lint !e506 !e681*/
407419
}
408420
else
@@ -572,6 +584,13 @@ SCIP_RETCODE parseExpr(
572584
/* check if we have a "coef * <term>" */
573585
if( SCIPstrToRealValue(expr, &coef, (char**)newpos) )
574586
{
587+
if( !SCIPisFinite(coef) || SCIPisInfinity(scip, coef) )
588+
{
589+
SCIPerrorMessage("Infinite or nan term coefficient in nonlinear expression %s\n", expr);
590+
SCIP_CALL( SCIPreleaseExpr(scip, exprtree) );
591+
return SCIP_INVALIDDATA;
592+
}
593+
575594
SCIP_CALL( SCIPskipSpace((char**)newpos) );
576595

577596
if( **newpos == '<' )

0 commit comments

Comments
 (0)