Scippy

SCIP

Solving Constraint Integer Programs

scip.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 scip.c
17  * @brief SCIP callable library
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Gerald Gamrath
21  * @author Stefan Heinz
22  * @author Gregor Hendel
23  * @author Thorsten Koch
24  * @author Alexander Martin
25  * @author Marc Pfetsch
26  * @author Michael Winkler
27  * @author Kati Wolter
28  *
29  * @todo check all checkStage() calls, use bit flags instead of the SCIP_Bool parameters
30  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
31  * @todo When making an interface change to SCIPcreateProb(), add an indication whether it is known that the objective
32  * function is integral or whether this is not known. This avoids a manual call of SCIPsetObjIntegral(). Moreover,
33  * then the detection could be performed incrementally, whenever a variable is added.
34  */
35 
36 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37 
38 #include <ctype.h>
39 #include <stdarg.h>
40 #include <assert.h>
41 #include <string.h>
42 #if defined(_WIN32) || defined(_WIN64)
43 #else
44 #include <strings.h>
45 #endif
46 
47 #ifdef WITH_ZLIB
48 #include <zlib.h>
49 #endif
50 
51 #include "scip/def.h"
52 #include "scip/retcode.h"
53 #include "scip/set.h"
54 #include "scip/paramset.h"
55 #include "scip/stat.h"
56 #include "scip/clock.h"
57 #include "scip/visual.h"
58 #include "scip/interrupt.h"
59 #include "scip/mem.h"
60 #include "scip/misc.h"
61 #include "scip/history.h"
62 #include "scip/event.h"
63 #include "scip/lp.h"
64 #include "scip/nlp.h"
65 #include "scip/var.h"
66 #include "scip/implics.h"
67 #include "scip/prob.h"
68 #include "scip/sol.h"
69 #include "scip/primal.h"
70 #include "scip/reopt.h"
71 #include "scip/tree.h"
72 #include "scip/pricestore.h"
73 #include "scip/sepastore.h"
74 #include "scip/conflictstore.h"
75 #include "scip/syncstore.h"
76 #include "scip/cutpool.h"
77 #include "scip/solve.h"
78 #include "scip/scipbuildflags.h"
79 #include "scip/scipgithash.h"
80 #include "scip/cuts.h"
81 #include "scip/scip.h"
82 #include "lpi/lpi.h"
83 
84 #include "scip/branch.h"
85 #include "scip/conflict.h"
86 #include "scip/cons.h"
87 #include "scip/dialog.h"
88 #include "scip/disp.h"
89 #include "scip/heur.h"
90 #include "scip/concsolver.h"
91 #include "scip/compr.h"
92 #include "scip/nodesel.h"
93 #include "scip/reader.h"
94 #include "scip/presol.h"
95 #include "scip/pricer.h"
96 #include "scip/relax.h"
97 #include "scip/sepa.h"
98 #include "scip/prop.h"
99 #include "nlpi/nlpi.h"
100 #include "nlpi/exprinterpret.h"
101 #include "scip/debug.h"
102 #include "scip/dialog_default.h"
103 #include "scip/message_default.h"
104 #include "scip/syncstore.h"
105 #include "scip/concurrent.h"
106 #include "xml/xml.h"
107 
108 /* We include the linear constraint handler to be able to copy a (multi)aggregation of variables (to a linear constraint).
109  * The better way would be to handle the distinction between original and transformed variables via a flag 'isoriginal'
110  * in the variable data structure. This would allow to have (multi)aggregated variables in the original problem.
111  *
112  * A second reason for including the linear constraint handler is for copying cuts to linear constraints.
113  */
114 #include "scip/cons_linear.h"
115 
116 /* We need to include the branching and the heurtistics for reoptimization after creating the reoptimization because we
117  * do not want to use these plugins by default if reoptimization is disabled. */
118 #include "scip/branch_nodereopt.h"
119 #include "scip/heur_reoptsols.h"
121 #include "scip/heur_ofins.h"
122 
123 /* In debug mode, we include the SCIP's structure in scip.c, such that no one can access
124  * this structure except the interface methods in scip.c.
125  * In optimized mode, the structure is included in scip.h, because some of the methods
126  * are implemented as defines for performance reasons (e.g. the numerical comparisons)
127  */
128 #ifndef NDEBUG
129 #include "scip/struct_scip.h"
130 #endif
131 
132 /*
133  * Local methods
134  */
135 
136 
137 /** checks, if SCIP is in one of the feasible stages */
138 #ifndef NDEBUG
139 static
141  SCIP* scip, /**< SCIP data structure */
142  const char* method, /**< method that was called */
143  SCIP_Bool init, /**< may method be called in the INIT stage? */
144  SCIP_Bool problem, /**< may method be called in the PROBLEM stage? */
145  SCIP_Bool transforming, /**< may method be called in the TRANSFORMING stage? */
146  SCIP_Bool transformed, /**< may method be called in the TRANSFORMED stage? */
147  SCIP_Bool initpresolve, /**< may method be called in the INITPRESOLVE stage? */
148  SCIP_Bool presolving, /**< may method be called in the PRESOLVING stage? */
149  SCIP_Bool exitpresolve, /**< may method be called in the EXITPRESOLE stage? */
150  SCIP_Bool presolved, /**< may method be called in the PRESOLVED stage? */
151  SCIP_Bool initsolve, /**< may method be called in the INITSOLVE stage? */
152  SCIP_Bool solving, /**< may method be called in the SOLVING stage? */
153  SCIP_Bool solved, /**< may method be called in the SOLVED stage? */
154  SCIP_Bool exitsolve, /**< may method be called in the EXITSOLVE stage? */
155  SCIP_Bool freetrans, /**< may method be called in the FREETRANS stage? */
156  SCIP_Bool freescip /**< may method be called in the FREE stage? */
157  )
158 {
159  assert(scip != NULL);
160  assert(method != NULL);
161 
162  /*SCIPdebugMsg(scip, "called method <%s> at stage %d ------------------------------------------------\n",
163  method, scip->set->stage);*/
164 
165  assert(scip->mem != NULL);
166  assert(scip->set != NULL);
167  assert(scip->interrupt != NULL);
168  assert(scip->dialoghdlr != NULL);
169  assert(scip->totaltime != NULL);
170 
171  switch( scip->set->stage )
172  {
173  case SCIP_STAGE_INIT:
174  assert(scip->stat == NULL);
175  assert(scip->origprob == NULL);
176  assert(scip->eventfilter == NULL);
177  assert(scip->eventqueue == NULL);
178  assert(scip->branchcand == NULL);
179  assert(scip->lp == NULL);
180  assert(scip->nlp == NULL);
181  assert(scip->primal == NULL);
182  assert(scip->tree == NULL);
183  assert(scip->conflict == NULL);
184  assert(scip->transprob == NULL);
185  assert(scip->pricestore == NULL);
186  assert(scip->sepastore == NULL);
187  assert(scip->cutpool == NULL);
188  assert(scip->delayedcutpool == NULL);
189 
190  if( !init )
191  {
192  SCIPerrorMessage("cannot call method <%s> in initialization stage\n", method);
193  return SCIP_INVALIDCALL;
194  }
195  return SCIP_OKAY;
196 
197  case SCIP_STAGE_PROBLEM:
198  assert(scip->stat != NULL);
199  assert(scip->origprob != NULL);
200  assert(scip->eventfilter == NULL);
201  assert(scip->eventqueue == NULL);
202  assert(scip->branchcand == NULL);
203  assert(scip->lp == NULL);
204  assert(scip->nlp == NULL);
205  assert(scip->primal == NULL);
206  assert(scip->tree == NULL);
207  assert(scip->conflict == NULL);
208  assert(scip->transprob == NULL);
209  assert(scip->pricestore == NULL);
210  assert(scip->sepastore == NULL);
211  assert(scip->cutpool == NULL);
212  assert(scip->delayedcutpool == NULL);
213 
214  if( !problem )
215  {
216  SCIPerrorMessage("cannot call method <%s> in problem creation stage\n", method);
217  return SCIP_INVALIDCALL;
218  }
219  return SCIP_OKAY;
220 
222  assert(scip->stat != NULL);
223  assert(scip->origprob != NULL);
224  assert(scip->eventfilter != NULL);
225  assert(scip->eventqueue != NULL);
226  assert(scip->branchcand != NULL);
227  assert(scip->lp != NULL);
228  assert(scip->primal != NULL);
229  assert(scip->tree != NULL);
230  assert(scip->conflict != NULL);
231  assert(scip->transprob != NULL);
232  assert(scip->pricestore == NULL);
233  assert(scip->sepastore == NULL);
234  assert(scip->cutpool == NULL);
235  assert(scip->delayedcutpool == NULL);
236 
237  if( !transforming )
238  {
239  SCIPerrorMessage("cannot call method <%s> in problem transformation stage\n", method);
240  return SCIP_INVALIDCALL;
241  }
242  return SCIP_OKAY;
243 
245  assert(scip->stat != NULL);
246  assert(scip->origprob != NULL);
247  assert(scip->eventfilter != NULL);
248  assert(scip->eventqueue != NULL);
249  assert(scip->branchcand != NULL);
250  assert(scip->lp != NULL);
251  assert(scip->primal != NULL);
252  assert(scip->tree != NULL);
253  assert(scip->conflict != NULL);
254  assert(scip->transprob != NULL);
255  assert(scip->pricestore == NULL);
256  assert(scip->sepastore == NULL);
257  assert(scip->cutpool == NULL);
258  assert(scip->delayedcutpool == NULL);
259 
260  if( !transformed )
261  {
262  SCIPerrorMessage("cannot call method <%s> in problem transformed stage\n", method);
263  return SCIP_INVALIDCALL;
264  }
265  return SCIP_OKAY;
266 
268  assert(scip->stat != NULL);
269  assert(scip->origprob != NULL);
270  assert(scip->eventfilter != NULL);
271  assert(scip->eventqueue != NULL);
272  assert(scip->branchcand != NULL);
273  assert(scip->lp != NULL);
274  assert(scip->primal != NULL);
275  assert(scip->tree != NULL);
276  assert(scip->conflict != NULL);
277  assert(scip->transprob != NULL);
278  assert(scip->pricestore == NULL);
279  assert(scip->sepastore == NULL);
280  assert(scip->cutpool == NULL);
281  assert(scip->delayedcutpool == NULL);
282 
283  if( !initpresolve )
284  {
285  SCIPerrorMessage("cannot call method <%s> in init presolving stage\n", method);
286  return SCIP_INVALIDCALL;
287  }
288  return SCIP_OKAY;
289 
291  assert(scip->stat != NULL);
292  assert(scip->origprob != NULL);
293  assert(scip->eventfilter != NULL);
294  assert(scip->eventqueue != NULL);
295  assert(scip->branchcand != NULL);
296  assert(scip->lp != NULL);
297  assert(scip->primal != NULL);
298  assert(scip->tree != NULL);
299  assert(scip->conflict != NULL);
300  assert(scip->transprob != NULL);
301  assert(scip->pricestore == NULL);
302  assert(scip->sepastore == NULL);
303  assert(scip->cutpool == NULL);
304  assert(scip->delayedcutpool == NULL);
305 
306  if( !presolving )
307  {
308  SCIPerrorMessage("cannot call method <%s> in presolving stage\n", method);
309  return SCIP_INVALIDCALL;
310  }
311  return SCIP_OKAY;
312 
314  assert(scip->stat != NULL);
315  assert(scip->origprob != NULL);
316  assert(scip->eventfilter != NULL);
317  assert(scip->eventqueue != NULL);
318  assert(scip->branchcand != NULL);
319  assert(scip->lp != NULL);
320  assert(scip->primal != NULL);
321  assert(scip->tree != NULL);
322  assert(scip->conflict != NULL);
323  assert(scip->transprob != NULL);
324  assert(scip->pricestore == NULL);
325  assert(scip->sepastore == NULL);
326  assert(scip->cutpool == NULL);
327  assert(scip->delayedcutpool == NULL);
328 
329  if( !exitpresolve )
330  {
331  SCIPerrorMessage("cannot call method <%s> in exit presolving stage\n", method);
332  return SCIP_INVALIDCALL;
333  }
334  return SCIP_OKAY;
335 
337  assert(scip->stat != NULL);
338  assert(scip->origprob != NULL);
339  assert(scip->eventfilter != NULL);
340  assert(scip->eventqueue != NULL);
341  assert(scip->branchcand != NULL);
342  assert(scip->lp != NULL);
343  assert(scip->primal != NULL);
344  assert(scip->tree != NULL);
345  assert(scip->conflict != NULL);
346  assert(scip->transprob != NULL);
347  assert(scip->pricestore == NULL);
348  assert(scip->sepastore == NULL);
349  assert(scip->cutpool == NULL);
350  assert(scip->delayedcutpool == NULL);
351 
352  if( !presolved )
353  {
354  SCIPerrorMessage("cannot call method <%s> in problem presolved stage\n", method);
355  return SCIP_INVALIDCALL;
356  }
357  return SCIP_OKAY;
358 
360  assert(scip->stat != NULL);
361  assert(scip->origprob != NULL);
362  assert(scip->eventfilter != NULL);
363  assert(scip->eventqueue != NULL);
364  assert(scip->branchcand != NULL);
365  assert(scip->lp != NULL);
366  assert(scip->primal != NULL);
367  assert(scip->tree != NULL);
368  assert(scip->transprob != NULL);
369 
370  if( !initsolve )
371  {
372  SCIPerrorMessage("cannot call method <%s> in init solve stage\n", method);
373  return SCIP_INVALIDCALL;
374  }
375  return SCIP_OKAY;
376 
377  case SCIP_STAGE_SOLVING:
378  assert(scip->stat != NULL);
379  assert(scip->origprob != NULL);
380  assert(scip->eventfilter != NULL);
381  assert(scip->eventqueue != NULL);
382  assert(scip->branchcand != NULL);
383  assert(scip->lp != NULL);
384  assert(scip->primal != NULL);
385  assert(scip->tree != NULL);
386  assert(scip->conflict != NULL);
387  assert(scip->transprob != NULL);
388  assert(scip->pricestore != NULL);
389  assert(scip->sepastore != NULL);
390  assert(scip->cutpool != NULL);
391  assert(scip->delayedcutpool != NULL);
392 
393  if( !solving )
394  {
395  SCIPerrorMessage("cannot call method <%s> in solving stage\n", method);
396  return SCIP_INVALIDCALL;
397  }
398  return SCIP_OKAY;
399 
400  case SCIP_STAGE_SOLVED:
401  assert(scip->stat != NULL);
402  assert(scip->origprob != NULL);
403  assert(scip->eventfilter != NULL);
404  assert(scip->eventqueue != NULL);
405  assert(scip->branchcand != NULL);
406  assert(scip->lp != NULL);
407  assert(scip->primal != NULL);
408  assert(scip->tree != NULL);
409  assert(scip->conflict != NULL);
410  assert(scip->transprob != NULL);
411  assert(scip->pricestore != NULL);
412  assert(scip->sepastore != NULL);
413  assert(scip->cutpool != NULL);
414  assert(scip->delayedcutpool != NULL);
415 
416  if( !solved )
417  {
418  SCIPerrorMessage("cannot call method <%s> in problem solved stage\n", method);
419  return SCIP_INVALIDCALL;
420  }
421  return SCIP_OKAY;
422 
424  assert(scip->stat != NULL);
425  assert(scip->origprob != NULL);
426  assert(scip->eventfilter != NULL);
427  assert(scip->eventqueue != NULL);
428  assert(scip->branchcand != NULL);
429  assert(scip->lp != NULL);
430  assert(scip->primal != NULL);
431  assert(scip->tree != NULL);
432  assert(scip->transprob != NULL);
433 
434  if( !exitsolve )
435  {
436  SCIPerrorMessage("cannot call method <%s> in solve deinitialization stage\n", method);
437  return SCIP_INVALIDCALL;
438  }
439  return SCIP_OKAY;
440 
442  assert(scip->stat != NULL);
443  assert(scip->origprob != NULL);
444  assert(scip->pricestore == NULL);
445  assert(scip->sepastore == NULL);
446  assert(scip->cutpool == NULL);
447  assert(scip->delayedcutpool == NULL);
448 
449  if( !freetrans )
450  {
451  SCIPerrorMessage("cannot call method <%s> in free transformed problem stage\n", method);
452  return SCIP_INVALIDCALL;
453  }
454  return SCIP_OKAY;
455 
456  case SCIP_STAGE_FREE:
457  if( !freescip )
458  {
459  SCIPerrorMessage("cannot call method <%s> in free stage\n", method);
460  return SCIP_INVALIDCALL;
461  }
462  return SCIP_OKAY;
463 
464  default:
465  /* note that this is in an internal SCIP error since all SCIP stages are covert in the switch above */
466  SCIPerrorMessage("invalid SCIP stage <%d>\n", scip->set->stage);
467  return SCIP_ERROR;
468  }
469 }
470 #else
471 #define checkStage(scip,method,init,problem,transforming,transformed,initpresolve,presolving,exitpresolve,presolved, \
472  initsolve,solving,solved,exitsolve,freetrans,freescip) SCIP_OKAY
473 #endif
474 
475 /** gets global lower (dual) bound in transformed problem */
476 static
478  SCIP* scip /**< SCIP data structure */
479  )
480 {
481  if( scip->set->stage <= SCIP_STAGE_INITSOLVE )
482  return -SCIPinfinity(scip);
483 
484  return SCIPtreeGetLowerbound(scip->tree, scip->set);
485 }
486 
487 /** gets global upper (primal) bound in transformed problem (objective value of best solution or user objective limit) */
488 static
490  SCIP* scip /**< SCIP data structure */
491  )
492 {
493  if( SCIPgetStatus(scip) == SCIP_STATUS_UNBOUNDED )
494  return -SCIPinfinity(scip);
495  else
496  return scip->primal->upperbound;
497 }
498 
499 
500 /** gets global primal bound (objective value of best solution or user objective limit) */
501 static
503  SCIP* scip /**< SCIP data structure */
504  )
505 {
506  return SCIPprobExternObjval(scip->transprob, scip->origprob, scip->set, getUpperbound(scip));
507 }
508 
509 /** gets global dual bound */
510 static
512  SCIP* scip /**< SCIP data structure */
513  )
514 {
515  SCIP_Real lowerbound;
516 
517  if( scip->set->stage <= SCIP_STAGE_INITSOLVE )
518  {
519  /* in case we are in presolving we use the stored dual bound if it exits, otherwise, minus or plus infinity
520  * depending on the objective sense
521  */
522  if( scip->transprob->dualbound < SCIP_INVALID )
523  lowerbound = SCIPprobInternObjval(scip->transprob, scip->origprob, scip->set, scip->transprob->dualbound);
524  else
525  return SCIPprobExternObjval(scip->transprob, scip->origprob, scip->set, -SCIPinfinity(scip));
526  }
527  else
528  lowerbound = SCIPtreeGetLowerbound(scip->tree, scip->set);
529 
530  if( SCIPsetIsInfinity(scip->set, lowerbound) )
531  {
532  /* in case we could not prove whether the problem is unbounded or infeasible, we want to terminate with
533  * dual bound = -inf instead of dual bound = primal bound = +inf
534  * also in case we prove that the problem is unbounded, it seems to make sense to return with dual bound = -inf,
535  * since -infinity is the only valid lower bound
536  */
538  return SCIPprobExternObjval(scip->transprob, scip->origprob, scip->set, -SCIPinfinity(scip));
539  else
540  return getPrimalbound(scip);
541  }
542  else
543  return SCIPprobExternObjval(scip->transprob, scip->origprob, scip->set, lowerbound);
544 }
545 
546 /*
547  * miscellaneous methods
548  */
549 
550 /** returns complete SCIP version number in the format "major . minor tech"
551  *
552  * @return complete SCIP version
553  */
555  void
556  )
557 {
558  return (SCIP_Real)(SCIP_VERSION)/100.0;
559 }
560 
561 /** returns SCIP major version
562  *
563  * @return major SCIP version
564  */
566  void
567  )
568 {
569  return SCIP_VERSION/100;
570 }
571 
572 /** returns SCIP minor version
573  *
574  * @return minor SCIP version
575  */
577  void
578  )
579 {
580  return (SCIP_VERSION/10) % 10; /*lint !e778*/
581 }
582 
583 /** returns SCIP technical version
584  *
585  * @return technical SCIP version
586  */
588  void
589  )
590 {
591  return SCIP_VERSION % 10; /*lint !e778*/
592 }
593 
594 /** returns SCIP sub version number
595  *
596  * @return subversion SCIP version
597  */
599  void
600  )
601 {
602  return SCIP_SUBVERSION;
603 }
604 
605 /** prints a version information line to a file stream via the message handler system
606  *
607  * @note If the message handler is set to a NULL pointer nothing will be printed
608  */
610  SCIP* scip, /**< SCIP data structure */
611  FILE* file /**< output file (or NULL for standard output) */
612  )
613 {
614  assert( scip != NULL );
615 
616  SCIPmessageFPrintInfo(scip->messagehdlr, file, "SCIP version %d.%d.%d",
618 #if SCIP_SUBVERSION > 0
619  SCIPmessageFPrintInfo(scip->messagehdlr, file, ".%d", SCIPsubversion());
620 #endif
621 
622  SCIPmessageFPrintInfo(scip->messagehdlr, file, " [precision: %d byte]", (int)sizeof(SCIP_Real));
623 
624 #ifndef BMS_NOBLOCKMEM
625  SCIPmessageFPrintInfo(scip->messagehdlr, file, " [memory: block]");
626 #else
627  SCIPmessageFPrintInfo(scip->messagehdlr, file, " [memory: standard]");
628 #endif
629 #ifndef NDEBUG
630  SCIPmessageFPrintInfo(scip->messagehdlr, file, " [mode: debug]");
631 #else
632  SCIPmessageFPrintInfo(scip->messagehdlr, file, " [mode: optimized]");
633 #endif
634  SCIPmessageFPrintInfo(scip->messagehdlr, file, " [LP solver: %s]", SCIPlpiGetSolverName());
635  SCIPmessageFPrintInfo(scip->messagehdlr, file, " [GitHash: %s]", SCIPgetGitHash());
636  SCIPmessageFPrintInfo(scip->messagehdlr, file, "\n");
637  SCIPmessageFPrintInfo(scip->messagehdlr, file, "%s\n", SCIP_COPYRIGHT);
638 }
639 
640 /** prints detailed information on the compile-time flags
641  *
642  * @note If the message handler is set to a NULL pointer nothing will be printed
643  */
645  SCIP* scip, /**< SCIP data structure */
646  FILE* file /**< output file (or NULL for standard output) */
647  )
648 {
649  assert( scip != NULL );
650 
651  /* compiler */
652  SCIPmessageFPrintInfo(scip->messagehdlr, file, "Compiler: ");
653 #if defined(__INTEL_COMPILER)
654  SCIPmessageFPrintInfo(scip->messagehdlr, file, "Intel %d\n", __INTEL_COMPILER);
655 #elif defined(__clang__)
656  SCIPmessageFPrintInfo(scip->messagehdlr, file, "clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__);
657 #elif defined(_MSC_VER)
658  SCIPmessageFPrintInfo(scip->messagehdlr, file, "microsoft visual c %d\n", _MSC_FULL_VER);
659 #elif defined(__GNUC__)
660  SCIPmessageFPrintInfo(scip->messagehdlr, file, "gcc %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
661 #else
662  SCIPmessageFPrintInfo(scip->messagehdlr, file, "unknown\n");
663 #endif
664 
665  /* build flags */
666  SCIPmessageFPrintInfo(scip->messagehdlr, file, "\nBuild options:\n%s", SCIPgetBuildFlags());
667 }
668 
669 /** prints error message for the given SCIP_RETCODE via the error prints method */
671  SCIP_RETCODE retcode /**< SCIP return code causing the error */
672  )
673 {
674  SCIPmessagePrintError("SCIP Error (%d): ", retcode);
675  SCIPretcodePrintError(retcode);
676  SCIPmessagePrintError("\n");
677 }
678 
679 /*
680  * general SCIP methods
681  */
682 
683 /** creates and initializes SCIP data structures
684  *
685  * @note The SCIP default message handler is installed. Use the method SCIPsetMessagehdlr() to install your own
686  * message handler or SCIPsetMessagehdlrLogfile() and SCIPsetMessagehdlrQuiet() to write into a log
687  * file and turn off/on the display output, respectively.
688  *
689  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
690  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
691  *
692  * @post After calling this method \SCIP reached the solving stage \ref SCIP_STAGE_INIT
693  *
694  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
695  */
697  SCIP** scip /**< pointer to SCIP data structure */
698  )
699 {
700  assert(scip != NULL);
701 
702  SCIP_ALLOC( BMSallocMemory(scip) );
703 
704  /* create a default message handler */
705  SCIP_CALL( SCIPcreateMessagehdlrDefault(&(*scip)->messagehdlr, TRUE, NULL, FALSE) );
706 
707  SCIP_CALL( SCIPmemCreate(&(*scip)->mem) );
708  SCIP_CALL( SCIPsetCreate(&(*scip)->set, (*scip)->messagehdlr, (*scip)->mem->setmem, *scip) );
709  SCIP_CALL( SCIPinterruptCreate(&(*scip)->interrupt) );
710  SCIP_CALL( SCIPdialoghdlrCreate((*scip)->set, &(*scip)->dialoghdlr) );
711  SCIP_CALL( SCIPclockCreate(&(*scip)->totaltime, SCIP_CLOCKTYPE_DEFAULT) );
712  SCIP_CALL( SCIPsyncstoreCreate( &(*scip)->syncstore ) );
713 
714  SCIPclockStart((*scip)->totaltime, (*scip)->set);
715  (*scip)->stat = NULL;
716  (*scip)->origprob = NULL;
717  (*scip)->origprimal = NULL;
718  (*scip)->eventfilter = NULL;
719  (*scip)->eventqueue = NULL;
720  (*scip)->branchcand = NULL;
721  (*scip)->lp = NULL;
722  (*scip)->nlp = NULL;
723  (*scip)->primal = NULL;
724  (*scip)->tree = NULL;
725  (*scip)->conflict = NULL;
726  (*scip)->transprob = NULL;
727  (*scip)->pricestore = NULL;
728  (*scip)->sepastore = NULL;
729  (*scip)->conflictstore = NULL;
730  (*scip)->cutpool = NULL;
731  (*scip)->delayedcutpool = NULL;
732  (*scip)->reopt = NULL;
733  (*scip)->concurrent = NULL;
734 
735  SCIP_CALL( SCIPnlpInclude((*scip)->set, SCIPblkmem(*scip)) );
736 
737  if( strcmp(SCIPlpiGetSolverName(), "NONE") != 0 )
738  {
740  }
741  if( strcmp(SCIPexprintGetName(), "NONE") != 0 )
742  {
744  }
745 
746 #ifdef WITH_ZLIB
747  SCIP_CALL( SCIPsetIncludeExternalCode((*scip)->set, "ZLIB " ZLIB_VERSION, "General purpose compression library by J. Gailly and M. Adler (zlib.net)") );
748 #endif
749 
750  return SCIP_OKAY;
751 }
752 
753 /** frees SCIP data structures
754  *
755  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
756  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
757  *
758  * @pre This method can be called if @p scip is in one of the following stages:
759  * - \ref SCIP_STAGE_INIT
760  * - \ref SCIP_STAGE_PROBLEM
761  * - \ref SCIP_STAGE_TRANSFORMED
762  * - \ref SCIP_STAGE_INITPRESOLVE
763  * - \ref SCIP_STAGE_PRESOLVING
764  * - \ref SCIP_STAGE_PRESOLVED
765  * - \ref SCIP_STAGE_EXITPRESOLVE
766  * - \ref SCIP_STAGE_SOLVING
767  * - \ref SCIP_STAGE_SOLVED
768  * - \ref SCIP_STAGE_FREE
769  *
770  * @post After calling this method \SCIP reached the solving stage \ref SCIP_STAGE_FREE
771  *
772  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
773  */
775  SCIP** scip /**< pointer to SCIP data structure */
776  )
777 {
778  assert(scip != NULL);
779  assert(*scip != NULL);
780 
781  SCIP_CALL( checkStage(*scip, "SCIPfree", TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE) );
782 
783  SCIP_CALL( SCIPfreeProb(*scip) );
784  assert((*scip)->set->stage == SCIP_STAGE_INIT);
785 
786  /* switch stage to FREE */
787  (*scip)->set->stage = SCIP_STAGE_FREE;
788 
789  SCIP_CALL( SCIPsyncstoreRelease(&(*scip)->syncstore) );
790  SCIP_CALL( SCIPsetFree(&(*scip)->set, (*scip)->mem->setmem) );
791  SCIP_CALL( SCIPdialoghdlrFree(*scip, &(*scip)->dialoghdlr) );
792  SCIPclockFree(&(*scip)->totaltime);
793  SCIPinterruptFree(&(*scip)->interrupt);
794  SCIP_CALL( SCIPmemFree(&(*scip)->mem) );
795 
796  /* release message handler */
797  SCIP_CALL( SCIPmessagehdlrRelease(&(*scip)->messagehdlr) );
798 
799  BMSfreeMemory(scip);
800 
801  return SCIP_OKAY;
802 }
803 
804 #undef SCIPgetStage
805 #undef SCIPhasPerformedPresolve
806 #undef SCIPisStopped
807 
808 /** returns current stage of SCIP
809  *
810  * @return the current SCIP stage
811  *
812  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
813  */
815  SCIP* scip /**< SCIP data structure */
816  )
817 {
818  assert(scip != NULL);
819  assert(scip->set != NULL);
820 
821  return scip->set->stage;
822 }
823 
824 /** outputs SCIP stage and solution status if applicable via the message handler
825  *
826  * @note If the message handler is set to a NULL pointer nothing will be printed
827  *
828  * @note If limits have been changed between the solution and the call to this function, the status is recomputed and
829  * thus may to correspond to the original status.
830  *
831  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
832  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
833  *
834  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
835  */
837  SCIP* scip, /**< SCIP data structure */
838  FILE* file /**< output file (or NULL for standard output) */
839  )
840 {
841  SCIP_CALL( checkStage(scip, "SCIPprintStage", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE) );
842 
843  switch( scip->set->stage )
844  {
845  case SCIP_STAGE_INIT:
846  SCIPmessageFPrintInfo(scip->messagehdlr, file, "initialization");
847  break;
848  case SCIP_STAGE_PROBLEM:
849  SCIPmessageFPrintInfo(scip->messagehdlr, file, "problem creation / modification");
850  break;
852  SCIPmessageFPrintInfo(scip->messagehdlr, file, "problem transformation");
853  break;
855  SCIPmessageFPrintInfo(scip->messagehdlr, file, "problem transformed");
856  break;
858  SCIPmessageFPrintInfo(scip->messagehdlr, file, "presolving is being initialized");
859  break;
861  if( SCIPsolveIsStopped(scip->set, scip->stat, TRUE) )
862  {
863  SCIPmessageFPrintInfo(scip->messagehdlr, file, "solving was interrupted [");
864  SCIP_CALL( SCIPprintStatus(scip, file) );
865  SCIPmessageFPrintInfo(scip->messagehdlr, file, "]");
866  }
867  else
868  SCIPmessageFPrintInfo(scip->messagehdlr, file, "presolving process is running");
869  break;
871  SCIPmessageFPrintInfo(scip->messagehdlr, file, "presolving is being exited");
872  break;
874  SCIPmessageFPrintInfo(scip->messagehdlr, file, "problem is presolved");
875  break;
877  SCIPmessageFPrintInfo(scip->messagehdlr, file, "solving process initialization");
878  break;
879  case SCIP_STAGE_SOLVING:
880  if( SCIPsolveIsStopped(scip->set, scip->stat, TRUE) )
881  {
882  SCIPmessageFPrintInfo(scip->messagehdlr, file, "solving was interrupted [");
883  SCIP_CALL( SCIPprintStatus(scip, file) );
884  SCIPmessageFPrintInfo(scip->messagehdlr, file, "]");
885  }
886  else
887  SCIPmessageFPrintInfo(scip->messagehdlr, file, "solving process is running");
888  break;
889  case SCIP_STAGE_SOLVED:
890  SCIPmessageFPrintInfo(scip->messagehdlr, file, "problem is solved [");
891  SCIP_CALL( SCIPprintStatus(scip, file) );
892  SCIPmessageFPrintInfo(scip->messagehdlr, file, "]");
893 
894  if( scip->primal->nlimsolsfound == 0 && !SCIPisInfinity(scip, (int)SCIPgetObjsense(scip) * getPrimalbound(scip)) )
895  SCIPmessageFPrintInfo(scip->messagehdlr, file, " (objective limit reached)");
896 
897  break;
899  SCIPmessageFPrintInfo(scip->messagehdlr, file, "solving process deinitialization");
900  break;
902  SCIPmessageFPrintInfo(scip->messagehdlr, file, "freeing transformed problem");
903  break;
904  case SCIP_STAGE_FREE:
905  SCIPmessageFPrintInfo(scip->messagehdlr, file, "freeing SCIP");
906  break;
907  default:
908  SCIPerrorMessage("invalid SCIP stage <%d>\n", scip->set->stage);
909  return SCIP_INVALIDDATA;
910  }
911 
912  return SCIP_OKAY;
913 }
914 
915 /** gets solution status
916  *
917  * @return SCIP solution status
918  *
919  * See \ref SCIP_Status "SCIP_STATUS" for a complete list of all possible solving status.
920  */
922  SCIP* scip /**< SCIP data structure */
923  )
924 {
925  SCIP_CALL_ABORT( checkStage(scip, "SCIPgetStatus", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE) );
926 
927  if( scip->set->stage == SCIP_STAGE_INIT || scip->set->stage == SCIP_STAGE_FREE )
928  return SCIP_STATUS_UNKNOWN;
929  else
930  {
931  assert(scip->stat != NULL);
932 
933  return scip->stat->status;
934  }
935 }
936 
937 /** outputs solution status
938  *
939  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
940  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
941  *
942  * See \ref SCIP_Status "SCIP_STATUS" for a complete list of all possible solving status.
943  */
945  SCIP* scip, /**< SCIP data structure */
946  FILE* file /**< output file (or NULL for standard output) */
947  )
948 {
949  SCIP_CALL( checkStage(scip, "SCIPprintStatus", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE) );
950 
951  switch( SCIPgetStatus(scip) )
952  {
953  case SCIP_STATUS_UNKNOWN:
954  SCIPmessageFPrintInfo(scip->messagehdlr, file, "unknown");
955  break;
957  SCIPmessageFPrintInfo(scip->messagehdlr, file, "user interrupt");
958  break;
960  SCIPmessageFPrintInfo(scip->messagehdlr, file, "node limit reached");
961  break;
963  SCIPmessageFPrintInfo(scip->messagehdlr, file, "total node limit reached");
964  break;
966  SCIPmessageFPrintInfo(scip->messagehdlr, file, "stall node limit reached");
967  break;
969  SCIPmessageFPrintInfo(scip->messagehdlr, file, "time limit reached");
970  break;
972  SCIPmessageFPrintInfo(scip->messagehdlr, file, "memory limit reached");
973  break;
975  SCIPmessageFPrintInfo(scip->messagehdlr, file, "gap limit reached");
976  break;
978  SCIPmessageFPrintInfo(scip->messagehdlr, file, "solution limit reached");
979  break;
981  SCIPmessageFPrintInfo(scip->messagehdlr, file, "solution improvement limit reached");
982  break;
984  SCIPmessageFPrintInfo(scip->messagehdlr, file, "restart limit reached");
985  break;
986  case SCIP_STATUS_OPTIMAL:
987  SCIPmessageFPrintInfo(scip->messagehdlr, file, "optimal solution found");
988  break;
990  SCIPmessageFPrintInfo(scip->messagehdlr, file, "infeasible");
991  break;
993  SCIPmessageFPrintInfo(scip->messagehdlr, file, "unbounded");
994  break;
996  SCIPmessageFPrintInfo(scip->messagehdlr, file, "infeasible or unbounded");
997  break;
998  default:
999  SCIPerrorMessage("invalid status code <%d>\n", SCIPgetStatus(scip));
1000  return SCIP_INVALIDDATA;
1001  }
1002 
1003  return SCIP_OKAY;
1004 }
1005 
1006 /** returns whether the current stage belongs to the transformed problem space
1007  *
1008  * @return Returns TRUE if the \SCIP instance is transformed, otherwise FALSE
1009  */
1011  SCIP* scip /**< SCIP data structure */
1012  )
1013 {
1014  assert(scip != NULL);
1015 
1016  return ((int)scip->set->stage >= (int)SCIP_STAGE_TRANSFORMING);
1017 }
1018 
1019 /** returns whether the solution process should be probably correct
1020  *
1021  * @note This feature is not supported yet!
1022  *
1023  * @return Returns TRUE if \SCIP is exact solving mode, otherwise FALSE
1024  */
1026  SCIP* scip /**< SCIP data structure */
1027  )
1028 {
1029  assert(scip != NULL);
1030  assert(scip->set != NULL);
1031 
1032  return (scip->set->misc_exactsolve);
1033 }
1034 
1035 /** returns whether the presolving process would be finished given no more presolving reductions are found in this
1036  * presolving round
1037  *
1038  * Checks whether the number of presolving rounds is not exceeded and the presolving reductions found in the current
1039  * presolving round suffice to trigger another presolving round.
1040  *
1041  * @note if subsequent presolvers find more reductions, presolving might continue even if the method returns FALSE
1042  * @note does not check whether infeasibility or unboundedness was already detected in presolving (which would result
1043  * in presolving being stopped although the method returns TRUE)
1044  *
1045  * @return Returns TRUE if presolving is finished if no further reductions are detected
1046  */
1048  SCIP* scip /**< SCIP data structure */
1049  )
1050 {
1051  int maxnrounds;
1052  SCIP_Bool finished;
1053 
1054  assert(scip != NULL);
1055  assert(scip->stat != NULL);
1056  assert(scip->transprob != NULL);
1057 
1058  SCIP_CALL_ABORT( checkStage(scip, "SCIPisPresolveFinished", FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1059 
1060  /* get maximum number of presolving rounds */
1061  maxnrounds = scip->set->presol_maxrounds;
1062  if( maxnrounds == -1 )
1063  maxnrounds = INT_MAX;
1064 
1065  /* don't abort, if enough changes were applied to the variables */
1066  finished = (scip->transprob->nvars == 0
1067  || (scip->stat->npresolfixedvars - scip->stat->lastnpresolfixedvars
1068  + scip->stat->npresolaggrvars - scip->stat->lastnpresolaggrvars
1070  + (scip->stat->npresolchgbds - scip->stat->lastnpresolchgbds)/10.0
1071  + (scip->stat->npresoladdholes - scip->stat->lastnpresoladdholes)/10.0
1072  <= scip->set->presol_abortfac * scip->transprob->nvars)); /*lint !e653*/
1073 
1074  /* don't abort, if enough changes were applied to the constraints */
1075  finished = finished
1076  && (scip->transprob->nconss == 0
1077  || (scip->stat->npresoldelconss - scip->stat->lastnpresoldelconss
1078  + scip->stat->npresoladdconss - scip->stat->lastnpresoladdconss
1080  + scip->stat->npresolchgsides - scip->stat->lastnpresolchgsides
1081  <= scip->set->presol_abortfac * scip->transprob->nconss));
1082 
1083  /* don't abort, if enough changes were applied to the coefficients (assume a 1% density of non-zero elements) */
1084  finished = finished
1085  && (scip->transprob->nvars == 0 || scip->transprob->nconss == 0
1086  || (scip->stat->npresolchgcoefs - scip->stat->lastnpresolchgcoefs
1087  <= scip->set->presol_abortfac * 0.01 * scip->transprob->nvars * scip->transprob->nconss));
1088 
1089 #ifdef SCIP_DISABLED_CODE
1090  /* since 2005, we do not take cliques and implications into account when deciding whether to stop presolving */
1091  /* don't abort, if enough new implications or cliques were found (assume 100 implications per variable) */
1092  finished = finished
1093  && (scip->stat->nimplications - scip->stat->lastnpresolimplications
1094  <= scip->set->presol_abortfac * 100 * scip->transprob->nbinvars)
1095  && (SCIPcliquetableGetNCliques(scip->cliquetable) - scip->stat->lastnpresolcliques
1096  <= scip->set->presol_abortfac * scip->transprob->nbinvars);
1097 #endif
1098 
1099  /* abort if maximal number of presolving rounds is reached */
1100  finished = finished || (scip->stat->npresolrounds + 1 >= maxnrounds);
1101 
1102  return finished;
1103 }
1104 
1105 /** returns whether SCIP has performed presolving during the last solve
1106  *
1107  * @return Returns TRUE if presolving was performed during the last solve
1108  */
1110  SCIP* scip /**< SCIP data structure */
1111  )
1112 {
1113  assert(scip != NULL);
1114  assert(scip->stat != NULL);
1115 
1116  SCIP_CALL_ABORT( checkStage(scip, "SCIPhasPerformedPresolve", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
1117 
1118  return scip->stat->performpresol;
1119 }
1120 
1121 /** returns whether the user pressed CTRL-C to interrupt the solving process
1122  *
1123  * @return Returns TRUE if Ctrl-C was pressed, otherwise FALSE.
1124  */
1126  SCIP* scip /**< SCIP data structure */
1127  )
1128 {
1129  return SCIPinterrupted();
1130 }
1131 
1132 /** returns whether the solving process should be / was stopped before proving optimality;
1133  * if the solving process should be / was stopped, the status returned by SCIPgetStatus() yields
1134  * the reason for the premature abort
1135  *
1136  * @return Returns TRUE if solving process is stopped/interrupted, otherwise FALSE.
1137  */
1139  SCIP* scip /**< SCIP data structure */
1140  )
1141 {
1142  SCIP_CALL_ABORT( checkStage(scip, "SCIPisStopped", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
1143 
1144  return SCIPsolveIsStopped(scip->set, scip->stat, FALSE);
1145 }
1146 
1147 /** enable debug solution mechanism
1148  *
1149  * the debug solution mechanism allows to trace back the invalidation of
1150  * a debug solution during the solution process of SCIP. It must be explicitly
1151  * enabled for the SCIP data structure.
1152  *
1153  * @see debug.h for more information on debug solution mechanism
1154  */
1156  SCIP* scip /**< SCIP data structure */
1157  )
1158 {
1159  SCIP_CALL_ABORT( checkStage(scip, "SCIPenableDebugSol", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
1160 
1161  SCIPdebugSolEnable(scip);
1162 }
1163 
1164 /** disable solution debugging mechanism
1165  *
1166  * @see debug.h for more information on debug solution mechanism
1167  */
1169  SCIP* scip /**< SCIP data structure */
1170  )
1171 {
1172  SCIP_CALL_ABORT( checkStage(scip, "SCIPdisableDebugSol", TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
1173 
1174  SCIPdebugSolDisable(scip);
1175 }
1176 
1177 /*
1178  * message output methods
1179  */
1180 
1181 /** installs the given message handler, such that all messages are passed to this handler. A messages handler can be
1182  * created via SCIPmessagehdlrCreate().
1183  *
1184  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1185  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1186  *
1187  * @pre this method can be called in one of the following stages of the SCIP solving process:
1188  * - \ref SCIP_STAGE_INIT
1189  * - \ref SCIP_STAGE_PROBLEM
1190  *
1191  * @note The currently installed messages handler gets freed if this SCIP instance is its last user (w.r.t. capture/release).
1192  */
1194  SCIP* scip, /**< SCIP data structure */
1195  SCIP_MESSAGEHDLR* messagehdlr /**< message handler to install, or NULL to suppress all output */
1196  )
1197 {
1198  int i;
1199 
1200  SCIP_CALL( checkStage(scip, "SCIPsetMessagehdlr", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
1201 
1202  assert(scip != NULL);
1203  assert(scip->set != NULL);
1204  assert(scip->set->nlpis != NULL || scip->set->nnlpis == 0);
1205 
1206  /* update message handler in NLP solver interfaces */
1207  for( i = 0; i < scip->set->nnlpis; ++i )
1208  {
1209  assert(scip->set->nlpis[i] != NULL);
1210 
1211  SCIP_CALL( SCIPnlpiSetMessageHdlr(scip->set->nlpis[i], messagehdlr) );
1212  }
1213 
1214  SCIPmessagehdlrCapture(messagehdlr);
1215 
1217  assert(scip->messagehdlr == NULL);
1218 
1219  scip->messagehdlr = messagehdlr;
1220 
1221  return SCIP_OKAY;
1222 }
1223 
1224 /** returns the currently installed message handler
1225  *
1226  * @return the currently installed message handler, or NULL if messages are currently suppressed
1227  */
1229  SCIP* scip /**< SCIP data structure */
1230  )
1231 {
1232  return scip->messagehdlr;
1233 }
1234 
1235 /** sets the log file name for the currently installed message handler */
1237  SCIP* scip, /**< SCIP data structure */
1238  const char* filename /**< name of log file, or NULL (no log) */
1239  )
1240 {
1241  if( scip->messagehdlr != NULL )
1242  {
1243  SCIPmessagehdlrSetLogfile(scip->messagehdlr, filename);
1244  }
1245 }
1246 
1247 /** sets the currently installed message handler to be quiet (or not) */
1249  SCIP* scip, /**< SCIP data structure */
1250  SCIP_Bool quiet /**< should screen messages be suppressed? */
1251  )
1252 {
1253  if( scip->messagehdlr != NULL )
1254  {
1255  SCIPmessagehdlrSetQuiet(scip->messagehdlr, quiet);
1256  }
1257 }
1258 
1259 /** prints a warning message via the message handler */
1261  SCIP* scip, /**< SCIP data structure */
1262  const char* formatstr, /**< format string like in printf() function */
1263  ... /**< format arguments line in printf() function */
1264  )
1265 {
1266  va_list ap;
1267 
1268  assert(scip != NULL);
1269 
1270  va_start(ap, formatstr); /*lint !e838*/
1271  SCIPmessageVFPrintWarning(scip->messagehdlr, formatstr, ap);
1272  va_end(ap);
1273 }
1274 
1275 /** prints a debug message */
1277  SCIP* scip, /**< SCIP data structure */
1278  const char* sourcefile, /**< name of the source file that called the function */
1279  int sourceline, /**< line in the source file where the function was called */
1280  const char* formatstr, /**< format string like in printf() function */
1281  ... /**< format arguments line in printf() function */
1282  )
1283 {
1284  int subscipdepth = 0;
1285  va_list ap;
1286 
1287  assert( sourcefile != NULL );
1288  assert( scip != NULL );
1289 
1290  if ( scip->stat != NULL )
1291  subscipdepth = scip->stat->subscipdepth;
1292  if ( subscipdepth > 0 )
1293  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "%d: [%s:%d] debug: ", subscipdepth, sourcefile, sourceline);
1294  else
1295  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "[%s:%d] debug: ", sourcefile, sourceline);
1296 
1297  va_start(ap, formatstr); /*lint !e838*/
1298  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
1299  va_end(ap);
1300 }
1301 
1302 /** prints a debug message without precode */
1304  SCIP* scip, /**< SCIP data structure */
1305  const char* formatstr, /**< format string like in printf() function */
1306  ... /**< format arguments line in printf() function */
1307  )
1308 {
1309  va_list ap;
1310 
1311  assert( scip != NULL );
1312 
1313  va_start(ap, formatstr); /*lint !e838*/
1314  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
1315  va_end(ap);
1316 }
1317 
1318 /** prints a dialog message that requests user interaction or is a direct response to a user interactive command */
1320  SCIP* scip, /**< SCIP data structure */
1321  FILE* file, /**< file stream to print into, or NULL for stdout */
1322  const char* formatstr, /**< format string like in printf() function */
1323  ... /**< format arguments line in printf() function */
1324  )
1325 {
1326  va_list ap;
1327 
1328  assert(scip != NULL);
1329 
1330  va_start(ap, formatstr); /*lint !e838*/
1331  SCIPmessageVFPrintDialog(scip->messagehdlr, file, formatstr, ap);
1332  va_end(ap);
1333 }
1334 
1335 /** prints a message */
1337  SCIP* scip, /**< SCIP data structure */
1338  FILE* file, /**< file stream to print into, or NULL for stdout */
1339  const char* formatstr, /**< format string like in printf() function */
1340  ... /**< format arguments line in printf() function */
1341  )
1342 {
1343  va_list ap;
1344 
1345  assert(scip != NULL);
1346 
1347  va_start(ap, formatstr); /*lint !e838*/
1348  SCIPmessageVFPrintInfo(scip->messagehdlr, file, formatstr, ap);
1349  va_end(ap);
1350 }
1351 
1352 /** prints a message depending on the verbosity level */
1354  SCIP* scip, /**< SCIP data structure */
1355  SCIP_VERBLEVEL msgverblevel, /**< verbosity level of this message */
1356  FILE* file, /**< file stream to print into, or NULL for stdout */
1357  const char* formatstr, /**< format string like in printf() function */
1358  ... /**< format arguments line in printf() function */
1359  )
1360 {
1361  va_list ap;
1362 
1363  assert(scip != NULL);
1364  assert(scip->set != NULL);
1365 
1366  va_start(ap, formatstr); /*lint !e838*/
1367  SCIPmessageVFPrintVerbInfo(scip->messagehdlr, scip->set->disp_verblevel, msgverblevel, file, formatstr, ap);
1368  va_end(ap);
1369 }
1370 
1371 /** returns the current message verbosity level
1372  *
1373  * @return message verbosity level of SCIP
1374  *
1375  * @see \ref SCIP_VerbLevel "SCIP_VERBLEVEL" for a list of all verbosity levels
1376  */
1378  SCIP* scip /**< SCIP data structure */
1379  )
1380 {
1381  assert(scip != NULL);
1382  assert(scip->set != NULL);
1383 
1384  return scip->set->disp_verblevel;
1385 }
1386 
1387 
1388 /*
1389  * SCIP copy methods
1390  */
1391 
1392 /** returns true if the @p cut matches the selection criterium for copying */
1393 static
1395  SCIP* scip, /**< SCIP data structure */
1396  SCIP_CUT* cut, /**< a cut */
1397  char cutsel /**< cut selection for sub SCIPs ('a'ge, activity 'q'uotient) */
1398  )
1399 {
1400  SCIP_Bool takecut;
1401 
1402  assert(cut != NULL);
1403 
1404  if( !SCIProwIsInLP(SCIPcutGetRow(cut)) )
1405  return FALSE;
1406 
1407  switch( cutsel )
1408  {
1409  case 'a':
1410  takecut = (SCIPcutGetAge(cut) == 0);
1411  break;
1412  case 'q':
1413  takecut = (SCIPcutGetLPActivityQuot(cut) >= scip->set->sepa_minactivityquot);
1414  break;
1415  default:
1416  SCIPerrorMessage("unknown cut selection strategy %c, must be either 'a' or 'q'\n");
1417  SCIPABORT();
1418  takecut = FALSE; /*lint !e527*/
1419  break;
1420  }
1421 
1422  return takecut;
1423 }
1424 
1425 /** copy active and tight cuts from one SCIP instance to linear constraints of another SCIP instance */
1426 static
1428  SCIP* sourcescip, /**< source SCIP data structure */
1429  SCIP* targetscip, /**< target SCIP data structure */
1430  SCIP_CUT** cuts, /**< cuts to copy */
1431  int ncuts, /**< number of cuts to copy */
1432  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
1433  * target variables, or NULL */
1434  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1435  * target constraints, or NULL */
1436  SCIP_Bool global, /**< create a global or a local copy? */
1437  int* ncutsadded /**< pointer to store number of copied cuts */
1438  )
1439 {
1440  int c;
1441 
1442  assert(sourcescip != NULL);
1443  assert(targetscip != NULL);
1444  assert(cuts != NULL || ncuts == 0);
1445  assert(ncutsadded != NULL);
1446 
1447  for( c = 0; c < ncuts; ++c )
1448  {
1449  SCIP_ROW* row;
1450  SCIP_Bool takecut;
1451 
1452  assert( cuts[c] != NULL ); /*lint !e613*/
1453  row = SCIPcutGetRow(cuts[c]); /*lint !e613*/
1454  assert(!SCIProwIsLocal(row));
1455  assert(!SCIProwIsModifiable(row));
1456 
1457  /* in case of a restart, convert the cuts with a good LP activity quotient; in other cases, e.g., when heuristics
1458  * copy cuts into subscips, take only currently active ones
1459  */
1460  if( sourcescip == targetscip )
1461  {
1462  assert( SCIPisInRestart(sourcescip) );
1463  takecut = takeCut(sourcescip, cuts[c], sourcescip->set->sepa_cutselrestart); /*lint !e613*/
1464  }
1465  else
1466  takecut = takeCut(sourcescip, cuts[c], sourcescip->set->sepa_cutselsubscip); /*lint !e613*/
1467 
1468  /* create a linear constraint out of the cut */
1469  if( takecut )
1470  {
1471  char name[SCIP_MAXSTRLEN];
1472  SCIP_CONS* cons;
1473  SCIP_COL** cols;
1474  SCIP_VAR** vars;
1475  int ncols;
1476  int i;
1477 
1478  cols = SCIProwGetCols(row);
1479  ncols = SCIProwGetNNonz(row);
1480 
1481  /* get all variables of the row */
1482  SCIP_CALL( SCIPallocBufferArray(targetscip, &vars, ncols) );
1483  for( i = 0; i < ncols; ++i )
1484  vars[i] = SCIPcolGetVar(cols[i]);
1485 
1486  /* get corresponding variables in targetscip if necessary */
1487  if( sourcescip != targetscip )
1488  {
1489  SCIP_Bool success;
1490 
1491  for( i = 0; i < ncols; ++i )
1492  {
1493  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, vars[i], &vars[i], varmap, consmap, global, &success) );
1494 
1495  if( !success )
1496  {
1497  SCIPdebugMsg(sourcescip, "Converting cuts to constraints failed.\n");
1498 
1499  /* free temporary memory */
1500  SCIPfreeBufferArray(targetscip, &vars);
1501  return SCIP_OKAY;
1502  }
1503  }
1504  }
1505 
1506  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%d", SCIProwGetName(row), SCIPgetNRuns(sourcescip));
1507  SCIP_CALL( SCIPcreateConsLinear(targetscip, &cons, name, ncols, vars, SCIProwGetVals(row),
1510  SCIP_CALL( SCIPaddCons(targetscip, cons) );
1511 
1512  SCIPdebugMsg(sourcescip, "Converted cut <%s> to constraint <%s>.\n", SCIProwGetName(row), SCIPconsGetName(cons));
1513  SCIPdebugPrintCons(targetscip, cons, NULL);
1514  SCIP_CALL( SCIPreleaseCons(targetscip, &cons) );
1515 
1516  /* free temporary memory */
1517  SCIPfreeBufferArray(targetscip, &vars);
1518 
1519  ++(*ncutsadded);
1520  }
1521  }
1522 
1523  return SCIP_OKAY;
1524 }
1525 
1526 /** copies plugins from sourcescip to targetscip; in case that a constraint handler which does not need constraints
1527  * cannot be copied, valid will return FALSE. All plugins can declare that, if their copy process failed, the
1528  * copied SCIP instance might not represent the same problem semantics as the original.
1529  * Note that in this case dual reductions might be invalid.
1530  *
1531  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1532  * Also, 'passmessagehdlr' should be set to FALSE.
1533  * @note Do not change the source SCIP environment during the copying process
1534  *
1535  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1536  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1537  *
1538  * @pre This method can be called if sourcescip is in one of the following stages:
1539  * - \ref SCIP_STAGE_PROBLEM
1540  * - \ref SCIP_STAGE_TRANSFORMED
1541  * - \ref SCIP_STAGE_INITPRESOLVE
1542  * - \ref SCIP_STAGE_PRESOLVING
1543  * - \ref SCIP_STAGE_EXITPRESOLVE
1544  * - \ref SCIP_STAGE_PRESOLVED
1545  * - \ref SCIP_STAGE_INITSOLVE
1546  * - \ref SCIP_STAGE_SOLVING
1547  * - \ref SCIP_STAGE_SOLVED
1548  *
1549  * @pre This method can be called if targetscip is in one of the following stages:
1550  * - \ref SCIP_STAGE_INIT
1551  * - \ref SCIP_STAGE_FREE
1552  *
1553  * @post After calling this method targetscip reaches one of the following stages depending on if and when the solution
1554  * process was interrupted:
1555  * - \ref SCIP_STAGE_PROBLEM
1556  *
1557  * @note sourcescip stage does not get changed
1558  *
1559  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1560  */
1562  SCIP* sourcescip, /**< source SCIP data structure */
1563  SCIP* targetscip, /**< target SCIP data structure */
1564  SCIP_Bool copyreaders, /**< should the file readers be copied */
1565  SCIP_Bool copypricers, /**< should the variable pricers be copied */
1566  SCIP_Bool copyconshdlrs, /**< should the constraint handlers be copied */
1567  SCIP_Bool copyconflicthdlrs, /**< should the conflict handlers be copied */
1568  SCIP_Bool copypresolvers, /**< should the presolvers be copied */
1569  SCIP_Bool copyrelaxators, /**< should the relaxation handlers be copied */
1570  SCIP_Bool copyseparators, /**< should the separators be copied */
1571  SCIP_Bool copypropagators, /**< should the propagators be copied */
1572  SCIP_Bool copyheuristics, /**< should the heuristics be copied */
1573  SCIP_Bool copyeventhdlrs, /**< should the event handlers be copied */
1574  SCIP_Bool copynodeselectors, /**< should the node selectors be copied */
1575  SCIP_Bool copybranchrules, /**< should the branchrules be copied */
1576  SCIP_Bool copydisplays, /**< should the display columns be copied */
1577  SCIP_Bool copydialogs, /**< should the dialogs be copied */
1578  SCIP_Bool copynlpis, /**< should the NLPIs be copied */
1579  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
1580  SCIP_Bool* valid /**< pointer to store whether plugins, in particular all constraint
1581  * handlers which do not need constraints were validly copied */
1582  )
1583 {
1584  assert(sourcescip != NULL);
1585  assert(targetscip != NULL);
1586  assert(sourcescip->set != NULL);
1587  assert(targetscip->set != NULL);
1588 
1589  /* check stages for both, the source and the target SCIP data structure */
1590  SCIP_CALL( checkStage(sourcescip, "SCIPcopyPlugins", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1591  SCIP_CALL( checkStage(targetscip, "SCIPcopyPlugins", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
1592 
1593  /* passes the message handler of the source SCIP to the target SCIP, also if NULL */
1594  if( passmessagehdlr )
1595  {
1596  SCIP_CALL( SCIPsetMessagehdlr(targetscip, SCIPgetMessagehdlr(sourcescip)) );
1597  }
1598 
1599  SCIP_CALL( SCIPsetCopyPlugins(sourcescip->set, targetscip->set,
1600  copyreaders, copypricers, copyconshdlrs, copyconflicthdlrs, copypresolvers, copyrelaxators, copyseparators, copypropagators,
1601  copyheuristics, copyeventhdlrs, copynodeselectors, copybranchrules, copydisplays, copydialogs, copynlpis, valid) );
1602 
1603  return SCIP_OKAY;
1604 }
1605 
1606 /** create a problem by copying the problem data of the source SCIP */
1607 static
1609  SCIP* sourcescip, /**< source SCIP data structure */
1610  SCIP* targetscip, /**< target SCIP data structure */
1611  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
1612  * target variables, or NULL */
1613  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1614  * target constraints, or NULL */
1615  SCIP_Bool original, /**< should the original problem be copied? */
1616  SCIP_Bool global, /**< create a global or a local copy? (set to TRUE for original copy) */
1617  const char* name /**< problem name of target */
1618  )
1619 {
1620  SCIP_PROB* sourceprob;
1621  SCIP_HASHMAP* localvarmap;
1622  SCIP_HASHMAP* localconsmap;
1623  SCIP_Bool uselocalvarmap;
1624  SCIP_Bool uselocalconsmap;
1625 
1626  assert(sourcescip != NULL);
1627  assert(targetscip != NULL);
1628  assert(!original || global);
1629 
1630  /* free old problem */
1631  SCIP_CALL( SCIPfreeProb(targetscip) );
1632  assert(targetscip->set->stage == SCIP_STAGE_INIT);
1633 
1634  uselocalvarmap = (varmap == NULL);
1635  uselocalconsmap = (consmap == NULL);
1636 
1637  if( uselocalvarmap )
1638  {
1639  /* create the variable mapping hash map */
1640  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
1641  }
1642  else
1643  localvarmap = varmap;
1644 
1645  if( uselocalconsmap )
1646  {
1647  /* create the constraint mapping hash map */
1648  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
1649  }
1650  else
1651  localconsmap = consmap;
1652 
1653  /* switch stage to PROBLEM */
1654  targetscip->set->stage = SCIP_STAGE_PROBLEM;
1655 
1656  if( !original && SCIPisTransformed(sourcescip) )
1657  sourceprob = sourcescip->transprob;
1658  else
1659  sourceprob = sourcescip->origprob;
1660 
1661  /* create the statistics data structure */
1662  SCIP_CALL( SCIPstatCreate(&targetscip->stat, targetscip->mem->probmem, targetscip->set, targetscip->transprob, targetscip->origprob, targetscip->messagehdlr) );
1663  targetscip->stat->subscipdepth = sourcescip->stat->subscipdepth + 1;
1664 
1665  /* create the problem by copying the source problem */
1666  SCIP_CALL( SCIPprobCopy(&targetscip->origprob, targetscip->mem->probmem, targetscip->set, name, sourcescip, sourceprob, localvarmap, localconsmap, global) );
1667 
1668  /* creating the solution candidates storage */
1669  /**@todo copy solution of source SCIP as candidates for the target SCIP */
1670  SCIP_CALL( SCIPprimalCreate(&targetscip->origprimal) );
1671 
1672  /* create conflict store to store conflict constraints */
1673  SCIP_CALL( SCIPconflictstoreCreate(&targetscip->conflictstore, targetscip->set) );
1674 
1675  if( uselocalvarmap )
1676  {
1677  /* free hash map */
1678  SCIPhashmapFree(&localvarmap);
1679  }
1680 
1681  if( uselocalconsmap )
1682  {
1683  /* free hash map */
1684  SCIPhashmapFree(&localconsmap);
1685  }
1686 
1687  return SCIP_OKAY;
1688 }
1689 
1690 
1691 /** create a problem by copying the problem data of the source SCIP
1692  *
1693  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1694  * @note Do not change the source SCIP environment during the copying process
1695  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1696  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1697  *
1698  * @pre This method can be called if sourcescip is in one of the following stages:
1699  * - \ref SCIP_STAGE_PROBLEM
1700  * - \ref SCIP_STAGE_TRANSFORMED
1701  * - \ref SCIP_STAGE_INITPRESOLVE
1702  * - \ref SCIP_STAGE_PRESOLVING
1703  * - \ref SCIP_STAGE_EXITPRESOLVE
1704  * - \ref SCIP_STAGE_PRESOLVED
1705  * - \ref SCIP_STAGE_INITSOLVE
1706  * - \ref SCIP_STAGE_SOLVING
1707  * - \ref SCIP_STAGE_SOLVED
1708  *
1709  * @pre This method can be called if targetscip is in one of the following stages:
1710  * - \ref SCIP_STAGE_INIT
1711  * - \ref SCIP_STAGE_PROBLEM
1712  * - \ref SCIP_STAGE_TRANSFORMED
1713  * - \ref SCIP_STAGE_INITPRESOLVE
1714  * - \ref SCIP_STAGE_PRESOLVING
1715  * - \ref SCIP_STAGE_EXITPRESOLVE
1716  * - \ref SCIP_STAGE_PRESOLVED
1717  * - \ref SCIP_STAGE_INITSOLVE
1718  * - \ref SCIP_STAGE_SOLVING
1719  * - \ref SCIP_STAGE_SOLVED
1720  * - \ref SCIP_STAGE_FREE
1721  *
1722  * @post After calling this method targetscip reaches one of the following stages depending on if and when the solution
1723  * process was interrupted:
1724  * - \ref SCIP_STAGE_PROBLEM
1725  *
1726  * @note sourcescip stage does not get changed
1727  *
1728  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1729  */
1731  SCIP* sourcescip, /**< source SCIP data structure */
1732  SCIP* targetscip, /**< target SCIP data structure */
1733  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
1734  * target variables, or NULL */
1735  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1736  * target constraints, or NULL */
1737  SCIP_Bool global, /**< create a global or a local copy? */
1738  const char* name /**< problem name of target */
1739  )
1740 {
1741  assert(sourcescip != NULL);
1742  assert(targetscip != NULL);
1743 
1744  /* check stages for both, the source and the target SCIP data structure */
1745  SCIP_CALL( checkStage(sourcescip, "SCIPcopyProb", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1746  SCIP_CALL( checkStage(targetscip, "SCIPcopyProb", TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE) );
1747 
1748  SCIP_CALL( copyProb(sourcescip, targetscip, varmap, consmap, FALSE, global, name) );
1749 
1750  return SCIP_OKAY;
1751 }
1752 
1753 /** create a problem by copying the original problem data of the source SCIP
1754  *
1755  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1756  * @note Do not change the source SCIP environment during the copying process
1757  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1758  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1759  *
1760  * @pre This method can be called if sourcescip is in one of the following stages:
1761  * - \ref SCIP_STAGE_PROBLEM
1762  * - \ref SCIP_STAGE_TRANSFORMED
1763  * - \ref SCIP_STAGE_INITPRESOLVE
1764  * - \ref SCIP_STAGE_PRESOLVING
1765  * - \ref SCIP_STAGE_EXITPRESOLVE
1766  * - \ref SCIP_STAGE_PRESOLVED
1767  * - \ref SCIP_STAGE_INITSOLVE
1768  * - \ref SCIP_STAGE_SOLVING
1769  * - \ref SCIP_STAGE_SOLVED
1770  *
1771  * @pre This method can be called if targetscip is in one of the following stages:
1772  * - \ref SCIP_STAGE_INIT
1773  * - \ref SCIP_STAGE_FREE
1774  *
1775  * @post After calling this method targetscip reaches one of the following stages depending on if and when the solution
1776  * process was interrupted:
1777  * - \ref SCIP_STAGE_PROBLEM
1778  *
1779  * @note sourcescip stage does not get changed
1780  *
1781  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1782  */
1784  SCIP* sourcescip, /**< source SCIP data structure */
1785  SCIP* targetscip, /**< target SCIP data structure */
1786  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
1787  * target variables, or NULL */
1788  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1789  * target constraints, or NULL */
1790  const char* name /**< problem name of target */
1791  )
1792 {
1793  assert(sourcescip != NULL);
1794  assert(targetscip != NULL);
1795 
1796  /* check stages for both, the source and the target SCIP data structure */
1797  SCIP_CALL( checkStage(sourcescip, "SCIPcopyOrigProb", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1798  SCIP_CALL( checkStage(targetscip, "SCIPcopyOrigProb", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
1799 
1800  SCIP_CALL( copyProb(sourcescip, targetscip, varmap, consmap, TRUE, TRUE, name) );
1801 
1802  /* set the correct objective sense; necessary if we maximize in the original problem */
1803  SCIP_CALL( SCIPsetObjsense(targetscip, SCIPgetObjsense(sourcescip)) );
1804 
1805  return SCIP_OKAY;
1806 }
1807 
1808 /** enables constraint compression.
1809  *
1810  * If constraint compression is enabled, fixed variables will be treated as constants
1811  * by all constraints that are copied after calling this method.
1812  *
1813  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1814  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1815  *
1816  * @pre This method can be called if scip is in one of the following stages:
1817  * - \ref SCIP_STAGE_PROBLEM
1818  *
1819  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1820  */
1822  SCIP* scip /**< source SCIP data structure */
1823  )
1824 {
1825  assert(scip != NULL);
1826  assert(scip->origprob != NULL);
1827 
1828 
1829  /* check stage */
1830  SCIP_CALL( checkStage(scip, "SCIPenableConsCompression", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1831 
1832  /* enable problem compression */
1834 
1835  return SCIP_OKAY;
1836 }
1837 
1838 /** is constraint compression enabled?
1839  *
1840  * If constraint compression is enabled, fixed variables can be treated as constants
1841  * by all constraints that are copied after calling this method.
1842  *
1843  * @return TRUE if problem constraint compression is enabled, otherwise FALSE
1844  *
1845  * @pre This method can be called if scip is in one of the following stages:
1846  * - \ref SCIP_STAGE_PROBLEM
1847  * - \ref SCIP_STAGE_TRANSFORMING
1848  * - \ref SCIP_STAGE_TRANSFORMED
1849  * - \ref SCIP_STAGE_INITPRESOLVE
1850  * - \ref SCIP_STAGE_PRESOLVING
1851  * - \ref SCIP_STAGE_EXITPRESOLVE
1852  * - \ref SCIP_STAGE_PRESOLVED
1853  * - \ref SCIP_STAGE_INITSOLVE
1854  * - \ref SCIP_STAGE_SOLVING
1855  * - \ref SCIP_STAGE_SOLVED
1856  * - \ref SCIP_STAGE_EXITSOLVE
1857  * - \ref SCIP_STAGE_FREETRANS
1858  *
1859  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1860  */
1862  SCIP* scip /**< source SCIP data structure */
1863  )
1864 {
1865  assert(scip != NULL);
1866  assert(scip->origprob != NULL);
1867 
1868  /* check stage */
1869  SCIP_CALL_ABORT( checkStage(scip, "SCIPisConsCompressionEnabled", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
1870 
1871  /* is problem compression enabled */
1873 }
1874 
1875 /** returns copy of the source variable; if there already is a copy of the source variable in the variable hash map,
1876  * it is just returned as target variable; otherwise a new variable will be created and added to the target SCIP; this
1877  * created variable is added to the variable hash map and returned as target variable
1878  *
1879  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1880  * @note Do not change the source SCIP environment during the copying process
1881  * @note if a new variable was created, this variable will be added to the target-SCIP, but it is not captured
1882  *
1883  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1884  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1885  *
1886  * @pre This method can be called if sourcescip is in one of the following stages:
1887  * - \ref SCIP_STAGE_PROBLEM
1888  * - \ref SCIP_STAGE_TRANSFORMED
1889  * - \ref SCIP_STAGE_INITPRESOLVE
1890  * - \ref SCIP_STAGE_PRESOLVING
1891  * - \ref SCIP_STAGE_EXITPRESOLVE
1892  * - \ref SCIP_STAGE_PRESOLVED
1893  * - \ref SCIP_STAGE_INITSOLVE
1894  * - \ref SCIP_STAGE_SOLVING
1895  * - \ref SCIP_STAGE_SOLVED
1896  *
1897  * @pre This method can be called if targetscip is in one of the following stages:
1898  * - \ref SCIP_STAGE_PROBLEM
1899  * - \ref SCIP_STAGE_TRANSFORMED
1900  * - \ref SCIP_STAGE_INITPRESOLVE
1901  * - \ref SCIP_STAGE_PRESOLVING
1902  * - \ref SCIP_STAGE_EXITPRESOLVE
1903  * - \ref SCIP_STAGE_SOLVING
1904  *
1905  * @note targetscip stage does not get changed
1906  *
1907  * @note sourcescip stage does not get changed
1908  *
1909  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1910  */
1912  SCIP* sourcescip, /**< source SCIP data structure */
1913  SCIP* targetscip, /**< target SCIP data structure */
1914  SCIP_VAR* sourcevar, /**< source variable */
1915  SCIP_VAR** targetvar, /**< pointer to store the target variable */
1916  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
1917  * target variables, or NULL */
1918  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1919  * target constraints, or NULL */
1920  SCIP_Bool global, /**< should global or local bounds be used? */
1921  SCIP_Bool* success /**< pointer to store whether the copying was successful or not */
1922  )
1923 {
1924  SCIP_HASHMAP* localvarmap;
1925  SCIP_HASHMAP* localconsmap;
1926  SCIP_VAR* var;
1927  SCIP_Bool uselocalvarmap;
1928  SCIP_Bool uselocalconsmap;
1929 
1930  assert(sourcescip != NULL);
1931  assert(targetscip != NULL);
1932  assert(sourcevar != NULL);
1933  assert(targetvar != NULL);
1934  assert(sourcevar->scip == sourcescip);
1935 
1936  /* check stages for both, the source and the target SCIP data structure */
1937  SCIP_CALL( checkStage(sourcescip, "SCIPgetVarCopy", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1938  SCIP_CALL( checkStage(targetscip, "SCIPgetVarCopy", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1939 
1940  uselocalvarmap = (varmap == NULL);
1941  uselocalconsmap = (consmap == NULL);
1942  *success = TRUE;
1943 
1944  /* try to retrieve copied variable from hashmap */
1945  if( !uselocalvarmap )
1946  {
1947  *targetvar = (SCIP_VAR*) SCIPhashmapGetImage(varmap, sourcevar);
1948  if( *targetvar != NULL )
1949  return SCIP_OKAY;
1950  }
1951 
1952  /* if the target SCIP is already in solving stage we currently are not copying the variable!
1953  * this has to be done because we cannot simply add variables to SCIP during solving and thereby enlarge the search
1954  * space.
1955  * unlike column generation we cannot assume here that the variable could be implicitly set to zero in all prior
1956  * computations
1957  */
1958  if( SCIPgetStage(targetscip) > SCIP_STAGE_PROBLEM )
1959  {
1960  *success = FALSE;
1961  *targetvar = NULL;
1962 
1963  return SCIP_OKAY;
1964  }
1965 
1966  /* create the variable mapping hash map */
1967  if( uselocalvarmap )
1968  {
1969  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
1970  }
1971  else
1972  localvarmap = varmap;
1973 
1974  if( uselocalconsmap )
1975  {
1976  /* create the constraint mapping hash map */
1977  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
1978  }
1979  else
1980  localconsmap = consmap;
1981 
1982  /* if variable does not exist yet in target SCIP, create it */
1983  switch( SCIPvarGetStatus(sourcevar) )
1984  {
1986  case SCIP_VARSTATUS_COLUMN:
1987  case SCIP_VARSTATUS_LOOSE:
1988  case SCIP_VARSTATUS_FIXED:
1989  SCIP_CALL( SCIPvarCopy(&var, targetscip->mem->probmem, targetscip->set, targetscip->stat,
1990  sourcescip, sourcevar, localvarmap, localconsmap, global) );
1991  break;
1992 
1994  {
1995  SCIP_CONS* cons;
1996  char name[SCIP_MAXSTRLEN];
1997 
1998  SCIP_VAR* sourceaggrvar;
1999  SCIP_VAR* targetaggrvar;
2000  SCIP_Real aggrcoef;
2001  SCIP_Real constant;
2002 
2003  /* get aggregation data */
2004  sourceaggrvar = SCIPvarGetAggrVar(sourcevar);
2005  aggrcoef = SCIPvarGetAggrScalar(sourcevar);
2006  constant = SCIPvarGetAggrConstant(sourcevar);
2007 
2008  /* get copy of the aggregation variable */
2009  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourceaggrvar, &targetaggrvar, localvarmap, localconsmap, global, success) );
2010  assert(*success);
2011 
2012  /* create copy of the aggregated variable */
2013  SCIP_CALL( SCIPvarCopy(&var, targetscip->mem->probmem, targetscip->set, targetscip->stat,
2014  sourcescip, sourcevar, localvarmap, localconsmap, global) );
2015 
2016  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_aggr", SCIPvarGetName(sourcevar));
2017 
2018  /* add aggregation x = a*y + c as linear constraint x - a*y = c */
2019  SCIP_CALL( SCIPcreateConsLinear(targetscip, &cons, name, 0, NULL, NULL, constant,
2020  constant, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2021  SCIP_CALL( SCIPaddCoefLinear(targetscip, cons, var, 1.0) );
2022  SCIP_CALL( SCIPaddCoefLinear(targetscip, cons, targetaggrvar, -aggrcoef) );
2023 
2024  SCIP_CALL( SCIPaddCons(targetscip, cons) );
2025  SCIP_CALL( SCIPreleaseCons(targetscip, &cons) );
2026 
2027  break;
2028  }
2030  {
2031  SCIP_CONS* cons;
2032  char name[SCIP_MAXSTRLEN];
2033 
2034  SCIP_VAR** sourceaggrvars;
2035  SCIP_VAR** targetaggrvars;
2036  SCIP_Real* aggrcoefs;
2037  SCIP_Real constant;
2038 
2039  int naggrvars;
2040  int i;
2041 
2042  /* get the active representation */
2043  SCIP_CALL( SCIPflattenVarAggregationGraph(sourcescip, sourcevar) );
2044 
2045  /* get multi-aggregation data */
2046  naggrvars = SCIPvarGetMultaggrNVars(sourcevar);
2047  sourceaggrvars = SCIPvarGetMultaggrVars(sourcevar);
2048  aggrcoefs = SCIPvarGetMultaggrScalars(sourcevar);
2049  constant = SCIPvarGetMultaggrConstant(sourcevar);
2050 
2051  SCIP_CALL( SCIPallocBufferArray(targetscip, &targetaggrvars, naggrvars) );
2052 
2053  /* get copies of the active variables of the multi-aggregation */
2054  for( i = 0; i < naggrvars; ++i )
2055  {
2056  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourceaggrvars[i], &targetaggrvars[i], localvarmap, localconsmap, global, success) );
2057  assert(*success);
2058  }
2059 
2060  /* create copy of the multi-aggregated variable */
2061  SCIP_CALL( SCIPvarCopy(&var, targetscip->mem->probmem, targetscip->set, targetscip->stat,
2062  sourcescip, sourcevar, localvarmap, localconsmap, global) );
2063 
2064  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_multaggr", SCIPvarGetName(sourcevar));
2065 
2066  /* add multi-aggregation x = a^T y + c as linear constraint a^T y - x = -c */
2067  SCIP_CALL( SCIPcreateConsLinear(targetscip, &cons, name, naggrvars, targetaggrvars, aggrcoefs, -constant,
2068  -constant, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2069  SCIP_CALL( SCIPaddCoefLinear(targetscip, cons, var, -1.0) );
2070  SCIP_CALL( SCIPaddCons(targetscip, cons) );
2071  SCIP_CALL( SCIPreleaseCons(targetscip, &cons) );
2072 
2073  SCIPfreeBufferArray(targetscip, &targetaggrvars);
2074 
2075  break;
2076  }
2078  {
2079  SCIP_VAR* sourcenegatedvar;
2080  SCIP_VAR* targetnegatedvar;
2081 
2082  /* get negated source variable */
2083  sourcenegatedvar = SCIPvarGetNegationVar(sourcevar);
2084  assert(sourcenegatedvar != NULL);
2085  assert(SCIPvarGetStatus(sourcenegatedvar) != SCIP_VARSTATUS_NEGATED);
2086 
2087  /* get copy of negated source variable */
2088  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourcenegatedvar, &targetnegatedvar, localvarmap, localconsmap, global, success) );
2089  assert(*success);
2090  assert(SCIPvarGetStatus(targetnegatedvar) != SCIP_VARSTATUS_NEGATED);
2091 
2092  /* get negation of copied negated source variable, this is the target variable */
2093  SCIP_CALL( SCIPgetNegatedVar(targetscip, targetnegatedvar, targetvar) );
2094  assert(SCIPvarGetStatus(*targetvar) == SCIP_VARSTATUS_NEGATED);
2095 
2096  /* free local hash maps if necessary */
2097  if( uselocalvarmap )
2098  SCIPhashmapFree(&localvarmap);
2099 
2100  if( uselocalconsmap )
2101  SCIPhashmapFree(&localconsmap);
2102 
2103  /* we have to return right away, to avoid adding the negated variable to the problem since the "not negated"
2104  * variable was already added */
2105  return SCIP_OKAY;
2106  }
2107  default:
2108  /* note that this is in an internal SCIP error since the variable status is only handled by the core */
2109  SCIPerrorMessage("unknown variable status\n");
2110  SCIPABORT();
2111  return SCIP_ERROR; /*lint !e527*/
2112  }
2113 
2114  /* add the (new) target variable to the target problem */
2115  SCIP_CALL( SCIPaddVar(targetscip, var) );
2116 
2117  *targetvar = var;
2118 
2119  /* remove the variable capture which was done due to the creation of the variable */
2120  SCIP_CALL( SCIPreleaseVar(targetscip, &var) );
2121 
2122  /* free local hash maps if necessary */
2123  if( uselocalvarmap )
2124  SCIPhashmapFree(&localvarmap);
2125 
2126  if( uselocalconsmap )
2127  SCIPhashmapFree(&localconsmap);
2128 
2129  return SCIP_OKAY;
2130 }
2131 
2132 /** copies all original or active variables from source-SCIP and adds these variable to the target-SCIP; the mapping
2133  * between these variables are stored in the variable hashmap, target-SCIP has to be in problem creation stage, fixed
2134  * and aggregated variables do not get copied
2135  */
2136 static
2138  SCIP* sourcescip, /**< source SCIP data structure */
2139  SCIP* targetscip, /**< target SCIP data structure */
2140  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
2141  * target variables, or NULL */
2142  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2143  * target constraints, or NULL */
2144  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
2145  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
2146  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
2147  SCIP_Bool original, /**< should original variables be copied? */
2148  SCIP_Bool global /**< should global or local bounds be used? (for original=FALSE) */
2149  )
2150 {
2151  SCIP_VAR** sourcevars;
2152  SCIP_HASHMAP* localvarmap;
2153  SCIP_HASHMAP* localconsmap;
2154  SCIP_Bool uselocalvarmap;
2155  SCIP_Bool uselocalconsmap;
2156  int nsourcevars;
2157  int i;
2158 
2159  assert(sourcescip != NULL);
2160  assert(targetscip != NULL);
2161  assert(nfixedvars == 0 || fixedvars != NULL);
2162  assert(nfixedvars == 0 || fixedvals != NULL);
2163 
2164  if( original )
2165  {
2166  /* get original variables of the source SCIP */
2167  SCIP_CALL( SCIPgetOrigVarsData(sourcescip, &sourcevars, &nsourcevars, NULL, NULL, NULL, NULL) );
2168  }
2169  else
2170  {
2171  /* get active variables of the source SCIP */
2172  SCIP_CALL( SCIPgetVarsData(sourcescip, &sourcevars, &nsourcevars, NULL, NULL, NULL, NULL) );
2173  }
2174 
2175  uselocalvarmap = (varmap == NULL);
2176  uselocalconsmap = (consmap == NULL);
2177 
2178  if( uselocalvarmap )
2179  {
2180  /* create the variable mapping hash map */
2181  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
2182  }
2183  else
2184  localvarmap = varmap;
2185 
2186  if( uselocalconsmap )
2187  {
2188  /* create the constraint mapping hash map */
2189  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
2190  }
2191  else
2192  localconsmap = consmap;
2193 
2194  /* create the variables of the target SCIP */
2195  for( i = 0; i < nsourcevars; ++i )
2196  {
2197  SCIP_Bool success;
2198  SCIP_VAR* targetvar;
2199 
2200  /* copy variable and add this copy to the target SCIP if the copying was valid */
2201  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourcevars[i], &targetvar, localvarmap, localconsmap, global, &success) );
2202  assert(success);
2203  assert(targetvar != NULL);
2204  }
2205 
2206  /* fix the variables that should be fixed right away */
2207  for( i = 0; i < nfixedvars; ++i )
2208  {
2209  SCIP_VAR* targetvar;
2210  SCIP_Bool infeasible;
2211  SCIP_Bool fixed;
2212 
2213  /* retrieve target variable as image of the source variable */
2214  targetvar = (SCIP_VAR*) SCIPhashmapGetImage(localvarmap, (void *)fixedvars[i]);
2215  assert(targetvar != NULL);
2216 
2217  /* fix the variable to the specified value */
2218  infeasible = fixed = FALSE;
2219  SCIP_CALL( SCIPfixVar(targetscip, targetvar, fixedvals[i], &infeasible, &fixed) );
2220 
2221  assert(!infeasible);
2222  assert(fixed);
2223  }
2224 
2225  /* integer variables that are fixed to zero or one or have bounds [0,1] will be converted to binaries */
2226 #ifndef NDEBUG
2227  if( original )
2228  {
2229  /* TODO : account for integers converted to binaries
2230  assert(SCIPgetNOrigBinVars(sourcescip) == SCIPgetNOrigBinVars(targetscip));
2231  assert(SCIPgetNOrigIntVars(sourcescip) == SCIPgetNOrigIntVars(targetscip));
2232  assert(SCIPgetNOrigImplVars(sourcescip) == SCIPgetNOrigImplVars(targetscip));
2233  assert(SCIPgetNOrigContVars(sourcescip) == SCIPgetNOrigContVars(targetscip));
2234  */
2235  }
2236  else
2237  {
2238  SCIP_VAR** sourcefixedvars;
2239  int nsourcefixedvars;
2240  int nfixedbinvars;
2241  int nfixedintvars;
2242  int nfixedimplvars;
2243  int nfixedcontvars;
2244 
2245  sourcefixedvars = SCIPgetFixedVars(sourcescip);
2246  nsourcefixedvars = SCIPgetNFixedVars(sourcescip);
2247  nfixedbinvars = 0;
2248  nfixedintvars = 0;
2249  nfixedimplvars = 0;
2250  nfixedcontvars = 0;
2251 
2252  /* count number of fixed variables for all variable types */
2253  for( i = 0; i < nsourcefixedvars; ++i )
2254  {
2255  switch( SCIPvarGetType(sourcefixedvars[i]) )
2256  {
2257  case SCIP_VARTYPE_BINARY:
2258  nfixedbinvars++;
2259  break;
2260  case SCIP_VARTYPE_INTEGER:
2261  nfixedintvars++;
2262  break;
2263  case SCIP_VARTYPE_IMPLINT:
2264  nfixedimplvars++;
2265  break;
2267  nfixedcontvars++;
2268  break;
2269  default:
2270  SCIPerrorMessage("unknown variable type\n");
2271  return SCIP_INVALIDDATA;
2272  }
2273  }
2274  assert(nsourcefixedvars == nfixedbinvars + nfixedintvars + nfixedimplvars + nfixedcontvars);
2275  assert(SCIPgetNBinVars(sourcescip) <= SCIPgetNBinVars(targetscip));
2276  assert(SCIPgetNIntVars(sourcescip) + SCIPgetNBinVars(sourcescip) <= SCIPgetNIntVars(targetscip) + SCIPgetNBinVars(targetscip)
2277  && SCIPgetNIntVars(targetscip) + SCIPgetNBinVars(targetscip) <= SCIPgetNIntVars(sourcescip) + SCIPgetNBinVars(sourcescip) + nfixedbinvars + nfixedintvars );
2278  assert(SCIPgetNImplVars(sourcescip) <= SCIPgetNImplVars(targetscip)
2279  && SCIPgetNImplVars(targetscip) <= SCIPgetNImplVars(sourcescip) + nfixedimplvars);
2280  assert(SCIPgetNContVars(sourcescip) <= SCIPgetNContVars(targetscip)
2281  && SCIPgetNContVars(targetscip) <= SCIPgetNContVars(targetscip) + nfixedcontvars);
2282  }
2283 #endif
2284 
2285  if( uselocalvarmap )
2286  {
2287  /* free hash map */
2288  SCIPhashmapFree(&localvarmap);
2289  }
2290 
2291  if( uselocalconsmap )
2292  {
2293  /* free hash map */
2294  SCIPhashmapFree(&localconsmap);
2295  }
2296 
2297  return SCIP_OKAY;
2298 }
2299 
2300 /** copies all active variables from source-SCIP and adds these variable to the target-SCIP; the mapping between these
2301  * variables are stored in the variable hashmap, target-SCIP has to be in problem creation stage, fixed and aggregated
2302  * variables are not copied
2303  *
2304  * @note the variables are added to the target-SCIP but not captured
2305  *
2306  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2307  * @note Do not change the source SCIP environment during the copying process
2308  *
2309  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2310  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2311  *
2312  * @pre This method can be called if sourcescip is in one of the following stages:
2313  * - \ref SCIP_STAGE_PROBLEM
2314  * - \ref SCIP_STAGE_TRANSFORMED
2315  * - \ref SCIP_STAGE_INITPRESOLVE
2316  * - \ref SCIP_STAGE_PRESOLVING
2317  * - \ref SCIP_STAGE_EXITPRESOLVE
2318  * - \ref SCIP_STAGE_PRESOLVED
2319  * - \ref SCIP_STAGE_INITSOLVE
2320  * - \ref SCIP_STAGE_SOLVING
2321  * - \ref SCIP_STAGE_SOLVED
2322  *
2323  * @pre This method can be called if targetscip is in one of the following stages:
2324  * - \ref SCIP_STAGE_PROBLEM
2325  *
2326  * @note sourcescip stage does not get changed
2327  *
2328  * @note targetscip stage does not get changed
2329  *
2330  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2331  */
2333  SCIP* sourcescip, /**< source SCIP data structure */
2334  SCIP* targetscip, /**< target SCIP data structure */
2335  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
2336  * target variables, or NULL */
2337  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2338  * target constraints, or NULL */
2339  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
2340  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
2341  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
2342  SCIP_Bool global /**< should global or local bounds be used? */
2343  )
2344 {
2345  assert(sourcescip != NULL);
2346  assert(targetscip != NULL);
2347 
2348  /* check stages for both, the source and the target SCIP data structure */
2349  SCIP_CALL( checkStage(sourcescip, "SCIPcopyVars", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2350  SCIP_CALL( checkStage(targetscip, "SCIPcopyVars", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2351 
2352  SCIP_CALL( copyVars(sourcescip, targetscip, varmap, consmap, fixedvars, fixedvals, nfixedvars, FALSE, global) );
2353 
2354  return SCIP_OKAY;
2355 }
2356 
2357 /** copies all original variables from source-SCIP and adds these variable to the target-SCIP; the mapping between these
2358  * variables are stored in the variable hashmap, target-SCIP has to be in problem creation stage, fixed and aggregated
2359  * variables do not get copied
2360  *
2361  * @note the variables are added to the target-SCIP but not captured
2362  *
2363  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2364  * @note Do not change the source SCIP environment during the copying process
2365  *
2366  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2367  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2368  *
2369  * @pre This method can be called if sourcescip is in one of the following stages:
2370  * - \ref SCIP_STAGE_PROBLEM
2371  * - \ref SCIP_STAGE_TRANSFORMED
2372  * - \ref SCIP_STAGE_INITPRESOLVE
2373  * - \ref SCIP_STAGE_PRESOLVING
2374  * - \ref SCIP_STAGE_EXITPRESOLVE
2375  * - \ref SCIP_STAGE_PRESOLVED
2376  * - \ref SCIP_STAGE_INITSOLVE
2377  * - \ref SCIP_STAGE_SOLVING
2378  * - \ref SCIP_STAGE_SOLVED
2379  *
2380  * @pre This method can be called if targetscip is in one of the following stages:
2381  * - \ref SCIP_STAGE_PROBLEM
2382  *
2383  * @note sourcescip stage does not get changed
2384  *
2385  * @note targetscip stage does not get changed
2386  *
2387  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2388  */
2390  SCIP* sourcescip, /**< source SCIP data structure */
2391  SCIP* targetscip, /**< target SCIP data structure */
2392  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
2393  * target variables, or NULL */
2394  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2395  * target constraints, or NULL */
2396  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
2397  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
2398  int nfixedvars /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
2399  )
2400 {
2401  assert(sourcescip != NULL);
2402  assert(targetscip != NULL);
2403 
2404  /* check stages for both, the source and the target SCIP data structure */
2405  SCIP_CALL( checkStage(sourcescip, "SCIPcopyOrigVars", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2406  SCIP_CALL( checkStage(targetscip, "SCIPcopyOrigVars", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2407 
2408  SCIP_CALL( copyVars(sourcescip, targetscip, varmap, consmap, fixedvars, fixedvals, nfixedvars, TRUE, TRUE) );
2409 
2410  return SCIP_OKAY;
2411 }
2412 
2413 /** merges the histories of variables from a source SCIP into a target SCIP. The two data structures should point to
2414  * different SCIP instances.
2415  *
2416  * @note the notion of source and target is inverted here; \p sourcescip usually denotes a copied SCIP instance, whereas
2417  * \p targetscip denotes the original instance
2418  */
2420  SCIP* sourcescip, /**< source SCIP data structure */
2421  SCIP* targetscip, /**< target SCIP data structure */
2422  SCIP_VAR** sourcevars, /**< source variables for history merge */
2423  SCIP_VAR** targetvars, /**< target variables for history merge */
2424  int nvars /**< number of variables in both variable arrays */
2425  )
2426 {
2427  int i;
2428 
2429  /* check if target scip has been set to allow merging variable statistics */
2430  if( !targetscip->set->history_allowmerge )
2431  return SCIP_OKAY;
2432 
2433  assert(nvars == 0 || (sourcevars != NULL && targetvars != NULL));
2434  assert(sourcescip != targetscip);
2435 
2436  /* we do not want to copy statistics from a scip that has not really started solving */
2437  if( SCIPgetStage(sourcescip) < SCIP_STAGE_SOLVING )
2438  return SCIP_OKAY;
2439 
2440  /* if the transformation of the source was subject to scaling, the history information cannot be just copied */
2441  if( !SCIPsetIsEQ(targetscip->set, 1.0, SCIPgetOrigObjscale(sourcescip))
2442  || !SCIPsetIsEQ(targetscip->set, 0.0, SCIPgetOrigObjoffset(sourcescip)) )
2443  return SCIP_OKAY;
2444 
2445  /* merge histories of the targetSCIP-variables to the SCIP variables. */
2446  for( i = 0; i < nvars; ++i )
2447  {
2448  SCIP_VARSTATUS sourcevarstatus;
2449 
2450  assert(sourcevars[i]->scip == sourcescip);
2451  assert(targetvars[i]->scip == targetscip);
2452 
2453  sourcevarstatus = SCIPvarGetStatus(sourcevars[i]);
2454 
2455  /* depending on the variable status, we use either the transformed variable history or the history of the col itself */
2456  switch( sourcevarstatus )
2457  {
2459  assert(NULL != SCIPvarGetTransVar(sourcevars[i]));
2460  SCIPvarMergeHistories(targetvars[i], SCIPvarGetTransVar(sourcevars[i]), targetscip->stat);
2461  break;
2462  case SCIP_VARSTATUS_COLUMN:
2463  SCIPvarMergeHistories(targetvars[i], sourcevars[i], targetscip->stat);
2464  break;
2465  default:
2466  /* other variable status are currently not supported for the merging */
2467  break;
2468  } /*lint !e788*/
2469  }
2470 
2471  return SCIP_OKAY;
2472 }
2473 
2474 /** returns copy of the source constraint; if there already is a copy of the source constraint in the constraint hash
2475  * map, it is just returned as target constraint; elsewise a new constraint will be created; this created constraint is
2476  * added to the constraint hash map and returned as target constraint; the variable map is used to map the variables of
2477  * the source SCIP to the variables of the target SCIP
2478  *
2479  * @warning If a constraint is marked to be checked for feasibility but not to be enforced, a LP or pseudo solution may
2480  * be declared feasible even if it violates this particular constraint. This constellation should only be
2481  * used, if no LP or pseudo solution can violate the constraint -- e.g. if a local constraint is redundant due
2482  * to the variable's local bounds.
2483  *
2484  * @note The constraint is not added to the target SCIP. You can check whether a constraint is added by calling
2485  * SCIPconsIsAdded(). (If you mix SCIPgetConsCopy() with SCIPcopyConss() you should pay attention to what you add
2486  * explicitly and what is already added.)
2487  *
2488  * @note The constraint is always captured, either during the creation of the copy or after finding the copy of the
2489  * constraint in the constraint hash map
2490  *
2491  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2492  * @note Do not change the source SCIP environment during the copying process
2493  *
2494  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2495  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2496  *
2497  * @pre This method can be called if sourcescip is in one of the following stages:
2498  * - \ref SCIP_STAGE_PROBLEM
2499  * - \ref SCIP_STAGE_TRANSFORMED
2500  * - \ref SCIP_STAGE_INITPRESOLVE
2501  * - \ref SCIP_STAGE_PRESOLVING
2502  * - \ref SCIP_STAGE_EXITPRESOLVE
2503  * - \ref SCIP_STAGE_PRESOLVED
2504  * - \ref SCIP_STAGE_INITSOLVE
2505  * - \ref SCIP_STAGE_SOLVING
2506  * - \ref SCIP_STAGE_SOLVED
2507  *
2508  * @pre This method can be called if targetscip is in one of the following stages:
2509  * - \ref SCIP_STAGE_PROBLEM
2510  * - \ref SCIP_STAGE_TRANSFORMING
2511  * - \ref SCIP_STAGE_INITPRESOLVE
2512  * - \ref SCIP_STAGE_PRESOLVING
2513  * - \ref SCIP_STAGE_EXITPRESOLVE
2514  * - \ref SCIP_STAGE_PRESOLVED
2515  * - \ref SCIP_STAGE_SOLVING
2516  * - \ref SCIP_STAGE_EXITSOLVE
2517  *
2518  * @note sourcescip stage does not get changed
2519  *
2520  * @note targetscip stage does not get changed
2521  *
2522  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2523  */
2525  SCIP* sourcescip, /**< source SCIP data structure */
2526  SCIP* targetscip, /**< target SCIP data structure */
2527  SCIP_CONS* sourcecons, /**< source constraint of the source SCIP */
2528  SCIP_CONS** targetcons, /**< pointer to store the created target constraint */
2529  SCIP_CONSHDLR* sourceconshdlr, /**< source constraint handler for this constraint */
2530  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to the corresponding
2531  * variables of the target SCIP, or NULL */
2532  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2533  * target constraints, or NULL */
2534  const char* name, /**< name of constraint, or NULL if the name of the source constraint should be used */
2535  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? */
2536  SCIP_Bool separate, /**< should the constraint be separated during LP processing? */
2537  SCIP_Bool enforce, /**< should the constraint be enforced during node processing? */
2538  SCIP_Bool check, /**< should the constraint be checked for feasibility? */
2539  SCIP_Bool propagate, /**< should the constraint be propagated during node processing? */
2540  SCIP_Bool local, /**< is constraint only valid locally? */
2541  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)? */
2542  SCIP_Bool dynamic, /**< is constraint subject to aging? */
2543  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup? */
2544  SCIP_Bool stickingatnode, /**< should the constraint always be kept at the node where it was added, even
2545  * if it may be moved to a more global node? */
2546  SCIP_Bool global, /**< create a global or a local copy? */
2547  SCIP_Bool* valid /**< pointer to store whether the copying was valid or not */
2548  )
2549 {
2550  SCIP_HASHMAP* localvarmap;
2551  SCIP_HASHMAP* localconsmap;
2552  SCIP_Bool uselocalvarmap;
2553  SCIP_Bool uselocalconsmap;
2554 
2555  assert(targetcons != NULL);
2556  assert(sourceconshdlr != NULL);
2557 
2558  SCIP_CALL( checkStage(sourcescip, "SCIPgetConsCopy", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2559  SCIP_CALL( checkStage(targetscip, "SCIPgetConsCopy", FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE) );
2560 
2561  uselocalvarmap = (varmap == NULL);
2562  uselocalconsmap = (consmap == NULL);
2563 
2564  /* a variables map and a constraint map is needed to avoid infinite recursion */
2565  if( uselocalvarmap )
2566  {
2567  /* create the variable mapping hash map */
2568  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
2569  }
2570  else
2571  localvarmap = varmap;
2572 
2573  *targetcons = NULL;
2574  if( uselocalconsmap )
2575  {
2576  /* create local constraint mapping hash map */
2577  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
2578  }
2579  else
2580  {
2581  /* use global map and try to retrieve copied constraint */
2582  localconsmap = consmap;
2583  *targetcons = (SCIP_CONS*) SCIPhashmapGetImage(localconsmap, sourcecons);
2584  }
2585 
2586  if( *targetcons != NULL )
2587  {
2588  /* if found capture existing copy of the constraint */
2589  SCIP_CALL( SCIPcaptureCons(targetscip, *targetcons) );
2590  *valid = TRUE;
2591  }
2592  else
2593  {
2594  /* otherwise create a copy of the constraint */
2595  SCIP_CALL( SCIPconsCopy(targetcons, targetscip->set, name, sourcescip, sourceconshdlr, sourcecons, localvarmap, localconsmap,
2596  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, global, valid) );
2597 
2598  /* it is possible for the constraint handler to declare the copy valid although no target constraint was created */
2599  assert(*targetcons == NULL || *valid);
2600 
2601  /* if a target constraint was created */
2602  if( *targetcons != NULL && !uselocalconsmap )
2603  {
2604  /* insert constraint into mapping between source SCIP and the target SCIP */
2605  SCIP_CALL( SCIPhashmapInsert(consmap, sourcecons, *targetcons) );
2606  }
2607  }
2608 
2609  /* free locally allocated hash maps */
2610  if( uselocalvarmap )
2611  {
2612  SCIPhashmapFree(&localvarmap);
2613  }
2614 
2615  if( uselocalconsmap )
2616  {
2617  SCIPhashmapFree(&localconsmap);
2618  }
2619 
2620  return SCIP_OKAY;
2621 }
2622 
2623 /** copies constraints from the source-SCIP and adds these to the target-SCIP; for mapping the
2624  * variables between the source and the target SCIP a hash map can be given; if the variable hash
2625  * map is NULL or necessary variable mapping is missing, the required variables are created in the
2626  * target-SCIP and added to the hash map, if not NULL; all variables which are created are added to
2627  * the target-SCIP but not (user) captured; if the constraint hash map is not NULL the mapping
2628  * between the constraints of the source and target-SCIP is stored
2629  *
2630  * @note the constraints are added to the target-SCIP but are not (user) captured in the target SCIP. (If you mix
2631  * SCIPgetConsCopy() with SCIPcopyConss() you should pay attention to what you add explicitly and what is already
2632  * added.) You can check whether a constraint is added by calling SCIPconsIsAdded().
2633  *
2634  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2635  * @note Do not change the source SCIP environment during the copying process
2636  *
2637  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2638  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2639  *
2640  * @pre This method can be called if sourcescip is in one of the following stages:
2641  * - \ref SCIP_STAGE_PROBLEM
2642  * - \ref SCIP_STAGE_TRANSFORMED
2643  * - \ref SCIP_STAGE_INITPRESOLVE
2644  * - \ref SCIP_STAGE_PRESOLVING
2645  * - \ref SCIP_STAGE_EXITPRESOLVE
2646  * - \ref SCIP_STAGE_PRESOLVED
2647  * - \ref SCIP_STAGE_INITSOLVE
2648  * - \ref SCIP_STAGE_SOLVING
2649  * - \ref SCIP_STAGE_SOLVED
2650  *
2651  * @pre This method can be called if targetscip is in one of the following stages:
2652  * - \ref SCIP_STAGE_PROBLEM
2653  *
2654  * @note sourcescip stage does not get changed
2655  *
2656  * @note targetscip stage does not get changed
2657  *
2658  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2659  */
2661  SCIP* sourcescip, /**< source SCIP data structure */
2662  SCIP* targetscip, /**< target SCIP data structure */
2663  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to the corresponding
2664  * variables of the target SCIP, or NULL */
2665  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2666  * target constraints, or NULL */
2667  SCIP_Bool global, /**< create a global or a local copy? */
2668  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance?
2669  * If TRUE, the modifiable flag of constraints will be copied. */
2670  SCIP_Bool* valid /**< pointer to store whether all constraints were validly copied */
2671  )
2672 {
2673  SCIP_CONSHDLR** sourceconshdlrs;
2674  SCIP_HASHMAP* localvarmap;
2675  SCIP_HASHMAP* localconsmap;
2676  SCIP_Bool uselocalvarmap;
2677  SCIP_Bool uselocalconsmap;
2678  int nsourceconshdlrs;
2679  int i;
2680 
2681  assert(sourcescip != NULL);
2682  assert(targetscip != NULL);
2683  assert(valid != NULL);
2684 
2685  /* check stages for both, the source and the target SCIP data structure */
2686  SCIP_CALL( checkStage(sourcescip, "SCIPcopyConss", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2687  SCIP_CALL( checkStage(targetscip, "SCIPcopyConss", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2688 
2689  /* check if we locally need to create a variable or constraint hash map */
2690  uselocalvarmap = (varmap == NULL);
2691  uselocalconsmap = (consmap == NULL);
2692 
2693  if( uselocalvarmap )
2694  {
2695  /* create the variable mapping hash map */
2696  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
2697  }
2698  else
2699  localvarmap = varmap;
2700 
2701  if( uselocalconsmap )
2702  {
2703  /* create the constraint mapping hash map */
2704  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
2705  }
2706  else
2707  localconsmap = consmap;
2708 
2709  nsourceconshdlrs = SCIPgetNConshdlrs(sourcescip);
2710  sourceconshdlrs = SCIPgetConshdlrs(sourcescip);
2711  assert(nsourceconshdlrs == 0 || sourceconshdlrs != NULL);
2712  assert(SCIPisTransformed(sourcescip));
2713 
2714  *valid = TRUE;
2715 
2716  /* copy constraints: loop through all (source) constraint handlers */
2717  for( i = 0; i < nsourceconshdlrs; ++i )
2718  {
2719  SCIP_CONS** sourceconss;
2720  SCIP_CONS* targetcons;
2721  int nsourceconss;
2722  int c;
2723 
2724  assert(sourceconshdlrs[i] != NULL);
2725 
2726  /* constraint handlers have to explicitly set the valid pointer to TRUE for every single constraint */
2727 
2728  /* Get all active constraints for copying; this array contains all active constraints;
2729  * constraints are active if they are globally valid and not deleted after presolving OR they
2730  * were locally added during the search and we are currently in a node which belongs to the
2731  * corresponding subtree.
2732  */
2733  nsourceconss = SCIPconshdlrGetNActiveConss(sourceconshdlrs[i]);
2734  sourceconss = SCIPconshdlrGetConss(sourceconshdlrs[i]);
2735 
2736 
2737 #ifdef SCIP_DISABLED_CODE
2738  /* @todo using the following might reduce the number of copied constraints - check whether this is better */
2739  /* Get all checked constraints for copying; this included local constraints */
2740  if( !global )
2741  {
2742  nsourceconss = SCIPconshdlrGetNCheckConss(sourceconshdlrs[i]);
2743  sourceconss = SCIPconshdlrGetCheckConss(sourceconshdlrs[i]);
2744  }
2745 #endif
2746 
2747  assert(nsourceconss == 0 || sourceconss != NULL);
2748 
2749  if( nsourceconss > 0 )
2750  {
2751  SCIPdebugMsg(sourcescip, "Attempting to copy %d %s constraints\n", nsourceconss, SCIPconshdlrGetName(sourceconshdlrs[i]));
2752  }
2753 
2754  /* copy all constraints of one constraint handler */
2755  for( c = 0; c < nsourceconss; ++c )
2756  {
2757  SCIP_Bool singlevalid = FALSE;
2758  /* all constraints have to be active */
2759  assert(sourceconss[c] != NULL);
2760  assert(SCIPconsIsActive(sourceconss[c]));
2761  assert(!SCIPconsIsDeleted(sourceconss[c]));
2762 
2763  /* in case of copying the global problem we have to ignore the local constraints which are active */
2764  if( global && SCIPconsIsLocal(sourceconss[c]) )
2765  {
2766  SCIPdebugMsg(sourcescip, "did not copy local constraint <%s> when creating global copy\n", SCIPconsGetName(sourceconss[c]));
2767  continue;
2768  }
2769 
2770  /* use the copy constructor of the constraint handler and creates and captures the constraint if possible */
2771  targetcons = NULL;
2772  SCIP_CALL( SCIPgetConsCopy(sourcescip, targetscip, sourceconss[c], &targetcons, sourceconshdlrs[i], localvarmap, localconsmap, NULL,
2773  SCIPconsIsInitial(sourceconss[c]), SCIPconsIsSeparated(sourceconss[c]),
2774  SCIPconsIsEnforced(sourceconss[c]), SCIPconsIsChecked(sourceconss[c]),
2775  SCIPconsIsPropagated(sourceconss[c]), FALSE, SCIPconsIsModifiable(sourceconss[c]),
2776  SCIPconsIsDynamic(sourceconss[c]), SCIPconsIsRemovable(sourceconss[c]), FALSE, global, &singlevalid) );
2777 
2778  /* it is possible for a constraint handler to declare the copy valid, although no target constraint was created */
2779  assert(targetcons == NULL || singlevalid);
2780 
2781  /* add the copied constraint to target SCIP if the copying process created a constraint */
2782  if( targetcons != NULL )
2783  {
2784 
2785  if( !enablepricing )
2786  SCIPconsSetModifiable(targetcons, FALSE);
2787 
2788  /* add constraint to target SCIP */
2789  SCIP_CALL( SCIPaddCons(targetscip, targetcons) );
2790 
2791  /* add the conflict constraint to the store of targetscip */
2792  if( SCIPconsIsConflict(sourceconss[c]) )
2793  {
2794  /* add the constraint as a conflict to the conflict pool of targetscip */
2795  SCIP_CALL( SCIPconflictstoreAddConflict(targetscip->conflictstore, targetscip->mem->probmem, targetscip->set,
2796  targetscip->stat, NULL, NULL, targetscip->reopt, targetcons, SCIP_CONFTYPE_UNKNOWN, FALSE, -SCIPinfinity(targetscip)) );
2797  }
2798 
2799  /* release constraint once for the creation capture */
2800  SCIP_CALL( SCIPreleaseCons(targetscip, &targetcons) );
2801  }
2802  else
2803  {
2804  *valid = (*valid && singlevalid);
2805  SCIPdebugMsg(sourcescip, "Constraint %s not copied, copy is %svalid\n",
2806  SCIPconsGetName(sourceconss[c]), *valid ? "" : "not ");
2807  }
2808  }
2809  }
2810 
2811  if( uselocalvarmap )
2812  {
2813  /* free hash map */
2814  SCIPhashmapFree(&localvarmap);
2815  }
2816 
2817  if( uselocalconsmap )
2818  {
2819  /* free hash map */
2820  SCIPhashmapFree(&localconsmap);
2821  }
2822 
2823  return SCIP_OKAY;
2824 }
2825 
2826 /** copies all original constraints from the source-SCIP and adds these to the target-SCIP; for mapping the
2827  * variables between the source and the target SCIP a hash map can be given; if the variable hash
2828  * map is NULL or necessary variable mapping is missing, the required variables are created in the
2829  * target-SCIP and added to the hash map, if not NULL; all variables which are created are added to
2830  * the target-SCIP but not (user) captured; if the constraint hash map is not NULL the mapping
2831  * between the constraints of the source and target-SCIP is stored
2832  *
2833  * @note the constraints are added to the target-SCIP but are not (user) captured in the target SCIP. (If you mix
2834  * SCIPgetConsCopy() with SCIPcopyConss() you should pay attention to what you add explicitly and what is already
2835  * added.) You can check whether a constraint is added by calling SCIPconsIsAdded().
2836  *
2837  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2838  * @note Do not change the source SCIP environment during the copying process
2839  *
2840  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2841  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2842  *
2843  * @pre This method can be called if sourcescip is in one of the following stages:
2844  * - \ref SCIP_STAGE_PROBLEM
2845  * - \ref SCIP_STAGE_TRANSFORMED
2846  * - \ref SCIP_STAGE_INITPRESOLVE
2847  * - \ref SCIP_STAGE_PRESOLVING
2848  * - \ref SCIP_STAGE_EXITPRESOLVE
2849  * - \ref SCIP_STAGE_PRESOLVED
2850  * - \ref SCIP_STAGE_INITSOLVE
2851  * - \ref SCIP_STAGE_SOLVING
2852  * - \ref SCIP_STAGE_SOLVED
2853  *
2854  * @pre This method can be called if targetscip is in one of the following stages:
2855  * - \ref SCIP_STAGE_PROBLEM
2856  *
2857  * @note sourcescip stage does not get changed
2858  *
2859  * @note targetscip stage does not get changed
2860  *
2861  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2862  */
2864  SCIP* sourcescip, /**< source SCIP data structure */
2865  SCIP* targetscip, /**< target SCIP data structure */
2866  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to the corresponding
2867  * variables of the target SCIP, or NULL */
2868  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2869  * target constraints, or NULL */
2870  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance?
2871  * If TRUE, the modifiable flag of constraints will be copied. */
2872  SCIP_Bool* valid /**< pointer to store whether all constraints were validly copied */
2873  )
2874 {
2875  SCIP_CONS** sourceconss;
2876  SCIP_HASHMAP* localvarmap;
2877  SCIP_HASHMAP* localconsmap;
2878  SCIP_Bool uselocalvarmap;
2879  SCIP_Bool uselocalconsmap;
2880  int nsourceconss;
2881  int c;
2882 
2883  assert(sourcescip != NULL);
2884  assert(targetscip != NULL);
2885  assert(valid != NULL);
2886 
2887  /* check stages for both, the source and the target SCIP data structure */
2888  SCIP_CALL( checkStage(sourcescip, "SCIPcopyOrigConss", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2889  SCIP_CALL( checkStage(targetscip, "SCIPcopyOrigConss", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2890 
2891  /* check if we locally need to create a variable or constraint hash map */
2892  uselocalvarmap = (varmap == NULL);
2893  uselocalconsmap = (consmap == NULL);
2894 
2895  if( uselocalvarmap )
2896  {
2897  /* create the variable mapping hash map */
2898  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
2899  }
2900  else
2901  localvarmap = varmap;
2902 
2903  if( uselocalconsmap )
2904  {
2905  /* create the constraint mapping hash map */
2906  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
2907  }
2908  else
2909  localconsmap = consmap;
2910 
2911  sourceconss = SCIPgetOrigConss(sourcescip);
2912  nsourceconss = SCIPgetNOrigConss(sourcescip);
2913 
2914  *valid = TRUE;
2915 
2916  SCIPdebugMsg(sourcescip, "Attempting to copy %d original constraints\n", nsourceconss);
2917 
2918  /* copy constraints: loop through all (source) constraint handlers */
2919  for( c = 0; c < nsourceconss; ++c )
2920  {
2921  SCIP_CONS* targetcons;
2922  SCIP_Bool success;
2923 
2924  /* constraint handlers have to explicitly set the success pointer to TRUE */
2925  success = FALSE;
2926 
2927  /* all constraints have to be active */
2928  assert(sourceconss[c] != NULL);
2929  assert(SCIPconsIsOriginal(sourceconss[c]));
2930 
2931  /* use the copy constructor of the constraint handler and creates and captures the constraint if possible */
2932  targetcons = NULL;
2933  SCIP_CALL( SCIPgetConsCopy(sourcescip, targetscip, sourceconss[c], &targetcons, SCIPconsGetHdlr(sourceconss[c]), localvarmap, localconsmap, NULL,
2934  SCIPconsIsInitial(sourceconss[c]), SCIPconsIsSeparated(sourceconss[c]),
2935  SCIPconsIsEnforced(sourceconss[c]), SCIPconsIsChecked(sourceconss[c]),
2936  SCIPconsIsPropagated(sourceconss[c]), FALSE, SCIPconsIsModifiable(sourceconss[c]),
2937  SCIPconsIsDynamic(sourceconss[c]), SCIPconsIsRemovable(sourceconss[c]), FALSE, TRUE, &success) );
2938 
2939  /* add the copied constraint to target SCIP if the copying process was valid */
2940  if( success )
2941  {
2942  assert(targetcons != NULL);
2943 
2944  if( !enablepricing )
2945  SCIPconsSetModifiable(targetcons, FALSE);
2946 
2947  /* add constraint to target SCIP */
2948  SCIP_CALL( SCIPaddCons(targetscip, targetcons) );
2949 
2950  /* release constraint once for the creation capture */
2951  SCIP_CALL( SCIPreleaseCons(targetscip, &targetcons) );
2952  }
2953  else
2954  {
2955  *valid = FALSE;
2956  SCIPdebugMsg(sourcescip, "failed to copy constraint %s\n", SCIPconsGetName(sourceconss[c]));
2957  }
2958  }
2959 
2960  if( uselocalvarmap )
2961  {
2962  /* free hash map */
2963  SCIPhashmapFree(&localvarmap);
2964  }
2965 
2966  if( uselocalconsmap )
2967  {
2968  /* free hash map */
2969  SCIPhashmapFree(&localconsmap);
2970  }
2971 
2972  return SCIP_OKAY;
2973 }
2974 
2975 
2976 /** convert all active cuts from cutpool to linear constraints
2977  *
2978  * @note Do not change the source SCIP environment during the copying process
2979  *
2980  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2981  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2982  *
2983  * @pre This method can be called if SCIP is in one of the following stages:
2984  * - \ref SCIP_STAGE_PROBLEM
2985  * - \ref SCIP_STAGE_INITPRESOLVE
2986  * - \ref SCIP_STAGE_PRESOLVING
2987  * - \ref SCIP_STAGE_EXITPRESOLVE
2988  * - \ref SCIP_STAGE_PRESOLVED
2989  * - \ref SCIP_STAGE_SOLVING
2990  * - \ref SCIP_STAGE_EXITSOLVE
2991  *
2992  * @note SCIP stage does not get changed
2993  *
2994  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2995  */
2997  SCIP* scip, /**< SCIP data structure */
2998  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2999  * target variables, or NULL */
3000  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3001  * target constraints, or NULL */
3002  SCIP_Bool global, /**< create a global or a local copy? */
3003  int* ncutsadded /**< pointer to store number of added cuts, or NULL */
3004  )
3005 {
3006  assert(scip != NULL);
3007  assert(scip->set != NULL);
3008 
3009  /* check stages for the SCIP data structure */
3010  SCIP_CALL( checkStage(scip, "SCIPconvertCutsToConss", FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE) );
3011 
3012  /* if we do not have any cuts, nothing can be converted */
3013  if( scip->set->stage < SCIP_STAGE_SOLVING )
3014  return SCIP_OKAY;
3015 
3016  /* create out of all active cuts in cutpool linear constraints in targetscip */
3017  SCIP_CALL( SCIPcopyCuts(scip, scip, varmap, consmap, global, ncutsadded) );
3018 
3019  return SCIP_OKAY;
3020 }
3021 
3022 /** copies all active cuts from cutpool of sourcescip to linear constraints in targetscip
3023  *
3024  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3025  * @note Do not change the source SCIP environment during the copying process
3026  *
3027  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3028  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3029  *
3030  * @pre This method can be called if sourcescip is in one of the following stages:
3031  * - \ref SCIP_STAGE_PROBLEM
3032  * - \ref SCIP_STAGE_TRANSFORMED
3033  * - \ref SCIP_STAGE_INITPRESOLVE
3034  * - \ref SCIP_STAGE_PRESOLVING
3035  * - \ref SCIP_STAGE_EXITPRESOLVE
3036  * - \ref SCIP_STAGE_PRESOLVED
3037  * - \ref SCIP_STAGE_SOLVING
3038  * - \ref SCIP_STAGE_SOLVED
3039  * - \ref SCIP_STAGE_EXITSOLVE
3040  *
3041  * @pre This method can be called if targetscip is in one of the following stages:
3042  * - \ref SCIP_STAGE_PROBLEM
3043  * - \ref SCIP_STAGE_INITPRESOLVE
3044  * - \ref SCIP_STAGE_PRESOLVING
3045  * - \ref SCIP_STAGE_EXITPRESOLVE
3046  * - \ref SCIP_STAGE_PRESOLVED
3047  * - \ref SCIP_STAGE_SOLVING
3048  * - \ref SCIP_STAGE_EXITSOLVE
3049  *
3050  * @note sourcescip stage does not get changed
3051  *
3052  * @note targetscip stage does not get changed
3053  *
3054  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3055  */
3057  SCIP* sourcescip, /**< source SCIP data structure */
3058  SCIP* targetscip, /**< target SCIP data structure */
3059  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3060  * target variables, or NULL */
3061  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3062  * target constraints, or NULL */
3063  SCIP_Bool global, /**< create a global or a local copy? */
3064  int* ncutsadded /**< pointer to store number of copied cuts, or NULL */
3065  )
3066 {
3067  SCIP_CUT** cuts;
3068  int ncuts;
3069  int nlocalcutsadded;
3070 
3071  assert(sourcescip != NULL);
3072  assert(targetscip != NULL);
3073 
3074  /* check stages for both, the source and the target SCIP data structure */
3075  SCIP_CALL( checkStage(sourcescip, "SCIPcopyCuts", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE) );
3076  SCIP_CALL( checkStage(targetscip, "SCIPcopyCuts", FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE) );
3077 
3078  if ( ncutsadded != NULL )
3079  *ncutsadded = 0;
3080  nlocalcutsadded = 0;
3081 
3082  /* if we do not have any cuts, nothing can be converted */
3083  if( sourcescip->set->stage < SCIP_STAGE_SOLVING )
3084  return SCIP_OKAY;
3085 
3086  if( SCIPfindConshdlr(targetscip, "linear") == NULL )
3087  {
3088  SCIPdebugMsg(sourcescip, "No linear constraint handler available. Cannot convert cuts.\n");
3089  return SCIP_OKAY;
3090  }
3091 
3092  /* convert cut from global cut pool */
3093  cuts = SCIPgetPoolCuts(sourcescip);
3094  ncuts = SCIPgetNPoolCuts(sourcescip);
3095 
3096  SCIP_CALL( copyCuts(sourcescip, targetscip, cuts, ncuts, varmap, consmap, global, &nlocalcutsadded) );
3097 
3098  SCIPdebugMsg(sourcescip, "Converted %d active cuts to constraints.\n", nlocalcutsadded);
3099 
3100  /* convert delayed cuts from global delayed cut pool */
3101  cuts = SCIPgetDelayedPoolCuts(sourcescip);
3102  ncuts = SCIPgetNDelayedPoolCuts(sourcescip);
3103 
3104  SCIP_CALL( copyCuts(sourcescip, targetscip, cuts, ncuts, varmap, consmap, global, &nlocalcutsadded) );
3105 
3106  if( ncutsadded != NULL )
3107  *ncutsadded = nlocalcutsadded;
3108 
3109  SCIPdebugMsg(sourcescip, "Converted %d active cuts to constraints.\n", nlocalcutsadded);
3110 
3111  return SCIP_OKAY;
3112 }
3113 
3114 /** copies all active conflicts from the conflict pool of sourcescip and adds them as linear constraints to targetscip
3115  *
3116  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3117  * @note Do not change the source SCIP environment during the copying process
3118  *
3119  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3120  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3121  *
3122  * @pre This method can be called if sourcescip is in one of the following stages:
3123  * - \ref SCIP_STAGE_PROBLEM
3124  * - \ref SCIP_STAGE_TRANSFORMED
3125  * - \ref SCIP_STAGE_INITPRESOLVE
3126  * - \ref SCIP_STAGE_PRESOLVING
3127  * - \ref SCIP_STAGE_EXITPRESOLVE
3128  * - \ref SCIP_STAGE_PRESOLVED
3129  * - \ref SCIP_STAGE_SOLVING
3130  * - \ref SCIP_STAGE_SOLVED
3131  * - \ref SCIP_STAGE_EXITSOLVE
3132  *
3133  * @pre This method can be called if targetscip is in one of the following stages:
3134  * - \ref SCIP_STAGE_PROBLEM
3135  * - \ref SCIP_STAGE_INITPRESOLVE
3136  * - \ref SCIP_STAGE_PRESOLVING
3137  * - \ref SCIP_STAGE_EXITPRESOLVE
3138  * - \ref SCIP_STAGE_PRESOLVED
3139  * - \ref SCIP_STAGE_SOLVING
3140  * - \ref SCIP_STAGE_EXITSOLVE
3141  *
3142  * @note sourcescip stage does not change
3143  *
3144  * @note targetscip stage does not change
3145  *
3146  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3147  */
3149  SCIP* sourcescip, /**< source SCIP data structure */
3150  SCIP* targetscip, /**< target SCIP data structure */
3151  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3152  * target variables, or NULL */
3153  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3154  * target constraints, or NULL */
3155  SCIP_Bool global, /**< create a global or a local copy? */
3156  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance?
3157  * If TRUE, the modifiable flag of constraints will be copied. */
3158  SCIP_Bool* valid /**< pointer to store whether all constraints were validly copied */
3159  )
3160 {
3161  SCIP_CONS** sourceconfs;
3162  SCIP_HASHMAP* localvarmap;
3163  SCIP_HASHMAP* localconsmap;
3164  SCIP_Bool uselocalvarmap;
3165  SCIP_Bool uselocalconsmap;
3166  SCIP_Bool success;
3167  int sourceconfssize;
3168  int nsourceconfs;
3169  int c;
3170 
3171  assert(sourcescip != NULL);
3172  assert(targetscip != NULL);
3173 
3174  /* check stages for both, the source and the target SCIP data structure */
3175  SCIP_CALL( checkStage(sourcescip, "SCIPcopyConss", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
3176  SCIP_CALL( checkStage(targetscip, "SCIPcopyConss", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
3177 
3178  /* check if we locally need to create a variable or constraint hash map */
3179  uselocalvarmap = (varmap == NULL);
3180  uselocalconsmap = (consmap == NULL);
3181 
3182  if( uselocalvarmap )
3183  {
3184  /* create the variable mapping hash map */
3185  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
3186  }
3187  else
3188  localvarmap = varmap;
3189 
3190  if( uselocalconsmap )
3191  {
3192  /* create the constraint mapping hash map */
3193  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
3194  }
3195  else
3196  localconsmap = consmap;
3197 
3198  /* get number of conflicts stored in the conflict pool */
3199  sourceconfssize = SCIPconflictstoreGetNConflictsInStore(sourcescip->conflictstore);
3200 
3201  /* allocate buffer */
3202  SCIP_CALL( SCIPallocBufferArray(sourcescip, &sourceconfs, sourceconfssize) );
3203 
3204  /* get all conflicts stored in the conflict pool */
3205  SCIP_CALL( SCIPconflictstoreGetConflicts(sourcescip->conflictstore, sourceconfs, sourceconfssize, &nsourceconfs) );
3206  assert(nsourceconfs <= sourceconfssize);
3207 
3208  assert(SCIPisTransformed(sourcescip));
3209 
3210  /* copy conflicts */
3211  for( c = 0; c < nsourceconfs; ++c )
3212  {
3213  SCIP_CONS* targetcons;
3214 
3215  /* all constraints have to be active */
3216  assert(sourceconfs[c] != NULL);
3217  assert(SCIPconsIsActive(sourceconfs[c]));
3218  assert(!SCIPconsIsDeleted(sourceconfs[c]));
3219  assert(SCIPconsIsConflict(sourceconfs[c]));
3220 
3221  /* in case of copying the global problem we have to ignore the local constraints which are active */
3222  if( global && SCIPconsIsLocal(sourceconfs[c]) )
3223  {
3224  SCIPdebugMsg(sourcescip, "did not copy local constraint <%s> when creating global copy\n", SCIPconsGetName(sourceconfs[c]));
3225  continue;
3226  }
3227 
3228  /* use the copy constructor of the constraint handler and creates and captures the constraint if possible */
3229  targetcons = NULL;
3230  SCIP_CALL( SCIPgetConsCopy(sourcescip, targetscip, sourceconfs[c], &targetcons, SCIPconsGetHdlr(sourceconfs[c]),
3231  localvarmap, localconsmap, NULL, SCIPconsIsInitial(sourceconfs[c]), SCIPconsIsSeparated(sourceconfs[c]),
3232  SCIPconsIsEnforced(sourceconfs[c]), SCIPconsIsChecked(sourceconfs[c]),
3233  SCIPconsIsPropagated(sourceconfs[c]), FALSE, SCIPconsIsModifiable(sourceconfs[c]),
3234  SCIPconsIsDynamic(sourceconfs[c]), SCIPconsIsRemovable(sourceconfs[c]), FALSE, global, &success) );
3235 
3236  /* add the copied constraint to target SCIP if the copying process was valid */
3237  if( success )
3238  {
3239  assert(targetcons != NULL);
3240 
3241  if( !enablepricing )
3242  SCIPconsSetModifiable(targetcons, FALSE);
3243 
3244  /* add constraint to target SCIP */
3245  SCIP_CALL( SCIPaddCons(targetscip, targetcons) );
3246 
3247  /* release constraint once for the creation capture */
3248  SCIP_CALL( SCIPreleaseCons(targetscip, &targetcons) );
3249  }
3250  else
3251  {
3252  *valid = FALSE;
3253  SCIPdebugMsg(sourcescip, "failed to copy constraint %s\n", SCIPconsGetName(sourceconfs[c]));
3254  }
3255  }
3256 
3257  if( uselocalvarmap )
3258  {
3259  /* free hash map */
3260  SCIPhashmapFree(&localvarmap);
3261  }
3262 
3263  if( uselocalconsmap )
3264  {
3265  /* free hash map */
3266  SCIPhashmapFree(&localconsmap);
3267  }
3268 
3269  return SCIP_OKAY;
3270 }
3271 
3272 /** copies implications and cliques of sourcescip to targetscip
3273  *
3274  * This function should be called for a targetscip in transformed stage. It can save time in presolving of the
3275  * targetscip, since implications and cliques are copied.
3276  *
3277  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3278  * @note Do not change the source SCIP environment during the copying process
3279  *
3280  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3281  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3282  *
3283  * @pre This method can be called if sourcescip is in one of the following stages:
3284  * - \ref SCIP_STAGE_TRANSFORMED
3285  * - \ref SCIP_STAGE_INITPRESOLVE
3286  * - \ref SCIP_STAGE_PRESOLVING
3287  * - \ref SCIP_STAGE_EXITPRESOLVE
3288  * - \ref SCIP_STAGE_PRESOLVED
3289  * - \ref SCIP_STAGE_SOLVING
3290  * - \ref SCIP_STAGE_SOLVED
3291  * - \ref SCIP_STAGE_EXITSOLVE
3292  *
3293  * @pre This method can be called if targetscip is in one of the following stages:
3294  * - \ref SCIP_STAGE_TRANSFORMED
3295  * - \ref SCIP_STAGE_INITPRESOLVE
3296  * - \ref SCIP_STAGE_PRESOLVING
3297  * - \ref SCIP_STAGE_EXITPRESOLVE
3298  * - \ref SCIP_STAGE_PRESOLVED
3299  * - \ref SCIP_STAGE_INITSOLVE
3300  * - \ref SCIP_STAGE_SOLVING
3301  *
3302  * @note sourcescip stage does not get changed
3303  *
3304  * @note targetscip stage does not get changed
3305  *
3306  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3307  */
3309  SCIP* sourcescip, /**< source SCIP data structure */
3310  SCIP* targetscip, /**< target SCIP data structure */
3311  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3312  * target variables, or NULL */
3313  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3314  * target constraints, or NULL */
3315  SCIP_Bool global, /**< create a global or a local copy? */
3316  SCIP_Bool* infeasible, /**< pointer to store whether an infeasibility was detected */
3317  int* nbdchgs, /**< pointer to store the number of performed bound changes, or NULL */
3318  int* ncopied /**< pointer to store number of copied implications and cliques, or NULL */
3319  )
3320 {
3321  SCIP_CLIQUE** cliques;
3322  SCIP_VAR** sourcevars;
3323  SCIP_Bool success;
3324  int nvars;
3325  int nbinvars;
3326  int ncliques;
3327  int j;
3328  int c;
3329 
3330  assert( sourcescip != NULL );
3331  assert( targetscip != NULL );
3332  assert( sourcescip != targetscip );
3333  assert( infeasible != NULL );
3334 
3335  /* check stages for both, the source and the target SCIP data structure */
3336  SCIP_CALL( checkStage(sourcescip, "SCIPcopyImplicationsCliques", FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE) );
3337  SCIP_CALL( checkStage(targetscip, "SCIPcopyImplicationsCliques", FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
3338 
3339  if ( ncopied != NULL )
3340  *ncopied = 0;
3341  if ( nbdchgs != NULL )
3342  *nbdchgs = 0;
3343 
3344  /* get all active variables */
3345  SCIP_CALL( SCIPgetVarsData(sourcescip, &sourcevars, &nvars, &nbinvars, NULL, NULL, NULL) );
3346 
3347  /* stop if no possible variables for cliques exist */
3348  if ( nbinvars == 0 )
3349  return SCIP_OKAY;
3350 
3351  /* get cliques */
3352  ncliques = SCIPgetNCliques(sourcescip);
3353  if ( ncliques > 0 )
3354  {
3355  SCIP_VAR** targetclique;
3356 
3357  /* get space for target cliques */
3358  SCIP_CALL( SCIPallocBufferArray(targetscip, &targetclique, nvars) );
3359  cliques = SCIPgetCliques(sourcescip);
3360 
3361  /* loop through all cliques */
3362  for (c = 0; c < ncliques; ++c)
3363  {
3364  SCIP_VAR** cliquevars;
3365  SCIP_Bool* cliquevals;
3366  int cliquesize;
3367  int nboundchg = 0;
3368 
3369  assert( cliques[c] != NULL );
3370  cliquevals = SCIPcliqueGetValues(cliques[c]);
3371  cliquevars = SCIPcliqueGetVars(cliques[c]);
3372  cliquesize = SCIPcliqueGetNVars(cliques[c]);
3373 
3374  /* get target variables of clique */
3375  for (j = 0; j < cliquesize; ++j)
3376  {
3377  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, cliquevars[j], &targetclique[j], varmap, consmap, global, &success) );
3378  if ( ! success )
3379  {
3380  SCIPdebugMsg(sourcescip, "Getting copy for variable <%s> failed.\n", SCIPvarGetName(cliquevars[j]));
3381  SCIPfreeBufferArray(targetscip, &targetclique);
3382  return SCIP_OKAY;
3383  }
3384  }
3385 
3386  /* create clique */
3387  SCIP_CALL( SCIPaddClique(targetscip, targetclique, cliquevals, cliquesize, SCIPcliqueIsEquation(cliques[c]),
3388  infeasible, &nboundchg) );
3389 
3390  if ( *infeasible )
3391  {
3392  SCIPfreeBufferArray(targetscip, &targetclique);
3393  return SCIP_OKAY;
3394  }
3395  if ( ncopied != NULL )
3396  ++(*ncopied);
3397  if ( nbdchgs != NULL )
3398  *nbdchgs += nboundchg;
3399  }
3400  SCIPfreeBufferArray(targetscip, &targetclique);
3401  }
3402 
3403  /* create binary implications */
3404  for (j = 0; j < nbinvars; ++j)
3405  {
3406  SCIP_VAR* sourcevar;
3407  SCIP_VAR* targetvar;
3408  SCIP_Bool d;
3409 
3410  sourcevar = sourcevars[j];
3411  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourcevar, &targetvar, varmap, consmap, global, &success) );
3412  if ( ! success )
3413  {
3414  SCIPdebugMsg(sourcescip, "Getting copy for variable <%s> failed.\n", SCIPvarGetName(sourcevar));
3415  return SCIP_OKAY;
3416  }
3417 
3418  /* consider both possible implications */
3419  for (d = 0; d <= 1; ++d)
3420  {
3421  SCIP_BOUNDTYPE* impltypes;
3422  SCIP_VAR** implvars;
3423  SCIP_Real* implbounds;
3424  int nimpls;
3425  int l;
3426 
3427  nimpls = SCIPvarGetNImpls(sourcevar, d);
3428  if ( nimpls == 0 )
3429  continue;
3430 
3431  impltypes = SCIPvarGetImplTypes(sourcevar, d);
3432  implvars = SCIPvarGetImplVars(sourcevar, d);
3433  implbounds = SCIPvarGetImplBounds(sourcevar, d);
3434 
3435  /* create implications */
3436  for (l = 0; l < nimpls; ++l)
3437  {
3438  SCIP_VAR* implvar;
3439  int nboundchg = 0;
3440 
3441  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, implvars[l], &implvar, varmap, consmap, global, &success) );
3442  if ( ! success )
3443  {
3444  SCIPdebugMsg(sourcescip, "Getting copy for variable <%s> failed.\n", SCIPvarGetName(implvars[l]));
3445  return SCIP_OKAY;
3446  }
3447 
3448  SCIP_CALL( SCIPaddVarImplication(targetscip, targetvar, d, implvar, impltypes[l], implbounds[l], infeasible, &nboundchg) );
3449  if ( *infeasible )
3450  return SCIP_OKAY;
3451  if ( ncopied != NULL )
3452  ++(*ncopied);
3453  if ( nbdchgs != NULL )
3454  *nbdchgs += nboundchg;
3455  }
3456  }
3457  }
3458 
3459  return SCIP_OKAY;
3460 }
3461 
3462 /** copies parameter settings from sourcescip to targetscip
3463  *
3464  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3465  * @note Do not change the source SCIP environment during the copying process
3466  *
3467  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3468  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3469  *
3470  * @pre This method can be called if sourcescip is in one of the following stages:
3471  * - \ref SCIP_STAGE_PROBLEM
3472  * - \ref SCIP_STAGE_TRANSFORMED
3473  * - \ref SCIP_STAGE_INITPRESOLVE
3474  * - \ref SCIP_STAGE_PRESOLVING
3475  * - \ref SCIP_STAGE_EXITPRESOLVE
3476  * - \ref SCIP_STAGE_PRESOLVED
3477  * - \ref SCIP_STAGE_INITSOLVE
3478  * - \ref SCIP_STAGE_SOLVING
3479  * - \ref SCIP_STAGE_SOLVED
3480  *
3481  * @pre This method can be called if targetscip is in one of the following stages:
3482  * - \ref SCIP_STAGE_INIT
3483  * - \ref SCIP_STAGE_PROBLEM
3484  * - \ref SCIP_STAGE_FREE
3485  *
3486  * @note sourcescip stage does not get changed
3487  *
3488  * @note targetscip stage does not get changed
3489  *
3490  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3491  */
3493  SCIP* sourcescip, /**< source SCIP data structure */
3494  SCIP* targetscip /**< target SCIP data structure */
3495  )
3496 {
3497  assert(sourcescip != NULL);
3498  assert(targetscip != NULL);
3499  assert(sourcescip->set != NULL);
3500  assert(targetscip->set != NULL);
3501 
3502  /* check stages for both, the source and the target SCIP data structure */
3503  SCIP_CALL( checkStage(sourcescip, "SCIPcopyParamSettings", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
3504  SCIP_CALL( checkStage(targetscip, "SCIPcopyParamSettings", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
3505 
3506  SCIP_CALL( SCIPsetCopyParams(sourcescip->set, targetscip->set, targetscip->messagehdlr) );
3507 
3508  return SCIP_OKAY;
3509 }
3510 
3511 /** gets depth of current scip instance (increased by each copy call)
3512  *
3513  * @return Depth of subscip of SCIP is returned.
3514  *
3515  * @pre This method can be called if SCIP is in one of the following stages:
3516  * - \ref SCIP_STAGE_PROBLEM
3517  * - \ref SCIP_STAGE_TRANSFORMING
3518  * - \ref SCIP_STAGE_TRANSFORMED
3519  * - \ref SCIP_STAGE_INITPRESOLVE
3520  * - \ref SCIP_STAGE_PRESOLVING
3521  * - \ref SCIP_STAGE_EXITPRESOLVE
3522  * - \ref SCIP_STAGE_PRESOLVED
3523  * - \ref SCIP_STAGE_INITSOLVE
3524  * - \ref SCIP_STAGE_SOLVING
3525  * - \ref SCIP_STAGE_SOLVED
3526  * - \ref SCIP_STAGE_EXITSOLVE
3527  * - \ref SCIP_STAGE_FREETRANS
3528  *
3529  * @note SCIP stage does not get changed
3530  *
3531  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3532  */
3534  SCIP* scip /**< SCIP data structure */
3535  )
3536 {
3537  assert( scip != NULL );
3538  assert( scip->stat != NULL );
3539 
3540  SCIP_CALL_ABORT( checkStage(scip, "SCIPgetSubscipDepth", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
3541 
3542  return scip->stat->subscipdepth;
3543 }
3544 
3545 /** copies source SCIP data into target SCIP data structure
3546  *
3547  * distinguishes between
3548  * - local and global copies
3549  * - copies of the original or transformed problem
3550  *
3551  * Allows for constraint compression by specifying a number of source variables
3552  * and values that should be fixed in the copy.
3553  */
3554 static
3556  SCIP* sourcescip, /**< source SCIP data structure */
3557  SCIP* targetscip, /**< target SCIP data structure */
3558  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3559  * target variables, or NULL */
3560  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3561  * target constraints, or NULL */
3562  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
3563  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
3564  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
3565  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
3566  SCIP_Bool useconscompression, /**< should constraint compression be used when constraints are created? */
3567  SCIP_Bool global, /**< create a global or a local copy? */
3568  SCIP_Bool original, /**< copy original or transformed problem? if TRUE, a copy using local bounds is not possible */
3569  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
3570  * plugins will be copied and activated, and the modifiable flag of
3571  * constraints will be respected. If FALSE, valid will be set to FALSE, when
3572  * there are pricers present */
3573  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
3574  SCIP_Bool* valid /**< pointer to store whether the copying was valid or not, or NULL */
3575  )
3576 {
3577  SCIP_HASHMAP* localvarmap;
3578  SCIP_HASHMAP* localconsmap;
3579  SCIP_Real startcopytime;
3580  SCIP_Real copytime;
3581  SCIP_Bool uselocalvarmap;
3582  SCIP_Bool uselocalconsmap;
3583  SCIP_Bool consscopyvalid;
3584  SCIP_Bool localvalid;
3585  SCIP_Bool msghdlrquiet;
3586  char name[SCIP_MAXSTRLEN];
3587 
3588  assert(sourcescip != NULL);
3589  assert(targetscip != NULL);
3590  assert(suffix != NULL);
3591  assert(global || !original);
3592 
3593  /* get time before start of copy procedure */
3594  startcopytime = SCIPclockGetTime(sourcescip->stat->copyclock);
3595 
3596  /* start time measuring */
3597  SCIPclockStart(sourcescip->stat->copyclock, sourcescip->set);
3598 
3599  /* copy all plugins */
3600  SCIP_CALL( SCIPcopyPlugins(sourcescip, targetscip, TRUE, enablepricing, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
3601  TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, passmessagehdlr, &localvalid) );
3602 
3603  /* in case there are active pricers and pricing is disabled the target SCIP will not be a valid copy of the source
3604  * SCIP
3605  */
3606  if( ! enablepricing && SCIPgetNActivePricers(sourcescip) > 0 )
3607  localvalid = FALSE;
3608 
3609  SCIPdebugMsg(sourcescip, "Copying plugins was%s valid.\n", localvalid ? "" : " not");
3610 
3611  uselocalvarmap = (varmap == NULL);
3612  uselocalconsmap = (consmap == NULL);
3613 
3614  if( uselocalvarmap )
3615  {
3616  /* create the variable mapping hash map */
3617  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
3618  }
3619  else
3620  localvarmap = varmap;
3621 
3622  if( uselocalconsmap )
3623  {
3624  /* create the constraint mapping hash map */
3625  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
3626  }
3627  else
3628  localconsmap = consmap;
3629 
3630  /* construct name for the target SCIP using the source problem name and the given suffix string */
3631  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%s", SCIPgetProbName(sourcescip), suffix);
3632 
3633  /* store the quiet state of the message handler, if existent */
3634  msghdlrquiet = SCIPmessagehdlrIsQuiet(targetscip->messagehdlr);
3635 
3636  /* explicitly suppress output when copying parameters */
3637  SCIPsetMessagehdlrQuiet(targetscip, TRUE);
3638  /* copy all settings */
3639  SCIP_CALL( SCIPcopyParamSettings(sourcescip, targetscip) );
3640 
3641  /* restore original quiet state */
3642  SCIPsetMessagehdlrQuiet(targetscip, msghdlrquiet);
3643 
3644  /* create problem in the target SCIP copying the source original or transformed problem data */
3645  if( original )
3646  {
3647  SCIP_CALL( SCIPcopyOrigProb(sourcescip, targetscip, localvarmap, localconsmap, name) );
3648  }
3649  else
3650  {
3651  SCIP_CALL( SCIPcopyProb(sourcescip, targetscip, localvarmap, localconsmap, global, name) );
3652  }
3653 
3654  /* copy original or transformed variables and perform fixings if needed */
3655  SCIP_CALL( copyVars(sourcescip, targetscip, localvarmap, localconsmap, fixedvars, fixedvals, nfixedvars, original, global) );
3656 
3657  /* if fixed variables are directly specified or inferred from local bounds,
3658  * enable constraint compression
3659  */
3660  if( useconscompression && (nfixedvars > 0 || !global) )
3661  {
3662  SCIP_CALL( SCIPenableConsCompression(targetscip) );
3663 
3664  /* domain reductions yield a copy that is no longer guaranteed to be valid */
3665  localvalid = FALSE;
3666  }
3667 
3668  /* copy all (original) constraints */
3669  if( original )
3670  {
3671  SCIP_CALL( SCIPcopyOrigConss(sourcescip, targetscip, localvarmap, localconsmap, enablepricing, &consscopyvalid) );
3672  }
3673  else
3674  {
3675  SCIP_CALL( SCIPcopyConss(sourcescip, targetscip, localvarmap, localconsmap, global, enablepricing, &consscopyvalid) );
3676  }
3677 
3678  SCIPdebugMsg(sourcescip, "Copying constraints was%s valid.\n", consscopyvalid ? "" : " not");
3679 
3680  localvalid = localvalid && consscopyvalid;
3681 
3682  if( uselocalvarmap )
3683  {
3684  /* free hash map */
3685  SCIPhashmapFree(&localvarmap);
3686  }
3687 
3688  if( uselocalconsmap )
3689  {
3690  /* free hash map */
3691  SCIPhashmapFree(&localconsmap);
3692  }
3693 
3694  /* stop time measuring */
3695  SCIPclockStop(sourcescip->stat->copyclock, sourcescip->set);
3696 
3697  /* get time after copying procedure */
3698  copytime = SCIPclockGetTime(sourcescip->stat->copyclock) - startcopytime;
3699 
3700  if( copytime > sourcescip->stat->maxcopytime )
3701  sourcescip->stat->maxcopytime = copytime;
3702  if( copytime < sourcescip->stat->mincopytime )
3703  sourcescip->stat->mincopytime = copytime;
3704 
3705  /* increase copy counter */
3706  ++(sourcescip->stat->ncopies);
3707 
3708  targetscip->concurrent = sourcescip->concurrent;
3709  SCIP_CALL( SCIPsyncstoreRelease(&targetscip->syncstore) );
3710  targetscip->syncstore = sourcescip->syncstore;
3711  SCIP_CALL( SCIPsyncstoreCapture(targetscip->syncstore) );
3712 
3713  /* return the information about a valid copy to the user */
3714  if( valid != NULL )
3715  *valid = localvalid;
3716 
3717  return SCIP_OKAY;
3718 }
3719 
3720 /** copies source SCIP to target SCIP; the copying process is done in the following order:
3721  * 1) copy the plugins
3722  * 2) copy the settings
3723  * 3) create problem data in target-SCIP and copy the problem data of the source-SCIP
3724  * 4) copy all active variables
3725  * 5) copy all constraints
3726  *
3727  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
3728  *
3729  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3730  * Also, 'passmessagehdlr' should be set to FALSE.
3731  * @note Do not change the source SCIP environment during the copying process
3732  *
3733  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3734  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3735  *
3736  * @pre This method can be called if sourcescip is in one of the following stages:
3737  * - \ref SCIP_STAGE_PROBLEM
3738  * - \ref SCIP_STAGE_TRANSFORMED
3739  * - \ref SCIP_STAGE_INITPRESOLVE
3740  * - \ref SCIP_STAGE_PRESOLVING
3741  * - \ref SCIP_STAGE_EXITPRESOLVE
3742  * - \ref SCIP_STAGE_PRESOLVED
3743  * - \ref SCIP_STAGE_INITSOLVE
3744  * - \ref SCIP_STAGE_SOLVING
3745  * - \ref SCIP_STAGE_SOLVED
3746  *
3747  * @pre This method can be called if targetscip is in one of the following stages:
3748  * - \ref SCIP_STAGE_INIT
3749  * - \ref SCIP_STAGE_FREE
3750  *
3751  * @note sourcescip stage does not get changed
3752  *
3753  * @note targetscip stage does not get changed
3754  *
3755  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3756  */
3758  SCIP* sourcescip, /**< source SCIP data structure */
3759  SCIP* targetscip, /**< target SCIP data structure */
3760  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3761  * target variables, or NULL */
3762  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3763  * target constraints, or NULL */
3764  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
3765  SCIP_Bool global, /**< create a global or a local copy? */
3766  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
3767  * plugins will be copied and activated, and the modifiable flag of
3768  * constraints will be respected. If FALSE, valid will be set to FALSE, when
3769  * there are pricers present */
3770  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
3771  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
3772  )
3773 {
3774  SCIP_VAR** fixedvars = NULL;
3775  SCIP_Real* fixedvals = NULL;
3776  int nfixedvars = 0;
3777  SCIP_Bool original = FALSE;
3778  SCIP_Bool useconscompression = FALSE;
3779 
3780  assert(sourcescip != NULL);
3781  assert(targetscip != NULL);
3782  assert(suffix != NULL);
3783 
3784  /* check stages for both, the source and the target SCIP data structure */
3785  SCIP_CALL( checkStage(sourcescip, "SCIPcopyConsCompression", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
3786  SCIP_CALL( checkStage(targetscip, "SCIPcopyConsCompression", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
3787 
3788  /* copy source SCIP data into target SCIP data structure */
3789  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
3790  useconscompression, global, original, enablepricing, passmessagehdlr, valid) );
3791 
3792  return SCIP_OKAY;
3793 }
3794 
3795 /** copies source SCIP to target SCIP but compresses constraints
3796  *
3797  * constraint compression is performed by removing fixed variables immediately
3798  * during constraint creation if the involved constraint handlers support
3799  * compression
3800  *
3801  * the copying process is done in the following order:
3802  * 1) copy the plugins
3803  * 2) copy the settings
3804  * 3) create problem data in target-SCIP and copy the problem data of the source-SCIP
3805  * 4) copy all active variables
3806  * a) fix all variable copies specified by \p fixedvars, \p fixedvals, and \p nfixedvars
3807  * b) enable constraint compression
3808  * 5) copy all constraints
3809  *
3810  * @note: in case that a combination of local bounds and explicit fixing values should be used,
3811  * the fixing value of a variable is prefered if local bounds and fixing value disagree.
3812  *
3813  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
3814  *
3815  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3816  * Also, 'passmessagehdlr' should be set to FALSE.
3817  * @note Do not change the source SCIP environment during the copying process
3818  *
3819  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3820  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3821  *
3822  * @pre This method can be called if sourcescip is in one of the following stages:
3823  * - \ref SCIP_STAGE_PROBLEM
3824  * - \ref SCIP_STAGE_TRANSFORMED
3825  * - \ref SCIP_STAGE_INITPRESOLVE
3826  * - \ref SCIP_STAGE_PRESOLVING
3827  * - \ref SCIP_STAGE_EXITPRESOLVE
3828  * - \ref SCIP_STAGE_PRESOLVED
3829  * - \ref SCIP_STAGE_INITSOLVE
3830  * - \ref SCIP_STAGE_SOLVING
3831  * - \ref SCIP_STAGE_SOLVED
3832  *
3833  * @pre This method can be called if targetscip is in one of the following stages:
3834  * - \ref SCIP_STAGE_INIT
3835  * - \ref SCIP_STAGE_FREE
3836  *
3837  * @note sourcescip stage does not get changed
3838  *
3839  * @note targetscip stage does not get changed
3840  *
3841  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3842  */
3844  SCIP* sourcescip, /**< source SCIP data structure */
3845  SCIP* targetscip, /**< target SCIP data structure */
3846  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3847  * target variables, or NULL */
3848  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3849  * target constraints, or NULL */
3850  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
3851  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
3852  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
3853  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
3854  SCIP_Bool global, /**< create a global or a local copy? */
3855  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
3856  * plugins will be copied and activated, and the modifiable flag of
3857  * constraints will be respected. If FALSE, valid will be set to FALSE, when
3858  * there are pricers present */
3859  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
3860  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
3861  )
3862 {
3863  SCIP_Bool original = FALSE;
3864  SCIP_Bool useconscompression = TRUE;
3865 
3866  assert(sourcescip != NULL);
3867  assert(targetscip != NULL);
3868  assert(suffix != NULL);
3869 
3870  /* check stages for both, the source and the target SCIP data structure */
3871  SCIP_CALL( checkStage(sourcescip, "SCIPcopyConsCompression", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
3872  SCIP_CALL( checkStage(targetscip, "SCIPcopyConsCompression", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
3873 
3874  /* copy the source problem data */
3875  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
3876  useconscompression, global, original, enablepricing, passmessagehdlr, valid) );
3877 
3878  return SCIP_OKAY;
3879 }
3880 
3881 
3882 /** copies source SCIP original problem to target SCIP; the copying process is done in the following order:
3883  * 1) copy the plugins
3884  * 2) copy the settings
3885  * 3) create problem data in target-SCIP and copy the original problem data of the source-SCIP
3886  * 4) copy all original variables
3887  * 5) copy all original constraints
3888  *
3889  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
3890  *
3891  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3892  * Also, 'passmessagehdlr' should be set to FALSE.
3893  * @note Do not change the source SCIP environment during the copying process
3894  *
3895  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3896  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3897  *
3898  * @pre This method can be called if sourcescip is in one of the following stages:
3899  * - \ref SCIP_STAGE_PROBLEM
3900  * - \ref SCIP_STAGE_TRANSFORMED
3901  * - \ref SCIP_STAGE_INITPRESOLVE
3902  * - \ref SCIP_STAGE_PRESOLVING
3903  * - \ref SCIP_STAGE_EXITPRESOLVE
3904  * - \ref SCIP_STAGE_PRESOLVED
3905  * - \ref SCIP_STAGE_INITSOLVE
3906  * - \ref SCIP_STAGE_SOLVING
3907  * - \ref SCIP_STAGE_SOLVED
3908  *
3909  * @pre This method can be called if targetscip is in one of the following stages:
3910  * - \ref SCIP_STAGE_INIT
3911  * - \ref SCIP_STAGE_FREE
3912  *
3913  * @note sourcescip stage does not get changed
3914  *
3915  * @note targetscip stage does not get changed
3916  *
3917  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3918  */
3920  SCIP* sourcescip, /**< source SCIP data structure */
3921  SCIP* targetscip, /**< target SCIP data structure */
3922  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3923  * target variables, or NULL */
3924  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3925  * target constraints, or NULL */
3926  const char* suffix, /**< suffix which will be added to the names of the target SCIP, might be empty */
3927  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
3928  * plugins will be copied and activated, and the modifiable flag of
3929  * constraints will be respected. If FALSE, valid will be set to FALSE, when
3930  * there are pricers present */
3931  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
3932  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
3933  )
3934 {
3935  SCIP_VAR** fixedvars = NULL;
3936  SCIP_Real* fixedvals = NULL;
3937  int nfixedvars = 0;
3938  SCIP_Bool global = TRUE;
3939  SCIP_Bool original = TRUE;
3940  SCIP_Bool useconscompression = FALSE;
3941 
3942  assert(sourcescip != NULL);
3943  assert(targetscip != NULL);
3944  assert(suffix != NULL);
3945 
3946  /* check stages for both, the source and the target SCIP data structure */
3947  SCIP_CALL( checkStage(sourcescip, "SCIPcopyOrig", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
3948  SCIP_CALL( checkStage(targetscip, "SCIPcopyOrig", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
3949 
3950  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
3951  useconscompression, global, original, enablepricing, passmessagehdlr, valid) );
3952 
3953  return SCIP_OKAY;
3954 }
3955 
3956 /** copies source SCIP original problem to target SCIP but compresses constraints
3957  *
3958  * constraint compression is performed by removing fixed variables immediately
3959  * during constraint creation if the involved constraint handlers support
3960  * compression
3961  *
3962  * the copying process is done in the following order:
3963  * 1) copy the plugins
3964  * 2) copy the settings
3965  * 3) create problem data in target-SCIP and copy the problem data of the source-SCIP
3966  * 4) copy all original variables
3967  * a) fix all variable copies specified by \p fixedvars, \p fixedvals, and \p nfixedvars
3968  * b) enable constraint compression
3969  * 5) copy all constraints
3970  *
3971  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
3972  *
3973  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3974  * Also, 'passmessagehdlr' should be set to FALSE.
3975  * @note Do not change the source SCIP environment during the copying process
3976  *
3977  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3978  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3979  *
3980  * @pre This method can be called if sourcescip is in one of the following stages:
3981  * - \ref SCIP_STAGE_PROBLEM
3982  * - \ref SCIP_STAGE_TRANSFORMED
3983  * - \ref SCIP_STAGE_INITPRESOLVE
3984  * - \ref SCIP_STAGE_PRESOLVING
3985  * - \ref SCIP_STAGE_EXITPRESOLVE
3986  * - \ref SCIP_STAGE_PRESOLVED
3987  * - \ref SCIP_STAGE_INITSOLVE
3988  * - \ref SCIP_STAGE_SOLVING
3989  * - \ref SCIP_STAGE_SOLVED
3990  *
3991  * @pre This method can be called if targetscip is in one of the following stages:
3992  * - \ref SCIP_STAGE_INIT
3993  * - \ref SCIP_STAGE_FREE
3994  *
3995  * @note sourcescip stage does not get changed
3996  *
3997  * @note targetscip stage does not get changed
3998  *
3999  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
4000  */
4002  SCIP* sourcescip, /**< source SCIP data structure */
4003  SCIP* targetscip, /**< target SCIP data structure */
4004  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
4005  * target variables, or NULL */
4006  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
4007  * target constraints, or NULL */
4008  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
4009  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
4010  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
4011  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
4012  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
4013  * plugins will be copied and activated, and the modifiable flag of
4014  * constraints will be respected. If FALSE, valid will be set to FALSE, when
4015  * there are pricers present */
4016  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
4017  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
4018  )
4019 {
4020  SCIP_Bool original = TRUE;
4021  SCIP_Bool global = TRUE;
4022  SCIP_Bool useconscompression = TRUE;
4023 
4024  assert(sourcescip != NULL);
4025  assert(targetscip != NULL);
4026  assert(suffix != NULL);
4027 
4028  /* check stages for both, the source and the target SCIP data structure */
4029  SCIP_CALL( checkStage(sourcescip, "SCIPcopyOrigConsCompression", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
4030  SCIP_CALL( checkStage(targetscip, "SCIPcopyOrigConsCompression", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
4031 
4032  /* copy the source problem data */
4033  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
4034  useconscompression, global, original, enablepricing, passmessagehdlr, valid) );
4035 
4036  SCIP_CALL( SCIPsyncstoreRelease(&targetscip->syncstore) );
4037  targetscip->syncstore = sourcescip->syncstore;
4038  SCIP_CALL( SCIPsyncstoreCapture(targetscip->syncstore) );
4039 
4040  return SCIP_OKAY;
4041 }
4042 
4043 /** return updated time limit for a sub-SCIP */
4044 static
4046  SCIP* sourcescip, /**< source SCIP data structure */
4047  SCIP_Real* timelimit /**< pointer to store sub-SCIP time limit */
4048  )
4049 {
4050  SCIP_CALL( SCIPgetRealParam(sourcescip, "limits/time", timelimit) );
4051  if( !SCIPisInfinity(sourcescip, *timelimit) )
4052  (*timelimit) -= SCIPgetSolvingTime(sourcescip);
4053 
4054  return SCIP_OKAY;
4055 }
4056 
4057 /** return updated memory limit for a sub-SCIP */
4058 static
4060  SCIP* sourcescip, /**< source SCIP data structure */
4061  SCIP_Real* memorylimit /**< pointer to store sub-SCIP memory limit */
4062  )
4063 {
4064  SCIP_CALL( SCIPgetRealParam(sourcescip, "limits/memory", memorylimit) );
4065 
4066  /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
4067  if( !SCIPisInfinity(sourcescip, *memorylimit) )
4068  (*memorylimit) -= (SCIPgetMemUsed(sourcescip) + SCIPgetMemExternEstim(sourcescip))/1048576.0;
4069 
4070  return SCIP_OKAY;
4071 }
4072 
4073 /** checks if there is enough time and memory left for copying the sourcescip into a sub-SCIP and solve the sub-SCIP
4074  *
4075  * This is the case if the time and memory limit that would be passed to the sub-SCIP are larger than 0.0
4076  *
4077  * @pre This method can be called if sourcescip is in one of the following stages:
4078  * - \ref SCIP_STAGE_PROBLEM
4079  * - \ref SCIP_STAGE_TRANSFORMED
4080  * - \ref SCIP_STAGE_INITPRESOLVE
4081  * - \ref SCIP_STAGE_PRESOLVING
4082  * - \ref SCIP_STAGE_EXITPRESOLVE
4083  * - \ref SCIP_STAGE_PRESOLVED
4084  * - \ref SCIP_STAGE_INITSOLVE
4085  * - \ref SCIP_STAGE_SOLVING
4086  * - \ref SCIP_STAGE_SOLVED
4087  *
4088  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
4089  */
4091  SCIP* sourcescip, /**< source SCIP data structure */
4092  SCIP_Bool* success /**< pointer to store whether there is time and memory left to copy the
4093  * problem and run the sub-SCIP */
4094  )
4095 {
4096  SCIP_Real timelimit;
4097  SCIP_Real memorylimit;
4098 
4099  SCIP_CALL( getCopyTimelimit(sourcescip, &timelimit) );
4100  SCIP_CALL( getCopyMemlimit(sourcescip, &memorylimit) );
4101 
4102  *success = timelimit > 0.0 && memorylimit > 2.0 * SCIPgetMemExternEstim(sourcescip) / 1048576.0;
4103 
4104  return SCIP_OKAY;
4105 }
4106 
4107 /** copies limits from source SCIP to target SCIP
4108  *
4109  * @note time and memory limit are reduced by the amount already spent in the source SCIP before installing the limit
4110  * in the target SCIP
4111  * @note all other limits are disabled and need to be enabled afterwards, if needed
4112  *
4113  * @pre This method can be called if sourcescip is in one of the following stages:
4114  * - \ref SCIP_STAGE_PROBLEM
4115  * - \ref SCIP_STAGE_TRANSFORMED
4116  * - \ref SCIP_STAGE_INITPRESOLVE
4117  * - \ref SCIP_STAGE_PRESOLVING
4118  * - \ref SCIP_STAGE_EXITPRESOLVE
4119  * - \ref SCIP_STAGE_PRESOLVED
4120  * - \ref SCIP_STAGE_INITSOLVE
4121  * - \ref SCIP_STAGE_SOLVING
4122  * - \ref SCIP_STAGE_SOLVED
4123  *
4124  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
4125  */
4127  SCIP* sourcescip, /**< source SCIP data structure */
4128  SCIP* targetscip /**< target SCIP data structure */
4129  )
4130 {
4131  SCIP_Real timelimit;
4132  SCIP_Real memorylimit;
4133 
4134  SCIP_CALL( getCopyTimelimit(sourcescip, &timelimit) );
4135  SCIP_CALL( getCopyMemlimit(sourcescip, &memorylimit) );
4136 
4137  /* avoid negative limits */
4138  if( timelimit < 0.0 )
4139  timelimit = 0.0;
4140  if( memorylimit < 0.0 )
4141  memorylimit = 0.0;
4142 
4143  /* set time and memory limit to the adjusted values */
4144  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/time", timelimit) );
4145  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/memory", memorylimit) );
4146 
4147  /* disable all other limits */
4148  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/absgap", 0.0) );
4149  SCIP_CALL( SCIPsetIntParam(targetscip, "limits/bestsol", -1) );
4150  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/gap", 0.0) );
4151  SCIP_CALL( SCIPsetLongintParam(targetscip, "limits/nodes", -1LL) );
4152  SCIP_CALL( SCIPsetIntParam(targetscip, "limits/restarts", -1) );
4153  SCIP_CALL( SCIPsetIntParam(targetscip, "limits/solutions", -1) );
4154  SCIP_CALL( SCIPsetLongintParam(targetscip, "limits/stallnodes", -1LL) );
4155  SCIP_CALL( SCIPsetLongintParam(targetscip, "limits/totalnodes", -1LL) );
4156 
4157  /* the soft time limit event handler might not be included so we need to check if the parameter exists */
4158  if( SCIPgetParam(targetscip, "limits/softtime") != NULL )
4159  {
4160  SCIP_CALL( SCIPsetLongintParam(targetscip, "limits/totalnodes", -1LL) );
4161  }
4162 
4163  return SCIP_OKAY;
4164 }
4165 
4166 
4167 /*
4168  * parameter settings
4169  */
4170 
4171 /** creates a SCIP_Bool parameter, sets it to its default value, and adds it to the parameter set
4172  *
4173  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4174  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4175  */
4177  SCIP* scip, /**< SCIP data structure */
4178  const char* name, /**< name of the parameter */
4179  const char* desc, /**< description of the parameter */
4180  SCIP_Bool* valueptr, /**< pointer to store the current parameter value, or NULL */
4181  SCIP_Bool isadvanced, /**< is this parameter an advanced parameter? */
4182  SCIP_Bool defaultvalue, /**< default value of the parameter */
4183  SCIP_DECL_PARAMCHGD ((*paramchgd)), /**< change information method of parameter */
4184  SCIP_PARAMDATA* paramdata /**< locally defined parameter specific data */
4185  )
4186 {
4187  assert(scip != NULL);
4188  assert(scip->set != NULL);
4189  assert(scip->mem != NULL);
4190 
4191  SCIP_CALL( SCIPsetAddBoolParam(scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, valueptr, isadvanced,
4192  defaultvalue, paramchgd, paramdata) );
4193 
4194  return SCIP_OKAY;
4195 }
4196 
4197 /** creates a int parameter, sets it to its default value, and adds it to the parameter set
4198  *
4199  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4200  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4201  */
4203  SCIP* scip, /**< SCIP data structure */
4204  const char* name, /**< name of the parameter */
4205  const char* desc, /**< description of the parameter */
4206  int* valueptr, /**< pointer to store the current parameter value, or NULL */
4207  SCIP_Bool isadvanced, /**< is this parameter an advanced parameter? */
4208  int defaultvalue, /**< default value of the parameter */
4209  int minvalue, /**< minimum value for parameter */
4210  int maxvalue, /**< maximum value for parameter */
4211  SCIP_DECL_PARAMCHGD ((*paramchgd)), /**< change information method of parameter */
4212  SCIP_PARAMDATA* paramdata /**< locally defined parameter specific data */
4213  )
4214 {
4215  assert(scip != NULL);
4216  assert(scip->set != NULL);
4217  assert(scip->mem != NULL);
4218 
4219  SCIP_CALL( SCIPsetAddIntParam(scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, valueptr, isadvanced,
4220  defaultvalue, minvalue, maxvalue, paramchgd, paramdata) );
4221 
4222  return SCIP_OKAY;
4223 }
4224 
4225 /** creates a SCIP_Longint parameter, sets it to its default value, and adds it to the parameter set
4226  *
4227  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4228  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4229  */
4231  SCIP* scip, /**< SCIP data structure */
4232  const char* name, /**< name of the parameter */
4233  const char* desc, /**< description of the parameter */
4234  SCIP_Longint* valueptr, /**< pointer to store the current parameter value, or NULL */
4235  SCIP_Bool isadvanced, /**< is this parameter an advanced parameter? */
4236  SCIP_Longint defaultvalue, /**< default value of the parameter */
4237  SCIP_Longint minvalue, /**< minimum value for parameter */
4238  SCIP_Longint maxvalue, /**< maximum value for parameter */
4239  SCIP_DECL_PARAMCHGD ((*paramchgd)), /**< change information method of parameter */
4240  SCIP_PARAMDATA* paramdata /**< locally defined parameter specific data */
4241  )
4242 {
4243  assert(scip != NULL);
4244  assert(scip->set != NULL);
4245  assert(scip->mem != NULL);
4246 
4247  SCIP_CALL( SCIPsetAddLongintParam(scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, valueptr, isadvanced,
4248  defaultvalue, minvalue, maxvalue, paramchgd, paramdata) );
4249 
4250  return SCIP_OKAY;
4251 }
4252 
4253 /** creates a SCIP_Real parameter, sets it to its default value, and adds it to the parameter set
4254  *
4255  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4256  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4257  */
4259  SCIP* scip, /**< SCIP data structure */
4260  const char* name, /**< name of the parameter */
4261  const char* desc, /**< description of the parameter */
4262  SCIP_Real* valueptr, /**< pointer to store the current parameter value, or NULL */
4263  SCIP_Bool isadvanced, /**< is this parameter an advanced parameter? */
4264  SCIP_Real defaultvalue, /**< default value of the parameter */
4265  SCIP_Real minvalue, /**< minimum value for parameter */
4266  SCIP_Real maxvalue, /**< maximum value for parameter */
4267  SCIP_DECL_PARAMCHGD ((*paramchgd)), /**< change information method of parameter */
4268  SCIP_PARAMDATA* paramdata /**< locally defined parameter specific data */
4269  )
4270 {
4271  assert(scip != NULL);
4272  assert(scip->set != NULL);
4273  assert(scip->mem != NULL);
4274 
4275  SCIP_CALL( SCIPsetAddRealParam(scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, valueptr, isadvanced,
4276  defaultvalue, minvalue, maxvalue, paramchgd, paramdata) );
4277 
4278  return SCIP_OKAY;
4279 }
4280 
4281 /** creates a char parameter, sets it to its default value, and adds it to the parameter set
4282  *
4283  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4284  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4285  */
4287  SCIP* scip, /**< SCIP data structure */
4288  const char* name, /**< name of the parameter */
4289  const char* desc, /**< description of the parameter */
4290  char* valueptr, /**< pointer to store the current parameter value, or NULL */
4291  SCIP_Bool isadvanced, /**< is this parameter an advanced parameter? */
4292  char defaultvalue, /**< default value of the parameter */
4293  const char* allowedvalues, /**< array with possible parameter values, or NULL if not restricted */
4294  SCIP_DECL_PARAMCHGD ((*paramchgd)), /**< change information method of parameter */
4295  SCIP_PARAMDATA* paramdata /**< locally defined parameter specific data */
4296  )
4297 {
4298  assert(scip != NULL);
4299  assert(scip->set != NULL);
4300  assert(scip->mem != NULL);
4301 
4302  SCIP_CALL( SCIPsetAddCharParam(scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, valueptr, isadvanced,
4303  defaultvalue, allowedvalues, paramchgd, paramdata) );
4304 
4305  return SCIP_OKAY;
4306 }
4307 
4308 /** creates a string(char*) parameter, sets it to its default value, and adds it to the parameter set
4309  *
4310  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4311  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4312  */
4314  SCIP* scip, /**< SCIP data structure */
4315  const char* name, /**< name of the parameter */
4316  const char* desc, /**< description of the parameter */
4317  char** valueptr, /**< pointer to store the current parameter value, or NULL; if not NULL then *valueptr should be NULL */
4318  SCIP_Bool isadvanced, /**< is this parameter an advanced parameter? */
4319  const char* defaultvalue, /**< default value of the parameter */
4320  SCIP_DECL_PARAMCHGD ((*paramchgd)), /**< change information method of parameter */
4321  SCIP_PARAMDATA* paramdata /**< locally defined parameter specific data */
4322  )
4323 {
4324  assert(scip != NULL);
4325  assert(scip->set != NULL);
4326  assert(scip->mem != NULL);
4327 
4328  SCIP_CALL( SCIPsetAddStringParam(scip->set, scip->messagehdlr, scip->mem->setmem, name, desc, valueptr, isadvanced,
4329  defaultvalue, paramchgd, paramdata) );
4330 
4331  return SCIP_OKAY;
4332 }
4333 
4334 /** gets the fixing status of an existing parameter
4335  *
4336  * @return TRUE if the parameter is fixed to a value, otherwise FALSE.
4337  */
4339  SCIP* scip, /**< SCIP data structure */
4340  const char* name /**< name of the parameter */
4341  )
4342 {
4343  assert(scip != NULL);
4344  assert(scip->set != NULL);
4345 
4346  return SCIPsetIsParamFixed(scip->set, name);
4347 }
4348 
4349 /** returns the pointer to the SCIP parameter with the given name
4350  *
4351  * @return pointer to the parameter with the given name
4352  */
4354  SCIP* scip, /**< SCIP data structure */
4355  const char* name /**< name of the parameter */
4356  )
4357 {
4358  assert(scip != NULL);
4359  assert(scip->set != NULL);
4360 
4361  return SCIPsetGetParam(scip->set, name);
4362 }
4363 
4364 /** gets the value of an existing SCIP_Bool parameter
4365  *
4366  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4367  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4368  */
4370  SCIP* scip, /**< SCIP data structure */
4371  const char* name, /**< name of the parameter */
4372  SCIP_Bool* value /**< pointer to store the parameter */
4373  )
4374 {
4375  assert(scip != NULL);
4376  assert(scip->set != NULL);
4377 
4378  SCIP_CALL( SCIPsetGetBoolParam(scip->set, name, value) );
4379 
4380  return SCIP_OKAY;
4381 }
4382 
4383 /** gets the value of an existing int parameter
4384  *
4385  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4386  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4387  */
4389  SCIP* scip, /**< SCIP data structure */
4390  const char* name, /**< name of the parameter */
4391  int* value /**< pointer to store the parameter */
4392  )
4393 {
4394  assert(scip != NULL);
4395  assert(scip->set != NULL);
4396 
4397  SCIP_CALL( SCIPsetGetIntParam(scip->set, name, value) );
4398 
4399  return SCIP_OKAY;
4400 }
4401 
4402 /** gets the value of an existing SCIP_Longint parameter
4403  *
4404  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4405  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4406  */
4408  SCIP* scip, /**< SCIP data structure */
4409  const char* name, /**< name of the parameter */
4410  SCIP_Longint* value /**< pointer to store the parameter */
4411  )
4412 {
4413  assert(scip != NULL);
4414  assert(scip->set != NULL);
4415 
4416  SCIP_CALL( SCIPsetGetLongintParam(scip->set, name, value) );
4417 
4418  return SCIP_OKAY;
4419 }
4420 
4421 /** gets the value of an existing SCIP_Real parameter
4422  *
4423  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4424  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4425  */
4427  SCIP* scip, /**< SCIP data structure */
4428  const char* name, /**< name of the parameter */
4429  SCIP_Real* value /**< pointer to store the parameter */
4430  )
4431 {
4432  assert(scip != NULL);
4433  assert(scip->set != NULL);
4434 
4435  SCIP_CALL( SCIPsetGetRealParam(scip->set, name, value) );
4436 
4437  return SCIP_OKAY;
4438 }
4439 
4440 /** gets the value of an existing char parameter
4441  *
4442  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4443  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4444  */
4446  SCIP* scip, /**< SCIP data structure */
4447  const char* name, /**< name of the parameter */
4448  char* value /**< pointer to store the parameter */
4449  )
4450 {
4451  assert(scip != NULL);
4452  assert(scip->set != NULL);
4453 
4454  SCIP_CALL( SCIPsetGetCharParam(scip->set, name, value) );
4455 
4456  return SCIP_OKAY;
4457 }
4458 
4459 /** gets the value of an existing string(char*) parameter
4460  *
4461  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4462  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4463  */
4465  SCIP* scip, /**< SCIP data structure */
4466  const char* name, /**< name of the parameter */
4467  char** value /**< pointer to store the parameter */
4468  )
4469 {
4470  assert(scip != NULL);
4471  assert(scip->set != NULL);
4472 
4473  SCIP_CALL( SCIPsetGetStringParam(scip->set, name, value) );
4474 
4475  return SCIP_OKAY;
4476 }
4477 
4478 /** fixes the value of an existing parameter
4479  *
4480  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4481  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4482  *
4483  * @note: Be careful with this method! Some general settings, e.g., the time or node limit, should not be fixed because
4484  * they have to be changed for sub-SCIPs.
4485  */
4487  SCIP* scip, /**< SCIP data structure */
4488  const char* name /**< name of the parameter */
4489  )
4490 {
4491  assert(scip != NULL);
4492  assert(scip->set != NULL);
4493 
4494  SCIP_CALL( SCIPsetChgParamFixed(scip->set, name, TRUE) );
4495 
4496  return SCIP_OKAY;
4497 }
4498 
4499 /** unfixes the value of an existing parameter
4500  *
4501  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4502  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4503  */
4505  SCIP* scip, /**< SCIP data structure */
4506  const char* name /**< name of the parameter */
4507  )
4508 {
4509  assert(scip != NULL);
4510  assert(scip->set != NULL);
4511 
4512  SCIP_CALL( SCIPsetChgParamFixed(scip->set, name, FALSE) );
4513 
4514  return SCIP_OKAY;
4515 }
4516 
4517 /** changes the value of an existing parameter
4518  *
4519  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4520  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4521  */
4523  SCIP* scip, /**< SCIP data structure */
4524  const char* name, /**< name of the parameter */
4525  void* value /**< new value of the parameter */
4526  )
4527 {
4528  assert(scip != NULL);
4529  assert(scip->set != NULL);
4530 
4531  SCIP_CALL( SCIPsetSetParam(scip->set, scip->messagehdlr, name, value) );
4532 
4533  return SCIP_OKAY;
4534 }
4535 
4536 /** changes the value of an existing SCIP_Bool parameter
4537  *
4538  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4539  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4540  */
4542  SCIP* scip, /**< SCIP data structure */
4543  SCIP_PARAM* param, /**< parameter */
4544  SCIP_Bool value /**< new value of the parameter */
4545  )
4546 {
4547  SCIP_RETCODE retcode;
4548 
4549  assert(scip != NULL);
4550  assert(scip->set != NULL);
4551 
4552  retcode = SCIPsetChgBoolParam(scip->set, scip->messagehdlr, param, value);
4553 
4554  if( retcode != SCIP_PARAMETERWRONGVAL )
4555  {
4556  SCIP_CALL( retcode );
4557  }
4558 
4559  return retcode;
4560 }
4561 
4562 /** changes the value of an existing SCIP_Bool parameter
4563  *
4564  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4565  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4566  */
4568  SCIP* scip, /**< SCIP data structure */
4569  const char* name, /**< name of the parameter */
4570  SCIP_Bool value /**< new value of the parameter */
4571  )
4572 {
4573  assert(scip != NULL);
4574  assert(scip->set != NULL);
4575 
4576  SCIP_CALL( SCIPsetSetBoolParam(scip->set, scip->messagehdlr, name, value) );
4577 
4578  return SCIP_OKAY;
4579 }
4580 
4581 /** checks whether the value of an existing SCIP_Bool parameter is valid */
4583  SCIP* scip, /**< SCIP data structure */
4584  SCIP_PARAM* param, /**< parameter */
4585  SCIP_Bool value /**< value to check */
4586  )
4587 {
4588  assert(scip != NULL);
4589  assert(param != NULL);
4590 
4591  return SCIPparamIsValidBool(param, value);
4592 }
4593 
4594 /** changes the value of an existing int parameter
4595  *
4596  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4597  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4598  */
4600  SCIP* scip, /**< SCIP data structure */
4601  SCIP_PARAM* param, /**< parameter */
4602  int value /**< new value of the parameter */
4603  )
4604 {
4605  SCIP_RETCODE retcode;
4606 
4607  assert(scip != NULL);
4608  assert(scip->set != NULL);
4609 
4610  retcode = SCIPsetChgIntParam(scip->set, scip->messagehdlr, param, value);
4611 
4612  if( retcode != SCIP_PARAMETERWRONGVAL )
4613  {
4614  SCIP_CALL( retcode );
4615  }
4616 
4617  return retcode;
4618 }
4619 
4620 /** changes the value of an existing int parameter
4621  *
4622  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4623  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4624  */
4626  SCIP* scip, /**< SCIP data structure */
4627  const char* name, /**< name of the parameter */
4628  int value /**< new value of the parameter */
4629  )
4630 {
4631  assert(scip != NULL);
4632  assert(scip->set != NULL);
4633 
4634  SCIP_CALL( SCIPsetSetIntParam(scip->set, scip->messagehdlr, name, value) );
4635 
4636  return SCIP_OKAY;
4637 }
4638 
4639 /** checks whether parameter value of an existing int paramter is valid */
4641  SCIP* scip, /**< SCIP data structure */
4642  SCIP_PARAM* param, /**< parameter */
4643  int value /**< value to check */
4644  )
4645 {
4646  assert(scip != NULL);
4647  assert(param != NULL);
4648 
4649  return SCIPparamIsValidInt(param, value);
4650 }
4651 
4652 /** changes the value of an existing SCIP_Longint parameter
4653  *
4654  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4655  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4656  */
4658  SCIP* scip, /**< SCIP data structure */
4659  SCIP_PARAM* param, /**< parameter */
4660  SCIP_Longint value /**< new value of the parameter */
4661  )
4662 {
4663  SCIP_RETCODE retcode;
4664 
4665  assert(scip != NULL);
4666  assert(scip->set != NULL);
4667 
4668  retcode = SCIPsetChgLongintParam(scip->set, scip->messagehdlr, param, value);
4669 
4670  if( retcode != SCIP_PARAMETERWRONGVAL )
4671  {
4672  SCIP_CALL( retcode );
4673  }
4674 
4675  return retcode;
4676 }
4677 
4678 /** changes the value of an existing SCIP_Longint parameter
4679  *
4680  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4681  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4682  */
4684  SCIP* scip, /**< SCIP data structure */
4685  const char* name, /**< name of the parameter */
4686  SCIP_Longint value /**< new value of the parameter */
4687  )
4688 {
4689  assert(scip != NULL);
4690  assert(scip->set != NULL);
4691 
4692  SCIP_CALL( SCIPsetSetLongintParam(scip->set, scip->messagehdlr, name, value) );
4693 
4694  return SCIP_OKAY;
4695 }
4696 
4697 /** checks whether parameter value of an existing SCIP_Longint paramter is valid */
4699  SCIP* scip, /**< SCIP data structure */
4700  SCIP_PARAM* param, /**< parameter */
4701  SCIP_Longint value /**< value to check */
4702  )
4703 {
4704  assert(scip != NULL);
4705  assert(param != NULL);
4706 
4707  return SCIPparamIsValidLongint(param, value);
4708 }
4709 
4710 /** changes the value of an existing SCIP_Real parameter
4711  *
4712  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4713  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4714  */
4716  SCIP* scip, /**< SCIP data structure */
4717  SCIP_PARAM* param, /**< parameter */
4718  SCIP_Real value /**< new value of the parameter */
4719  )
4720 {
4721  SCIP_RETCODE retcode;
4722 
4723  assert(scip != NULL);
4724  assert(scip->set != NULL);
4725 
4726  retcode = SCIPsetChgRealParam(scip->set, scip->messagehdlr, param, value);
4727 
4728  if( retcode != SCIP_PARAMETERWRONGVAL )
4729  {
4730  SCIP_CALL( retcode );
4731  }
4732 
4733  return retcode;
4734 }
4735 
4736 /** changes the value of an existing SCIP_Real parameter
4737  *
4738  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4739  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4740  */
4742  SCIP* scip, /**< SCIP data structure */
4743  const char* name, /**< name of the parameter */
4744  SCIP_Real value /**< new value of the parameter */
4745  )
4746 {
4747  assert(scip != NULL);
4748  assert(scip->set != NULL);
4749 
4750  SCIP_CALL( SCIPsetSetRealParam(scip->set, scip->messagehdlr, name, value) );
4751 
4752  return SCIP_OKAY;
4753 }
4754 
4755 /** checks whether parameter value of an existing SCIP_Real paramter is valid */
4757  SCIP* scip, /**< SCIP data structure */
4758  SCIP_PARAM* param, /**< parameter */
4759  SCIP_Real value /**< value to check */
4760  )
4761 {
4762  assert(scip != NULL);
4763  assert(param != NULL);
4764 
4765  return SCIPparamIsValidReal(param, value);
4766 }
4767 
4768 /** changes the value of an existing char parameter
4769  *
4770  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4771  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4772  */
4774  SCIP* scip, /**< SCIP data structure */
4775  SCIP_PARAM* param, /**< parameter */
4776  char value /**< new value of the parameter */
4777  )
4778 {
4779  SCIP_RETCODE retcode;
4780 
4781  assert(scip != NULL);
4782  assert(scip->set != NULL);
4783 
4784  retcode = SCIPsetChgCharParam(scip->set, scip->messagehdlr, param, value);
4785 
4786  if( retcode != SCIP_PARAMETERWRONGVAL )
4787  {
4788  SCIP_CALL( retcode );
4789  }
4790 
4791  return retcode;
4792 }
4793 
4794 /** changes the value of an existing char parameter
4795  *
4796  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4797  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4798  */
4800  SCIP* scip, /**< SCIP data structure */
4801  const char* name, /**< name of the parameter */
4802  char value /**< new value of the parameter */
4803  )
4804 {
4805  assert(scip != NULL);
4806  assert(scip->set != NULL);
4807 
4808  SCIP_CALL( SCIPsetSetCharParam(scip->set, scip->messagehdlr, name, value) );
4809 
4810  return SCIP_OKAY;
4811 }
4812 
4813 /** checks whether parameter value for a given SCIP_Real parameter is valid */
4815  SCIP* scip, /**< SCIP data structure */
4816  SCIP_PARAM* param, /**< parameter */
4817  const char value /**< value to check */
4818  )
4819 {
4820  assert(scip != NULL);
4821  assert(param != NULL);
4822 
4823  return SCIPparamIsValidChar(param, value);
4824 }
4825 
4826 /** changes the value of an existing string(char*) parameter
4827  *
4828  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4829  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4830  */
4832  SCIP* scip, /**< SCIP data structure */
4833  SCIP_PARAM* param, /**< parameter */
4834  const char* value /**< new value of the parameter */
4835  )
4836 {
4837  SCIP_RETCODE retcode;
4838 
4839  assert(scip != NULL);
4840  assert(scip->set != NULL);
4841 
4842  retcode = SCIPsetChgStringParam(scip->set, scip->messagehdlr, param, value);
4843 
4844  if( retcode != SCIP_PARAMETERWRONGVAL )
4845  {
4846  SCIP_CALL( retcode );
4847  }
4848 
4849  return retcode;
4850 }
4851 
4852 /** changes the value of an existing string(char*) parameter
4853  *
4854  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4855  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4856  */
4858  SCIP* scip, /**< SCIP data structure */
4859  const char* name, /**< name of the parameter */
4860  const char* value /**< new value of the parameter */
4861  )
4862 {
4863  assert(scip != NULL);
4864  assert(scip->set != NULL);
4865 
4866  SCIP_CALL( SCIPsetSetStringParam(scip->set, scip->messagehdlr, name, value) );
4867 
4868  return SCIP_OKAY;
4869 }
4870 
4871 /** checks whether parameter value for a given string parameter is valid */
4873  SCIP* scip, /**< SCIP data structure */
4874  SCIP_PARAM* param, /**< parameter */
4875  const char* value /**< value to check */
4876  )
4877 {
4878  assert(scip != NULL);
4879  assert(param != NULL);
4880 
4881  return SCIPparamIsValidString(param, value);
4882 }
4883 
4884 /** reads parameters from a file
4885  *
4886  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4887  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4888  */
4890  SCIP* scip, /**< SCIP data structure */
4891  const char* filename /**< file name */
4892  )
4893 {
4894  assert(scip != NULL);
4895  assert(scip->set != NULL);
4896 
4897  SCIP_CALL( SCIPsetReadParams(scip->set, scip->messagehdlr, filename) );
4898 
4899  return SCIP_OKAY;
4900 }
4901 
4902 /** writes a single parameter to a file
4903  *
4904  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4905  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4906  */
4908  SCIP* scip, /**< SCIP data structure */
4909  SCIP_PARAM* param, /**< parameter */
4910  const char* filename, /**< file name, or NULL for stdout */
4911  SCIP_Bool comments, /**< should parameter descriptions be written as comments? */
4912  SCIP_Bool onlychanged /**< should only those parameters be written that are changed from their
4913  * default value?
4914  */
4915  )
4916 {
4917  assert(scip != NULL);
4918  assert(param != NULL);
4919 
4920  SCIP_CALL( SCIPparamWrite(param, scip->messagehdlr, filename, comments, onlychanged) );
4921 
4922  return SCIP_OKAY;
4923 }
4924 
4925 /** writes all parameters in the parameter set to a file
4926  *
4927  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4928  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4929  */
4931  SCIP* scip, /**< SCIP data structure */
4932  const char* filename, /**< file name, or NULL for stdout */
4933  SCIP_Bool comments, /**< should parameter descriptions be written as comments? */
4934  SCIP_Bool onlychanged /**< should only those parameters be written that are changed from their
4935  * default value?
4936  */
4937  )
4938 {
4939  assert(scip != NULL);
4940  assert(scip->set != NULL);
4941 
4942  SCIP_CALL( SCIPsetWriteParams(scip->set, scip->messagehdlr, filename, comments, onlychanged) );
4943 
4944  return SCIP_OKAY;
4945 }
4946 
4947 /** resets a single parameter to its default value
4948  *
4949  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4950  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4951  */
4953  SCIP* scip, /**< SCIP data structure */
4954  const char* name /**< name of the parameter */
4955  )
4956 {
4957  assert(scip != NULL);
4958  assert(scip->set != NULL);
4959 
4960  SCIP_CALL( SCIPsetResetParam(scip->set, scip->messagehdlr, name) );
4961 
4962  return SCIP_OKAY;
4963 }
4964 
4965 /** resets all parameters to their default values
4966  *
4967  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4968  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4969  */
4971  SCIP* scip /**< SCIP data structure */
4972  )
4973 {
4974  assert(scip != NULL);
4975  assert(scip->set != NULL);
4976 
4977  SCIP_CALL( SCIPsetResetParams(scip->set, scip->messagehdlr) );
4978 
4979  return SCIP_OKAY;
4980 }
4981 
4982 /** sets parameters to
4983  *
4984  * - \ref SCIP_PARAMEMPHASIS_DEFAULT to use default values (see also SCIPresetParams())
4985  * - \ref SCIP_PARAMEMPHASIS_COUNTER to get feasible and "fast" counting process
4986  * - \ref SCIP_PARAMEMPHASIS_CPSOLVER to get CP like search (e.g. no LP relaxation)
4987  * - \ref SCIP_PARAMEMPHASIS_EASYCIP to solve easy problems fast
4988  * - \ref SCIP_PARAMEMPHASIS_FEASIBILITY to detect feasibility fast
4989  * - \ref SCIP_PARAMEMPHASIS_HARDLP to be capable to handle hard LPs
4990  * - \ref SCIP_PARAMEMPHASIS_OPTIMALITY to prove optimality fast
4991  * - \ref SCIP_PARAMEMPHASIS_PHASEFEAS to find feasible solutions during a 3 phase solution process
4992  * - \ref SCIP_PARAMEMPHASIS_PHASEIMPROVE to find improved solutions during a 3 phase solution process
4993  * - \ref SCIP_PARAMEMPHASIS_PHASEPROOF to proof optimality during a 3 phase solution process
4994  *
4995  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
4996  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
4997  */
4999  SCIP* scip, /**< SCIP data structure */
5000  SCIP_PARAMEMPHASIS paramemphasis, /**< parameter settings */
5001  SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
5002  )
5003 {
5004  assert(scip != NULL);
5005  assert(scip->set != NULL);
5006 
5007  SCIP_CALL( SCIPsetSetEmphasis(scip->set, scip->messagehdlr, paramemphasis, quiet) );
5008 
5009  return SCIP_OKAY;
5010 }
5011 
5012 /** sets parameters to deactivate separators and heuristics that use auxiliary SCIP instances; should be called for
5013  * auxiliary SCIP instances to avoid recursion
5014  *
5015  * @note only deactivates plugins which could cause recursion, some plugins which use sub-SCIPs stay activated
5016  *
5017  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
5018  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
5019  */
5021  SCIP* scip, /**< (auxiliary) SCIP data structure */
5022  SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
5023  )
5024 {
5025  assert(scip != NULL);
5026  assert(scip->set != NULL);
5027 
5028  SCIP_CALL( SCIPsetSetSubscipsOff(scip->set, scip->messagehdlr, quiet) );
5029 
5030  return SCIP_OKAY;
5031 }
5032 
5033 /** sets heuristic parameters values to
5034  *
5035  * - SCIP_PARAMSETTING_DEFAULT which are the default values of all heuristic parameters
5036  * - SCIP_PARAMSETTING_FAST such that the time spend for heuristic is decreased
5037  * - SCIP_PARAMSETTING_AGGRESSIVE such that the heuristic are called more aggregative
5038  * - SCIP_PARAMSETTING_OFF which turn off all heuristics
5039  *
5040  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
5041  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
5042  */
5044  SCIP* scip, /**< SCIP data structure */
5045  SCIP_PARAMSETTING paramsetting, /**< parameter settings */
5046  SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
5047  )
5048 {
5049  assert(scip != NULL);
5050  assert(scip->set != NULL);
5051  assert(paramsetting == SCIP_PARAMSETTING_DEFAULT || paramsetting == SCIP_PARAMSETTING_FAST
5052  || paramsetting == SCIP_PARAMSETTING_AGGRESSIVE || paramsetting == SCIP_PARAMSETTING_OFF);
5053 
5054  SCIP_CALL( SCIPsetSetHeuristics(scip->set, scip->messagehdlr, paramsetting, quiet) );
5055 
5056  return SCIP_OKAY;
5057 }
5058 
5059 /** sets presolving parameters to
5060  *
5061  * - SCIP_PARAMSETTING_DEFAULT which are the default values of all presolving parameters
5062  * - SCIP_PARAMSETTING_FAST such that the time spend for presolving is decreased
5063  * - SCIP_PARAMSETTING_AGGRESSIVE such that the presolving is more aggregative
5064  * - SCIP_PARAMSETTING_OFF which turn off all presolving
5065  *
5066  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
5067  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
5068  */
5070  SCIP* scip, /**< SCIP data structure */
5071  SCIP_PARAMSETTING paramsetting, /**< parameter settings */
5072  SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
5073  )
5074 {
5075  assert(scip != NULL);
5076  assert(scip->set != NULL);
5077  assert(paramsetting == SCIP_PARAMSETTING_DEFAULT || paramsetting == SCIP_PARAMSETTING_FAST
5078  || paramsetting == SCIP_PARAMSETTING_AGGRESSIVE || paramsetting == SCIP_PARAMSETTING_OFF);
5079 
5080  SCIP_CALL( SCIPsetSetPresolving(scip->set, scip->messagehdlr, paramsetting, quiet) );
5081 
5082  return SCIP_OKAY;
5083 }
5084 
5085 /** sets separating parameters to
5086  *
5087  * - SCIP_PARAMSETTING_DEFAULT which are the default values of all separating parameters
5088  * - SCIP_PARAMSETTING_FAST such that the time spend for separating is decreased
5089  * - SCIP_PARAMSETTING_AGGRESSIVE such that the separating is done more aggregative
5090  * - SCIP_PARAMSETTING_OFF which turn off all separating
5091  *
5092  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
5093  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
5094  */
5096  SCIP* scip, /**< SCIP data structure */
5097  SCIP_PARAMSETTING paramsetting, /**< parameter settings */
5098  SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
5099  )
5100 {
5101  assert(scip != NULL);
5102  assert(scip->set != NULL);
5103  assert(paramsetting == SCIP_PARAMSETTING_DEFAULT || paramsetting == SCIP_PARAMSETTING_FAST
5104  || paramsetting == SCIP_PARAMSETTING_AGGRESSIVE || paramsetting == SCIP_PARAMSETTING_OFF);
5105 
5106  SCIP_CALL( SCIPsetSetSeparating(scip->set, scip->messagehdlr, paramsetting, quiet) );
5107 
5108  return SCIP_OKAY;
5109 }
5110 
5111 /** returns the array of all available SCIP parameters
5112  *
5113  * @return SCIP_PARAM* array, containing all SCIP parameters.
5114  */
5116  SCIP* scip /**< SCIP data structure */
5117  )
5118 {
5119  assert(scip != NULL);
5120  assert(scip->set != NULL);
5121 
5122  return SCIPsetGetParams(scip->set);
5123 }
5124 
5125 /** returns the total number of all available SCIP parameters
5126  *
5127  * @return number of all SCIP parameters.
5128  */
5130  SCIP* scip /**< SCIP data structure */
5131  )
5132 {
5133  assert(scip != NULL);
5134  assert(scip->set != NULL);
5135 
5136  return SCIPsetGetNParams(scip->set);
5137 }
5138 
5139 
5140 
5141 
5142 /*
5143  * SCIP user functionality methods: managing plugins
5144  */
5145 
5146 /** creates a reader and includes it in SCIP
5147  *
5148  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
5149  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
5150  *
5151  * @pre This method can be called if SCIP is in one of the following stages:
5152  * - \ref SCIP_STAGE_INIT
5153  * - \ref SCIP_STAGE_PROBLEM
5154  *
5155  * @note method has all reader callbacks as arguments and is thus changed every time a new callback is added
5156  * in future releases; consider using SCIPincludeReaderBasic() and setter functions
5157  * if you seek for a method which is less likely to change in future releases
5158  */
5160  SCIP* scip, /**< SCIP data structure */
5161  const char* name, /**< name of reader */
5162  const char* desc, /**< description of reader */
5163  const char* extension, /**< file extension that reader processes */
5164  SCIP_DECL_READERCOPY ((*readercopy)), /**< copy method of reader or NULL if you don't want to copy your plugin into sub-SCIPs */
5165  SCIP_DECL_READERFREE ((*readerfree)), /**< destructor of reader */
5166  SCIP_DECL_READERREAD ((*readerread)), /**< read method */
5167  SCIP_DECL_READERWRITE ((*readerwrite)), /**< write method */
5168  SCIP_READERDATA* readerdata /**< reader data */
5169  )
5170 {
5171  SCIP_READER* reader;
5172 
5173  SCIP_CALL( checkStage(scip, "SCIPincludeReader", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
5174 
5175  /* check whether reader is already present */
5176  if( SCIPfindReader(scip, name) != NULL )
5177  {
5178  SCIPerrorMessage("reader <%s> already included.\n", name);
5179  return SCIP_INVALIDDATA;
5180  }
5181 
5182  SCIP_CALL( SCIPreaderCreate(&reader, name, desc, extension, readercopy, readerfree, readerread, readerwrite, readerdata) );
5183  SCIP_CALL( SCIPsetIncludeReader(scip->set, reader) );
5184 
5185  return SCIP_OKAY;
5186 }
5187 
5188 /** creates a reader and includes it in SCIP. All non-fundamental (or optional) callbacks will be set to NULL.
5189  * Optional callbacks can be set via specific setter functions, see
5190  * SCIPsetReaderCopy(), SCIPsetReaderFree(), SCIPsetReaderRead(), SCIPsetReaderWrite().
5191  *
5192  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
5193  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
5194  *
5195  * @pre This method can be called if SCIP is in one of the following stages:
5196  * - \ref SCIP_STAGE_INIT
5197  * - \ref SCIP_STAGE_PROBLEM
5198  *
5199  * @note if you want to set all callbacks with a single method call, consider using SCIPincludeReader() instead
5200  */
5202  SCIP* scip, /**< SCIP data structure */
5203  SCIP_READER** readerptr, /**< reference to reader pointer, or NULL */
5204  const char* n