Scippy

SCIP

Solving Constraint Integer Programs

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