Skip to content

Commit 2165263

Browse files
Merge branch 'fix-var-exact' into 'master'
Initialize real values See merge request integer/scip!3820
2 parents 57a6893 + d92b3a9 commit 2165263

File tree

6 files changed

+145
-117
lines changed

6 files changed

+145
-117
lines changed

check/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ set(basenames_opb_wrongformat
831831
flugpl_rational.mps
832832
gt2.mps
833833
lseu_dcmulti.cip
834-
MANN_a9.clq.lp
835834
misc03.mps
836835
misc03.zpl
837836
rgn.mps

src/scip/cons_indicator.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,8 @@ SCIP_DECL_EVENTEXEC(eventExecIndicatorRestart)
776776
SCIP_Real oldbound;
777777
SCIP_Real newbound;
778778

779-
assert( SCIPvarGetType(SCIPeventGetVar(event)) == SCIP_VARTYPE_BINARY &&
780-
!SCIPvarIsImpliedIntegral(SCIPeventGetVar(event)) );
779+
assert( SCIPvarIsBinary(SCIPeventGetVar(event)) );
780+
assert( !SCIPvarIsImpliedIntegral(SCIPeventGetVar(event)) );
781781
oldbound = SCIPeventGetOldbound(event);
782782
newbound = SCIPeventGetNewbound(event);
783783
assert( SCIPisIntegral(scip, oldbound) );
@@ -3411,7 +3411,7 @@ SCIP_RETCODE consdataCreate(
34113411
(*consdata)->binvar = var;
34123412

34133413
/* check type */
3414-
if ( SCIPvarGetType(var) != SCIP_VARTYPE_BINARY || SCIPvarIsImpliedIntegral(var) )
3414+
if ( !SCIPvarIsBinary(var) || SCIPvarIsImpliedIntegral(var) )
34153415
{
34163416
SCIPerrorMessage("Indicator variable <%s> is not binary %d.\n", SCIPvarGetName(var), SCIPvarGetType(var));
34173417
return SCIP_ERROR;
@@ -4639,11 +4639,8 @@ SCIP_RETCODE separateIISRounding(
46394639

46404640
/* check whether complementary (negated) variable is present as well */
46414641
binvarneg = SCIPvarGetNegatedVar(consdata->binvar);
4642-
assert( binvarneg != NULL );
4643-
4644-
/* negated variable is present as well */
46454642
assert( conshdlrdata->binvarhash != NULL );
4646-
if ( SCIPhashmapExists(conshdlrdata->binvarhash, (void*) binvarneg) )
4643+
if ( binvarneg != NULL && SCIPhashmapExists(conshdlrdata->binvarhash, (void*) binvarneg) )
46474644
{
46484645
SCIP_Real binvarnegval = SCIPgetVarSol(scip, binvarneg);
46494646

@@ -8956,7 +8953,7 @@ SCIP_RETCODE SCIPsetBinaryVarIndicator(
89568953
assert( consdata != NULL );
89578954

89588955
/* check type */
8959-
if ( SCIPvarGetType(binvar) != SCIP_VARTYPE_BINARY || SCIPvarIsImpliedIntegral(binvar) )
8956+
if ( !SCIPvarIsBinary(binvar) || SCIPvarIsImpliedIntegral(binvar) )
89608957
{
89618958
SCIPerrorMessage("Indicator variable <%s> is not binary %d.\n", SCIPvarGetName(binvar), SCIPvarGetType(binvar));
89628959
return SCIP_ERROR;

src/scip/cons_xor.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,26 +1074,9 @@ SCIP_RETCODE applyFixings(
10741074

10751075
if( aggregated )
10761076
{
1077-
(*naggrvars)++;
1078-
1079-
if( SCIPvarIsActive(newvar) )
1080-
{
1081-
SCIP_CALL( setIntvar(scip, cons, newvar) );
1082-
SCIP_CALL( SCIPreleaseVar(scip, &newvar) );
1083-
}
1084-
/* the new variable should only by inactive if it was fixed due to the aggregation, so also the old variable
1085-
* should be fixed now.
1086-
*
1087-
* @todo if newvar is not active we may want to transform the xor into a linear constraint
1088-
*/
1089-
else
1090-
{
1091-
assert(SCIPvarGetStatus(newvar) == SCIP_VARSTATUS_FIXED);
1092-
assert(SCIPisEQ(scip, SCIPvarGetLbGlobal(consdata->intvar), SCIPvarGetUbGlobal(consdata->intvar)));
1093-
1094-
SCIP_CALL( setIntvar(scip, cons, newvar) );
1095-
SCIP_CALL( SCIPreleaseVar(scip, &newvar) );
1096-
}
1077+
++(*naggrvars);
1078+
SCIP_CALL( setIntvar(scip, cons, newvar) );
1079+
SCIP_CALL( SCIPreleaseVar(scip, &newvar) );
10971080
}
10981081
else
10991082
{
@@ -4306,7 +4289,7 @@ SCIP_RETCODE preprocessConstraintPairs(
43064289

43074290
if( aggregated )
43084291
{
4309-
(*naggrvars)++;
4292+
++(*naggrvars);
43104293
assert(SCIPvarIsActive(consdata0->intvar));
43114294
}
43124295
else
@@ -4460,7 +4443,7 @@ SCIP_RETCODE preprocessConstraintPairs(
44604443

44614444
*cutoff = *cutoff || infeasible;
44624445
if( aggregated )
4463-
(*naggrvars)++;
4446+
++(*naggrvars);
44644447

44654448
if( redundant )
44664449
{
@@ -4483,7 +4466,7 @@ SCIP_RETCODE preprocessConstraintPairs(
44834466

44844467
*cutoff = *cutoff || infeasible;
44854468
if( aggregated )
4486-
(*naggrvars)++;
4469+
++(*naggrvars);
44874470
}
44884471
}
44894472
}
@@ -5415,7 +5398,7 @@ SCIP_DECL_CONSPRESOL(consPresolXor)
54155398
if( aggregated )
54165399
{
54175400
assert(redundant);
5418-
(*naggrvars)++;
5401+
++(*naggrvars);
54195402
}
54205403

54215404
/* the constraint can be deleted if the intvar is fixed or NULL */

src/scip/reader_opb.c

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4613,23 +4613,29 @@ SCIP_RETCODE SCIPwriteOpb(
46134613
SCIP_CONSHDLR* indicatorhdlr = SCIPfindConshdlr(scip, "indicator");
46144614
SCIP_Bool existands;
46154615
SCIP_Bool existandconshdlr;
4616+
SCIP_Bool ispseudoboolean;
46164617
SCIP_RETCODE retcode = SCIP_OKAY;
46174618
int* nandvars;
4618-
int nresvars;
4619+
int nintegralvars = nvars - ncontvars;
46194620
int nindicatorconss = indicatorhdlr != NULL ? SCIPconshdlrGetNConss(indicatorhdlr) : 0;
4621+
int nresvars;
46204622
int v;
46214623

4622-
/* computes all and-resultants and their corresponding constraint variables */
4623-
/* coverity[leaked_storage] */
4624-
SCIP_CALL( computeAndConstraintInfos(scip, transformed, &resvars, &nresvars, &andvars, &nandvars, &existandconshdlr, &existands) );
4625-
4626-
if( nintvars > 0 || ncontvars > nindicatorconss )
4624+
/* check whether problem is pseudoboolean */
4625+
ispseudoboolean = (ncontvars <= nindicatorconss);
4626+
for( v = nbinvars; v < nintegralvars && ispseudoboolean; ++v )
46274627
{
4628-
SCIPwarningMessage(scip, "only binary problems can be written in OPB format.\n");
4629-
*result = SCIP_DIDNOTRUN;
4628+
if( !SCIPvarIsBinary(vars[v])
4629+
&& ( SCIPvarGetType(vars[v]) == SCIP_VARTYPE_INTEGER || ++ncontvars > nindicatorconss ) )
4630+
ispseudoboolean = FALSE;
46304631
}
4631-
else
4632+
4633+
if( ispseudoboolean )
46324634
{
4635+
/* computes all and-resultants and their corresponding constraint variables */
4636+
/* coverity[leaked_storage] */
4637+
SCIP_CALL( computeAndConstraintInfos(scip, transformed, &resvars, &nresvars, &andvars, &nandvars, &existandconshdlr, &existands) );
4638+
46334639
if( genericnames )
46344640
{
46354641
#ifndef NDEBUG
@@ -4733,25 +4739,30 @@ SCIP_RETCODE SCIPwriteOpb(
47334739
}
47344740
}
47354741

4736-
*result = SCIP_SUCCESS;
4737-
}
4742+
if( existands )
4743+
{
4744+
/* free temporary buffers */
4745+
assert(resvars != NULL);
4746+
assert(andvars != NULL);
4747+
assert(nandvars != NULL);
47384748

4739-
if( existands )
4740-
{
4741-
/* free temporary buffers */
4742-
assert(resvars != NULL);
4743-
assert(andvars != NULL);
4744-
assert(nandvars != NULL);
4749+
for( v = nresvars - 1; v >= 0; --v )
4750+
{
4751+
assert(andvars[v] != NULL);
4752+
SCIPfreeMemoryArray(scip, &andvars[v]);
4753+
}
47454754

4746-
for( v = nresvars - 1; v >= 0; --v )
4747-
{
4748-
assert(andvars[v] != NULL);
4749-
SCIPfreeMemoryArray(scip, &andvars[v]);
4755+
SCIPfreeMemoryArray(scip, &nandvars);
4756+
SCIPfreeMemoryArray(scip, &andvars);
4757+
SCIPfreeMemoryArray(scip, &resvars);
47504758
}
47514759

4752-
SCIPfreeMemoryArray(scip, &nandvars);
4753-
SCIPfreeMemoryArray(scip, &andvars);
4754-
SCIPfreeMemoryArray(scip, &resvars);
4760+
*result = SCIP_SUCCESS;
4761+
}
4762+
else
4763+
{
4764+
SCIPwarningMessage(scip, "only binary problems can be written in OPB format.\n");
4765+
*result = SCIP_DIDNOTRUN;
47554766
}
47564767

47574768
if( retcode == SCIP_INVALIDDATA )

0 commit comments

Comments
 (0)