Skip to content

Commit c57aadf

Browse files
committed
Merge branch '3940-fix-heur_alns-c-1379-void-tryadd2variablebuffer-scip-scip_var-double-scip_var-double-int-unsigned' into 'v92-bugfix'
Resolve "heur_alns.c:1379: void tryAdd2variableBuffer(SCIP *, SCIP_VAR *, double, SCIP_VAR **, double *, int *, unsigned int): Assertion `SCIPisFeasIntegral(scip, val) || ! SCIPvarIsIntegral(var)' failed." See merge request integer/scip!3906
2 parents d36a8bd + fdf9cdc commit c57aadf

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Fixed bugs
1919
- avoid overwriting set cutoff flag in tightenCoefs(), preprocessConstraintPairs(), and applyFixings() of cons_varbound.c to reject infeasible solutions
2020
- fix memory leak in exprinterpret_cppad.cpp w.r.t. user expressions
2121
- adjust bound before checking feasibility in SCIPvarAddVlb() and SCIPvarAddVub() to detect integrality cutoff
22+
- choose incumbent solution as reference in varFixingsRins() and varFixingsDins() of heur_alns.c to ensure integrality
23+
- consider variable type in selectInitialVariableRandomly() of heur_gins.c to count integral variables
2224

2325
Build system
2426
------------

check/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ set(pairs_Issue
517517
"instances/Issue/3932.cip\;+infinity\;reduced_tolerance"
518518
"instances/Issue/3934.cip\;-5007\;conflict_off_reduced_presolving_subrestart"
519519
"instances/Issue/3935.cip\;-24793.9840277416\;default"
520+
"instances/Issue/3940.cip\;-2549.22\;unscaled_tolerance"
520521
)
521522

522523
#
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lp/scaling = 0
2+
numerics/sumepsilon = 1e-9
3+
numerics/feastol = 1e-9

check/instances/Issue/3940.cip

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
STATISTICS
2+
Problem name : seed
3+
Variables : 5 (0 binary, 5 integer, 0 implicit integer, 0 continuous)
4+
Constraints : 0 initial, 8 maximal
5+
OBJECTIVE
6+
Sense : minimize
7+
VARIABLES
8+
[integer] <x0>: obj=-78, original bounds=[-200,+inf]
9+
[integer] <x1>: obj=-81.3, original bounds=[-200,+inf]
10+
[integer] <x2>: obj=63, original bounds=[-200,+inf]
11+
[integer] <x3>: obj=-84.66, original bounds=[0,200]
12+
[integer] <x4>: obj=21, original bounds=[-200,+inf]
13+
CONSTRAINTS
14+
[linear] <_C10>: -24.52<x0>[I] -52.76<x1>[I] +94.84<x2>[I] -20.18<x3>[I] -79.99<x4>[I] >= -4291.3;
15+
[linear] <_C11>: -44<x2>[I] -47<x4>[I] <= 0;
16+
[linear] <_C13>: -49.18<x0>[I] +7.64<x1>[I] -36.45<x2>[I] +20.37<x3>[I] +32.91<x4>[I] <= 3645.24;
17+
[linear] <_C14>: +39<x2>[I] +45<x4>[I] >= 0;
18+
[linear] <_C17>: +81.01<x0>[I] +45.36<x1>[I] +91.01<x2>[I] -47.28<x3>[I] +34.98<x4>[I] <= -2042.31;
19+
[linear] <_C4>: -21<x1>[I] >= 0;
20+
[linear] <_C5>: +59.51<x3>[I] +92.41<x4>[I] >= 0;
21+
[linear] <_C6>: -22.28<x0>[I] -1.96<x1>[I] +84.7<x2>[I] -83.65<x3>[I] +88.9<x4>[I] >= 185.1;
22+
END

src/scip/heur_alns.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ SCIP_Real getVariablePscostScore(
13381338
SCIP_Bool uselocallpsol /**< should local LP solution be used? */
13391339
)
13401340
{
1341-
SCIP_Real lpsolval;
1341+
SCIP_Real soldiff;
13421342

13431343
assert(scip != NULL);
13441344
assert(var != NULL);
@@ -1347,13 +1347,13 @@ SCIP_Real getVariablePscostScore(
13471347
if( SCIPvarGetStatus(var) != SCIP_VARSTATUS_COLUMN )
13481348
return 0.0;
13491349

1350-
lpsolval = uselocallpsol ? SCIPvarGetLPSol(var) : SCIPvarGetRootSol(var);
1350+
soldiff = refsolval - (uselocallpsol ? SCIPvarGetLPSol(var) : SCIPvarGetRootSol(var));
13511351

13521352
/* the score is 0.0 if the values are equal */
1353-
if( SCIPisEQ(scip, lpsolval, refsolval) )
1353+
if( SCIPisFeasZero(scip, soldiff) )
13541354
return 0.0;
13551355
else
1356-
return SCIPgetVarPseudocostVal(scip, var, refsolval - lpsolval);
1356+
return SCIPgetVarPseudocostVal(scip, var, soldiff);
13571357
}
13581358

13591359
/** add variable and solution value to buffer data structure for variable fixings. The method checks if
@@ -1370,12 +1370,8 @@ void tryAdd2variableBuffer(
13701370
SCIP_Bool integer /**< is this an integer variable? */
13711371
)
13721372
{
1373-
/* todo: this assert can fail when there was a dual reduction that changed a variable to
1374-
* an integral type after the reference solution was found and the variable has a fractional
1375-
* value in this solution, e.g., for boxQP instances (spar*)
1376-
* implicit integer variables could also be an issue, as they can take fractional values in feasible solutions
1377-
*/
1378-
assert(SCIPisFeasIntegral(scip, val) || ! SCIPvarIsIntegral(var));
1373+
assert(integer == (SCIPvarGetType(var) == SCIP_VARTYPE_BINARY || SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER));
1374+
assert(!integer || SCIPisFeasIntegral(scip, val));
13791375
assert(*nfixings < SCIPgetNVars(scip));
13801376

13811377
/* round the value to its nearest integer */
@@ -2774,9 +2770,13 @@ DECL_VARFIXINGS(varFixingsRens)
27742770
/* loop over binary and integer variables; determine those that should be fixed in the sub-SCIP */
27752771
for( nfracs = 0, i = 0; i < nbinvars + nintvars; ++i )
27762772
{
2777-
SCIP_VAR* var = vars[i];
2778-
SCIP_Real lpsolval = SCIPvarGetLPSol(var);
2779-
assert((i < nbinvars && SCIPvarIsBinary(var)) || (i >= nbinvars && SCIPvarIsIntegral(var)));
2773+
SCIP_VAR* var;
2774+
SCIP_Real lpsolval;
2775+
2776+
var = vars[i];
2777+
assert(SCIPvarGetType(var) == SCIP_VARTYPE_BINARY || SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER);
2778+
assert((i < nbinvars) == (SCIPvarGetType(var) == SCIP_VARTYPE_BINARY));
2779+
lpsolval = SCIPvarGetLPSol(var);
27802780

27812781
/* fix all binary and integer variables with integer LP solution value */
27822782
if( SCIPisFeasIntegral(scip, lpsolval) )
@@ -2897,19 +2897,19 @@ SCIP_RETCODE fixMatchingSolutionValues(
28972897
/* loop over integer and binary variables and check if their solution values match in all solutions */
28982898
for( v = 0; v < nvars; ++v )
28992899
{
2900-
SCIP_Real solval;
29012900
SCIP_VAR* var;
2901+
SCIP_Real solval;
29022902
int s;
29032903

29042904
var = vars[v];
2905-
assert((v < SCIPgetNBinVars(scip) && SCIPvarIsBinary(var)) || (v >= SCIPgetNBinVars(scip) && SCIPvarIsIntegral(var)));
2905+
assert(SCIPvarGetType(var) == SCIP_VARTYPE_BINARY || SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER);
2906+
assert((v < SCIPgetNBinVars(scip)) == (SCIPvarGetType(var) == SCIP_VARTYPE_BINARY));
29062907
solval = SCIPgetSolVal(scip, firstsol, var);
29072908

29082909
/* determine if solution values match in all given solutions */
29092910
for( s = 1; s < nsols; ++s )
29102911
{
2911-
SCIP_Real solval2 = SCIPgetSolVal(scip, sols[s], var);
2912-
if( ! SCIPisEQ(scip, solval, solval2) )
2912+
if( !SCIPisFeasZero(scip, solval - SCIPgetSolVal(scip, sols[s], var)) )
29132913
break;
29142914
}
29152915

@@ -2961,8 +2961,9 @@ DECL_VARFIXINGS(varFixingsRins)
29612961
if( nbinvars + nintvars == 0 )
29622962
return SCIP_OKAY;
29632963

2964-
sols[0] = NULL;
2965-
sols[1] = incumbent;
2964+
/* incumbent is reference */
2965+
sols[0] = incumbent;
2966+
sols[1] = NULL;
29662967

29672968
SCIP_CALL( fixMatchingSolutionValues(scip, sols, 2, vars, nbinvars + nintvars, varbuf, valbuf, nfixings) );
29682969

@@ -3518,11 +3519,11 @@ DECL_VARFIXINGS(varFixingsDins)
35183519
nsols = nmipsols + 2;
35193520

35203521
SCIP_CALL( SCIPallocBufferArray(scip, &sols, nsols) );
3521-
sols[0] = NULL; /* node LP solution */
3522-
sols[1] = rootlpsol;
35233522

3524-
/* copy the remaining MIP solutions after the LP solutions */
3525-
BMScopyMemoryArray(&sols[2], SCIPgetSols(scip), nmipsols); /*lint !e866*/
3523+
/* incumbent is reference */
3524+
BMScopyMemoryArray(sols, SCIPgetSols(scip), nmipsols); /*lint !e866*/
3525+
sols[nmipsols] = NULL;
3526+
sols[nmipsols + 1] = rootlpsol;
35263527

35273528
/* 1. Binary variables are fixed if their values agree in all the solutions */
35283529
if( nbinvars > 0 )

src/scip/heur_gins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ SCIP_RETCODE selectInitialVariableRandomly(
16101610
break;
16111611
}
16121612

1613-
assert(SCIPvarIsIntegral(choosevar));
1613+
assert(SCIPvarGetType(choosevar) == SCIP_VARTYPE_BINARY || SCIPvarGetType(choosevar) == SCIP_VARTYPE_INTEGER);
16141614

16151615
/* get neighborhood storage */
16161616
SCIP_CALL( SCIPallocBufferArray(scip, &neighborhood, nvars) );
@@ -1643,7 +1643,7 @@ SCIP_RETCODE selectInitialVariableRandomly(
16431643
neighborhood[neighborhoodsize++] = currvar;
16441644

16451645
/* increase discrete variables counter */
1646-
if( SCIPvarIsIntegral(currvar) )
1646+
if( SCIPvarGetType(currvar) <= SCIP_VARTYPE_INTEGER )
16471647
++ndiscvarsneighborhood;
16481648
}
16491649
}

0 commit comments

Comments
 (0)