-
Notifications
You must be signed in to change notification settings - Fork 3
/
cons_conjunction.c
788 lines (641 loc) · 25.2 KB
/
cons_conjunction.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the program and library */
/* SCIP --- Solving Constraint Integer Programs */
/* */
/* Copyright (C) 2002-2014 Konrad-Zuse-Zentrum */
/* fuer Informationstechnik Berlin */
/* */
/* SCIP is distributed under the terms of the ZIB Academic License. */
/* */
/* You should have received a copy of the ZIB Academic License */
/* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file cons_conjunction.c
* @brief constraint handler for conjunction constraints
* @author Tobias Achterberg
*/
/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
#include <assert.h>
#include <string.h>
#include <limits.h>
#include "scip/cons_conjunction.h"
/* constraint handler properties */
#define CONSHDLR_NAME "conjunction"
#define CONSHDLR_DESC "conjunction of constraints"
#define CONSHDLR_ENFOPRIORITY +900000 /**< priority of the constraint handler for constraint enforcing */
#define CONSHDLR_CHECKPRIORITY -900000 /**< priority of the constraint handler for checking feasibility */
#define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
* propagation and enforcement, -1 for no eager evaluations, 0 for first only */
#define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
#define CONSHDLR_DELAYPRESOL FALSE /**< should presolving method be delayed, if other presolvers found reductions? */
#define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
/*
* Data structures
*/
/** constraint data for conjunction constraints */
struct SCIP_ConsData
{
SCIP_CONS** conss; /**< constraints in conjunction */
int consssize; /**< size of conss array */
int nconss; /**< number of constraints in conjunction */
};
/*
* Local methods
*/
/** creates conjunction constraint data, captures initial constraints of conjunction */
static
SCIP_RETCODE consdataCreate(
SCIP* scip, /**< SCIP data structure */
SCIP_CONSDATA** consdata, /**< pointer to constraint data */
SCIP_CONS** conss, /**< initial constraint in conjunction */
int nconss /**< number of initial constraints in conjunction */
)
{
assert(consdata != NULL);
SCIP_CALL( SCIPallocBlockMemory(scip, consdata) );
if( nconss > 0 )
{
SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &(*consdata)->conss, conss, nconss) );
(*consdata)->consssize = nconss;
(*consdata)->nconss = nconss;
if( SCIPisTransformed(scip) )
{
SCIP_CALL( SCIPtransformConss(scip, nconss, (*consdata)->conss, (*consdata)->conss) );
}
else
{
int c;
for( c = 0; c < nconss; ++c )
{
SCIP_CALL( SCIPcaptureCons(scip, conss[c]) );
}
}
}
else
{
(*consdata)->conss = NULL;
(*consdata)->consssize = 0;
(*consdata)->nconss = 0;
}
return SCIP_OKAY;
}
/** frees constraint data and releases all constraints in conjunction */
static
SCIP_RETCODE consdataFree(
SCIP* scip, /**< SCIP data structure */
SCIP_CONSDATA** consdata /**< pointer to constraint data */
)
{
int c;
assert(consdata != NULL);
assert(*consdata != NULL);
/* release constraints */
for( c = 0; c < (*consdata)->nconss; ++c )
{
SCIP_CALL( SCIPreleaseCons(scip, &(*consdata)->conss[c]) );
}
/* free memory */
SCIPfreeBlockMemoryArrayNull(scip, &(*consdata)->conss, (*consdata)->consssize);
SCIPfreeBlockMemory(scip, consdata);
return SCIP_OKAY;
}
/** adds constraint to conjunction */
static
SCIP_RETCODE consdataAddCons(
SCIP* scip, /**< SCIP data structure */
SCIP_CONSDATA* consdata, /**< constraint data */
SCIP_CONS* cons /**< constraint to add to the conjunction */
)
{
assert(consdata != NULL);
/* get memory for additional constraint */
SCIP_CALL( SCIPensureBlockMemoryArray(scip, &consdata->conss, &consdata->consssize, consdata->nconss+1) );
assert(consdata->conss != NULL);
assert(consdata->nconss < consdata->consssize);
/* insert constraint in array */
consdata->conss[consdata->nconss] = cons;
consdata->nconss++;
if( SCIPisTransformed(scip) )
{
SCIP_CALL( SCIPtransformCons(scip, consdata->conss[consdata->nconss - 1], &(consdata->conss[consdata->nconss - 1])) );
}
else
{
/* capture constraint */
SCIP_CALL( SCIPcaptureCons(scip, cons) );
}
return SCIP_OKAY;
}
/** adds all constraints in conjunction constraints to the problem; disables unmodifiable conjunction constraints */
static
SCIP_RETCODE addAllConss(
SCIP* scip, /**< SCIP data structure */
SCIP_CONS** conss, /**< active conjunction constraints */
int nconss, /**< number of active conjunction constraints */
SCIP_RESULT* result /**< pointer to store the result */
)
{
SCIP_CONSDATA* consdata;
int c;
int i;
assert(result != NULL);
for( c = 0; c < nconss; ++c )
{
consdata = SCIPconsGetData(conss[c]);
assert(consdata != NULL);
/* add all inactive constraints to local subproblem */
for( i = 0; i < consdata->nconss; ++i )
{
/* update check flag for sub constraints when upgrade takes place */
if( SCIPconsIsChecked(conss[c]) )
{
/* make sure, the constraint is checked for feasibility */
SCIP_CALL( SCIPsetConsChecked(scip, consdata->conss[i], TRUE) );
}
if( !SCIPconsIsActive(consdata->conss[i]) )
{
SCIPdebugMessage("adding constraint <%s> from add conjunction <%s>\n",
SCIPconsGetName(consdata->conss[i]), SCIPconsGetName(conss[c]));
SCIP_CALL( SCIPaddConsLocal(scip, consdata->conss[i], NULL) );
*result = SCIP_CONSADDED;
}
}
/* disable conjunction constraint, if it is unmodifiable */
if( !SCIPconsIsModifiable(conss[c]) )
{
SCIP_CALL( SCIPdelConsLocal(scip, conss[c]) );
}
}
return SCIP_OKAY;
}
/** checks all constraints in conjunction constraints for feasibility */
static
SCIP_RETCODE checkAllConss(
SCIP* scip, /**< SCIP data structure */
SCIP_CONS** conss, /**< active conjunction constraints */
int nconss, /**< number of active conjunction constraints */
SCIP_SOL* sol, /**< solution to check */
SCIP_Bool checkintegrality, /**< has integrality to be checked? */
SCIP_Bool checklprows, /**< have current LP rows to be checked? */
SCIP_Bool printreason, /**< should the reason for the violation be printed? */
SCIP_RESULT* result /**< pointer to store the result */
)
{
SCIP_CONSDATA* consdata;
int c;
int i;
assert(result != NULL);
for( c = 0; c < nconss && *result == SCIP_FEASIBLE; ++c )
{
consdata = SCIPconsGetData(conss[c]);
assert(consdata != NULL);
/* check all constraints */
for( i = 0; i < consdata->nconss && *result == SCIP_FEASIBLE; ++i )
{
SCIP_CALL( SCIPcheckCons(scip, consdata->conss[i], sol, checkintegrality, checklprows, printreason, result) );
assert(*result == SCIP_FEASIBLE || *result == SCIP_INFEASIBLE);
}
if( printreason && *result == SCIP_INFEASIBLE )
{
SCIPinfoMessage(scip, NULL, "conjunction constraint %s is violated, at least the sub-constraint %s is violated by this given solution\n", SCIPconsGetName(conss[c]), SCIPconsGetName(consdata->conss[i-1]));
SCIPdebug( SCIP_CALL( SCIPprintCons(scip, conss[c], NULL) ) );
}
}
return SCIP_OKAY;
}
/*
* Callback methods of constraint handler
*/
#if 0
/** copy method for constraint handler plugins (called when SCIP copies plugins) */
static
SCIP_DECL_CONSHDLRCOPY(conshdlrCopyConjunction)
{ /*lint --e{715}*/
assert(scip != NULL);
assert(conshdlr != NULL);
assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
/* call inclusion method of constraint handler */
SCIP_CALL( SCIPincludeConshdlrConjunction(scip) );
*valid = TRUE;
return SCIP_OKAY;
}
#endif
/** frees specific constraint data */
static
SCIP_DECL_CONSDELETE(consDeleteConjunction)
{ /*lint --e{715}*/
SCIP_CALL( consdataFree(scip, consdata) );
return SCIP_OKAY;
}
/** transforms constraint data into data belonging to the transformed problem */
static
SCIP_DECL_CONSTRANS(consTransConjunction)
{ /*lint --e{715}*/
SCIP_CONSDATA* sourcedata;
SCIP_CONSDATA* targetdata;
int c;
/* create constraint data for target constraint */
SCIP_CALL( SCIPallocBlockMemory(scip, &targetdata) );
/* get constraint data of source constraint */
sourcedata = SCIPconsGetData(sourcecons);
if( sourcedata->nconss > 0 )
{
targetdata->consssize = sourcedata->nconss;
targetdata->nconss = sourcedata->nconss;
SCIP_CALL( SCIPallocBlockMemoryArray(scip, &targetdata->conss, targetdata->consssize) );
for( c = 0; c < sourcedata->nconss; ++c )
{
SCIP_CALL( SCIPtransformCons(scip, sourcedata->conss[c], &targetdata->conss[c]) );
}
}
else
{
targetdata->conss = NULL;
targetdata->consssize = 0;
targetdata->nconss = 0;
}
/* create target constraint */
SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata,
SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons),
SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons),
SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons),
SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) );
return SCIP_OKAY;
}
/** constraint enforcing method of constraint handler for LP solutions */
static
SCIP_DECL_CONSENFOLP(consEnfolpConjunction)
{ /*lint --e{715}*/
*result = SCIP_FEASIBLE;
/* add all constraints to the current node */
SCIP_CALL( addAllConss(scip, conss, nconss, result) );
return SCIP_OKAY;
}
/** constraint enforcing method of constraint handler for pseudo solutions */
static
SCIP_DECL_CONSENFOPS(consEnfopsConjunction)
{ /*lint --e{715}*/
*result = SCIP_FEASIBLE;
/* add all constraints to the current node */
SCIP_CALL( addAllConss(scip, conss, nconss, result) );
return SCIP_OKAY;
}
/** feasibility check method of constraint handler for integral solutions */
static
SCIP_DECL_CONSCHECK(consCheckConjunction)
{ /*lint --e{715}*/
*result = SCIP_FEASIBLE;
/* check all constraints of the conjunction */
SCIP_CALL( checkAllConss(scip, conss, nconss, sol, checkintegrality, checklprows, printreason, result) );
return SCIP_OKAY;
}
/** presolving method of constraint handler */
static
SCIP_DECL_CONSPRESOL(consPresolConjunction)
{ /*lint --e{715}*/
SCIP_CONSDATA* consdata;
int c;
int i;
assert(result != NULL);
*result = SCIP_DIDNOTFIND;
/* all constraints in a conjunction constraint of the global problem can be added directly to the problem and
* removed from the conjunction constraint;
* an unmodifiable conjunction constraint can be deleted
*/
for( c = 0; c < nconss; ++c )
{
consdata = SCIPconsGetData(conss[c]);
assert(consdata != NULL);
/* add all inactive constraints to the global problem */
for( i = 0; i < consdata->nconss; ++i )
{
/* update check flag for sub constraints when upgrade takes place */
if( SCIPconsIsChecked(conss[c]) )
{
/* make sure, the constraint is checked for feasibility */
SCIP_CALL( SCIPsetConsChecked(scip, consdata->conss[i], TRUE) );
}
/* add constraint, if it is not active yet */
if( !SCIPconsIsActive(consdata->conss[i]) )
{
SCIPdebugMessage("adding constraint <%s> from add conjunction <%s>\n",
SCIPconsGetName(consdata->conss[i]), SCIPconsGetName(conss[c]));
SCIP_CALL( SCIPaddCons(scip, consdata->conss[i]) );
*result = SCIP_SUCCESS;
}
/* release constraint because it will be removed from the conjunction constraint */
SCIP_CALL( SCIPreleaseCons(scip, &(consdata->conss[i])) );
}
/* all constraints where removed, so we need to clear the array */
consdata->nconss = 0;
/* delete conjunction constraint, if it is unmodifiable */
if( !SCIPconsIsModifiable(conss[c]) )
{
SCIP_CALL( SCIPdelCons(scip, conss[c]) );
}
}
return SCIP_OKAY;
}
/** variable rounding lock method of constraint handler */
static
SCIP_DECL_CONSLOCK(consLockConjunction)
{ /*lint --e{715}*/
SCIP_CONSDATA* consdata;
int c;
consdata = SCIPconsGetData(cons);
assert(consdata != NULL);
/* lock sub constraints */
for( c = 0; c < consdata->nconss; ++c )
{
SCIP_CALL( SCIPaddConsLocks(scip, consdata->conss[c], nlockspos, nlocksneg) );
}
return SCIP_OKAY;
}
/** constraint display method of constraint handler */
static
SCIP_DECL_CONSPRINT(consPrintConjunction)
{ /*lint --e{715}*/
SCIP_CONSDATA* consdata;
int i;
assert( scip != NULL );
assert( conshdlr != NULL );
assert( cons != NULL );
consdata = SCIPconsGetData(cons);
assert(consdata != NULL);
SCIPinfoMessage(scip, file, "conjunction(");
for( i = 0; i < consdata->nconss; ++i )
{
if( i > 0 )
SCIPinfoMessage(scip, file, ", ");
SCIP_CALL( SCIPprintCons(scip, consdata->conss[i], file) );
}
SCIPinfoMessage(scip, file, ")");
return SCIP_OKAY;
}
/** constraint parsing method of constraint handler */
static
SCIP_DECL_CONSPARSE(consParseConjunction)
{ /*lint --e{715}*/
SCIP_CONS** conss;
int nconss;
int sconss;
char* token;
char* saveptr;
char* nexttokenstart;
char* copystr;
assert(scip != NULL);
assert(conshdlr != NULL);
assert(cons != NULL);
assert(success != NULL);
assert(str != NULL);
assert(name != NULL);
SCIPdebugMessage("parsing conjunction <%s>\n", name);
*success = TRUE;
/* allocate memory for constraint in conjunction, initial size is set to 10 */
nconss = 0;
sconss = 10;
SCIP_CALL( SCIPallocBufferArray(scip, &conss, sconss) );
SCIP_CALL( SCIPduplicateBufferArray(scip, ©str, str, (int)strlen(str)+1) );
/* find '(' at the beginning, string should start with 'conjunction(' */
saveptr = strpbrk(copystr, "("); /*lint !e158*/
if( saveptr == NULL )
{
SCIPdebugMessage("error parsing conjunctive constraint: \"%s\"\n", str);
*success = FALSE;
goto TERMINATE;
}
/* skip '(' */
++saveptr;
/* remember token start position */
nexttokenstart = saveptr;
/* brackets '(' and ')' can exist co we check for them and the constraint delimeter */
saveptr = strpbrk(saveptr, "(,");
/* brackets '(' and ')' can exist in the rest of the string so we need to skip them to find the end of the first
* sub-constraint marked by a ','
*/
if( saveptr != NULL )
{
do
{
int bracketcounter = 0;
if( *saveptr == '(' )
{
do
{
++bracketcounter;
++saveptr;
/* find last ending bracket */
while( bracketcounter > 0 )
{
saveptr = strpbrk(saveptr, "()");
if( saveptr != NULL )
{
if( *saveptr == '(' )
++bracketcounter;
else
--bracketcounter;
++saveptr;
}
else
{
SCIPdebugMessage("error parsing conjunctive constraint: \"%s\"\n", str);
*success = FALSE;
goto TERMINATE;
}
}
saveptr = strpbrk(saveptr, "(,");
}
while( saveptr != NULL && *saveptr == '(' );
}
/* we found a ',' so the end of the first sub-constraint is determined */
if( saveptr != NULL )
{
assert(*saveptr == ',');
/* resize constraint array if necessary */
if( nconss == sconss )
{
sconss = SCIPcalcMemGrowSize(scip, nconss+1);
assert(nconss < sconss);
SCIP_CALL( SCIPreallocBufferArray(scip, &conss, sconss) );
}
assert(saveptr > nexttokenstart);
/* extract token for parsing */
SCIP_CALL( SCIPduplicateBufferArray(scip, &token, nexttokenstart, saveptr - nexttokenstart + 1) );
token[saveptr - nexttokenstart] = '\0';
SCIPdebugMessage("conjunctive parsing token(constraint): %s\n", token);
/* parsing a constraint, part of the conjunction */
SCIP_CALL( SCIPparseCons(scip, &(conss[nconss]), token, initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, success) );
SCIPfreeBufferArray(scip, &token);
if( *success )
++nconss;
else
{
SCIPdebugMessage("error parsing conjunctive constraint: \"%s\"\n", str);
goto TERMINATE;
}
/* skip ',' delimeter */
++saveptr;
/* remember token start position */
nexttokenstart = saveptr;
saveptr = strpbrk(saveptr, "(,");
}
}
while( saveptr != NULL );
}
/* find end of conjunction constraint */
saveptr = strrchr(nexttokenstart, ')');
if( saveptr == NULL )
{
SCIPdebugMessage("error parsing conjunctive constraint: \"%s\"\n", str);
*success = FALSE;
goto TERMINATE;
}
/* parse last sub-constraint */
else
{
/* resize constraint array if necessary */
if( nconss == sconss )
{
++sconss;
SCIP_CALL( SCIPreallocBufferArray(scip, &conss, sconss) );
}
assert(saveptr > nexttokenstart);
/* extract token for parsing */
SCIP_CALL( SCIPduplicateBufferArray(scip, &token, nexttokenstart, saveptr - nexttokenstart + 1) );
token[saveptr - nexttokenstart] = '\0';
SCIPdebugMessage("conjunctive parsing token(constraint): %s\n", token);
/* parsing a constraint, part of the conjunction */
SCIP_CALL( SCIPparseCons(scip, &(conss[nconss]), token, initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, success) );
if( *success )
++nconss;
SCIPfreeBufferArray(scip, &token);
}
assert(nconss > 0 || !(*success));
/* if parsing sub-constraints was fine, create the conjunctive constraint */
if( *success )
{
/* create conjunctive constraint */
SCIP_CALL( SCIPcreateConsConjunction(scip, cons, name, nconss, conss,
enforce, check, local, modifiable, dynamic) );
}
/* free parsed constraints */
for( --nconss; nconss >= 0; --nconss )
{
SCIP_CALL( SCIPreleaseCons(scip, &conss[nconss]) );
}
TERMINATE:
/* free temporary memory */
SCIPfreeBufferArray(scip, ©str);
SCIPfreeBufferArray(scip, &conss);
return SCIP_OKAY;
}
/*
* constraint specific interface methods
*/
/** creates the handler for conjunction constraints and includes it in SCIP */
SCIP_RETCODE SCIPincludeConshdlrConjunction(
SCIP* scip /**< SCIP data structure */
)
{
SCIP_CONSHDLRDATA* conshdlrdata;
SCIP_CONSHDLR* conshdlr;
/* create conjunction constraint handler data */
conshdlrdata = NULL;
/* include constraint handler */
SCIP_CALL( SCIPincludeConshdlrBasic(scip, &conshdlr, CONSHDLR_NAME, CONSHDLR_DESC,
CONSHDLR_ENFOPRIORITY, CONSHDLR_CHECKPRIORITY, CONSHDLR_EAGERFREQ, CONSHDLR_NEEDSCONS,
consEnfolpConjunction, consEnfopsConjunction, consCheckConjunction, consLockConjunction,
conshdlrdata) );
assert(conshdlr != NULL);
/* set non-fundamental callbacks via specific setter functions */
SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteConjunction) );
SCIP_CALL( SCIPsetConshdlrParse(scip, conshdlr, consParseConjunction) );
SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolConjunction, CONSHDLR_MAXPREROUNDS,
CONSHDLR_DELAYPRESOL) );
SCIP_CALL( SCIPsetConshdlrPrint(scip, conshdlr, consPrintConjunction) );
SCIP_CALL( SCIPsetConshdlrTrans(scip, conshdlr, consTransConjunction) );
return SCIP_OKAY;
}
/** creates and captures a conjunction constraint
*
* @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
*/
SCIP_RETCODE SCIPcreateConsConjunction(
SCIP* scip, /**< SCIP data structure */
SCIP_CONS** cons, /**< pointer to hold the created constraint */
const char* name, /**< name of constraint */
int nconss, /**< number of initial constraints in conjunction */
SCIP_CONS** conss, /**< initial constraint in conjunction */
SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
* TRUE for model constraints, FALSE for additional, redundant constraints. */
SCIP_Bool check, /**< should the constraint be checked for feasibility?
* TRUE for model constraints, FALSE for additional, redundant constraints. */
SCIP_Bool local, /**< is constraint only valid locally?
* Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
* Usually set to FALSE. In column generation applications, set to TRUE if pricing
* adds coefficients to this constraint. */
SCIP_Bool dynamic /**< is constraint subject to aging?
* Usually set to FALSE. Set to TRUE for own cuts which
* are separated as constraints. */
)
{
SCIP_CONSHDLR* conshdlr;
SCIP_CONSDATA* consdata;
/* find the conjunction constraint handler */
conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
if( conshdlr == NULL )
{
SCIPerrorMessage("conjunction constraint handler not found\n");
return SCIP_PLUGINNOTFOUND;
}
/* create constraint data */
SCIP_CALL( consdataCreate(scip, &consdata, conss, nconss) );
/* create constraint */
SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, FALSE, FALSE, enforce, check, FALSE,
local, modifiable, dynamic, FALSE, FALSE) );
return SCIP_OKAY;
}
/** creates and captures an and constraint
* in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
* method SCIPcreateConsConjunction(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
*
* @see SCIPcreateConsConjunction() for information about the basic constraint flag configuration
*
* @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
*/
SCIP_RETCODE SCIPcreateConsBasicConjunction(
SCIP* scip, /**< SCIP data structure */
SCIP_CONS** cons, /**< pointer to hold the created constraint */
const char* name, /**< name of constraint */
int nconss, /**< number of initial constraints in conjunction */
SCIP_CONS** conss /**< initial constraint in conjunction */
)
{
assert(scip != NULL);
SCIP_CALL( SCIPcreateConsConjunction(scip, cons, name, nconss, conss,
TRUE, TRUE, FALSE, FALSE, FALSE) );
return SCIP_OKAY;
}
/** adds constraint to the conjunction of constraints */
SCIP_RETCODE SCIPaddConsElemConjunction(
SCIP* scip, /**< SCIP data structure */
SCIP_CONS* cons, /**< conjunction constraint */
SCIP_CONS* addcons /**< additional constraint in conjunction */
)
{
SCIP_CONSDATA* consdata;
assert(cons != NULL);
assert(addcons != NULL);
if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
{
SCIPerrorMessage("constraint is not a conjunction constraint\n");
return SCIP_INVALIDDATA;
}
consdata = SCIPconsGetData(cons);
assert(consdata != NULL);
SCIP_CALL( consdataAddCons(scip, consdata, addcons) );
return SCIP_OKAY;
}