Skip to content

Commit 5797258

Browse files
committed
Merge remote-tracking branch 'origin/v9-minor'
2 parents 8531b34 + b80f688 commit 5797258

File tree

2 files changed

+65
-13
lines changed

2 files changed

+65
-13
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Fixed bugs
149149
----------
150150

151151
- skip constraint propagation if the residual activity bound cancels the side precision in tightenVarBounds() of cons_linear.c
152+
- use indices of negation counterparts and accept fixings when ordering and-resultants of pseudoboolean constraints
152153

153154
Unit tests
154155
----------

src/scip/cons_pseudoboolean.c

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,25 +237,44 @@ struct SCIP_ConshdlrData
237237
/** comparison method for sorting and-resultants according to their problem index, which is used instead of the
238238
* original index because the implicit resultants are shuffled when creating the constraints that otherwise results in
239239
* shuffled problem copies,
240-
* if an and-resultant is deleted, it will be put in front with respect to its original index while sorting
240+
* if an and-resultant is fixed, it will be put in front with respect to its original index
241+
* if an and-resultant is negated, it will be put in front of its negation counterpart
241242
*/
242243
static
243244
SCIP_DECL_SORTPTRCOMP(resvarComp)
244245
{
245-
int varind1 = SCIPvarGetProbindex((SCIP_VAR*)elem1);
246-
int varind2 = SCIPvarGetProbindex((SCIP_VAR*)elem2);
246+
SCIP_VAR* var1 = elem1;
247+
SCIP_VAR* var2 = elem2;
248+
SCIP_Bool varneg1 = SCIPvarIsNegated(var1);
249+
SCIP_Bool varneg2 = SCIPvarIsNegated(var2);
250+
251+
if( varneg1 )
252+
var1 = SCIPvarGetNegatedVar(var1);
253+
254+
if( varneg2 )
255+
var2 = SCIPvarGetNegatedVar(var2);
256+
257+
int varind1 = SCIPvarGetProbindex(var1);
258+
int varind2 = SCIPvarGetProbindex(var2);
259+
260+
if( varind1 == -1 && varind2 == -1 )
261+
{
262+
varind1 = SCIPvarGetIndex(var1);
263+
varind2 = SCIPvarGetIndex(var2);
264+
}
247265

248266
if( varind1 < varind2 )
249267
return -1;
250-
else if( varind1 > varind2 )
268+
if( varind1 > varind2 )
269+
return +1;
270+
271+
if( varneg1 && !varneg2 )
272+
return -1;
273+
if( !varneg1 && varneg2 )
251274
return +1;
252-
else if( varind1 != -1 )
253-
{
254-
assert(elem1 == elem2);
255-
return 0;
256-
}
257275

258-
return SCIPvarComp(elem1, elem2);
276+
assert(elem1 == elem2);
277+
return 0;
259278
}
260279

261280
/** comparison method for sorting consanddatas according to the problem index of their corresponding and-resultants,
@@ -4219,6 +4238,7 @@ SCIP_RETCODE correctLocksAndCaptures(
42194238
SCIP_CONS* andcons;
42204239
SCIP_VAR* res1;
42214240
SCIP_VAR* res2;
4241+
int compval;
42224242

42234243
assert(consanddatas[c] != NULL);
42244244

@@ -4263,8 +4283,11 @@ SCIP_RETCODE correctLocksAndCaptures(
42634283
assert(res2 != NULL);
42644284
assert(SCIPhashmapGetImage(conshdlrdata->hashmap, (void*)res2) != NULL);
42654285

4286+
/* get comparison value */
4287+
compval = resvarComp((void*)res1, (void*)res2);
4288+
42664289
/* collect new consanddata objects sorted with respect to the problem index of corresponding and-resultants */
4267-
if( SCIPvarGetProbindex(res1) < SCIPvarGetProbindex(res2) )
4290+
if( compval == -1 )
42684291
{
42694292
assert(!SCIPisZero(scip, oldandcoefs[c]));
42704293
assert(consanddatas[c]->nuses > 0);
@@ -4279,7 +4302,7 @@ SCIP_RETCODE correctLocksAndCaptures(
42794302
consdata->propagated = FALSE;
42804303
consdata->presolved = FALSE;
42814304
}
4282-
else if( SCIPvarGetProbindex(res1) > SCIPvarGetProbindex(res2) )
4305+
else if( compval == +1 )
42834306
{
42844307
assert(!SCIPisZero(scip, andcoefs[c1]));
42854308
assert(SCIPhashmapExists(conshdlrdata->hashmap, (void*)res2));
@@ -4462,6 +4485,10 @@ SCIP_RETCODE correctLocksAndCaptures(
44624485
{
44634486
SCIP_VAR* res1;
44644487
SCIP_VAR* res2;
4488+
SCIP_Bool resneg1;
4489+
SCIP_Bool resneg2;
4490+
int resind1;
4491+
int resind2;
44654492

44664493
assert(consanddatas[c] != NULL);
44674494
assert(consanddatas[c]->cons != NULL);
@@ -4471,8 +4498,32 @@ SCIP_RETCODE correctLocksAndCaptures(
44714498
assert(consanddatas[c - 1]->cons != NULL);
44724499
res2 = SCIPgetResultantAnd(scip, consanddatas[c - 1]->cons);
44734500
assert(res2 != NULL);
4501+
resneg1 = SCIPvarIsNegated(res1);
4502+
if( resneg1 )
4503+
{
4504+
res1 = SCIPvarGetNegatedVar(res1);
4505+
assert(res1 != NULL);
4506+
}
4507+
resneg2 = SCIPvarIsNegated(res2);
4508+
if( resneg2 )
4509+
{
4510+
res2 = SCIPvarGetNegatedVar(res2);
4511+
assert(res2 != NULL);
4512+
}
4513+
resind1 = SCIPvarGetProbindex(res1);
4514+
resind2 = SCIPvarGetProbindex(res2);
4515+
if( resind1 == -1 && resind2 == -1 )
4516+
{
4517+
resind1 = SCIPvarGetIndex(res1);
4518+
resind2 = SCIPvarGetIndex(res2);
4519+
}
44744520

4475-
assert(SCIPvarGetProbindex(res1) > SCIPvarGetProbindex(res2));
4521+
if( resind1 <= resind2 )
4522+
{
4523+
assert(resind1 == resind2);
4524+
assert(!resneg1);
4525+
assert(resneg2);
4526+
}
44764527
}
44774528
#endif
44784529

0 commit comments

Comments
 (0)