Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v80-bugfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
scip-ci committed Jul 20, 2023
2 parents e1ce3e2 + f60730d commit 97efde3
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 97 deletions.
1 change: 1 addition & 0 deletions check/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ set(instances_MIP
"instances/MIP/lseu.mps\;1120"
"instances/MIP/MANN_a9.clq.lp\;16"
"instances/MIP/misc03.mps\;3360"
"instances/MIP/Negated.cip\;1"
"instances/MIP/p0033.osil\;3089"
"instances/MIP/p0548.mps\;8691"
"instances/MIP/rgn.mps\;82.19999924"
Expand Down
11 changes: 11 additions & 0 deletions check/instances/MIP/Negated.cip
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
STATISTICS
Problem name : model
Variables : 1 (1 binary, 0 integer, 0 implicit integer, 0 continuous)
Constraints : 1 initial, 1 maximal
OBJECTIVE
Sense : minimize
VARIABLES
[binary] <x0>: obj=1, original bounds=[0,1]
CONSTRAINTS
[linear] <c0>: +2<~x0>[B] <= 1;
END
2 changes: 1 addition & 1 deletion check/interactiveshell/readertest.bat.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ presolve
write transproblem temp/${basename}_trans.${extension}
read temp/${basename}_trans.${extension}
optimize
validatesolve "${optval}" "${optval}"
validatesolve inf "${optval}"
read temp/${basename}.${extension}
optimize
validatesolve "${optval}" "${optval}"
Expand Down
48 changes: 28 additions & 20 deletions src/scip/reader_fzn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3859,57 +3859,65 @@ SCIP_RETCODE readFZNFile(
* Local methods (for writing)
*/


/** transforms given variables, scalars, and constant to the corresponding active variables, scalars, and constant */
static
SCIP_RETCODE getActiveVariables(
SCIP* scip, /**< SCIP data structure */
SCIP_VAR** vars, /**< vars array to get active variables for */
SCIP_Real* scalars, /**< scalars a_1, ..., a_n in linear sum a_1*x_1 + ... + a_n*x_n + c */
SCIP_VAR*** vars, /**< pointer to vars array to get active variables for */
SCIP_Real** scalars, /**< pointer to scalars a_1, ..., a_n in linear sum a_1*x_1 + ... + a_n*x_n + c */
int* nvars, /**< pointer to number of variables and values in vars and vals array */
SCIP_Real* constant, /**< pointer to constant c in linear sum a_1*x_1 + ... + a_n*x_n + c */
SCIP_Bool transformed /**< transformed constraint? */
)
{
int requiredsize; /* number of active variables */
int requiredsize;
int v;

assert( scip != NULL );
assert( scalars != NULL );
assert( nvars != NULL );
assert( vars != NULL || *nvars == 0 );
assert( constant != NULL );
assert(scip != NULL);
assert(vars != NULL);
assert(scalars != NULL);
assert(nvars != NULL);
assert(*vars != NULL || *nvars == 0);
assert(*scalars != NULL || *nvars == 0);
assert(constant != NULL);

if( transformed )
{
SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, *nvars, constant, &requiredsize, TRUE) );

/* avoid overflow by reallocation */
if( requiredsize > *nvars )
{
SCIP_CALL( SCIPreallocBufferArray(scip, &vars, requiredsize) );
SCIP_CALL( SCIPreallocBufferArray(scip, &scalars, requiredsize) );
SCIP_CALL( SCIPreallocBufferArray(scip, vars, requiredsize) );
SCIP_CALL( SCIPreallocBufferArray(scip, scalars, requiredsize) );

SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, requiredsize, constant, &requiredsize, TRUE) );
SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize, TRUE) );
assert( requiredsize <= *nvars );
}
}
else
{
if( *nvars > 0 && (vars == NULL || scalars == NULL) ) /*lint !e774 !e845*/
if( *nvars > 0 && ( *vars == NULL || *scalars == NULL ) ) /*lint !e774 !e845*/
{
SCIPerrorMessage("Null pointer"); /* should not happen */
SCIPerrorMessage("Null pointer in FZN reader\n"); /* should not happen */
SCIPABORT();
return SCIP_INVALIDDATA; /*lint !e527*/
}

for( v = 0; v < *nvars; ++v )
{
assert(vars != NULL);
SCIP_CALL( SCIPvarGetOrigvarSum(&vars[v], &scalars[v], constant) );
SCIP_CALL( SCIPvarGetOrigvarSum(&(*vars)[v], &(*scalars)[v], constant) );

/* negated variables with an original counterpart may also be returned by SCIPvarGetOrigvarSum();
* make sure we get the original variable in that case
*/
if( SCIPvarGetStatus((*vars)[v]) == SCIP_VARSTATUS_NEGATED )
{
(*vars)[v] = SCIPvarGetNegatedVar((*vars)[v]);
*constant += (*scalars)[v];
(*scalars)[v] *= -1.0;
}
}
}

return SCIP_OKAY;
}

Expand Down Expand Up @@ -4144,7 +4152,7 @@ SCIP_RETCODE printLinearCons(
{
assert( activevars != NULL );
assert( activevals != NULL );
SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
SCIP_CALL( getActiveVariables(scip, &activevars, &activevals, &nactivevars, &activeconstant, transformed) );
}

/* If there may be continuous variables or coefficients in the constraint, scan for them */
Expand Down
13 changes: 10 additions & 3 deletions src/scip/reader_lp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2534,9 +2534,9 @@ SCIP_RETCODE getActiveVariables(
assert(scip != NULL);
assert(vars != NULL);
assert(scalars != NULL);
assert(*vars != NULL);
assert(*scalars != NULL);
assert(nvars != NULL);
assert(*vars != NULL || *nvars == 0);
assert(*scalars != NULL || *nvars == 0);
assert(constant != NULL);

if( transformed )
Expand All @@ -2554,6 +2554,13 @@ SCIP_RETCODE getActiveVariables(
}
else
{
if( *nvars > 0 && ( *vars == NULL || *scalars == NULL ) ) /*lint !e774 !e845*/
{
SCIPerrorMessage("Null pointer in LP reader\n"); /* should not happen */
SCIPABORT();
return SCIP_INVALIDDATA; /*lint !e527*/
}

for( v = 0; v < *nvars; ++v )
{
SCIP_CALL( SCIPvarGetOrigvarSum(&(*vars)[v], &(*scalars)[v], constant) );
Expand All @@ -2564,8 +2571,8 @@ SCIP_RETCODE getActiveVariables(
if( SCIPvarGetStatus((*vars)[v]) == SCIP_VARSTATUS_NEGATED )
{
(*vars)[v] = SCIPvarGetNegatedVar((*vars)[v]);
*constant += (*scalars)[v];
(*scalars)[v] *= -1.0;
*constant += 1.0;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scip/reader_mps.c
Original file line number Diff line number Diff line change
Expand Up @@ -2978,8 +2978,8 @@ SCIP_RETCODE getLinearCoeffs(
if( SCIPvarGetStatus(activevars[v]) == SCIP_VARSTATUS_NEGATED )
{
activevars[v] = SCIPvarGetNegatedVar(activevars[v]);
activeconstant += activevals[v];
activevals[v] *= -1.0;
activeconstant += 1.0;
}
}
}
Expand Down
107 changes: 50 additions & 57 deletions src/scip/reader_opb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2674,39 +2674,42 @@ SCIP_RETCODE printNonLinearCons(
SCIP_Real activeconstant;
SCIP_Longint mult;
SCIP_RETCODE retcode;
int v;
int nactivevars;
int v;

assert(scip != NULL);
assert(vars != NULL);
assert(nvars > 0);
assert(lhs <= rhs);
assert(vars != NULL || nvars == 0);
assert(resvars != NULL);
assert(nresvars > 0);
assert(andvars != NULL && nandvars != NULL);

if( SCIPisInfinity(scip, -lhs) && SCIPisInfinity(scip, rhs) )
return SCIP_OKAY;

activeconstant = 0.0;
nactivevars = nvars;
activevars = NULL;
activevals = NULL;
activeconstant = 0.0;

/* duplicate variable and value array */
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) );
if( vals != NULL )
{
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) );
}
else
if( vars != NULL )
{
SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) );
if( vals != NULL )
{
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) );
}
else
{
SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );

for( v = 0; v < nactivevars; ++v )
activevals[v] = 1.0;
}
for( v = 0; v < nactivevars; ++v )
activevals[v] = 1.0;
}

/* retransform given variables to active variables */
SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
/* retransform given variables to active variables */
SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
}

mult = 1;
retcode = SCIP_OKAY;
Expand Down Expand Up @@ -2740,8 +2743,11 @@ SCIP_RETCODE printNonLinearCons(
}

/* free buffer arrays */
SCIPfreeBufferArray(scip, &activevars);
SCIPfreeBufferArray(scip, &activevals);
if( vars != NULL )
{
SCIPfreeBufferArray(scip, &activevars);
SCIPfreeBufferArray(scip, &activevals);
}

return retcode;
}
Expand Down Expand Up @@ -2859,39 +2865,42 @@ SCIP_RETCODE printLinearCons(
{
SCIP_VAR** activevars;
SCIP_Real* activevals;
int nactivevars;
SCIP_Real activeconstant;
SCIP_Longint mult;
SCIP_RETCODE retcode;
int nactivevars;
int v;

assert( scip != NULL );
assert( vars != NULL );
assert( nvars > 0 );
assert( lhs <= rhs );
assert( vars != NULL || nvars == 0 );

if( SCIPisInfinity(scip, -lhs) && SCIPisInfinity(scip, rhs) )
return SCIP_OKAY;

nactivevars = nvars;
activevars = NULL;
activevals = NULL;
activeconstant = 0.0;

/* duplicate variable and value array */
nactivevars = nvars;
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) );
if( vals != NULL )
{
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) );
}
else
if( vars != NULL )
{
SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) );
if( vals != NULL )
{
SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) );
}
else
{
SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );

for( v = 0; v < nactivevars; ++v )
activevals[v] = 1.0;
}
for( v = 0; v < nactivevars; ++v )
activevals[v] = 1.0;
}

/* retransform given variables to active variables */
SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
/* retransform given variables to active variables */
SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
}

mult = 1;
retcode = SCIP_OKAY;
Expand Down Expand Up @@ -2925,8 +2934,11 @@ SCIP_RETCODE printLinearCons(
}

/* free buffer arrays */
SCIPfreeBufferArray(scip, &activevars);
SCIPfreeBufferArray(scip, &activevals);
if( vars != NULL )
{
SCIPfreeBufferArray(scip, &activevars);
SCIPfreeBufferArray(scip, &activevals);
}

return retcode;
}
Expand Down Expand Up @@ -3461,16 +3473,6 @@ SCIP_RETCODE writeOpbConstraints(
{
if( strcmp(conshdlrname, "linear") == 0 )
{
if( SCIPgetNVarsLinear(scip, cons) == 0 )
{
if( SCIPisGT(scip, SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons)) )
{
SCIPerrorMessage("Cannot print empty violated constraint %s, %g <= %g is not fulfilled\n",
SCIPconsGetName(cons), SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons));
}
continue;
}

if( existands )
{
retcode = printNonLinearCons(scip, file,
Expand All @@ -3490,9 +3492,6 @@ SCIP_RETCODE writeOpbConstraints(
consvars = SCIPgetVarsSetppc(scip, cons);
nconsvars = SCIPgetNVarsSetppc(scip, cons);

if( nconsvars == 0 )
continue;

switch( SCIPgetTypeSetppc(scip, cons) )
{
case SCIP_SETPPCTYPE_PARTITIONING :
Expand Down Expand Up @@ -3537,9 +3536,6 @@ SCIP_RETCODE writeOpbConstraints(
}
else if( strcmp(conshdlrname, "logicor") == 0 )
{
if( SCIPgetNVarsLogicor(scip, cons) == 0 )
continue;

if( existands )
{
retcode = printNonLinearCons(scip, file,
Expand All @@ -3560,9 +3556,6 @@ SCIP_RETCODE writeOpbConstraints(
consvars = SCIPgetVarsKnapsack(scip, cons);
nconsvars = SCIPgetNVarsKnapsack(scip, cons);

if( nconsvars == 0 )
continue;

/* copy Longint array to SCIP_Real array */
weights = SCIPgetWeightsKnapsack(scip, cons);
SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) );
Expand Down
Loading

0 comments on commit 97efde3

Please sign in to comment.