@@ -237,25 +237,44 @@ struct SCIP_ConshdlrData
237
237
/** comparison method for sorting and-resultants according to their problem index, which is used instead of the
238
238
* original index because the implicit resultants are shuffled when creating the constraints that otherwise results in
239
239
* 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
241
242
*/
242
243
static
243
244
SCIP_DECL_SORTPTRCOMP (resvarComp )
244
245
{
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
+ }
247
265
248
266
if ( varind1 < varind2 )
249
267
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 )
251
274
return +1 ;
252
- else if ( varind1 != -1 )
253
- {
254
- assert (elem1 == elem2 );
255
- return 0 ;
256
- }
257
275
258
- return SCIPvarComp (elem1 , elem2 );
276
+ assert (elem1 == elem2 );
277
+ return 0 ;
259
278
}
260
279
261
280
/** comparison method for sorting consanddatas according to the problem index of their corresponding and-resultants,
@@ -4219,6 +4238,7 @@ SCIP_RETCODE correctLocksAndCaptures(
4219
4238
SCIP_CONS * andcons ;
4220
4239
SCIP_VAR * res1 ;
4221
4240
SCIP_VAR * res2 ;
4241
+ int compval ;
4222
4242
4223
4243
assert (consanddatas [c ] != NULL );
4224
4244
@@ -4263,8 +4283,11 @@ SCIP_RETCODE correctLocksAndCaptures(
4263
4283
assert (res2 != NULL );
4264
4284
assert (SCIPhashmapGetImage (conshdlrdata -> hashmap , (void * )res2 ) != NULL );
4265
4285
4286
+ /* get comparison value */
4287
+ compval = resvarComp ((void * )res1 , (void * )res2 );
4288
+
4266
4289
/* 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 )
4268
4291
{
4269
4292
assert (!SCIPisZero (scip , oldandcoefs [c ]));
4270
4293
assert (consanddatas [c ]-> nuses > 0 );
@@ -4279,7 +4302,7 @@ SCIP_RETCODE correctLocksAndCaptures(
4279
4302
consdata -> propagated = FALSE;
4280
4303
consdata -> presolved = FALSE;
4281
4304
}
4282
- else if ( SCIPvarGetProbindex ( res1 ) > SCIPvarGetProbindex ( res2 ) )
4305
+ else if ( compval == +1 )
4283
4306
{
4284
4307
assert (!SCIPisZero (scip , andcoefs [c1 ]));
4285
4308
assert (SCIPhashmapExists (conshdlrdata -> hashmap , (void * )res2 ));
@@ -4462,6 +4485,10 @@ SCIP_RETCODE correctLocksAndCaptures(
4462
4485
{
4463
4486
SCIP_VAR * res1 ;
4464
4487
SCIP_VAR * res2 ;
4488
+ SCIP_Bool resneg1 ;
4489
+ SCIP_Bool resneg2 ;
4490
+ int resind1 ;
4491
+ int resind2 ;
4465
4492
4466
4493
assert (consanddatas [c ] != NULL );
4467
4494
assert (consanddatas [c ]-> cons != NULL );
@@ -4471,8 +4498,32 @@ SCIP_RETCODE correctLocksAndCaptures(
4471
4498
assert (consanddatas [c - 1 ]-> cons != NULL );
4472
4499
res2 = SCIPgetResultantAnd (scip , consanddatas [c - 1 ]-> cons );
4473
4500
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
+ }
4474
4520
4475
- assert (SCIPvarGetProbindex (res1 ) > SCIPvarGetProbindex (res2 ));
4521
+ if ( resind1 <= resind2 )
4522
+ {
4523
+ assert (resind1 == resind2 );
4524
+ assert (!resneg1 );
4525
+ assert (resneg2 );
4526
+ }
4476
4527
}
4477
4528
#endif
4478
4529
0 commit comments