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-2017 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  SCIPdebugMsg(scip, "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_Bool completely, /**< Should all violations be checked? */
218  SCIP_RESULT* result /**< pointer to store the result */
219  )
220 {
221  SCIP_CONSDATA* consdata;
222  int c;
223  int i;
224 
225  assert(result != NULL);
226 
227  *result = SCIP_FEASIBLE;
228 
229  for( c = 0; c < nconss && (*result == SCIP_FEASIBLE || completely); ++c )
230  {
231  SCIP_RESULT subresult = SCIP_FEASIBLE;
232 
233  consdata = SCIPconsGetData(conss[c]);
234  assert(consdata != NULL);
235 
236  /* check all constraints */
237  for( i = 0; i < consdata->nconss && subresult == SCIP_FEASIBLE; ++i )
238  {
239  SCIP_CALL( SCIPcheckCons(scip, consdata->conss[i], sol, checkintegrality, checklprows, printreason, &subresult) );
240  assert(subresult == SCIP_FEASIBLE || subresult == SCIP_INFEASIBLE);
241  }
242 
243  if( subresult == SCIP_INFEASIBLE )
244  {
245  /* mark solution as violated */
246  *result = SCIP_INFEASIBLE;
247  if( printreason )
248  {
249  assert( 0 < i && i <= consdata->nconss );
250  SCIPinfoMessage(scip, NULL, "Conjunction constraint %s is violated, at least the sub-constraint %s is violated by this given solution.\n",
251  SCIPconsGetName(conss[c]), SCIPconsGetName(consdata->conss[i-1]));
252  SCIPdebug( SCIP_CALL( SCIPprintCons(scip, conss[c], NULL) ) );
253  }
254  }
255  }
256 
257  return SCIP_OKAY;
258 }
259 
260 
261 /*
262  * Callback methods of constraint handler
263  */
264 
265 
266  /** copy method for constraint handler plugins (called when SCIP copies plugins) */
267 static
268 SCIP_DECL_CONSHDLRCOPY(conshdlrCopyConjunction)
269 { /*lint --e{715}*/
270  assert(scip != NULL);
271  assert(conshdlr != NULL);
272  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
273 
274  /* call inclusion method of constraint handler */
276 
277  *valid = TRUE;
278 
279  return SCIP_OKAY;
280 }
281 
282 
283 /** frees specific constraint data */
284 static
285 SCIP_DECL_CONSDELETE(consDeleteConjunction)
286 { /*lint --e{715}*/
287  SCIP_CALL( consdataFree(scip, consdata) );
288 
289  return SCIP_OKAY;
290 }
291 
292 /** transforms constraint data into data belonging to the transformed problem */
293 static
294 SCIP_DECL_CONSTRANS(consTransConjunction)
295 { /*lint --e{715}*/
296  SCIP_CONSDATA* sourcedata;
297  SCIP_CONSDATA* targetdata;
298  int c;
299 
300  /* create constraint data for target constraint */
301  SCIP_CALL( SCIPallocBlockMemory(scip, &targetdata) );
302 
303  /* get constraint data of source constraint */
304  sourcedata = SCIPconsGetData(sourcecons);
305 
306  if( sourcedata->nconss > 0 )
307  {
308  targetdata->consssize = sourcedata->nconss;
309  targetdata->nconss = sourcedata->nconss;
310  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &targetdata->conss, targetdata->consssize) );
311  for( c = 0; c < sourcedata->nconss; ++c )
312  {
313  SCIP_CALL( SCIPtransformCons(scip, sourcedata->conss[c], &targetdata->conss[c]) );
314  }
315  }
316  else
317  {
318  targetdata->conss = NULL;
319  targetdata->consssize = 0;
320  targetdata->nconss = 0;
321  }
322 
323  /* create target constraint */
324  SCIP_CALL( SCIPcreateCons(scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata,
325  SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons), SCIPconsIsEnforced(sourcecons),
326  SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons),
327  SCIPconsIsLocal(sourcecons), SCIPconsIsModifiable(sourcecons),
328  SCIPconsIsDynamic(sourcecons), SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) );
329 
330  return SCIP_OKAY;
331 }
332 
333 
334 /** constraint enforcing method of constraint handler for LP solutions */
335 static
336 SCIP_DECL_CONSENFOLP(consEnfolpConjunction)
337 { /*lint --e{715}*/
338  *result = SCIP_FEASIBLE;
339 
340  /* add all constraints to the current node */
341  SCIP_CALL( addAllConss(scip, conss, nconss, result) );
342 
343  return SCIP_OKAY;
344 }
345 
346 
347 /** constraint enforcing method of constraint handler for relaxation solutions */
348 static
349 SCIP_DECL_CONSENFORELAX(consEnforelaxConjunction)
350 { /*lint --e{715}*/
351  *result = SCIP_FEASIBLE;
352 
353  /* add all constraints to the current node */
354  SCIP_CALL( addAllConss(scip, conss, nconss, result) );
355 
356  return SCIP_OKAY;
357 }
358 
359 
360 /** constraint enforcing method of constraint handler for pseudo solutions */
361 static
362 SCIP_DECL_CONSENFOPS(consEnfopsConjunction)
363 { /*lint --e{715}*/
364  *result = SCIP_FEASIBLE;
365 
366  /* add all constraints to the current node */
367  SCIP_CALL( addAllConss(scip, conss, nconss, result) );
368 
369  return SCIP_OKAY;
370 }
371 
372 
373 /** feasibility check method of constraint handler for integral solutions */
374 static
375 SCIP_DECL_CONSCHECK(consCheckConjunction)
376 { /*lint --e{715}*/
377  *result = SCIP_FEASIBLE;
378 
379  /* check all constraints of the conjunction */
380  SCIP_CALL( checkAllConss(scip, conss, nconss, sol, checkintegrality, checklprows, printreason, completely, result) );
381 
382  return SCIP_OKAY;
383 }
384 
385 
386 /** presolving method of constraint handler */
387 static
388 SCIP_DECL_CONSPRESOL(consPresolConjunction)
389 { /*lint --e{715}*/
390  SCIP_CONSDATA* consdata;
391  int c;
392  int i;
393 
394  assert(result != NULL);
395 
396  *result = SCIP_DIDNOTFIND;
397 
398  /* all constraints in a conjunction constraint of the global problem can be added directly to the problem and
399  * removed from the conjunction constraint;
400  * an unmodifiable conjunction constraint can be deleted
401  */
402  for( c = 0; c < nconss; ++c )
403  {
404  consdata = SCIPconsGetData(conss[c]);
405  assert(consdata != NULL);
406 
407  /* add all inactive constraints to the global problem */
408  for( i = 0; i < consdata->nconss; ++i )
409  {
410  /* update check flag for sub constraints when upgrade takes place */
411  if( SCIPconsIsChecked(conss[c]) )
412  {
413  /* make sure, the constraint is checked for feasibility */
414  SCIP_CALL( SCIPsetConsChecked(scip, consdata->conss[i], TRUE) );
415  }
416 
417  /* add constraint, if it is not active yet */
418  if( !SCIPconsIsActive(consdata->conss[i]) )
419  {
420  SCIPdebugMsg(scip, "adding constraint <%s> from add conjunction <%s>\n",
421  SCIPconsGetName(consdata->conss[i]), SCIPconsGetName(conss[c]));
422  SCIP_CALL( SCIPaddCons(scip, consdata->conss[i]) );
423  *result = SCIP_SUCCESS;
424  }
425  /* release constraint because it will be removed from the conjunction constraint */
426  SCIP_CALL( SCIPreleaseCons(scip, &(consdata->conss[i])) );
427  }
428  /* all constraints where removed, so we need to clear the array */
429  consdata->nconss = 0;
430 
431  /* delete conjunction constraint, if it is unmodifiable */
432  if( !SCIPconsIsModifiable(conss[c]) )
433  {
434  SCIP_CALL( SCIPdelCons(scip, conss[c]) );
435  }
436  }
437 
438  return SCIP_OKAY;
439 }
440 
441 
442 /** variable rounding lock method of constraint handler */
443 static
444 SCIP_DECL_CONSLOCK(consLockConjunction)
445 { /*lint --e{715}*/
446  SCIP_CONSDATA* consdata;
447  int c;
448 
449  consdata = SCIPconsGetData(cons);
450  assert(consdata != NULL);
451 
452  /* lock sub constraints */
453  for( c = 0; c < consdata->nconss; ++c )
454  {
455  SCIP_CALL( SCIPaddConsLocks(scip, consdata->conss[c], nlockspos, nlocksneg) );
456  }
457 
458  return SCIP_OKAY;
459 }
460 
461 
462 /** constraint display method of constraint handler */
463 static
464 SCIP_DECL_CONSPRINT(consPrintConjunction)
465 { /*lint --e{715}*/
466  SCIP_CONSDATA* consdata;
467  int i;
468 
469  assert( scip != NULL );
470  assert( conshdlr != NULL );
471  assert( cons != NULL );
472 
473  consdata = SCIPconsGetData(cons);
474  assert(consdata != NULL);
475 
476  SCIPinfoMessage(scip, file, "conjunction(");
477 
478  for( i = 0; i < consdata->nconss; ++i )
479  {
480  if( i > 0 )
481  SCIPinfoMessage(scip, file, ", ");
482  SCIP_CALL( SCIPprintCons(scip, consdata->conss[i], file) );
483  }
484  SCIPinfoMessage(scip, file, ")");
485 
486  return SCIP_OKAY;
487 }
488 
489 /** constraint parsing method of constraint handler */
490 static
491 SCIP_DECL_CONSPARSE(consParseConjunction)
492 { /*lint --e{715}*/
493  SCIP_CONS** conss;
494  int nconss;
495  int sconss;
496  char* token;
497  char* saveptr;
498  char* nexttokenstart;
499  char* copystr;
500 
501  assert(scip != NULL);
502  assert(conshdlr != NULL);
503  assert(cons != NULL);
504  assert(success != NULL);
505  assert(str != NULL);
506  assert(name != NULL);
507 
508  SCIPdebugMsg(scip, "parsing conjunction <%s>\n", name);
509 
510  *success = TRUE;
511 
512  /* allocate memory for constraint in conjunction, initial size is set to 10 */
513  nconss = 0;
514  sconss = 10;
515  SCIP_CALL( SCIPallocBufferArray(scip, &conss, sconss) );
516  SCIP_CALL( SCIPduplicateBufferArray(scip, &copystr, str, (int)strlen(str)+1) );
517 
518  /* find '(' at the beginning, string should start with 'conjunction(' */
519  saveptr = strpbrk(copystr, "("); /*lint !e158*/
520 
521  if( saveptr == NULL )
522  {
523  SCIPdebugMsg(scip, "error parsing conjunctive constraint: \"%s\"\n", str);
524  *success = FALSE;
525  goto TERMINATE;
526  }
527 
528  /* skip '(' */
529  ++saveptr;
530  /* remember token start position */
531  nexttokenstart = saveptr;
532 
533  /* brackets '(' and ')' can exist co we check for them and the constraint delimeter */
534  saveptr = strpbrk(saveptr, "(,");
535 
536  /* brackets '(' and ')' can exist in the rest of the string so we need to skip them to find the end of the first
537  * sub-constraint marked by a ','
538  */
539  if( saveptr != NULL )
540  {
541  do
542  {
543  int bracketcounter = 0;
544 
545  if( *saveptr == '(' )
546  {
547  do
548  {
549  ++bracketcounter;
550  ++saveptr;
551 
552  /* find last ending bracket */
553  while( bracketcounter > 0 )
554  {
555  saveptr = strpbrk(saveptr, "()");
556 
557  if( saveptr != NULL )
558  {
559  if( *saveptr == '(' )
560  ++bracketcounter;
561  else
562  --bracketcounter;
563 
564  ++saveptr;
565  }
566  else
567  {
568  SCIPdebugMsg(scip, "error parsing conjunctive constraint: \"%s\"\n", str);
569  *success = FALSE;
570  goto TERMINATE;
571  }
572  }
573 
574  saveptr = strpbrk(saveptr, "(,");
575  }
576  while( saveptr != NULL && *saveptr == '(' );
577  }
578 
579  /* we found a ',' so the end of the first sub-constraint is determined */
580  if( saveptr != NULL )
581  {
582  assert(*saveptr == ',');
583 
584  /* resize constraint array if necessary */
585  if( nconss == sconss )
586  {
587  sconss = SCIPcalcMemGrowSize(scip, nconss+1);
588  assert(nconss < sconss);
589 
590  SCIP_CALL( SCIPreallocBufferArray(scip, &conss, sconss) );
591  }
592 
593  assert(saveptr > nexttokenstart);
594 
595  /* extract token for parsing */
596  SCIP_CALL( SCIPduplicateBufferArray(scip, &token, nexttokenstart, saveptr - nexttokenstart + 1) );
597  token[saveptr - nexttokenstart] = '\0';
598 
599  SCIPdebugMsg(scip, "conjunctive parsing token(constraint): %s\n", token);
600 
601  /* parsing a constraint, part of the conjunction */
602  SCIP_CALL( SCIPparseCons(scip, &(conss[nconss]), token, initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, success) );
603 
604  SCIPfreeBufferArray(scip, &token);
605 
606  if( *success )
607  ++nconss;
608  else
609  {
610  SCIPdebugMsg(scip, "error parsing conjunctive constraint: \"%s\"\n", str);
611  goto TERMINATE;
612  }
613  /* skip ',' delimeter */
614  ++saveptr;
615  /* remember token start position */
616  nexttokenstart = saveptr;
617 
618  saveptr = strpbrk(saveptr, "(,");
619  }
620  }
621  while( saveptr != NULL );
622  }
623 
624  /* find end of conjunction constraint */
625  saveptr = strrchr(nexttokenstart, ')');
626 
627  if( saveptr == NULL )
628  {
629  SCIPdebugMsg(scip, "error parsing conjunctive constraint: \"%s\"\n", str);
630  *success = FALSE;
631  goto TERMINATE;
632  }
633  /* parse last sub-constraint */
634  else
635  {
636  /* resize constraint array if necessary */
637  if( nconss == sconss )
638  {
639  ++sconss;
640  SCIP_CALL( SCIPreallocBufferArray(scip, &conss, sconss) );
641  }
642 
643  assert(saveptr > nexttokenstart);
644 
645  /* extract token for parsing */
646  SCIP_CALL( SCIPduplicateBufferArray(scip, &token, nexttokenstart, saveptr - nexttokenstart + 1) );
647  token[saveptr - nexttokenstart] = '\0';
648 
649  SCIPdebugMsg(scip, "conjunctive parsing token(constraint): %s\n", token);
650 
651  /* parsing a constraint, part of the conjunction */
652  SCIP_CALL( SCIPparseCons(scip, &(conss[nconss]), token, initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, success) );
653 
654  if( *success )
655  ++nconss;
656 
657  SCIPfreeBufferArray(scip, &token);
658  }
659  assert(nconss > 0 || !(*success));
660 
661  /* if parsing sub-constraints was fine, create the conjunctive constraint */
662  if( *success )
663  {
664  /* create conjunctive constraint */
665  SCIP_CALL( SCIPcreateConsConjunction(scip, cons, name, nconss, conss,
666  enforce, check, local, modifiable, dynamic) );
667  }
668 
669  /* free parsed constraints */
670  for( --nconss; nconss >= 0; --nconss )
671  {
672  SCIP_CALL( SCIPreleaseCons(scip, &conss[nconss]) );
673  }
674 
675  TERMINATE:
676  /* free temporary memory */
677  SCIPfreeBufferArray(scip, &copystr);
678  SCIPfreeBufferArray(scip, &conss);
679 
680  return SCIP_OKAY;
681 }
682 
683 /** constraint copying method of constraint handler */
684 static
685 SCIP_DECL_CONSCOPY(consCopyConjunction)
686 { /*lint --e{715}*/
687  SCIP_CONSDATA* sourcedata;
688  SCIP_CONS** sourceconss;
689  SCIP_CONS** conss;
690  int nconss;
691  int c;
692 
693  *valid = TRUE;
694 
695  sourcedata = SCIPconsGetData(sourcecons);
696  assert(sourcedata != NULL);
697 
698  sourceconss = sourcedata->conss;
699  nconss = sourcedata->nconss;
700 
701  if( nconss > 0 )
702  {
703  assert(sourceconss != NULL);
704 
705  SCIP_CALL( SCIPallocBufferArray(scip, &conss, nconss) );
706 
707  /* copy each constraint one by one */
708  for( c = 0; c < nconss && (*valid); ++c )
709  {
710  SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourceconss[c], &conss[c], SCIPconsGetHdlr(sourceconss[c]),
711  varmap, consmap, SCIPconsGetName(sourceconss[c]),
712  SCIPconsIsInitial(sourceconss[c]), SCIPconsIsSeparated(sourceconss[c]), SCIPconsIsEnforced(sourceconss[c]),
713  SCIPconsIsChecked(sourceconss[c]), SCIPconsIsPropagated(sourceconss[c]),
714  SCIPconsIsLocal(sourceconss[c]), SCIPconsIsModifiable(sourceconss[c]),
715  SCIPconsIsDynamic(sourceconss[c]), SCIPconsIsRemovable(sourceconss[c]), SCIPconsIsStickingAtNode(sourceconss[c]),
716  global, valid) );
717  assert(!(*valid) || conss[c] != NULL);
718  }
719 
720  if( *valid )
721  {
722  if( name == NULL )
723  {
724  SCIP_CALL( SCIPcreateConsConjunction(scip, cons, SCIPconsGetName(sourcecons), nconss, conss,
725  enforce, check, local, modifiable, dynamic) );
726  }
727  else
728  {
729  SCIP_CALL( SCIPcreateConsConjunction(scip, cons, name, nconss, conss,
730  enforce, check, local, modifiable, dynamic) );
731  }
732  }
733 
734  /* release the copied constraints */
735  for( c = (*valid ? c - 1 : c - 2); c >= 0; --c )
736  {
737  assert(conss[c] != NULL);
738  SCIP_CALL( SCIPreleaseCons(scip, &conss[c]) );
739  }
740 
741  SCIPfreeBufferArray(scip, &conss);
742  }
743 
744  return SCIP_OKAY;
745 }
746 
747 
748 /*
749  * constraint specific interface methods
750  */
751 
752 /** creates the handler for conjunction constraints and includes it in SCIP */
754  SCIP* scip /**< SCIP data structure */
755  )
756 {
757  SCIP_CONSHDLR* conshdlr;
758 
759  /* include constraint handler */
762  consEnfolpConjunction, consEnfopsConjunction, consCheckConjunction, consLockConjunction,
763  NULL) );
764 
765  assert(conshdlr != NULL);
766 
767  /* set non-fundamental callbacks via specific setter functions */
768  SCIP_CALL( SCIPsetConshdlrCopy(scip, conshdlr, conshdlrCopyConjunction, consCopyConjunction) );
769  SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteConjunction) );
770  SCIP_CALL( SCIPsetConshdlrParse(scip, conshdlr, consParseConjunction) );
771  SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolConjunction, CONSHDLR_MAXPREROUNDS,
773  SCIP_CALL( SCIPsetConshdlrPrint(scip, conshdlr, consPrintConjunction) );
774  SCIP_CALL( SCIPsetConshdlrTrans(scip, conshdlr, consTransConjunction) );
775  SCIP_CALL( SCIPsetConshdlrEnforelax(scip, conshdlr, consEnforelaxConjunction) );
776 
777  return SCIP_OKAY;
778 }
779 
780 /** creates and captures a conjunction constraint
781  *
782  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
783  */
785  SCIP* scip, /**< SCIP data structure */
786  SCIP_CONS** cons, /**< pointer to hold the created constraint */
787  const char* name, /**< name of constraint */
788  int nconss, /**< number of initial constraints in conjunction */
789  SCIP_CONS** conss, /**< initial constraint in conjunction */
790  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
791  * TRUE for model constraints, FALSE for additional, redundant constraints. */
792  SCIP_Bool check, /**< should the constraint be checked for feasibility?
793  * TRUE for model constraints, FALSE for additional, redundant constraints. */
794  SCIP_Bool local, /**< is constraint only valid locally?
795  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
796  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)?
797  * Usually set to FALSE. In column generation applications, set to TRUE if pricing
798  * adds coefficients to this constraint. */
799  SCIP_Bool dynamic /**< is constraint subject to aging?
800  * Usually set to FALSE. Set to TRUE for own cuts which
801  * are separated as constraints. */
802  )
803 {
804  SCIP_CONSHDLR* conshdlr;
805  SCIP_CONSDATA* consdata;
806 
807  /* find the conjunction constraint handler */
808  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
809  if( conshdlr == NULL )
810  {
811  SCIPerrorMessage("conjunction constraint handler not found\n");
812  return SCIP_PLUGINNOTFOUND;
813  }
814 
815  /* create constraint data */
816  SCIP_CALL( consdataCreate(scip, &consdata, conss, nconss) );
817 
818  /* create constraint */
819  SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, FALSE, FALSE, enforce, check, FALSE,
820  local, modifiable, dynamic, FALSE, FALSE) );
821 
822  return SCIP_OKAY;
823 }
824 
825 /** creates and captures an and constraint
826  * in its most basic version, i. e., all constraint flags are set to their basic value as explained for the
827  * method SCIPcreateConsConjunction(); all flags can be set via SCIPsetConsFLAGNAME-methods in scip.h
828  *
829  * @see SCIPcreateConsConjunction() for information about the basic constraint flag configuration
830  *
831  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
832  */
834  SCIP* scip, /**< SCIP data structure */
835  SCIP_CONS** cons, /**< pointer to hold the created constraint */
836  const char* name, /**< name of constraint */
837  int nconss, /**< number of initial constraints in conjunction */
838  SCIP_CONS** conss /**< initial constraint in conjunction */
839  )
840 {
841  assert(scip != NULL);
842 
843  SCIP_CALL( SCIPcreateConsConjunction(scip, cons, name, nconss, conss,
844  TRUE, TRUE, FALSE, FALSE, FALSE) );
845 
846  return SCIP_OKAY;
847 }
848 
849 /** adds constraint to the conjunction of constraints */
851  SCIP* scip, /**< SCIP data structure */
852  SCIP_CONS* cons, /**< conjunction constraint */
853  SCIP_CONS* addcons /**< additional constraint in conjunction */
854  )
855 {
856  SCIP_CONSDATA* consdata;
857 
858  assert(cons != NULL);
859  assert(addcons != NULL);
860 
861  if( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
862  {
863  SCIPerrorMessage("constraint is not a conjunction constraint\n");
864  return SCIP_INVALIDDATA;
865  }
866 
867  consdata = SCIPconsGetData(cons);
868  assert(consdata != NULL);
869 
870  SCIP_CALL( consdataAddCons(scip, consdata, addcons) );
871 
872  return SCIP_OKAY;
873 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_RETCODE SCIPsetConshdlrDelete(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELETE((*consdelete)))
Definition: scip.c:6228
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip.h:21892
static SCIP_DECL_CONSPARSE(consParseConjunction)
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:8140
SCIP_RETCODE SCIPsetConshdlrTrans(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSTRANS((*constrans)))
Definition: scip.c:6251
#define CONSHDLR_DESC
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:6541
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
Definition: scip.c:5973
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:12481
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip.c:45601
SCIP_RETCODE SCIPtransformConss(SCIP *scip, int nconss, SCIP_CONS **conss, SCIP_CONS **transconss)
Definition: scip.c:27775
#define FALSE
Definition: def.h:64
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:5831
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:27230
#define TRUE
Definition: def.h:63
#define SCIPdebug(x)
Definition: pub_message.h:74
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_Bool SCIPconsIsStickingAtNode(SCIP_CONS *cons)
Definition: cons.c:8160
static SCIP_RETCODE checkAllConss(SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_SOL *sol, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool printreason, SCIP_Bool completely, SCIP_RESULT *result)
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip.h:21907
static SCIP_RETCODE consdataCreate(SCIP *scip, SCIP_CONSDATA **consdata, SCIP_CONS **conss, int nconss)
static SCIP_DECL_CONSCOPY(consCopyConjunction)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip.h:21933
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:21937
#define CONSHDLR_ENFOPRIORITY
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip.h:21890
SCIP_Bool SCIPisTransformed(SCIP *scip)
Definition: scip.c:1010
static SCIP_DECL_CONSLOCK(consLockConjunction)
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:8150
#define SCIPdebugMsg
Definition: scip.h:451
SCIP_RETCODE SCIPsetConshdlrParse(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPARSE((*consparse)))
Definition: scip.c:6458
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:7942
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip.c:1336
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:27146
#define CONSHDLR_NAME
static SCIP_RETCODE consdataFree(SCIP *scip, SCIP_CONSDATA **consdata)
#define CONSHDLR_EAGERFREQ
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
Definition: scip.h:21904
SCIP_RETCODE SCIPcreateConsBasicConjunction(SCIP *scip, SCIP_CONS **cons, const char *name, int nconss, SCIP_CONS **conss)
static SCIP_DECL_CONSCHECK(consCheckConjunction)
SCIP_RETCODE SCIPsetConshdlrCopy(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSCOPY((*conscopy)))
Definition: scip.c:5997
constraint handler for conjunction constraints
#define SCIPerrorMessage
Definition: pub_message.h:45
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4113
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:12410
static SCIP_RETCODE consdataAddCons(SCIP *scip, SCIP_CONSDATA *consdata, SCIP_CONS *cons)
SCIP_RETCODE SCIPaddConsLocal(SCIP *scip, SCIP_CONS *cons, SCIP_NODE *validnode)
Definition: scip.c:13030
SCIP_RETCODE SCIPdelConsLocal(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:13111
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:28252
SCIP_RETCODE SCIPsetConsChecked(SCIP *scip, SCIP_CONS *cons, SCIP_Bool check)
Definition: scip.c:27496
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7881
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
Definition: cons.c:8100
#define NULL
Definition: lpi_spx1.cpp:137
SCIP_RETCODE SCIPaddConsElemConjunction(SCIP *scip, SCIP_CONS *cons, SCIP_CONS *addcons)
SCIP_RETCODE SCIPtransformCons(SCIP *scip, SCIP_CONS *cons, SCIP_CONS **transcons)
Definition: scip.c:27734
#define SCIP_CALL(x)
Definition: def.h:306
SCIP_RETCODE SCIPincludeConshdlrConjunction(SCIP *scip)
#define SCIPensureBlockMemoryArray(scip, ptr, arraysizeptr, minsize)
Definition: scip.h:21906
static SCIP_DECL_CONSENFOLP(consEnfolpConjunction)
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8120
#define CONSHDLR_PRESOLTIMING
SCIP_RETCODE SCIPcaptureCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:27288
struct SCIP_ConsData SCIP_CONSDATA
Definition: type_cons.h:50
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 *valid)
Definition: scip.c:2524
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:21925
#define SCIP_Bool
Definition: def.h:61
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
Definition: scip.c:28652
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:7901
static SCIP_DECL_CONSENFORELAX(consEnforelaxConjunction)
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8080
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:8050
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 SCIPsetConshdlrPrint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRINT((*consprint)))
Definition: scip.c:6435
static SCIP_DECL_CONSPRINT(consPrintConjunction)
#define CONSHDLR_CHECKPRIORITY
static SCIP_DECL_CONSDELETE(consDeleteConjunction)
SCIP_CONSDATA * SCIPconsGetData(SCIP_CONS *cons)
Definition: cons.c:7911
static SCIP_DECL_CONSENFOPS(consEnfopsConjunction)
static SCIP_DECL_CONSTRANS(consTransConjunction)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:27323
SCIP_RETCODE SCIPsetConshdlrPresol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRESOL((*conspresol)), int maxprerounds, SCIP_PRESOLTIMING presoltiming)
Definition: scip.c:6190
static SCIP_DECL_CONSHDLRCOPY(conshdlrCopyConjunction)
static SCIP_DECL_CONSPRESOL(consPresolConjunction)
#define CONSHDLR_MAXPREROUNDS
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:8130
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:8070
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:8060
SCIP_RETCODE SCIPaddConsLocks(SCIP *scip, SCIP_CONS *cons, int nlockspos, int nlocksneg)
Definition: scip.c:28222
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
Definition: scip.h:21910
#define CONSHDLR_NEEDSCONS
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:21929
static SCIP_RETCODE addAllConss(SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_RESULT *result)