Skip to content

Commit 49cb199

Browse files
author
Ksenia Bestuzheva
committed
Merge branch 'gh92-nl-set-objvar-initsol' into 'v90-bugfix'
compute and set value for objvar when having initsol in nl-reader See merge request integer/scip!3431
2 parents 84a4929 + cc2571a commit 49cb199

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Fixed bugs
1111
- make sure that symmetry detection callbacks report success
1212
- make arithmetics in cuts.c more robust to avoid invalid scg cuts due to numerical rounding sensitivity
1313
- allow to copy cons_pseudoboolean even if no AND constraints are present in order to avoid a warning
14+
- set value for variable that is introduced to reformulate nonlinear objective function when reading .nl files with initial solution
1415

1516
Miscellaneous
1617
-------------

src/scip/reader_nl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,20 @@ class AMPLProblemHandler : public mp::NLHandler<AMPLProblemHandler, SCIP_EXPR*>
15731573
SCIP_CALL_THROW( SCIPaddLinearVarNonlinear(scip, objcons, objvar, -1.0) );
15741574
SCIP_CALL_THROW( SCIPaddCons(scip, objcons) );
15751575

1576+
if( initsol != NULL )
1577+
{
1578+
/* compute value for objvar in initial solution from other variable values */
1579+
SCIP_CALL_THROW( SCIPevalExpr(scip, objexpr, initsol, 0) );
1580+
if( SCIPexprGetEvalValue(objexpr) != SCIP_INVALID )
1581+
{
1582+
SCIPsetSolVal(scip, initsol, objvar, SCIPexprGetEvalValue(objexpr));
1583+
}
1584+
else
1585+
{
1586+
SCIPwarningMessage(scip, "Objective function could not be evaluated in initial point. Domain error.");
1587+
}
1588+
}
1589+
15761590
SCIP_CALL_THROW( SCIPreleaseCons(scip, &objcons) );
15771591
SCIP_CALL_THROW( SCIPreleaseVar(scip, &objvar) );
15781592
}

tests/src/reader/nl.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,26 @@ Test(readernl, dualsol, .description = "check whether solving a LP without preso
282282

283283
free(args[1]);
284284
}
285+
286+
/* check whether initial value of introduced nlobjvar is set */
287+
Test(readernl, nlobjvar, .description = "check whether initial value of introduced nlobjvar is set")
288+
{
289+
char filename[SCIP_MAXSTRLEN];
290+
291+
/* skip test if nl reader not available (SCIP compiled with AMPL=false) */
292+
if( SCIPfindReader(scip, "nlreader") == NULL )
293+
return;
294+
295+
/* get file to read: suffix1.nl that lives in the same directory as this file */
296+
TESTsetTestfilename(filename, __FILE__, "nlobj.nl");
297+
298+
/* read nl file */
299+
SCIP_CALL( SCIPreadProb(scip, filename, NULL) );
300+
301+
/* we should have an initial solution as well */
302+
cr_expect(SCIPgetNSols(scip) == 1);
303+
304+
/* only if the solution is feasible, it will be available in the transformed problem, too */
305+
SCIP_CALL( SCIPtransformProb(scip) );
306+
cr_expect(SCIPgetNSols(scip) == 1);
307+
}

tests/src/reader/nlobj.mod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# create nl file via ampl -P -ognlobj nlobj.mod
2+
3+
var x >= 0 := 1;
4+
var y >= 0 := 2;
5+
6+
minimize obj: x + 2*y*y + 5 ;

tests/src/reader/nlobj.nl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
g3 0 1 0 # problem nlobj
2+
2 0 1 0 0 # vars, constraints, objectives, ranges, eqns
3+
0 1 # nonlinear constraints, objectives
4+
0 0 # network constraints: nonlinear, linear
5+
0 1 0 # nonlinear vars in constraints, objectives, both
6+
0 0 0 1 # linear network variables; functions; arith, flags
7+
0 0 0 0 0 # discrete variables: binary, integer, nonlinear (b,c,o)
8+
0 2 # nonzeros in Jacobian, gradients
9+
0 0 # max name lengths: constraints, variables
10+
0 0 0 0 0 # common exprs: b,c,o,c1,o1
11+
O0 0
12+
o0
13+
o2
14+
o2
15+
n2
16+
v0
17+
v0
18+
n5
19+
x2
20+
0 2
21+
1 1
22+
b
23+
2 0
24+
2 0
25+
k1
26+
0
27+
G0 2
28+
0 0
29+
1 1

0 commit comments

Comments
 (0)