Scippy

SCIP

Solving Constraint Integer Programs

scip_copy.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-2023 Zuse Institute Berlin (ZIB) */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file scip_copy.c
26  * @ingroup OTHER_CFILES
27  * @brief public methods for problem copies
28  * @author Tobias Achterberg
29  * @author Timo Berthold
30  * @author Gerald Gamrath
31  * @author Leona Gottwald
32  * @author Stefan Heinz
33  * @author Gregor Hendel
34  * @author Thorsten Koch
35  * @author Alexander Martin
36  * @author Marc Pfetsch
37  * @author Michael Winkler
38  * @author Kati Wolter
39  *
40  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
41  */
42 
43 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
44 
45 #include "blockmemshell/memory.h"
46 #include "scip/benders.h"
47 #include "scip/clock.h"
48 #include "scip/conflictstore.h"
49 #include "scip/cons.h"
50 #include "scip/cons_linear.h"
51 #include "scip/dcmp.h"
52 #include "scip/debug.h"
53 #include "scip/primal.h"
54 #include "scip/prob.h"
55 #include "scip/pub_cons.h"
56 #include "scip/pub_cutpool.h"
57 #include "scip/pub_implics.h"
58 #include "scip/pub_lp.h"
59 #include "scip/pub_message.h"
60 #include "scip/pub_misc.h"
61 #include "scip/pub_nlpi.h"
62 #include "scip/pub_sol.h"
63 #include "scip/pub_var.h"
64 #include "scip/scip_branch.h"
65 #include "scip/scip_cons.h"
66 #include "scip/scip_copy.h"
67 #include "scip/scip_cut.h"
68 #include "scip/scip_general.h"
69 #include "scip/scip_mem.h"
70 #include "scip/scip_message.h"
71 #include "scip/scip_nodesel.h"
72 #include "scip/scip_numerics.h"
73 #include "scip/scip_param.h"
74 #include "scip/scip_pricer.h"
75 #include "scip/scip_prob.h"
76 #include "scip/scip_sol.h"
77 #include "scip/scip_solve.h"
78 #include "scip/scip_solvingstats.h"
79 #include "scip/scip_timing.h"
80 #include "scip/scip_var.h"
81 #include "scip/set.h"
82 #include "scip/stat.h"
83 #include "scip/struct_mem.h"
84 #include "scip/struct_scip.h"
85 #include "scip/struct_set.h"
86 #include "scip/struct_stat.h"
87 #include "scip/struct_var.h"
88 #include "scip/syncstore.h"
89 #include "scip/var.h"
90 
91 /** returns true if the @p cut matches the selection criterium for copying */
92 static
94  SCIP* scip, /**< SCIP data structure */
95  SCIP_CUT* cut, /**< a cut */
96  char cutsel /**< cut selection for sub SCIPs ('a'ge, activity 'q'uotient) */
97  )
98 {
99  SCIP_Bool takecut;
100 
101  assert(cut != NULL);
102 
103  if( !SCIProwIsInLP(SCIPcutGetRow(cut)) )
104  return FALSE;
105 
106  switch( cutsel )
107  {
108  case 'a':
109  takecut = (SCIPcutGetAge(cut) == 0);
110  break;
111  case 'q':
112  takecut = (SCIPcutGetLPActivityQuot(cut) >= scip->set->sepa_minactivityquot);
113  break;
114  default:
115  SCIPerrorMessage("unknown cut selection strategy %c, must be either 'a' or 'q'\n", cutsel);
116  SCIPABORT();
117  takecut = FALSE; /*lint !e527*/
118  break;
119  }
120 
121  return takecut;
122 }
123 
124 /** copy active and tight cuts from one SCIP instance to linear constraints of another SCIP instance */
125 static
127  SCIP* sourcescip, /**< source SCIP data structure */
128  SCIP* targetscip, /**< target SCIP data structure */
129  SCIP_CUT** cuts, /**< cuts to copy */
130  int ncuts, /**< number of cuts to copy */
131  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
132  * target variables, or NULL */
133  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
134  * target constraints, or NULL */
135  SCIP_Bool global, /**< create a global or a local copy? */
136  int* ncutsadded /**< pointer to store number of copied cuts */
137  )
138 {
139  int c;
140 
141  assert(sourcescip != NULL);
142  assert(targetscip != NULL);
143  assert(cuts != NULL || ncuts == 0);
144  assert(ncutsadded != NULL);
145 
146  for( c = 0; c < ncuts; ++c )
147  {
148  SCIP_ROW* row;
149  SCIP_Bool takecut;
150 
151  assert( cuts[c] != NULL ); /*lint !e613*/
152  row = SCIPcutGetRow(cuts[c]); /*lint !e613*/
153  assert(!SCIProwIsLocal(row));
154  assert(!SCIProwIsModifiable(row));
155 
156  /* in case of a restart, convert the cuts with a good LP activity quotient; in other cases, e.g., when heuristics
157  * copy cuts into subscips, take only currently active ones
158  */
159  if( sourcescip == targetscip )
160  {
161  assert( SCIPisInRestart(sourcescip) );
162  takecut = takeCut(sourcescip, cuts[c], sourcescip->set->sepa_cutselrestart); /*lint !e613*/
163  }
164  else
165  takecut = takeCut(sourcescip, cuts[c], sourcescip->set->sepa_cutselsubscip); /*lint !e613*/
166 
167  /* create a linear constraint out of the cut */
168  if( takecut )
169  {
170  char name[SCIP_MAXSTRLEN];
171  SCIP_CONS* cons;
172  SCIP_COL** cols;
173  SCIP_VAR** vars;
174  int ncols;
175  int i;
176 
177  cols = SCIProwGetCols(row);
178  ncols = SCIProwGetNNonz(row);
179 
180  /* get all variables of the row */
181  SCIP_CALL( SCIPallocBufferArray(targetscip, &vars, ncols) );
182  for( i = 0; i < ncols && takecut; ++i )
183  {
184  vars[i] = SCIPcolGetVar(cols[i]);
185  takecut = !SCIPvarIsRelaxationOnly(vars[i]);
186  }
187 
188  /* discard cut if it contains a variable which is invalid after a restart */
189  if( !takecut )
190  {
191  /* free temporary memory */
192  SCIPfreeBufferArray(targetscip, &vars);
193  continue;
194  }
195 
196  /* get corresponding variables in targetscip if necessary */
197  if( sourcescip != targetscip )
198  {
199  SCIP_Bool success;
200 
201  for( i = 0; i < ncols; ++i )
202  {
203  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, vars[i], &vars[i], varmap, consmap, global, &success) );
204 
205  if( !success )
206  {
207  SCIPdebugMsg(sourcescip, "Converting cuts to constraints failed.\n");
208 
209  /* free temporary memory */
210  SCIPfreeBufferArray(targetscip, &vars);
211  return SCIP_OKAY;
212  }
213  }
214  }
215 
216  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%d", SCIProwGetName(row), SCIPgetNRuns(sourcescip));
217  SCIP_CALL( SCIPcreateConsLinear(targetscip, &cons, name, ncols, vars, SCIProwGetVals(row),
220  SCIP_CALL( SCIPaddCons(targetscip, cons) );
221 
222  SCIPdebugMsg(sourcescip, "Converted cut <%s> to constraint <%s>.\n", SCIProwGetName(row), SCIPconsGetName(cons));
223  SCIPdebugPrintCons(targetscip, cons, NULL);
224  SCIP_CALL( SCIPreleaseCons(targetscip, &cons) );
225 
226  /* free temporary memory */
227  SCIPfreeBufferArray(targetscip, &vars);
228 
229  ++(*ncutsadded);
230  }
231  }
232 
233  return SCIP_OKAY;
234 }
235 
236 /** copies plugins from sourcescip to targetscip; in case that a constraint handler which does not need constraints
237  * cannot be copied, valid will return FALSE. All plugins can declare that, if their copy process failed, the
238  * copied SCIP instance might not represent the same problem semantics as the original.
239  * Note that in this case dual reductions might be invalid.
240  *
241  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
242  * Also, 'passmessagehdlr' should be set to FALSE.
243  *
244  * @note Do not change the source SCIP environment during the copying process
245  *
246  * @note This method does not copy Benders' plugins. To this end, the method SCIPcopyBenders() must be called
247  * separately.
248  *
249  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
250  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
251  *
252  * @pre This method can be called if sourcescip is in one of the following stages:
253  * - \ref SCIP_STAGE_PROBLEM
254  * - \ref SCIP_STAGE_TRANSFORMED
255  * - \ref SCIP_STAGE_INITPRESOLVE
256  * - \ref SCIP_STAGE_PRESOLVING
257  * - \ref SCIP_STAGE_EXITPRESOLVE
258  * - \ref SCIP_STAGE_PRESOLVED
259  * - \ref SCIP_STAGE_INITSOLVE
260  * - \ref SCIP_STAGE_SOLVING
261  * - \ref SCIP_STAGE_SOLVED
262  *
263  * @pre This method can be called if targetscip is in one of the following stages:
264  * - \ref SCIP_STAGE_INIT
265  * - \ref SCIP_STAGE_FREE
266  *
267  * @post After calling this method targetscip reaches one of the following stages depending on if and when the solution
268  * process was interrupted:
269  * - \ref SCIP_STAGE_PROBLEM
270  *
271  * @note sourcescip stage does not get changed
272  *
273  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
274  */
276  SCIP* sourcescip, /**< source SCIP data structure */
277  SCIP* targetscip, /**< target SCIP data structure */
278  SCIP_Bool copyreaders, /**< should the file readers be copied */
279  SCIP_Bool copypricers, /**< should the variable pricers be copied */
280  SCIP_Bool copyconshdlrs, /**< should the constraint handlers be copied */
281  SCIP_Bool copyconflicthdlrs, /**< should the conflict handlers be copied */
282  SCIP_Bool copypresolvers, /**< should the presolvers be copied */
283  SCIP_Bool copyrelaxators, /**< should the relaxation handlers be copied */
284  SCIP_Bool copyseparators, /**< should the separators be copied */
285  SCIP_Bool copycutselectors, /**< should the cut selectors be copied */
286  SCIP_Bool copypropagators, /**< should the propagators be copied */
287  SCIP_Bool copyheuristics, /**< should the heuristics be copied */
288  SCIP_Bool copyeventhdlrs, /**< should the event handlers be copied */
289  SCIP_Bool copynodeselectors, /**< should the node selectors be copied */
290  SCIP_Bool copybranchrules, /**< should the branchrules be copied */
291  SCIP_Bool copydisplays, /**< should the display columns be copied */
292  SCIP_Bool copydialogs, /**< should the dialogs be copied */
293  SCIP_Bool copytables, /**< should the statistics tables be copied */
294  SCIP_Bool copyexprhdlrs, /**< should the expression handlers be copied */
295  SCIP_Bool copynlpis, /**< should the NLPIs be copied */
296  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
297  SCIP_Bool* valid /**< pointer to store whether plugins, in particular all constraint
298  * handlers which do not need constraints were validly copied */
299  )
300 {
301  assert(sourcescip != NULL);
302  assert(targetscip != NULL);
303  assert(sourcescip->set != NULL);
304  assert(targetscip->set != NULL);
305 
306  /* check stages for both, the source and the target SCIP data structure */
307  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyPlugins", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
308  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyPlugins", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
309 
310  /* passes the message handler of the source SCIP to the target SCIP, also if NULL */
311  if( passmessagehdlr )
312  {
313  SCIP_CALL( SCIPsetMessagehdlr(targetscip, SCIPgetMessagehdlr(sourcescip)) );
314  }
315 
316  SCIP_CALL( SCIPsetCopyPlugins(sourcescip->set, targetscip->set,
317  copyreaders, copypricers, copyconshdlrs, copyconflicthdlrs, copypresolvers, copyrelaxators, copyseparators, copycutselectors, copypropagators,
318  copyheuristics, copyeventhdlrs, copynodeselectors, copybranchrules, copydisplays, copydialogs, copytables, copyexprhdlrs, copynlpis, valid) );
319 
320  return SCIP_OKAY;
321 }
322 
323 /** copies all Benders' decomposition plugins
324  *
325  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
326  * @note the 'threadsafe' parameter should only be set to TRUE if you are absolutely certain that the source and target
327  * SCIP instances will be solved in parallel. The usual case is to set this to FALSE, since thread safety
328  * typically incurs a performance cost.
329  *
330  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
331  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
332  *
333  * @pre This method can be called if sourcescip is in one of the following stages:
334  * - \ref SCIP_STAGE_PROBLEM
335  * - \ref SCIP_STAGE_TRANSFORMED
336  * - \ref SCIP_STAGE_INITPRESOLVE
337  * - \ref SCIP_STAGE_PRESOLVING
338  * - \ref SCIP_STAGE_EXITPRESOLVE
339  * - \ref SCIP_STAGE_PRESOLVED
340  * - \ref SCIP_STAGE_INITSOLVE
341  * - \ref SCIP_STAGE_SOLVING
342  * - \ref SCIP_STAGE_SOLVED
343  *
344  * @pre This method can be called if targetscip is in one of the following stages:
345  * - \ref SCIP_STAGE_INIT
346  * - \ref SCIP_STAGE_FREE
347  * - \ref SCIP_STAGE_PROBLEM
348  *
349  * @post After calling this method targetscip reaches one of the following stages depending on if and when the solution
350  * process was interrupted:
351  * - \ref SCIP_STAGE_PROBLEM
352  *
353  * @note sourcescip stage does not get changed
354  *
355  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
356  */
358  SCIP* sourcescip, /**< source SCIP data structure */
359  SCIP* targetscip, /**< target SCIP data structure */
360  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
361  * target variables; if NULL the transfer of cuts is not possible */
362  SCIP_Bool threadsafe, /**< FALSE, if data can be safely shared between the source and target
363  * SCIP, otherwise TRUE. This is usually set to FALSE */
364  SCIP_Bool* valid /**< pointer to store whether all plugins were validly copied */
365  )
366 {
367  /* TODO: If the Benders' decomposition is not copied, then cons_benders needs to be deactivated. */
368  SCIP_Bool copybendersvalid;
369  int p;
370 
371  assert(sourcescip != NULL);
372  assert(targetscip != NULL);
373  assert(sourcescip != targetscip);
374  assert(sourcescip->set != NULL);
375  assert(targetscip->set != NULL);
376  assert(valid != NULL);
377 
378  /* check stages for both, the source and the target SCIP data structure */
379  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyBenders", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
380  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyBenders", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
381 
382  *valid = TRUE;
383 
384  if( sourcescip->set->benders != NULL )
385  {
386  for( p = sourcescip->set->nbenders - 1; p >= 0; --p )
387  {
388  copybendersvalid = FALSE;
389  SCIP_CALL( SCIPbendersCopyInclude(sourcescip->set->benders[p], sourcescip->set, targetscip->set, varmap,
390  threadsafe, &copybendersvalid) );
391  *valid = *valid && copybendersvalid;
392  }
393  }
394 
395  return SCIP_OKAY;
396 }
397 
398 /** create a problem by copying the problem data of the source SCIP */
399 static
401  SCIP* sourcescip, /**< source SCIP data structure */
402  SCIP* targetscip, /**< target SCIP data structure */
403  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
404  * target variables, or NULL */
405  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
406  * target constraints, or NULL */
407  SCIP_Bool original, /**< should the original problem be copied? */
408  SCIP_Bool global, /**< create a global or a local copy? (set to TRUE for original copy) */
409  const char* name /**< problem name of target */
410  )
411 {
412  SCIP_PROB* sourceprob;
413  SCIP_HASHMAP* localvarmap;
414  SCIP_HASHMAP* localconsmap;
415  SCIP_Bool uselocalvarmap;
416  SCIP_Bool uselocalconsmap;
417 
418  assert(sourcescip != NULL);
419  assert(targetscip != NULL);
420  assert(!original || global);
421  assert(original || SCIPisTransformed(sourcescip));
422 
423  /* free old problem */
424  SCIP_CALL( SCIPfreeProb(targetscip) );
425  assert(targetscip->set->stage == SCIP_STAGE_INIT);
426 
427  uselocalvarmap = (varmap == NULL);
428  uselocalconsmap = (consmap == NULL);
429 
430  if( uselocalvarmap )
431  {
432  /* create the variable mapping hash map */
433  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
434  }
435  else
436  localvarmap = varmap;
437 
438  if( uselocalconsmap )
439  {
440  /* create the constraint mapping hash map */
441  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
442  }
443  else
444  localconsmap = consmap;
445 
446  /* switch stage to PROBLEM */
447  targetscip->set->stage = SCIP_STAGE_PROBLEM;
448 
449  if( original )
450  sourceprob = sourcescip->origprob;
451  else
452  sourceprob = sourcescip->transprob;
453 
454  /* create the statistics data structure */
455  SCIP_CALL( SCIPstatCreate(&targetscip->stat, targetscip->mem->probmem, targetscip->set, targetscip->transprob, targetscip->origprob, targetscip->messagehdlr) );
456  targetscip->stat->subscipdepth = sourcescip->stat->subscipdepth + 1;
457 
458  /* create the problem by copying the source problem */
459  SCIP_CALL( SCIPprobCopy(&targetscip->origprob, targetscip->mem->probmem, targetscip->set, name, sourcescip, sourceprob, localvarmap, localconsmap, global) );
460 
461  /* creating the solution candidates storage */
462  /**@todo copy solution of source SCIP as candidates for the target SCIP */
463  SCIP_CALL( SCIPprimalCreate(&targetscip->origprimal) );
464 
465  /* create conflict store to store conflict constraints */
466  SCIP_CALL( SCIPconflictstoreCreate(&targetscip->conflictstore, targetscip->set) );
467 
469 
471 
472  if( uselocalvarmap )
473  {
474  /* free hash map */
475  SCIPhashmapFree(&localvarmap);
476  }
477 
478  if( uselocalconsmap )
479  {
480  /* free hash map */
481  SCIPhashmapFree(&localconsmap);
482  }
483 
484  return SCIP_OKAY;
485 }
486 
487 
488 /** create a problem by copying the problem data of the source SCIP
489  *
490  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
491  * @note Do not change the source SCIP environment during the copying process
492  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
493  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
494  *
495  * @pre This method can be called if sourcescip is in one of the following stages:
496  * - \ref SCIP_STAGE_PROBLEM
497  * - \ref SCIP_STAGE_TRANSFORMED
498  * - \ref SCIP_STAGE_INITPRESOLVE
499  * - \ref SCIP_STAGE_PRESOLVING
500  * - \ref SCIP_STAGE_EXITPRESOLVE
501  * - \ref SCIP_STAGE_PRESOLVED
502  * - \ref SCIP_STAGE_INITSOLVE
503  * - \ref SCIP_STAGE_SOLVING
504  * - \ref SCIP_STAGE_SOLVED
505  *
506  * @pre This method can be called if targetscip is in one of the following stages:
507  * - \ref SCIP_STAGE_INIT
508  * - \ref SCIP_STAGE_PROBLEM
509  * - \ref SCIP_STAGE_TRANSFORMED
510  * - \ref SCIP_STAGE_INITPRESOLVE
511  * - \ref SCIP_STAGE_PRESOLVING
512  * - \ref SCIP_STAGE_EXITPRESOLVE
513  * - \ref SCIP_STAGE_PRESOLVED
514  * - \ref SCIP_STAGE_INITSOLVE
515  * - \ref SCIP_STAGE_SOLVING
516  * - \ref SCIP_STAGE_SOLVED
517  * - \ref SCIP_STAGE_FREE
518  *
519  * @post After calling this method targetscip reaches one of the following stages depending on if and when the solution
520  * process was interrupted:
521  * - \ref SCIP_STAGE_PROBLEM
522  *
523  * @note sourcescip stage does not get changed
524  *
525  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
526  */
528  SCIP* sourcescip, /**< source SCIP data structure */
529  SCIP* targetscip, /**< target SCIP data structure */
530  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
531  * target variables, or NULL */
532  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
533  * target constraints, or NULL */
534  SCIP_Bool global, /**< create a global or a local copy? */
535  const char* name /**< problem name of target */
536  )
537 {
538  assert(sourcescip != NULL);
539  assert(targetscip != NULL);
540 
541  /* check stages for both, the source and the target SCIP data structure */
542  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyProb", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
543  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyProb", TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE) );
544 
545  SCIP_CALL( copyProb(sourcescip, targetscip, varmap, consmap, FALSE, global, name) );
546 
547  return SCIP_OKAY;
548 }
549 
550 /** create a problem by copying the original problem data of the source SCIP
551  *
552  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
553  * @note Do not change the source SCIP environment during the copying process
554  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
555  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
556  *
557  * @pre This method can be called if sourcescip is in one of the following stages:
558  * - \ref SCIP_STAGE_PROBLEM
559  * - \ref SCIP_STAGE_TRANSFORMED
560  * - \ref SCIP_STAGE_INITPRESOLVE
561  * - \ref SCIP_STAGE_PRESOLVING
562  * - \ref SCIP_STAGE_EXITPRESOLVE
563  * - \ref SCIP_STAGE_PRESOLVED
564  * - \ref SCIP_STAGE_INITSOLVE
565  * - \ref SCIP_STAGE_SOLVING
566  * - \ref SCIP_STAGE_SOLVED
567  *
568  * @pre This method can be called if targetscip is in one of the following stages:
569  * - \ref SCIP_STAGE_INIT
570  * - \ref SCIP_STAGE_FREE
571  *
572  * @post After calling this method targetscip reaches one of the following stages depending on if and when the solution
573  * process was interrupted:
574  * - \ref SCIP_STAGE_PROBLEM
575  *
576  * @note sourcescip stage does not get changed
577  *
578  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
579  */
581  SCIP* sourcescip, /**< source SCIP data structure */
582  SCIP* targetscip, /**< target SCIP data structure */
583  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
584  * target variables, or NULL */
585  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
586  * target constraints, or NULL */
587  const char* name /**< problem name of target */
588  )
589 {
590  assert(sourcescip != NULL);
591  assert(targetscip != NULL);
592 
593  /* check stages for both, the source and the target SCIP data structure */
594  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyOrigProb", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
595  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyOrigProb", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
596 
597  SCIP_CALL( copyProb(sourcescip, targetscip, varmap, consmap, TRUE, TRUE, name) );
598 
599  /* set the correct objective sense; necessary if we maximize in the original problem */
600  SCIP_CALL( SCIPsetObjsense(targetscip, SCIPgetObjsense(sourcescip)) );
601 
602  /* set the objective offset */
603  SCIP_CALL( SCIPaddOrigObjoffset(targetscip, SCIPgetOrigObjoffset(sourcescip)) );
604 
605  return SCIP_OKAY;
606 }
607 
608 /** enables constraint compression.
609  *
610  * If constraint compression is enabled, fixed variables will be treated as constants
611  * by all constraints that are copied after calling this method.
612  *
613  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
614  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
615  *
616  * @pre This method can be called if scip is in one of the following stages:
617  * - \ref SCIP_STAGE_PROBLEM
618  *
619  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
620  */
622  SCIP* scip /**< source SCIP data structure */
623  )
624 {
625  assert(scip != NULL);
626  assert(scip->origprob != NULL);
627 
628  /* check stage */
629  SCIP_CALL( SCIPcheckStage(scip, "SCIPenableConsCompression", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
630 
631  /* enable problem compression */
633 
634  return SCIP_OKAY;
635 }
636 
637 /** is constraint compression enabled?
638  *
639  * If constraint compression is enabled, fixed variables can be treated as constants
640  * by all constraints that are copied after calling this method.
641  *
642  * @return TRUE if problem constraint compression is enabled, otherwise FALSE
643  *
644  * @pre This method can be called if scip is in one of the following stages:
645  * - \ref SCIP_STAGE_PROBLEM
646  * - \ref SCIP_STAGE_TRANSFORMING
647  * - \ref SCIP_STAGE_TRANSFORMED
648  * - \ref SCIP_STAGE_INITPRESOLVE
649  * - \ref SCIP_STAGE_PRESOLVING
650  * - \ref SCIP_STAGE_EXITPRESOLVE
651  * - \ref SCIP_STAGE_PRESOLVED
652  * - \ref SCIP_STAGE_INITSOLVE
653  * - \ref SCIP_STAGE_SOLVING
654  * - \ref SCIP_STAGE_SOLVED
655  * - \ref SCIP_STAGE_EXITSOLVE
656  * - \ref SCIP_STAGE_FREETRANS
657  *
658  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
659  */
661  SCIP* scip /**< source SCIP data structure */
662  )
663 {
664  assert(scip != NULL);
665  assert(scip->origprob != NULL);
666 
667  /* check stage */
668  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPisConsCompressionEnabled", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
669 
670  /* is problem compression enabled */
672 }
673 
674 /** returns copy of the source variable; if there already is a copy of the source variable in the variable hash map,
675  * it is just returned as target variable; otherwise, if the variables it not marked as relaxation-only, a new variable
676  * will be created and added to the target SCIP; this created variable is added to the variable hash map and returned as target variable;
677  * relaxation-only variables are not copied and FALSE is returned in *success
678  *
679  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
680  * @note Do not change the source SCIP environment during the copying process
681  * @note if a new variable was created, this variable will be added to the target-SCIP, but it is not captured
682  *
683  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
684  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
685  *
686  * @pre This method can be called if sourcescip is in one of the following stages:
687  * - \ref SCIP_STAGE_PROBLEM
688  * - \ref SCIP_STAGE_TRANSFORMED
689  * - \ref SCIP_STAGE_INITPRESOLVE
690  * - \ref SCIP_STAGE_PRESOLVING
691  * - \ref SCIP_STAGE_EXITPRESOLVE
692  * - \ref SCIP_STAGE_PRESOLVED
693  * - \ref SCIP_STAGE_INITSOLVE
694  * - \ref SCIP_STAGE_SOLVING
695  * - \ref SCIP_STAGE_SOLVED
696  *
697  * @pre This method can be called if targetscip is in one of the following stages:
698  * - \ref SCIP_STAGE_PROBLEM
699  * - \ref SCIP_STAGE_TRANSFORMED
700  * - \ref SCIP_STAGE_INITPRESOLVE
701  * - \ref SCIP_STAGE_PRESOLVING
702  * - \ref SCIP_STAGE_EXITPRESOLVE
703  * - \ref SCIP_STAGE_SOLVING
704  *
705  * @note targetscip stage does not get changed
706  *
707  * @note sourcescip stage does not get changed
708  *
709  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
710  */
712  SCIP* sourcescip, /**< source SCIP data structure */
713  SCIP* targetscip, /**< target SCIP data structure */
714  SCIP_VAR* sourcevar, /**< source variable */
715  SCIP_VAR** targetvar, /**< pointer to store the target variable */
716  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
717  * target variables, or NULL */
718  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
719  * target constraints, or NULL */
720  SCIP_Bool global, /**< should global or local bounds be used? */
721  SCIP_Bool* success /**< pointer to store whether the copying was successful or not */
722  )
723 {
724  SCIP_HASHMAP* localvarmap;
725  SCIP_HASHMAP* localconsmap;
726  SCIP_VAR* var;
727  SCIP_Bool uselocalvarmap;
728  SCIP_Bool uselocalconsmap;
729 
730  assert(sourcescip != NULL);
731  assert(targetscip != NULL);
732  assert(sourcevar != NULL);
733  assert(targetvar != NULL);
734  assert(sourcevar->scip == sourcescip);
735 
736  /* check stages for both, the source and the target SCIP data structure */
737  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPgetVarCopy", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
738  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPgetVarCopy", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE) );
739 
740  uselocalvarmap = (varmap == NULL);
741  uselocalconsmap = (consmap == NULL);
742  *success = TRUE;
743 
744  /* try to retrieve copied variable from hashmap */
745  if( !uselocalvarmap )
746  {
747  *targetvar = (SCIP_VAR*) SCIPhashmapGetImage(varmap, sourcevar);
748  if( *targetvar != NULL )
749  return SCIP_OKAY;
750  }
751 
752  /* reject copying of relaxation-only variables */
753  if( SCIPvarIsRelaxationOnly(sourcevar) )
754  {
755  *success = FALSE;
756  *targetvar = NULL;
757  }
758 
759  /* if the target SCIP is already in solving stage we currently are not copying the variable!
760  * this has to be done because we cannot simply add variables to SCIP during solving and thereby enlarge the search
761  * space.
762  * unlike column generation we cannot assume here that the variable could be implicitly set to zero in all prior
763  * computations
764  */
765  if( SCIPgetStage(targetscip) > SCIP_STAGE_PROBLEM )
766  {
767  *success = FALSE;
768  *targetvar = NULL;
769 
770  return SCIP_OKAY;
771  }
772 
773  /* create the variable mapping hash map */
774  if( uselocalvarmap )
775  {
776  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
777  }
778  else
779  localvarmap = varmap;
780 
781  if( uselocalconsmap )
782  {
783  /* create the constraint mapping hash map */
784  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
785  }
786  else
787  localconsmap = consmap;
788 
789  /* if variable does not exist yet in target SCIP, create it */
790  switch( SCIPvarGetStatus(sourcevar) )
791  {
796  SCIP_CALL( SCIPvarCopy(&var, targetscip->mem->probmem, targetscip->set, targetscip->stat,
797  sourcescip, sourcevar, localvarmap, localconsmap, global) );
798  break;
799 
801  {
802  SCIP_CONS* cons;
803  char name[SCIP_MAXSTRLEN];
804 
805  SCIP_VAR* sourceaggrvar;
806  SCIP_VAR* targetaggrvar;
807  SCIP_Real aggrcoef;
808  SCIP_Real constant;
809 
810  /* get aggregation data */
811  sourceaggrvar = SCIPvarGetAggrVar(sourcevar);
812  aggrcoef = SCIPvarGetAggrScalar(sourcevar);
813  constant = SCIPvarGetAggrConstant(sourcevar);
814 
815  /* get copy of the aggregation variable */
816  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourceaggrvar, &targetaggrvar, localvarmap, localconsmap, global, success) );
817  assert(*success);
818 
819  /* create copy of the aggregated variable */
820  SCIP_CALL( SCIPvarCopy(&var, targetscip->mem->probmem, targetscip->set, targetscip->stat,
821  sourcescip, sourcevar, localvarmap, localconsmap, global) );
822 
823  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_aggr", SCIPvarGetName(sourcevar));
824 
825  /* add aggregation x = a*y + c as linear constraint x - a*y = c */
826  SCIP_CALL( SCIPcreateConsLinear(targetscip, &cons, name, 0, NULL, NULL, constant,
827  constant, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
828  SCIP_CALL( SCIPaddCoefLinear(targetscip, cons, var, 1.0) );
829  SCIP_CALL( SCIPaddCoefLinear(targetscip, cons, targetaggrvar, -aggrcoef) );
830 
831  SCIP_CALL( SCIPaddCons(targetscip, cons) );
832  SCIP_CALL( SCIPreleaseCons(targetscip, &cons) );
833 
834  break;
835  }
837  {
838  SCIP_CONS* cons;
839  char name[SCIP_MAXSTRLEN];
840 
841  SCIP_VAR** sourceaggrvars;
842  SCIP_VAR** targetaggrvars;
843  SCIP_Real* aggrcoefs;
844  SCIP_Real constant;
845 
846  int naggrvars;
847  int i;
848 
849  /* get the active representation */
850  SCIP_CALL( SCIPflattenVarAggregationGraph(sourcescip, sourcevar) );
851 
852  /* get multi-aggregation data */
853  naggrvars = SCIPvarGetMultaggrNVars(sourcevar);
854  sourceaggrvars = SCIPvarGetMultaggrVars(sourcevar);
855  aggrcoefs = SCIPvarGetMultaggrScalars(sourcevar);
856  constant = SCIPvarGetMultaggrConstant(sourcevar);
857 
858  SCIP_CALL( SCIPallocBufferArray(targetscip, &targetaggrvars, naggrvars) );
859 
860  /* get copies of the active variables of the multi-aggregation */
861  for( i = 0; i < naggrvars; ++i )
862  {
863  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourceaggrvars[i], &targetaggrvars[i], localvarmap, localconsmap, global, success) );
864  assert(*success);
865  }
866 
867  /* create copy of the multi-aggregated variable */
868  SCIP_CALL( SCIPvarCopy(&var, targetscip->mem->probmem, targetscip->set, targetscip->stat,
869  sourcescip, sourcevar, localvarmap, localconsmap, global) );
870 
871  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_multaggr", SCIPvarGetName(sourcevar));
872 
873  /* add multi-aggregation x = a^T y + c as linear constraint a^T y - x = -c */
874  SCIP_CALL( SCIPcreateConsLinear(targetscip, &cons, name, naggrvars, targetaggrvars, aggrcoefs, -constant,
875  -constant, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
876  SCIP_CALL( SCIPaddCoefLinear(targetscip, cons, var, -1.0) );
877  SCIP_CALL( SCIPaddCons(targetscip, cons) );
878  SCIP_CALL( SCIPreleaseCons(targetscip, &cons) );
879 
880  SCIPfreeBufferArray(targetscip, &targetaggrvars);
881 
882  break;
883  }
885  {
886  SCIP_VAR* sourcenegatedvar;
887  SCIP_VAR* targetnegatedvar;
888 
889  /* get negated source variable */
890  sourcenegatedvar = SCIPvarGetNegationVar(sourcevar);
891  assert(sourcenegatedvar != NULL);
892  assert(SCIPvarGetStatus(sourcenegatedvar) != SCIP_VARSTATUS_NEGATED);
893 
894  /* get copy of negated source variable */
895  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourcenegatedvar, &targetnegatedvar, localvarmap, localconsmap, global, success) );
896  assert(*success);
897  assert(SCIPvarGetStatus(targetnegatedvar) != SCIP_VARSTATUS_NEGATED);
898 
899  /* get negation of copied negated source variable, this is the target variable */
900  SCIP_CALL( SCIPgetNegatedVar(targetscip, targetnegatedvar, targetvar) );
901  assert(SCIPvarGetStatus(*targetvar) == SCIP_VARSTATUS_NEGATED);
902 
903  /* free local hash maps if necessary */
904  if( uselocalvarmap )
905  SCIPhashmapFree(&localvarmap);
906 
907  if( uselocalconsmap )
908  SCIPhashmapFree(&localconsmap);
909 
910  /* we have to return right away, to avoid adding the negated variable to the problem since the "not negated"
911  * variable was already added */
912  return SCIP_OKAY;
913  }
914  default:
915  /* note that this is in an internal SCIP error since the variable status is only handled by the core */
916  SCIPerrorMessage("unknown variable status\n");
917  SCIPABORT();
918  return SCIP_ERROR; /*lint !e527*/
919  }
920 
921  /* add the (new) target variable to the target problem */
922  SCIP_CALL( SCIPaddVar(targetscip, var) );
923 
924  *targetvar = var;
925 
926  /* remove the variable capture which was done due to the creation of the variable */
927  SCIP_CALL( SCIPreleaseVar(targetscip, &var) );
928 
929  /* free local hash maps if necessary */
930  if( uselocalvarmap )
931  SCIPhashmapFree(&localvarmap);
932 
933  if( uselocalconsmap )
934  SCIPhashmapFree(&localconsmap);
935 
936  return SCIP_OKAY;
937 }
938 
939 /** copies all original or active variables from source-SCIP except those that are marked as relaxation-only, fixed, or aggregated
940  * and adds these variable to the target-SCIP
941  *
942  * the mapping between these variables are stored in the variable hashmap
943  * target-SCIP has to be in problem creation stage
944  */
945 static
947  SCIP* sourcescip, /**< source SCIP data structure */
948  SCIP* targetscip, /**< target SCIP data structure */
949  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
950  * target variables, or NULL */
951  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
952  * target constraints, or NULL */
953  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
954  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
955  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
956  SCIP_Bool original, /**< should original variables be copied? */
957  SCIP_Bool global /**< should global or local bounds be used? (for original=FALSE) */
958  )
959 {
960  SCIP_VAR** sourcevars;
961  SCIP_HASHMAP* localvarmap;
962  SCIP_HASHMAP* localconsmap;
963  SCIP_Bool uselocalvarmap;
964  SCIP_Bool uselocalconsmap;
965  int nsourcevars;
966 #ifndef NDEBUG
967  int nrelaxonlybinvars = 0;
968  int nrelaxonlyintvars = 0;
969  int nrelaxonlyimplvars = 0;
970  int nrelaxonlycontvars = 0;
971 #endif
972  int i;
973 
974  assert(sourcescip != NULL);
975  assert(targetscip != NULL);
976  assert(nfixedvars == 0 || fixedvars != NULL);
977  assert(nfixedvars == 0 || fixedvals != NULL);
978 
979  if( original )
980  {
981  /* get original variables of the source SCIP */
982  SCIP_CALL( SCIPgetOrigVarsData(sourcescip, &sourcevars, &nsourcevars, NULL, NULL, NULL, NULL) );
983  }
984  else
985  {
986  /* get active variables of the source SCIP */
987  SCIP_CALL( SCIPgetVarsData(sourcescip, &sourcevars, &nsourcevars, NULL, NULL, NULL, NULL) );
988  }
989 
990  uselocalvarmap = (varmap == NULL);
991  uselocalconsmap = (consmap == NULL);
992 
993  if( uselocalvarmap )
994  {
995  /* create the variable mapping hash map */
996  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
997  }
998  else
999  localvarmap = varmap;
1000 
1001  if( uselocalconsmap )
1002  {
1003  /* create the constraint mapping hash map */
1004  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
1005  }
1006  else
1007  localconsmap = consmap;
1008 
1009  /* create the variables of the target SCIP */
1010  for( i = 0; i < nsourcevars; ++i )
1011  {
1012  SCIP_Bool success;
1013  SCIP_VAR* targetvar;
1014 
1015  if( SCIPvarIsRelaxationOnly(sourcevars[i]) )
1016  {
1017 #ifndef NDEBUG
1018  switch( SCIPvarGetType(sourcevars[i]) )
1019  {
1020  case SCIP_VARTYPE_BINARY:
1021  nrelaxonlybinvars++;
1022  break;
1023  case SCIP_VARTYPE_INTEGER:
1024  nrelaxonlyintvars++;
1025  break;
1026  case SCIP_VARTYPE_IMPLINT:
1027  nrelaxonlyimplvars++;
1028  break;
1030  nrelaxonlycontvars++;
1031  break;
1032  default:
1033  SCIPerrorMessage("unknown variable type\n");
1034  return SCIP_INVALIDDATA;
1035  }
1036 #endif
1037  continue;
1038  }
1039 
1040  /* copy variable and add this copy to the target SCIP if the copying was valid */
1041  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourcevars[i], &targetvar, localvarmap, localconsmap, global, &success) );
1042  assert(success);
1043  assert(targetvar != NULL);
1044  }
1045 
1046  /* fix the variables that should be fixed right away */
1047  for( i = 0; i < nfixedvars; ++i )
1048  {
1049  SCIP_VAR* targetvar;
1050  SCIP_Bool infeasible;
1051  SCIP_Bool fixed;
1052 
1053  if( SCIPvarIsRelaxationOnly(sourcevars[i]) )
1054  continue;
1055 
1056  /* retrieve target variable as image of the source variable */
1057  targetvar = (SCIP_VAR*) SCIPhashmapGetImage(localvarmap, (void *)fixedvars[i]);
1058  assert(targetvar != NULL);
1059 
1060  /* fix the variable to the specified value */
1061  infeasible = fixed = FALSE;
1062  SCIP_CALL( SCIPfixVar(targetscip, targetvar, fixedvals[i], &infeasible, &fixed) );
1063 
1064  assert(!infeasible);
1065  assert(fixed);
1066  }
1067 
1068  /* integer variables that are fixed to zero or one or have bounds [0,1] will be converted to binaries */
1069 #ifndef NDEBUG
1070  if( original )
1071  {
1072  /* TODO : account for integers converted to binaries
1073  assert(SCIPgetNOrigBinVars(sourcescip) == SCIPgetNOrigBinVars(targetscip));
1074  assert(SCIPgetNOrigIntVars(sourcescip) == SCIPgetNOrigIntVars(targetscip));
1075  assert(SCIPgetNOrigImplVars(sourcescip) == SCIPgetNOrigImplVars(targetscip));
1076  assert(SCIPgetNOrigContVars(sourcescip) == SCIPgetNOrigContVars(targetscip));
1077  */
1078  }
1079  else
1080  {
1081  SCIP_VAR** sourcefixedvars;
1082  int nsourcefixedvars;
1083  int nfixedbinvars;
1084  int nfixedintvars;
1085  int nfixedimplvars;
1086  int nfixedcontvars;
1087 
1088  sourcefixedvars = SCIPgetFixedVars(sourcescip);
1089  nsourcefixedvars = SCIPgetNFixedVars(sourcescip);
1090  nfixedbinvars = 0;
1091  nfixedintvars = 0;
1092  nfixedimplvars = 0;
1093  nfixedcontvars = 0;
1094 
1095  /* count number of fixed variables for all variable types */
1096  for( i = 0; i < nsourcefixedvars; ++i )
1097  {
1098  switch( SCIPvarGetType(sourcefixedvars[i]) )
1099  {
1100  case SCIP_VARTYPE_BINARY:
1101  nfixedbinvars++;
1102  break;
1103  case SCIP_VARTYPE_INTEGER:
1104  nfixedintvars++;
1105  break;
1106  case SCIP_VARTYPE_IMPLINT:
1107  nfixedimplvars++;
1108  break;
1110  nfixedcontvars++;
1111  break;
1112  default:
1113  SCIPerrorMessage("unknown variable type\n");
1114  return SCIP_INVALIDDATA;
1115  }
1116  }
1117  assert(nsourcefixedvars == nfixedbinvars + nfixedintvars + nfixedimplvars + nfixedcontvars);
1118  assert(SCIPgetNBinVars(sourcescip) <= SCIPgetNBinVars(targetscip) + nrelaxonlybinvars);
1119  assert(SCIPgetNIntVars(sourcescip) + SCIPgetNBinVars(sourcescip) <= SCIPgetNIntVars(targetscip) + nrelaxonlyintvars + SCIPgetNBinVars(targetscip) + nrelaxonlybinvars);
1120  assert(SCIPgetNIntVars(targetscip) + nrelaxonlyintvars + SCIPgetNBinVars(targetscip) + nrelaxonlybinvars <= SCIPgetNIntVars(sourcescip) + SCIPgetNBinVars(sourcescip) + nfixedbinvars + nfixedintvars );
1121  assert(SCIPgetNImplVars(sourcescip) <= SCIPgetNImplVars(targetscip) + nrelaxonlyimplvars);
1122  assert(SCIPgetNImplVars(targetscip) + nrelaxonlyimplvars <= SCIPgetNImplVars(sourcescip) + nfixedimplvars);
1123  assert(SCIPgetNContVars(sourcescip) <= SCIPgetNContVars(targetscip) + nrelaxonlycontvars);
1124  assert(SCIPgetNContVars(targetscip) + nrelaxonlycontvars <= SCIPgetNContVars(sourcescip) + nfixedcontvars);
1125  }
1126 #endif
1127 
1128  if( uselocalvarmap )
1129  {
1130  /* free hash map */
1131  SCIPhashmapFree(&localvarmap);
1132  }
1133 
1134  if( uselocalconsmap )
1135  {
1136  /* free hash map */
1137  SCIPhashmapFree(&localconsmap);
1138  }
1139 
1140  return SCIP_OKAY;
1141 }
1142 
1143 /** Copies all active (thus unfixed) variables from source-SCIP, except those that are marked as relaxation only,
1144  * and adds these variable to the target-SCIP.
1145  *
1146  * The mapping between these variables are stored in the variable hashmap.
1147  *
1148  * The target-SCIP has to be in problem creation stage.
1149  *
1150  * @note the variables are added to the target-SCIP but not captured
1151  *
1152  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1153  * @note Do not change the source SCIP environment during the copying process
1154  *
1155  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1156  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1157  *
1158  * @pre This method can be called if sourcescip is in one of the following stages:
1159  * - \ref SCIP_STAGE_PROBLEM
1160  * - \ref SCIP_STAGE_TRANSFORMED
1161  * - \ref SCIP_STAGE_INITPRESOLVE
1162  * - \ref SCIP_STAGE_PRESOLVING
1163  * - \ref SCIP_STAGE_EXITPRESOLVE
1164  * - \ref SCIP_STAGE_PRESOLVED
1165  * - \ref SCIP_STAGE_INITSOLVE
1166  * - \ref SCIP_STAGE_SOLVING
1167  * - \ref SCIP_STAGE_SOLVED
1168  *
1169  * @pre This method can be called if targetscip is in one of the following stages:
1170  * - \ref SCIP_STAGE_PROBLEM
1171  *
1172  * @note sourcescip stage does not get changed
1173  *
1174  * @note targetscip stage does not get changed
1175  *
1176  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1177  */
1179  SCIP* sourcescip, /**< source SCIP data structure */
1180  SCIP* targetscip, /**< target SCIP data structure */
1181  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
1182  * target variables, or NULL */
1183  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1184  * target constraints, or NULL */
1185  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
1186  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
1187  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
1188  SCIP_Bool global /**< should global or local bounds be used? */
1189  )
1190 {
1191  assert(sourcescip != NULL);
1192  assert(targetscip != NULL);
1193 
1194  /* check stages for both, the source and the target SCIP data structure */
1195  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyVars", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1196  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyVars", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1197 
1198  SCIP_CALL( copyVars(sourcescip, targetscip, varmap, consmap, fixedvars, fixedvals, nfixedvars, FALSE, global) );
1199 
1200  return SCIP_OKAY;
1201 }
1202 
1203 /** copies all original variables from source-SCIP and adds these variable to the target-SCIP; the mapping between these
1204  * variables are stored in the variable hashmap, target-SCIP has to be in problem creation stage, fixed and aggregated
1205  * variables do not get copied
1206  *
1207  * @note the variables are added to the target-SCIP but not captured
1208  *
1209  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1210  * @note Do not change the source SCIP environment during the copying process
1211  *
1212  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1213  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1214  *
1215  * @pre This method can be called if sourcescip is in one of the following stages:
1216  * - \ref SCIP_STAGE_PROBLEM
1217  * - \ref SCIP_STAGE_TRANSFORMED
1218  * - \ref SCIP_STAGE_INITPRESOLVE
1219  * - \ref SCIP_STAGE_PRESOLVING
1220  * - \ref SCIP_STAGE_EXITPRESOLVE
1221  * - \ref SCIP_STAGE_PRESOLVED
1222  * - \ref SCIP_STAGE_INITSOLVE
1223  * - \ref SCIP_STAGE_SOLVING
1224  * - \ref SCIP_STAGE_SOLVED
1225  *
1226  * @pre This method can be called if targetscip is in one of the following stages:
1227  * - \ref SCIP_STAGE_PROBLEM
1228  *
1229  * @note sourcescip stage does not get changed
1230  *
1231  * @note targetscip stage does not get changed
1232  *
1233  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1234  */
1236  SCIP* sourcescip, /**< source SCIP data structure */
1237  SCIP* targetscip, /**< target SCIP data structure */
1238  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables to the corresponding
1239  * target variables, or NULL */
1240  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1241  * target constraints, or NULL */
1242  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
1243  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
1244  int nfixedvars /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
1245  )
1246 {
1247  assert(sourcescip != NULL);
1248  assert(targetscip != NULL);
1249 
1250  /* check stages for both, the source and the target SCIP data structure */
1251  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyOrigVars", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1252  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyOrigVars", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1253 
1254  SCIP_CALL( copyVars(sourcescip, targetscip, varmap, consmap, fixedvars, fixedvals, nfixedvars, TRUE, TRUE) );
1255 
1256  return SCIP_OKAY;
1257 }
1258 
1259 /** merges the histories of variables from a source SCIP into a target SCIP. The two data structures should point to
1260  * different SCIP instances.
1261  *
1262  * @note the notion of source and target is inverted here; \p sourcescip usually denotes a copied SCIP instance, whereas
1263  * \p targetscip denotes the original instance
1264  */
1266  SCIP* sourcescip, /**< source SCIP data structure */
1267  SCIP* targetscip, /**< target SCIP data structure */
1268  SCIP_VAR** sourcevars, /**< source variables for history merge, NULL entries are ignored */
1269  SCIP_VAR** targetvars, /**< target variables for history merge, NULL entries are ignored */
1270  int nvars /**< number of variables in both variable arrays */
1271  )
1272 {
1273  int i;
1274 
1275  /* check if target scip has been set to allow merging variable statistics */
1276  if( !targetscip->set->history_allowmerge )
1277  return SCIP_OKAY;
1278 
1279  assert(nvars == 0 || (sourcevars != NULL && targetvars != NULL));
1280  assert(sourcescip != targetscip);
1281 
1282  /* we do not want to copy statistics from a scip that has not really started solving */
1283  if( SCIPgetStage(sourcescip) < SCIP_STAGE_SOLVING )
1284  return SCIP_OKAY;
1285 
1286  /* if the transformation of the source was subject to scaling, the history information cannot be just copied */
1287  if( !SCIPsetIsEQ(targetscip->set, 1.0, SCIPgetOrigObjscale(sourcescip))
1288  || !SCIPsetIsEQ(targetscip->set, 0.0, SCIPgetOrigObjoffset(sourcescip)) )
1289  return SCIP_OKAY;
1290 
1291  /* merge histories of the targetSCIP-variables to the SCIP variables. */
1292  for( i = 0; i < nvars; ++i )
1293  {
1294  SCIP_VARSTATUS sourcevarstatus;
1295 
1296  if( sourcevars[i] == NULL || targetvars[i] == NULL )
1297  continue;
1298 
1299  assert(sourcevars[i]->scip == sourcescip);
1300  assert(targetvars[i]->scip == targetscip);
1301 
1302  sourcevarstatus = SCIPvarGetStatus(sourcevars[i]);
1303 
1304  /* depending on the variable status, we use either the transformed variable history or the history of the col itself */
1305  switch( sourcevarstatus )
1306  {
1308  assert(NULL != SCIPvarGetTransVar(sourcevars[i]));
1309  SCIPvarMergeHistories(targetvars[i], SCIPvarGetTransVar(sourcevars[i]), targetscip->stat);
1310  break;
1311  case SCIP_VARSTATUS_COLUMN:
1312  SCIPvarMergeHistories(targetvars[i], sourcevars[i], targetscip->stat);
1313  break;
1314  default:
1315  /* other variable status are currently not supported for the merging */
1316  break;
1317  } /*lint !e788*/
1318  }
1319 
1320  return SCIP_OKAY;
1321 }
1322 
1323 /** merges the statistics of NLPIs from a source SCIP into a target SCIP
1324  *
1325  * The two SCIP instances should point to different SCIP instances.
1326  *
1327  * @note the notion of source and target is inverted here; \p sourcescip usually denotes a copied SCIP instance, whereas
1328  * \p targetscip denotes the original instance
1329  */
1331  SCIP* sourcescip, /**< source SCIP data structure */
1332  SCIP* targetscip, /**< target SCIP data structure */
1333  SCIP_Bool reset /**< whether to reset statistics in sourcescip */
1334  )
1335 {
1336  int i;
1337 
1338  assert(sourcescip != targetscip);
1339 
1340  for( i = 0; i < sourcescip->set->nnlpis; ++i )
1341  {
1342  SCIP_NLPI* sourcenlpi;
1343  SCIP_NLPI* targetnlpi;
1344 
1345  sourcenlpi = sourcescip->set->nlpis[i];
1346  /* probably NLPI is on same position in target and source, otherwise do search */
1347  if( strcmp(SCIPnlpiGetName(targetscip->set->nlpis[i]), SCIPnlpiGetName(sourcenlpi)) == 0 )
1348  targetnlpi = targetscip->set->nlpis[i];
1349  else
1350  targetnlpi = SCIPsetFindNlpi(targetscip->set, SCIPnlpiGetName(sourcenlpi));
1351 
1352  if( targetnlpi != NULL )
1353  SCIPnlpiMergeStatistics(targetnlpi, sourcenlpi, reset);
1354  else
1355  {
1356  SCIPdebugMsg(targetscip, "NLPI <%s> from source SCIP not available in target SCIP\n", SCIPnlpiGetName(sourcenlpi));
1357  }
1358  }
1359 }
1360 
1361 /** provides values of a solution from a subscip according to the variable in the main scip
1362  *
1363  * Given a subscip solution, fills an array with solution values, matching the variables given by SCIPgetVars().
1364  * Variables that are relaxation-only in the master SCIP are set to 0 or the bound closest to 0. Such variables
1365  * are represented as NULL entry in the \p subvars array.
1366  */
1367 static
1369  SCIP* scip, /**< SCIP data structure of the original problem */
1370  SCIP* subscip, /**< SCIP data structure of the subproblem */
1371  SCIP_SOL* subsol, /**< solution of the subproblem */
1372  SCIP_VAR** subvars, /**< the variables from the subproblem in the same order as the main \p scip */
1373  SCIP_Real* solvals /**< array where to set values taken from subsol, must have length at least SCIPgetNVars(scip) */
1374  )
1375 {
1376  SCIP_VAR** vars;
1377  int nvars;
1378  int i;
1379 
1380  assert(scip != NULL);
1381  assert(subscip != NULL);
1382  assert(subsol != NULL);
1383  assert(subvars != NULL);
1384  assert(solvals != NULL);
1385 
1386  /* copy the solution */
1387  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
1388 
1389  /* copy the solution */
1390  for( i = 0; i < nvars; ++i )
1391  {
1392  if( subvars[i] != NULL )
1393  solvals[i] = SCIPgetSolVal(subscip, subsol, subvars[i]);
1394  else
1395  solvals[i] = MIN(MAX(0.0, SCIPvarGetLbLocal(vars[i])), SCIPvarGetUbLocal(vars[i])); /*lint !e666*/
1396  }
1397 
1398  return SCIP_OKAY;
1399 }
1400 
1401 /** translates a solution from a subscip to the main scip
1402  *
1403  * Variables that are relaxation-only in the master SCIP are set to 0 or the bound closest to 0. Such variables
1404  * are represented as NULL entry in the \p subvars array.
1405  *
1406  * @note This method allocates a new solution of the main \p scip that needs to be freed by the user.
1407  */
1409  SCIP* scip, /**< SCIP data structure of the original problem */
1410  SCIP* subscip, /**< SCIP data structure of the subproblem */
1411  SCIP_SOL* subsol, /**< solution of the subproblem */
1412  SCIP_HEUR* heur, /**< heuristic that found the solution */
1413  SCIP_VAR** subvars, /**< the variables from the subproblem in the same order as the main \p scip */
1414  SCIP_SOL** newsol /**< buffer to store pointer to created solution in main SCIP */
1415  )
1416 {
1417  SCIP_VAR** vars;
1418  int nvars;
1419  SCIP_Real* subsolvals;
1420 
1421  assert(scip != NULL);
1422  assert(subscip != NULL);
1423  assert(subsol != NULL);
1424  assert(subvars != NULL);
1425  assert(newsol != NULL);
1426 
1427  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
1428 
1429  SCIP_CALL( SCIPallocBufferArray(scip, &subsolvals, nvars) );
1430 
1431  /* get the solution values */
1432  SCIP_CALL( translateSubSol(scip, subscip, subsol, subvars, subsolvals) );
1433 
1434  /* create new solution for the original problem */
1435  SCIP_CALL( SCIPcreateSol(scip, newsol, heur) );
1436  SCIP_CALL( SCIPsetSolVals(scip, *newsol, nvars, vars, subsolvals) );
1437 
1438  SCIPfreeBufferArray(scip, &subsolvals);
1439 
1440  return SCIP_OKAY;
1441 }
1442 
1443 /** checks the solutions from the subscip and adds the first one that is found feasible to the master SCIP
1444  *
1445  * Variables that are relaxation-only in the master SCIP are set to 0 or the bound closest to 0. Such variables
1446  * are represented as NULL entry in the \p subvars array.
1447  */
1449  SCIP* scip, /**< the SCIP data structure */
1450  SCIP* subscip, /**< SCIP data structure of the subproblem */
1451  SCIP_HEUR* heur, /**< heuristic that found the solution */
1452  SCIP_VAR** subvars, /**< the variables from the subproblem in the same order as the main \p scip */
1453  SCIP_Bool* success, /**< pointer to store, whether new solution was found */
1454  int* solindex /**< pointer to store solution index of stored solution, or NULL if not of interest */
1455  )
1456 {
1457  SCIP_SOL* newsol = NULL;
1458  SCIP_SOL** subsols;
1459  int nsubsols;
1460  int i;
1461  SCIP_VAR** vars;
1462  int nvars;
1463  SCIP_Real* solvals;
1464 
1465  assert(scip != NULL);
1466  assert(subscip != NULL);
1467  assert(heur != NULL);
1468  assert(subvars != NULL);
1469  assert(success != NULL);
1470 
1471  *success = FALSE;
1472 
1473  /* check, whether a solution was found */
1474  if( SCIPgetNSols(subscip) == 0 )
1475  return SCIP_OKAY;
1476 
1477  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, NULL, NULL, NULL, NULL) );
1478 
1479  SCIP_CALL( SCIPallocBufferArray(scip, &solvals, nvars) );
1480 
1481  /* check, whether a solution was found;
1482  * due to numerics, it might happen that not all solutions are feasible -> try all solutions until one was accepted
1483  */
1484  nsubsols = SCIPgetNSols(subscip);
1485  subsols = SCIPgetSols(subscip);
1486  for( i = 0; i < nsubsols; ++i )
1487  {
1488  /* better do not copy unbounded solutions as this will mess up the SCIP solution status */
1489  if( SCIPisInfinity(scip, -SCIPgetSolOrigObj(subscip, subsols[i])) )
1490  continue;
1491 
1492  if( newsol == NULL )
1493  {
1494  SCIP_CALL( SCIPcreateSol(scip, &newsol, heur) );
1495  if( solindex != NULL )
1496  *solindex = SCIPsolGetIndex(newsol);
1497  }
1498 
1499  /* put values from subsol into newsol */
1500  SCIP_CALL( translateSubSol(scip, subscip, subsols[i], subvars, solvals) );
1501  SCIP_CALL( SCIPsetSolVals(scip, newsol, nvars, vars, solvals) );
1502 
1503  /* check whether feasible */
1504  SCIP_CALL( SCIPcheckSol(scip, newsol, FALSE, FALSE, TRUE, TRUE, TRUE, success) );
1505  if( *success )
1506  {
1507  /* if feasible, then there is a good chance that we can add it
1508  * we use SCIPaddSolFree to make sure that newsol is indeed added and not some copy, so *solindex stays valid
1509  */
1510  SCIP_CALL( SCIPaddSolFree(scip, &newsol, success) );
1511  if( *success )
1512  {
1513  SCIPdebugMsg(scip, "-> accepted solution of value %g\n", SCIPgetSolOrigObj(subscip, subsols[i]));
1514  break;
1515  }
1516  else
1517  {
1518  /* continue with next subsol
1519  * as we have used addSolFree, newsol should be NULL now
1520  */
1521  assert(newsol == NULL);
1522  }
1523  }
1524  }
1525 
1526  SCIPfreeBufferArray(scip, &solvals);
1527 
1528  if( newsol != NULL )
1529  {
1530  SCIP_CALL( SCIPfreeSol(scip, &newsol) );
1531  }
1532 
1533  return SCIP_OKAY;
1534 }
1535 
1536 /** returns copy of the source constraint; if there already is a copy of the source constraint in the constraint hash
1537  * map, it is just returned as target constraint; elsewise a new constraint will be created; this created constraint is
1538  * added to the constraint hash map and returned as target constraint; the variable map is used to map the variables of
1539  * the source SCIP to the variables of the target SCIP
1540  *
1541  * @warning If a constraint is marked to be checked for feasibility but not to be enforced, a LP or pseudo solution may
1542  * be declared feasible even if it violates this particular constraint. This constellation should only be
1543  * used, if no LP or pseudo solution can violate the constraint -- e.g. if a local constraint is redundant due
1544  * to the variable's local bounds.
1545  *
1546  * @note The constraint is not added to the target SCIP. You can check whether a constraint is added by calling
1547  * SCIPconsIsAdded(). (If you mix SCIPgetConsCopy() with SCIPcopyConss() you should pay attention to what you add
1548  * explicitly and what is already added.)
1549  *
1550  * @note The constraint is always captured, either during the creation of the copy or after finding the copy of the
1551  * constraint in the constraint hash map
1552  *
1553  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1554  * @note Do not change the source SCIP environment during the copying process
1555  *
1556  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1557  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1558  *
1559  * @pre This method can be called if sourcescip is in one of the following stages:
1560  * - \ref SCIP_STAGE_PROBLEM
1561  * - \ref SCIP_STAGE_TRANSFORMED
1562  * - \ref SCIP_STAGE_INITPRESOLVE
1563  * - \ref SCIP_STAGE_PRESOLVING
1564  * - \ref SCIP_STAGE_EXITPRESOLVE
1565  * - \ref SCIP_STAGE_PRESOLVED
1566  * - \ref SCIP_STAGE_INITSOLVE
1567  * - \ref SCIP_STAGE_SOLVING
1568  * - \ref SCIP_STAGE_SOLVED
1569  *
1570  * @pre This method can be called if targetscip is in one of the following stages:
1571  * - \ref SCIP_STAGE_PROBLEM
1572  * - \ref SCIP_STAGE_TRANSFORMING
1573  * - \ref SCIP_STAGE_INITPRESOLVE
1574  * - \ref SCIP_STAGE_PRESOLVING
1575  * - \ref SCIP_STAGE_EXITPRESOLVE
1576  * - \ref SCIP_STAGE_PRESOLVED
1577  * - \ref SCIP_STAGE_SOLVING
1578  * - \ref SCIP_STAGE_EXITSOLVE
1579  *
1580  * @note sourcescip stage does not get changed
1581  *
1582  * @note targetscip stage does not get changed
1583  *
1584  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1585  */
1587  SCIP* sourcescip, /**< source SCIP data structure */
1588  SCIP* targetscip, /**< target SCIP data structure */
1589  SCIP_CONS* sourcecons, /**< source constraint of the source SCIP */
1590  SCIP_CONS** targetcons, /**< pointer to store the created target constraint */
1591  SCIP_CONSHDLR* sourceconshdlr, /**< source constraint handler for this constraint */
1592  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to the corresponding
1593  * variables of the target SCIP, or NULL */
1594  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1595  * target constraints, or NULL */
1596  const char* name, /**< name of constraint, or NULL if the name of the source constraint should be used */
1597  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP? */
1598  SCIP_Bool separate, /**< should the constraint be separated during LP processing? */
1599  SCIP_Bool enforce, /**< should the constraint be enforced during node processing? */
1600  SCIP_Bool check, /**< should the constraint be checked for feasibility? */
1601  SCIP_Bool propagate, /**< should the constraint be propagated during node processing? */
1602  SCIP_Bool local, /**< is constraint only valid locally? */
1603  SCIP_Bool modifiable, /**< is constraint modifiable (subject to column generation)? */
1604  SCIP_Bool dynamic, /**< is constraint subject to aging? */
1605  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup? */
1606  SCIP_Bool stickingatnode, /**< should the constraint always be kept at the node where it was added, even
1607  * if it may be moved to a more global node? */
1608  SCIP_Bool global, /**< create a global or a local copy? */
1609  SCIP_Bool* valid /**< pointer to store whether the copying was valid or not */
1610  )
1611 {
1612  SCIP_HASHMAP* localvarmap;
1613  SCIP_HASHMAP* localconsmap;
1614  SCIP_Bool uselocalvarmap;
1615  SCIP_Bool uselocalconsmap;
1616 
1617  assert(targetcons != NULL);
1618  assert(sourceconshdlr != NULL);
1619 
1620  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPgetConsCopy", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1621  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPgetConsCopy", FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE) );
1622 
1623  uselocalvarmap = (varmap == NULL);
1624  uselocalconsmap = (consmap == NULL);
1625 
1626  /* a variables map and a constraint map is needed to avoid infinite recursion */
1627  if( uselocalvarmap )
1628  {
1629  /* create the variable mapping hash map */
1630  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
1631  }
1632  else
1633  localvarmap = varmap;
1634 
1635  *targetcons = NULL;
1636  if( uselocalconsmap )
1637  {
1638  /* create local constraint mapping hash map */
1639  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
1640  }
1641  else
1642  {
1643  /* use global map and try to retrieve copied constraint */
1644  localconsmap = consmap;
1645  *targetcons = (SCIP_CONS*) SCIPhashmapGetImage(localconsmap, sourcecons);
1646  }
1647 
1648  if( *targetcons != NULL )
1649  {
1650  /* if found capture existing copy of the constraint */
1651  SCIP_CALL( SCIPcaptureCons(targetscip, *targetcons) );
1652  *valid = TRUE;
1653  }
1654  else
1655  {
1656  /* otherwise create a copy of the constraint */
1657  SCIP_CALL( SCIPconsCopy(targetcons, targetscip->set, name, sourcescip, sourceconshdlr, sourcecons, localvarmap, localconsmap,
1658  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode, global, valid) );
1659 
1660  /* it is possible for the constraint handler to declare the copy valid although no target constraint was created */
1661  assert(*targetcons == NULL || *valid);
1662 
1663  /* if a target constraint was created */
1664  if( *targetcons != NULL && !uselocalconsmap )
1665  {
1666  /* insert constraint into mapping between source SCIP and the target SCIP */
1667  SCIP_CALL( SCIPhashmapInsert(consmap, sourcecons, *targetcons) );
1668  }
1669  }
1670 
1671  /* free locally allocated hash maps */
1672  if( uselocalvarmap )
1673  {
1674  SCIPhashmapFree(&localvarmap);
1675  }
1676 
1677  if( uselocalconsmap )
1678  {
1679  SCIPhashmapFree(&localconsmap);
1680  }
1681 
1682  return SCIP_OKAY;
1683 }
1684 
1685 /** copies constraints from the source-SCIP and adds these to the target-SCIP; for mapping the
1686  * variables between the source and the target SCIP a hash map can be given; if the variable hash
1687  * map is NULL or necessary variable mapping is missing, the required variables are created in the
1688  * target-SCIP and added to the hash map, if not NULL; all variables which are created are added to
1689  * the target-SCIP but not (user) captured; if the constraint hash map is not NULL the mapping
1690  * between the constraints of the source and target-SCIP is stored
1691  *
1692  * *valid is set to TRUE iff all constraints that are marked as checked or enforced were copied successfully.
1693  * If other constraints could not be copied, *valid can still be set to TRUE.
1694  *
1695  * @note the constraints are added to the target-SCIP but are not (user) captured in the target SCIP. (If you mix
1696  * SCIPgetConsCopy() with SCIPcopyConss() you should pay attention to what you add explicitly and what is already
1697  * added.) You can check whether a constraint is added by calling SCIPconsIsAdded().
1698  *
1699  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1700  * @note Do not change the source SCIP environment during the copying process
1701  *
1702  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1703  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1704  *
1705  * @pre This method can be called if sourcescip is in one of the following stages:
1706  * - \ref SCIP_STAGE_PROBLEM
1707  * - \ref SCIP_STAGE_TRANSFORMED
1708  * - \ref SCIP_STAGE_INITPRESOLVE
1709  * - \ref SCIP_STAGE_PRESOLVING
1710  * - \ref SCIP_STAGE_EXITPRESOLVE
1711  * - \ref SCIP_STAGE_PRESOLVED
1712  * - \ref SCIP_STAGE_INITSOLVE
1713  * - \ref SCIP_STAGE_SOLVING
1714  * - \ref SCIP_STAGE_SOLVED
1715  *
1716  * @pre This method can be called if targetscip is in one of the following stages:
1717  * - \ref SCIP_STAGE_PROBLEM
1718  *
1719  * @note sourcescip stage does not get changed
1720  *
1721  * @note targetscip stage does not get changed
1722  *
1723  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1724  */
1726  SCIP* sourcescip, /**< source SCIP data structure */
1727  SCIP* targetscip, /**< target SCIP data structure */
1728  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to the corresponding
1729  * variables of the target SCIP, or NULL */
1730  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1731  * target constraints, or NULL */
1732  SCIP_Bool global, /**< create a global or a local copy? */
1733  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance?
1734  * If TRUE, the modifiable flag of constraints will be copied. */
1735  SCIP_Bool* valid /**< pointer to store whether all checked or enforced constraints were validly copied */
1736  )
1737 {
1738  SCIP_CONSHDLR** sourceconshdlrs;
1739  SCIP_HASHMAP* localvarmap;
1740  SCIP_HASHMAP* localconsmap;
1741  SCIP_Bool uselocalvarmap;
1742  SCIP_Bool uselocalconsmap;
1743  int nsourceconshdlrs;
1744  int i;
1745 
1746  assert(sourcescip != NULL);
1747  assert(targetscip != NULL);
1748  assert(valid != NULL);
1749 
1750  /* check stages for both, the source and the target SCIP data structure */
1751  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyConss", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1752  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyConss", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1753 
1754  /* check if we locally need to create a variable or constraint hash map */
1755  uselocalvarmap = (varmap == NULL);
1756  uselocalconsmap = (consmap == NULL);
1757 
1758  if( uselocalvarmap )
1759  {
1760  /* create the variable mapping hash map */
1761  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
1762  }
1763  else
1764  localvarmap = varmap;
1765 
1766  if( uselocalconsmap )
1767  {
1768  /* create the constraint mapping hash map */
1769  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
1770  }
1771  else
1772  localconsmap = consmap;
1773 
1774  nsourceconshdlrs = SCIPgetNConshdlrs(sourcescip);
1775  sourceconshdlrs = SCIPgetConshdlrs(sourcescip);
1776  assert(nsourceconshdlrs == 0 || sourceconshdlrs != NULL);
1777 
1778  *valid = TRUE;
1779 
1780  /* copy constraints: loop through all (source) constraint handlers */
1781  for( i = 0; i < nsourceconshdlrs; ++i )
1782  {
1783  SCIP_CONS** sourceconss;
1784  SCIP_CONS* targetcons;
1785  int nsourceconss;
1786  int c;
1787 
1788  assert(sourceconshdlrs[i] != NULL);
1789 
1790  /* constraint handlers have to explicitly set the valid pointer to TRUE for every single constraint */
1791 
1792  /* Get all active constraints for copying; this array contains all active constraints;
1793  * constraints are active if they are globally valid and not deleted after presolving OR they
1794  * were locally added during the search and we are currently in a node which belongs to the
1795  * corresponding subtree.
1796  */
1797  nsourceconss = SCIPconshdlrGetNActiveConss(sourceconshdlrs[i]);
1798  sourceconss = SCIPconshdlrGetConss(sourceconshdlrs[i]);
1799 
1800 #ifdef SCIP_DISABLED_CODE
1801  /* @todo using the following might reduce the number of copied constraints - check whether this is better */
1802  /* Get all checked constraints for copying; this included local constraints */
1803  if( !global )
1804  {
1805  nsourceconss = SCIPconshdlrGetNCheckConss(sourceconshdlrs[i]);
1806  sourceconss = SCIPconshdlrGetCheckConss(sourceconshdlrs[i]);
1807  }
1808 #endif
1809 
1810  assert(nsourceconss == 0 || sourceconss != NULL);
1811 
1812  if( nsourceconss > 0 )
1813  {
1814  SCIPdebugMsg(sourcescip, "Attempting to copy %d %s constraints\n", nsourceconss, SCIPconshdlrGetName(sourceconshdlrs[i]));
1815  }
1816 
1817  /* copy all constraints of one constraint handler */
1818  for( c = 0; c < nsourceconss; ++c )
1819  {
1820  SCIP_Bool singlevalid = FALSE;
1821  /* all constraints have to be active */
1822  assert(sourceconss[c] != NULL);
1823  assert(SCIPconsIsActive(sourceconss[c]));
1824  assert(!SCIPconsIsDeleted(sourceconss[c]));
1825 
1826  /* in case of copying the global problem we have to ignore the local constraints which are active */
1827  if( global && SCIPconsIsLocal(sourceconss[c]) )
1828  {
1829  SCIPdebugMsg(sourcescip, "did not copy local constraint <%s> when creating global copy\n", SCIPconsGetName(sourceconss[c]));
1830  continue;
1831  }
1832 
1833  /* use the copy constructor of the constraint handler and creates and captures the constraint if possible */
1834  targetcons = NULL;
1835  SCIP_CALL( SCIPgetConsCopy(sourcescip, targetscip, sourceconss[c], &targetcons, sourceconshdlrs[i], localvarmap, localconsmap, NULL,
1836  SCIPconsIsInitial(sourceconss[c]), SCIPconsIsSeparated(sourceconss[c]),
1837  SCIPconsIsEnforced(sourceconss[c]), SCIPconsIsChecked(sourceconss[c]),
1838  SCIPconsIsPropagated(sourceconss[c]), FALSE, SCIPconsIsModifiable(sourceconss[c]),
1839  SCIPconsIsDynamic(sourceconss[c]), SCIPconsIsRemovable(sourceconss[c]), FALSE, global, &singlevalid) );
1840 
1841  /* it is possible for a constraint handler to declare the copy valid, although no target constraint was created */
1842  assert(targetcons == NULL || singlevalid);
1843 
1844  /* add the copied constraint to target SCIP if the copying process created a constraint */
1845  if( targetcons != NULL )
1846  {
1847  if( !enablepricing )
1848  SCIPconsSetModifiable(targetcons, FALSE);
1849 
1850  /* add constraint to target SCIP */
1851  SCIP_CALL( SCIPaddCons(targetscip, targetcons) );
1852 
1853  /* add the conflict constraint to the store of targetscip */
1854  if( SCIPconsIsConflict(sourceconss[c]) )
1855  {
1856  /* add the constraint as a conflict to the conflict pool of targetscip */
1857  SCIP_CALL( SCIPconflictstoreAddConflict(targetscip->conflictstore, targetscip->mem->probmem, targetscip->set,
1858  targetscip->stat, NULL, NULL, targetscip->reopt, targetcons, SCIP_CONFTYPE_UNKNOWN, FALSE, -SCIPinfinity(targetscip)) );
1859  }
1860 
1861  /* release constraint once for the creation capture */
1862  SCIP_CALL( SCIPreleaseCons(targetscip, &targetcons) );
1863  }
1864  else
1865  {
1866  /* if an enforced or checked constraint could not be copied, then the copy is not valid, i.e.,
1867  * the feasible set may be larger; for other constraints, it should be safe if they are omitted
1868  * from the copy
1869  */
1870  if( SCIPconsIsEnforced(sourceconss[c]) || SCIPconsIsChecked(sourceconss[c]) )
1871  *valid = FALSE;
1872  SCIPdebugMsg(sourcescip, "Constraint %s not copied, copy is %svalid\n",
1873  SCIPconsGetName(sourceconss[c]), *valid ? "" : "not ");
1874  }
1875  }
1876  }
1877 
1878  if( uselocalvarmap )
1879  {
1880  /* free hash map */
1881  SCIPhashmapFree(&localvarmap);
1882  }
1883 
1884  if( uselocalconsmap )
1885  {
1886  /* free hash map */
1887  SCIPhashmapFree(&localconsmap);
1888  }
1889 
1890  return SCIP_OKAY;
1891 }
1892 
1893 /** copies all original constraints from the source-SCIP and adds these to the target-SCIP; for mapping the
1894  * variables between the source and the target SCIP a hash map can be given; if the variable hash
1895  * map is NULL or necessary variable mapping is missing, the required variables are created in the
1896  * target-SCIP and added to the hash map, if not NULL; all variables which are created are added to
1897  * the target-SCIP but not (user) captured; if the constraint hash map is not NULL the mapping
1898  * between the constraints of the source and target-SCIP is stored
1899  *
1900  * @note the constraints are added to the target-SCIP but are not (user) captured in the target SCIP. (If you mix
1901  * SCIPgetConsCopy() with SCIPcopyConss() you should pay attention to what you add explicitly and what is already
1902  * added.) You can check whether a constraint is added by calling SCIPconsIsAdded().
1903  *
1904  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
1905  * @note Do not change the source SCIP environment during the copying process
1906  *
1907  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
1908  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
1909  *
1910  * @pre This method can be called if sourcescip is in one of the following stages:
1911  * - \ref SCIP_STAGE_PROBLEM
1912  * - \ref SCIP_STAGE_TRANSFORMED
1913  * - \ref SCIP_STAGE_INITPRESOLVE
1914  * - \ref SCIP_STAGE_PRESOLVING
1915  * - \ref SCIP_STAGE_EXITPRESOLVE
1916  * - \ref SCIP_STAGE_PRESOLVED
1917  * - \ref SCIP_STAGE_INITSOLVE
1918  * - \ref SCIP_STAGE_SOLVING
1919  * - \ref SCIP_STAGE_SOLVED
1920  *
1921  * @pre This method can be called if targetscip is in one of the following stages:
1922  * - \ref SCIP_STAGE_PROBLEM
1923  *
1924  * @note sourcescip stage does not get changed
1925  *
1926  * @note targetscip stage does not get changed
1927  *
1928  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
1929  */
1931  SCIP* sourcescip, /**< source SCIP data structure */
1932  SCIP* targetscip, /**< target SCIP data structure */
1933  SCIP_HASHMAP* varmap, /**< a SCIP_HASHMAP mapping variables of the source SCIP to the corresponding
1934  * variables of the target SCIP, or NULL */
1935  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
1936  * target constraints, or NULL */
1937  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance?
1938  * If TRUE, the modifiable flag of constraints will be copied. */
1939  SCIP_Bool* valid /**< pointer to store whether all constraints were validly copied */
1940  )
1941 {
1942  SCIP_CONS** sourceconss;
1943  SCIP_HASHMAP* localvarmap;
1944  SCIP_HASHMAP* localconsmap;
1945  SCIP_Bool uselocalvarmap;
1946  SCIP_Bool uselocalconsmap;
1947  int nsourceconss;
1948  int c;
1949 
1950  assert(sourcescip != NULL);
1951  assert(targetscip != NULL);
1952  assert(valid != NULL);
1953 
1954  /* check stages for both, the source and the target SCIP data structure */
1955  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyOrigConss", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
1956  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyOrigConss", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
1957 
1958  /* check if we locally need to create a variable or constraint hash map */
1959  uselocalvarmap = (varmap == NULL);
1960  uselocalconsmap = (consmap == NULL);
1961 
1962  if( uselocalvarmap )
1963  {
1964  /* create the variable mapping hash map */
1965  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
1966  }
1967  else
1968  localvarmap = varmap;
1969 
1970  if( uselocalconsmap )
1971  {
1972  /* create the constraint mapping hash map */
1973  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
1974  }
1975  else
1976  localconsmap = consmap;
1977 
1978  sourceconss = SCIPgetOrigConss(sourcescip);
1979  nsourceconss = SCIPgetNOrigConss(sourcescip);
1980 
1981  *valid = TRUE;
1982 
1983  SCIPdebugMsg(sourcescip, "Attempting to copy %d original constraints\n", nsourceconss);
1984 
1985  /* copy constraints: loop through all (source) constraint handlers */
1986  for( c = 0; c < nsourceconss; ++c )
1987  {
1988  SCIP_CONS* targetcons;
1989  SCIP_Bool success;
1990 
1991  /* constraint handlers have to explicitly set the success pointer to TRUE */
1992  success = FALSE;
1993 
1994  /* all constraints have to be active */
1995  assert(sourceconss[c] != NULL);
1996  assert(SCIPconsIsOriginal(sourceconss[c]));
1997 
1998  /* use the copy constructor of the constraint handler and creates and captures the constraint if possible */
1999  targetcons = NULL;
2000  SCIP_CALL( SCIPgetConsCopy(sourcescip, targetscip, sourceconss[c], &targetcons, SCIPconsGetHdlr(sourceconss[c]), localvarmap, localconsmap, NULL,
2001  SCIPconsIsInitial(sourceconss[c]), SCIPconsIsSeparated(sourceconss[c]),
2002  SCIPconsIsEnforced(sourceconss[c]), SCIPconsIsChecked(sourceconss[c]),
2003  SCIPconsIsPropagated(sourceconss[c]), FALSE, SCIPconsIsModifiable(sourceconss[c]),
2004  SCIPconsIsDynamic(sourceconss[c]), SCIPconsIsRemovable(sourceconss[c]), FALSE, TRUE, &success) );
2005 
2006  /* add the copied constraint to target SCIP if the copying process was valid */
2007  if( success )
2008  {
2009  assert(targetcons != NULL);
2010 
2011  if( !enablepricing )
2012  SCIPconsSetModifiable(targetcons, FALSE);
2013 
2014  /* add constraint to target SCIP */
2015  SCIP_CALL( SCIPaddCons(targetscip, targetcons) );
2016 
2017  /* release constraint once for the creation capture */
2018  SCIP_CALL( SCIPreleaseCons(targetscip, &targetcons) );
2019  }
2020  else
2021  {
2022  *valid = FALSE;
2023  SCIPdebugMsg(sourcescip, "failed to copy constraint %s\n", SCIPconsGetName(sourceconss[c]));
2024  }
2025  }
2026 
2027  if( uselocalvarmap )
2028  {
2029  /* free hash map */
2030  SCIPhashmapFree(&localvarmap);
2031  }
2032 
2033  if( uselocalconsmap )
2034  {
2035  /* free hash map */
2036  SCIPhashmapFree(&localconsmap);
2037  }
2038 
2039  return SCIP_OKAY;
2040 }
2041 
2042 
2043 /** convert all active cuts from cutpool to linear constraints
2044  *
2045  * @note Do not change the source SCIP environment during the copying process
2046  *
2047  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2048  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2049  *
2050  * @pre This method can be called if SCIP is in one of the following stages:
2051  * - \ref SCIP_STAGE_PROBLEM
2052  * - \ref SCIP_STAGE_INITPRESOLVE
2053  * - \ref SCIP_STAGE_PRESOLVING
2054  * - \ref SCIP_STAGE_EXITPRESOLVE
2055  * - \ref SCIP_STAGE_PRESOLVED
2056  * - \ref SCIP_STAGE_SOLVING
2057  * - \ref SCIP_STAGE_EXITSOLVE
2058  *
2059  * @note SCIP stage does not get changed
2060  *
2061  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2062  */
2064  SCIP* scip, /**< SCIP data structure */
2065  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2066  * target variables, or NULL */
2067  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2068  * target constraints, or NULL */
2069  SCIP_Bool global, /**< create a global or a local copy? */
2070  int* ncutsadded /**< pointer to store number of added cuts, or NULL */
2071  )
2072 {
2073  assert(scip != NULL);
2074  assert(scip->set != NULL);
2075 
2076  /* check stages for the SCIP data structure */
2077  SCIP_CALL( SCIPcheckStage(scip, "SCIPconvertCutsToConss", FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE) );
2078 
2079  /* if we do not have any cuts, nothing can be converted */
2080  if( scip->set->stage < SCIP_STAGE_SOLVING )
2081  return SCIP_OKAY;
2082 
2083  /* create out of all active cuts in cutpool linear constraints in targetscip */
2084  SCIP_CALL( SCIPcopyCuts(scip, scip, varmap, consmap, global, ncutsadded) );
2085 
2086  return SCIP_OKAY;
2087 }
2088 
2089 /** copies all active cuts from cutpool of sourcescip to linear constraints in targetscip
2090  *
2091  * Cuts that contain variables that are marked as relaxation-only are skipped.
2092  *
2093  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2094  * @note Do not change the source SCIP environment during the copying process
2095  *
2096  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2097  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2098  *
2099  * @pre This method can be called if sourcescip is in one of the following stages:
2100  * - \ref SCIP_STAGE_PROBLEM
2101  * - \ref SCIP_STAGE_TRANSFORMED
2102  * - \ref SCIP_STAGE_INITPRESOLVE
2103  * - \ref SCIP_STAGE_PRESOLVING
2104  * - \ref SCIP_STAGE_EXITPRESOLVE
2105  * - \ref SCIP_STAGE_PRESOLVED
2106  * - \ref SCIP_STAGE_SOLVING
2107  * - \ref SCIP_STAGE_SOLVED
2108  * - \ref SCIP_STAGE_EXITSOLVE
2109  *
2110  * @pre This method can be called if targetscip is in one of the following stages:
2111  * - \ref SCIP_STAGE_PROBLEM
2112  * - \ref SCIP_STAGE_INITPRESOLVE
2113  * - \ref SCIP_STAGE_PRESOLVING
2114  * - \ref SCIP_STAGE_EXITPRESOLVE
2115  * - \ref SCIP_STAGE_PRESOLVED
2116  * - \ref SCIP_STAGE_SOLVING
2117  * - \ref SCIP_STAGE_EXITSOLVE
2118  *
2119  * @note sourcescip stage does not get changed
2120  *
2121  * @note targetscip stage does not get changed
2122  *
2123  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2124  */
2126  SCIP* sourcescip, /**< source SCIP data structure */
2127  SCIP* targetscip, /**< target SCIP data structure */
2128  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2129  * target variables, or NULL */
2130  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2131  * target constraints, or NULL */
2132  SCIP_Bool global, /**< create a global or a local copy? */
2133  int* ncutsadded /**< pointer to store number of copied cuts, or NULL */
2134  )
2135 {
2136  SCIP_CUT** cuts;
2137  int ncuts;
2138  int nlocalcutsadded;
2139 
2140  assert(sourcescip != NULL);
2141  assert(targetscip != NULL);
2142 
2143  /* check stages for both, the source and the target SCIP data structure */
2144  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyCuts", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE) );
2145  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyCuts", FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, FALSE) );
2146 
2147  if ( ncutsadded != NULL )
2148  *ncutsadded = 0;
2149  nlocalcutsadded = 0;
2150 
2151  /* if we do not have any cuts, nothing can be converted */
2152  if( sourcescip->set->stage < SCIP_STAGE_SOLVING )
2153  return SCIP_OKAY;
2154 
2155  if( SCIPfindConshdlr(targetscip, "linear") == NULL )
2156  {
2157  SCIPdebugMsg(sourcescip, "No linear constraint handler available. Cannot convert cuts.\n");
2158  return SCIP_OKAY;
2159  }
2160 
2161  /* convert cut from global cut pool */
2162  cuts = SCIPgetPoolCuts(sourcescip);
2163  ncuts = SCIPgetNPoolCuts(sourcescip);
2164 
2165  SCIP_CALL( copyCuts(sourcescip, targetscip, cuts, ncuts, varmap, consmap, global, &nlocalcutsadded) );
2166 
2167  SCIPdebugMsg(sourcescip, "Converted %d active cuts to constraints.\n", nlocalcutsadded);
2168 
2169  /* convert delayed cuts from global delayed cut pool */
2170  cuts = SCIPgetDelayedPoolCuts(sourcescip);
2171  ncuts = SCIPgetNDelayedPoolCuts(sourcescip);
2172 
2173  SCIP_CALL( copyCuts(sourcescip, targetscip, cuts, ncuts, varmap, consmap, global, &nlocalcutsadded) );
2174 
2175  if( ncutsadded != NULL )
2176  *ncutsadded = nlocalcutsadded;
2177 
2178  SCIPdebugMsg(sourcescip, "Converted %d active cuts to constraints.\n", nlocalcutsadded);
2179 
2180  return SCIP_OKAY;
2181 }
2182 
2183 /** copies all active conflicts from the conflict pool of sourcescip and adds them as linear constraints to targetscip
2184  *
2185  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2186  * @note Do not change the source SCIP environment during the copying process
2187  *
2188  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2189  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2190  *
2191  * @pre This method can be called if sourcescip is in one of the following stages:
2192  * - \ref SCIP_STAGE_PROBLEM
2193  * - \ref SCIP_STAGE_TRANSFORMED
2194  * - \ref SCIP_STAGE_INITPRESOLVE
2195  * - \ref SCIP_STAGE_PRESOLVING
2196  * - \ref SCIP_STAGE_EXITPRESOLVE
2197  * - \ref SCIP_STAGE_PRESOLVED
2198  * - \ref SCIP_STAGE_SOLVING
2199  * - \ref SCIP_STAGE_SOLVED
2200  * - \ref SCIP_STAGE_EXITSOLVE
2201  *
2202  * @pre This method can be called if targetscip is in one of the following stages:
2203  * - \ref SCIP_STAGE_PROBLEM
2204  * - \ref SCIP_STAGE_INITPRESOLVE
2205  * - \ref SCIP_STAGE_PRESOLVING
2206  * - \ref SCIP_STAGE_EXITPRESOLVE
2207  * - \ref SCIP_STAGE_PRESOLVED
2208  * - \ref SCIP_STAGE_SOLVING
2209  * - \ref SCIP_STAGE_EXITSOLVE
2210  *
2211  * @note sourcescip stage does not change
2212  *
2213  * @note targetscip stage does not change
2214  *
2215  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2216  */
2218  SCIP* sourcescip, /**< source SCIP data structure */
2219  SCIP* targetscip, /**< target SCIP data structure */
2220  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2221  * target variables, or NULL */
2222  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2223  * target constraints, or NULL */
2224  SCIP_Bool global, /**< create a global or a local copy? */
2225  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance?
2226  * If TRUE, the modifiable flag of constraints will be copied. */
2227  SCIP_Bool* valid /**< pointer to store whether all constraints were validly copied */
2228  )
2229 {
2230  SCIP_CONS** sourceconfs;
2231  SCIP_HASHMAP* localvarmap;
2232  SCIP_HASHMAP* localconsmap;
2233  SCIP_Bool uselocalvarmap;
2234  SCIP_Bool uselocalconsmap;
2235  SCIP_Bool success;
2236  int sourceconfssize;
2237  int nsourceconfs;
2238  int c;
2239 
2240  assert(sourcescip != NULL);
2241  assert(targetscip != NULL);
2242 
2243  /* check stages for both, the source and the target SCIP data structure */
2244  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyConss", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2245  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyConss", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2246 
2247  /* check if we locally need to create a variable or constraint hash map */
2248  uselocalvarmap = (varmap == NULL);
2249  uselocalconsmap = (consmap == NULL);
2250 
2251  if( uselocalvarmap )
2252  {
2253  /* create the variable mapping hash map */
2254  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
2255  }
2256  else
2257  localvarmap = varmap;
2258 
2259  if( uselocalconsmap )
2260  {
2261  /* create the constraint mapping hash map */
2262  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
2263  }
2264  else
2265  localconsmap = consmap;
2266 
2267  /* get number of conflicts stored in the conflict pool */
2268  sourceconfssize = SCIPconflictstoreGetNConflictsInStore(sourcescip->conflictstore);
2269 
2270  /* allocate buffer */
2271  SCIP_CALL( SCIPallocBufferArray(sourcescip, &sourceconfs, sourceconfssize) );
2272 
2273  /* get all conflicts stored in the conflict pool */
2274  SCIP_CALL( SCIPconflictstoreGetConflicts(sourcescip->conflictstore, sourceconfs, sourceconfssize, &nsourceconfs) );
2275  assert(nsourceconfs <= sourceconfssize);
2276 
2277  /* copy conflicts */
2278  for( c = 0; c < nsourceconfs; ++c )
2279  {
2280  SCIP_CONS* targetcons;
2281 
2282  /* all constraints have to be active */
2283  assert(sourceconfs[c] != NULL);
2284  assert(SCIPconsIsActive(sourceconfs[c]));
2285  assert(!SCIPconsIsDeleted(sourceconfs[c]));
2286  assert(SCIPconsIsConflict(sourceconfs[c]));
2287 
2288  /* in case of copying the global problem we have to ignore the local constraints which are active */
2289  if( global && SCIPconsIsLocal(sourceconfs[c]) )
2290  {
2291  SCIPdebugMsg(sourcescip, "did not copy local constraint <%s> when creating global copy\n", SCIPconsGetName(sourceconfs[c]));
2292  continue;
2293  }
2294 
2295  /* use the copy constructor of the constraint handler and creates and captures the constraint if possible */
2296  targetcons = NULL;
2297  SCIP_CALL( SCIPgetConsCopy(sourcescip, targetscip, sourceconfs[c], &targetcons, SCIPconsGetHdlr(sourceconfs[c]),
2298  localvarmap, localconsmap, NULL, SCIPconsIsInitial(sourceconfs[c]), SCIPconsIsSeparated(sourceconfs[c]),
2299  SCIPconsIsEnforced(sourceconfs[c]), SCIPconsIsChecked(sourceconfs[c]),
2300  SCIPconsIsPropagated(sourceconfs[c]), FALSE, SCIPconsIsModifiable(sourceconfs[c]),
2301  SCIPconsIsDynamic(sourceconfs[c]), SCIPconsIsRemovable(sourceconfs[c]), FALSE, global, &success) );
2302 
2303  /* add the copied constraint to target SCIP if the copying process was valid */
2304  if( success )
2305  {
2306  assert(targetcons != NULL);
2307 
2308  if( !enablepricing )
2309  SCIPconsSetModifiable(targetcons, FALSE);
2310 
2311  /* add constraint to target SCIP */
2312  SCIP_CALL( SCIPaddCons(targetscip, targetcons) );
2313 
2314  /* release constraint once for the creation capture */
2315  SCIP_CALL( SCIPreleaseCons(targetscip, &targetcons) );
2316  }
2317  else
2318  {
2319  *valid = FALSE;
2320  SCIPdebugMsg(sourcescip, "failed to copy constraint %s\n", SCIPconsGetName(sourceconfs[c]));
2321  }
2322  }
2323 
2324  if( uselocalvarmap )
2325  {
2326  /* free hash map */
2327  SCIPhashmapFree(&localvarmap);
2328  }
2329 
2330  if( uselocalconsmap )
2331  {
2332  /* free hash map */
2333  SCIPhashmapFree(&localconsmap);
2334  }
2335 
2336  return SCIP_OKAY;
2337 }
2338 
2339 /** copies implications and cliques of sourcescip to targetscip
2340  *
2341  * This function should be called for a targetscip in transformed stage. It can save time in presolving of the
2342  * targetscip, since implications and cliques are copied.
2343  *
2344  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2345  * @note Do not change the source SCIP environment during the copying process
2346  *
2347  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2348  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2349  *
2350  * @pre This method can be called if sourcescip is in one of the following stages:
2351  * - \ref SCIP_STAGE_TRANSFORMED
2352  * - \ref SCIP_STAGE_INITPRESOLVE
2353  * - \ref SCIP_STAGE_PRESOLVING
2354  * - \ref SCIP_STAGE_EXITPRESOLVE
2355  * - \ref SCIP_STAGE_PRESOLVED
2356  * - \ref SCIP_STAGE_SOLVING
2357  * - \ref SCIP_STAGE_SOLVED
2358  * - \ref SCIP_STAGE_EXITSOLVE
2359  *
2360  * @pre This method can be called if targetscip is in one of the following stages:
2361  * - \ref SCIP_STAGE_TRANSFORMED
2362  * - \ref SCIP_STAGE_INITPRESOLVE
2363  * - \ref SCIP_STAGE_PRESOLVING
2364  * - \ref SCIP_STAGE_EXITPRESOLVE
2365  * - \ref SCIP_STAGE_PRESOLVED
2366  * - \ref SCIP_STAGE_INITSOLVE
2367  * - \ref SCIP_STAGE_SOLVING
2368  *
2369  * @note sourcescip stage does not get changed
2370  *
2371  * @note targetscip stage does not get changed
2372  *
2373  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2374  */
2376  SCIP* sourcescip, /**< source SCIP data structure */
2377  SCIP* targetscip, /**< target SCIP data structure */
2378  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2379  * target variables, or NULL */
2380  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2381  * target constraints, or NULL */
2382  SCIP_Bool global, /**< create a global or a local copy? */
2383  SCIP_Bool* infeasible, /**< pointer to store whether an infeasibility was detected */
2384  int* nbdchgs, /**< pointer to store the number of performed bound changes, or NULL */
2385  int* ncopied /**< pointer to store number of copied implications and cliques, or NULL */
2386  )
2387 {
2388  SCIP_CLIQUE** cliques;
2389  SCIP_VAR** sourcevars;
2390  SCIP_Bool success;
2391  int nvars;
2392  int nbinvars;
2393  int ncliques;
2394  int j;
2395  int c;
2396 
2397  assert( sourcescip != NULL );
2398  assert( targetscip != NULL );
2399  assert( sourcescip != targetscip );
2400  assert( infeasible != NULL );
2401 
2402  /* check stages for both, the source and the target SCIP data structure */
2403  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyImplicationsCliques", FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE) );
2404  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyImplicationsCliques", FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
2405 
2406  if ( ncopied != NULL )
2407  *ncopied = 0;
2408  if ( nbdchgs != NULL )
2409  *nbdchgs = 0;
2410 
2411  /* get all active variables */
2412  SCIP_CALL( SCIPgetVarsData(sourcescip, &sourcevars, &nvars, &nbinvars, NULL, NULL, NULL) );
2413 
2414  /* stop if no possible variables for cliques exist */
2415  if ( nbinvars == 0 )
2416  return SCIP_OKAY;
2417 
2418  /* get cliques */
2419  ncliques = SCIPgetNCliques(sourcescip);
2420  if ( ncliques > 0 )
2421  {
2422  SCIP_VAR** targetclique;
2423 
2424  /* get space for target cliques */
2425  SCIP_CALL( SCIPallocBufferArray(targetscip, &targetclique, nvars) );
2426  cliques = SCIPgetCliques(sourcescip);
2427 
2428  /* loop through all cliques */
2429  for (c = 0; c < ncliques; ++c)
2430  {
2431  SCIP_VAR** cliquevars;
2432  SCIP_Bool* cliquevals;
2433  int cliquesize;
2434  int nboundchg = 0;
2435 
2436  assert( cliques[c] != NULL );
2437  cliquevals = SCIPcliqueGetValues(cliques[c]);
2438  cliquevars = SCIPcliqueGetVars(cliques[c]);
2439  cliquesize = SCIPcliqueGetNVars(cliques[c]);
2440 
2441  /* get target variables of clique */
2442  for (j = 0; j < cliquesize; ++j)
2443  {
2444  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, cliquevars[j], &targetclique[j], varmap, consmap, global, &success) );
2445  if ( ! success )
2446  {
2447  SCIPdebugMsg(sourcescip, "Getting copy for variable <%s> failed.\n", SCIPvarGetName(cliquevars[j]));
2448  SCIPfreeBufferArray(targetscip, &targetclique);
2449  return SCIP_OKAY;
2450  }
2451  }
2452 
2453  /* create clique */
2454  SCIP_CALL( SCIPaddClique(targetscip, targetclique, cliquevals, cliquesize, SCIPcliqueIsEquation(cliques[c]),
2455  infeasible, &nboundchg) );
2456 
2457  if ( *infeasible )
2458  {
2459  SCIPfreeBufferArray(targetscip, &targetclique);
2460  return SCIP_OKAY;
2461  }
2462  if ( ncopied != NULL )
2463  ++(*ncopied);
2464  if ( nbdchgs != NULL )
2465  *nbdchgs += nboundchg;
2466  }
2467  SCIPfreeBufferArray(targetscip, &targetclique);
2468  }
2469 
2470  /* create binary implications */
2471  for (j = 0; j < nbinvars; ++j)
2472  {
2473  SCIP_VAR* sourcevar;
2474  SCIP_VAR* targetvar;
2475  SCIP_Bool d;
2476 
2477  sourcevar = sourcevars[j];
2478  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, sourcevar, &targetvar, varmap, consmap, global, &success) );
2479  if ( ! success )
2480  {
2481  SCIPdebugMsg(sourcescip, "Getting copy for variable <%s> failed.\n", SCIPvarGetName(sourcevar));
2482  return SCIP_OKAY;
2483  }
2484 
2485  /* consider both possible implications */
2486  for (d = 0; d <= 1; ++d)
2487  {
2488  SCIP_BOUNDTYPE* impltypes;
2489  SCIP_VAR** implvars;
2490  SCIP_Real* implbounds;
2491  int nimpls;
2492  int l;
2493 
2494  nimpls = SCIPvarGetNImpls(sourcevar, d);
2495  if ( nimpls == 0 )
2496  continue;
2497 
2498  impltypes = SCIPvarGetImplTypes(sourcevar, d);
2499  implvars = SCIPvarGetImplVars(sourcevar, d);
2500  implbounds = SCIPvarGetImplBounds(sourcevar, d);
2501 
2502  /* create implications */
2503  for (l = 0; l < nimpls; ++l)
2504  {
2505  SCIP_VAR* implvar;
2506  int nboundchg = 0;
2507 
2508  SCIP_CALL( SCIPgetVarCopy(sourcescip, targetscip, implvars[l], &implvar, varmap, consmap, global, &success) );
2509  if ( ! success )
2510  {
2511  SCIPdebugMsg(sourcescip, "Getting copy for variable <%s> failed.\n", SCIPvarGetName(implvars[l]));
2512  return SCIP_OKAY;
2513  }
2514 
2515  SCIP_CALL( SCIPaddVarImplication(targetscip, targetvar, d, implvar, impltypes[l], implbounds[l], infeasible, &nboundchg) );
2516  if ( *infeasible )
2517  return SCIP_OKAY;
2518  if ( ncopied != NULL )
2519  ++(*ncopied);
2520  if ( nbdchgs != NULL )
2521  *nbdchgs += nboundchg;
2522  }
2523  }
2524  }
2525 
2526  return SCIP_OKAY;
2527 }
2528 
2529 /** copies parameter settings from sourcescip to targetscip
2530  *
2531  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2532  * @note Do not change the source SCIP environment during the copying process
2533  *
2534  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2535  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2536  *
2537  * @pre This method can be called if sourcescip is in one of the following stages:
2538  * - \ref SCIP_STAGE_PROBLEM
2539  * - \ref SCIP_STAGE_TRANSFORMED
2540  * - \ref SCIP_STAGE_INITPRESOLVE
2541  * - \ref SCIP_STAGE_PRESOLVING
2542  * - \ref SCIP_STAGE_EXITPRESOLVE
2543  * - \ref SCIP_STAGE_PRESOLVED
2544  * - \ref SCIP_STAGE_INITSOLVE
2545  * - \ref SCIP_STAGE_SOLVING
2546  * - \ref SCIP_STAGE_SOLVED
2547  *
2548  * @pre This method can be called if targetscip is in one of the following stages:
2549  * - \ref SCIP_STAGE_INIT
2550  * - \ref SCIP_STAGE_PROBLEM
2551  * - \ref SCIP_STAGE_FREE
2552  *
2553  * @note sourcescip stage does not get changed
2554  *
2555  * @note targetscip stage does not get changed
2556  *
2557  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2558  */
2560  SCIP* sourcescip, /**< source SCIP data structure */
2561  SCIP* targetscip /**< target SCIP data structure */
2562  )
2563 {
2564  assert(sourcescip != NULL);
2565  assert(targetscip != NULL);
2566  assert(sourcescip->set != NULL);
2567  assert(targetscip->set != NULL);
2568 
2569  /* check stages for both, the source and the target SCIP data structure */
2570  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyParamSettings", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2571  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyParamSettings", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
2572 
2573  SCIP_CALL( SCIPsetCopyParams(sourcescip->set, targetscip->set, targetscip->messagehdlr) );
2574 
2575  return SCIP_OKAY;
2576 }
2577 
2578 /** gets depth of current scip instance (increased by each copy call)
2579  *
2580  * @return Depth of subscip of SCIP is returned.
2581  *
2582  * @pre This method can be called if SCIP is in one of the following stages:
2583  * - \ref SCIP_STAGE_PROBLEM
2584  * - \ref SCIP_STAGE_TRANSFORMING
2585  * - \ref SCIP_STAGE_TRANSFORMED
2586  * - \ref SCIP_STAGE_INITPRESOLVE
2587  * - \ref SCIP_STAGE_PRESOLVING
2588  * - \ref SCIP_STAGE_EXITPRESOLVE
2589  * - \ref SCIP_STAGE_PRESOLVED
2590  * - \ref SCIP_STAGE_INITSOLVE
2591  * - \ref SCIP_STAGE_SOLVING
2592  * - \ref SCIP_STAGE_SOLVED
2593  * - \ref SCIP_STAGE_EXITSOLVE
2594  * - \ref SCIP_STAGE_FREETRANS
2595  *
2596  * @note SCIP stage does not get changed
2597  *
2598  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2599  */
2601  SCIP* scip /**< SCIP data structure */
2602  )
2603 {
2604  assert( scip != NULL );
2605  assert( scip->stat != NULL );
2606 
2607  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPgetSubscipDepth", FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE) );
2608 
2609  return scip->stat->subscipdepth;
2610 }
2611 
2612 /** sets depth of scip instance
2613  *
2614  * @pre This method can be called if SCIP is in one of the following stages:
2615  * - \ref SCIP_STAGE_PROBLEM
2616  *
2617  * @note SCIP stage does not get changed
2618  *
2619  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2620  */
2622  SCIP* scip, /**< SCIP data structure */
2623  int newdepth /**< new subscip depth */
2624  )
2625 {
2626  assert( scip != NULL );
2627  assert( newdepth > 0 );
2628 
2629  SCIP_CALL_ABORT( SCIPcheckStage(scip, "SCIPsetSubscipDepth", FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
2630 
2631  assert( scip->stat != NULL );
2632  scip->stat->subscipdepth = newdepth;
2633 }
2634 
2635 /** copies source SCIP data into target SCIP data structure
2636  *
2637  * distinguishes between
2638  * - local and global copies
2639  * - copies of the original or transformed problem
2640  *
2641  * Allows for constraint compression by specifying a number of source variables
2642  * and values that should be fixed in the copy.
2643  */
2644 static
2646  SCIP* sourcescip, /**< source SCIP data structure */
2647  SCIP* targetscip, /**< target SCIP data structure */
2648  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2649  * target variables, or NULL */
2650  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2651  * target constraints, or NULL */
2652  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
2653  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
2654  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
2655  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
2656  SCIP_Bool useconscompression, /**< should constraint compression be used when constraints are created? */
2657  SCIP_Bool global, /**< create a global or a local copy? */
2658  SCIP_Bool original, /**< copy original or transformed problem? if TRUE, a copy using local bounds is not possible */
2659  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
2660  * plugins will be copied and activated, and the modifiable flag of
2661  * constraints will be respected. If FALSE, valid will be set to FALSE, when
2662  * there are pricers present */
2663  SCIP_Bool threadsafe, /**< FALSE, if data can be safely shared between the source and target
2664  * SCIP, otherwise TRUE. This is usually set to FALSE */
2665  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
2666  SCIP_Bool* valid /**< pointer to store whether the copying was valid or not, or NULL */
2667  )
2668 {
2669  SCIP_HASHMAP* localvarmap;
2670  SCIP_HASHMAP* localconsmap;
2671  SCIP_Real startcopytime;
2672  SCIP_Real copytime;
2673  SCIP_Bool uselocalvarmap;
2674  SCIP_Bool uselocalconsmap;
2675  SCIP_Bool consscopyvalid;
2676  SCIP_Bool benderscopyvalid;
2677  SCIP_Bool localvalid;
2678  SCIP_Bool msghdlrquiet;
2679  char name[SCIP_MAXSTRLEN];
2680 
2681  assert(sourcescip != NULL);
2682  assert(targetscip != NULL);
2683  assert(suffix != NULL);
2684 
2685  /* copy the original problem if we are in SCIP_STAGE_PROBLEM stage */
2686  if( SCIPgetStage(sourcescip) == SCIP_STAGE_PROBLEM )
2687  original = TRUE;
2688 
2689  /* global must be TRUE for the original problem */
2690  assert(global || !original);
2691 
2692  /* get time before start of copy procedure */
2693  startcopytime = SCIPclockGetTime(sourcescip->stat->copyclock);
2694 
2695  /* start time measuring */
2696  SCIPclockStart(sourcescip->stat->copyclock, sourcescip->set);
2697 
2698  /* copy all plugins */
2699  SCIP_CALL( SCIPcopyPlugins(sourcescip, targetscip, TRUE, enablepricing, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
2700  TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, passmessagehdlr, &localvalid) );
2701 
2702  /* in case there are active pricers and pricing is disabled, targetscip will not be a valid copy of sourcescip */
2703  if( ! enablepricing && SCIPgetNActivePricers(sourcescip) > 0 )
2704  localvalid = FALSE;
2705 
2706  SCIPdebugMsg(sourcescip, "Copying plugins was%s valid.\n", localvalid ? "" : " not");
2707 
2708  uselocalvarmap = (varmap == NULL);
2709  uselocalconsmap = (consmap == NULL);
2710 
2711  if( uselocalvarmap )
2712  {
2713  /* create the variable mapping hash map */
2714  SCIP_CALL( SCIPhashmapCreate(&localvarmap, SCIPblkmem(targetscip), SCIPgetNVars(sourcescip)) );
2715  }
2716  else
2717  localvarmap = varmap;
2718 
2719  if( uselocalconsmap )
2720  {
2721  /* create the constraint mapping hash map */
2722  SCIP_CALL( SCIPhashmapCreate(&localconsmap, SCIPblkmem(targetscip), SCIPgetNConss(sourcescip)) );
2723  }
2724  else
2725  localconsmap = consmap;
2726 
2727  /* construct name for the target SCIP using the source problem name and the given suffix string */
2728  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%s", SCIPgetProbName(sourcescip), suffix);
2729 
2730  /* store the quiet state of the message handler, if existent */
2731  msghdlrquiet = SCIPmessagehdlrIsQuiet(targetscip->messagehdlr);
2732 
2733  /* explicitly suppress output when copying parameters */
2734  SCIPsetMessagehdlrQuiet(targetscip, TRUE);
2735 
2736  /* copy all settings */
2737  SCIP_CALL( SCIPcopyParamSettings(sourcescip, targetscip) );
2738 
2739  /* restore original quiet state */
2740  SCIPsetMessagehdlrQuiet(targetscip, msghdlrquiet);
2741 
2742  /* create problem in the target SCIP copying the source original or transformed problem data */
2743  if( original )
2744  {
2745  SCIP_CALL( SCIPcopyOrigProb(sourcescip, targetscip, localvarmap, localconsmap, name) );
2746  }
2747  else
2748  {
2749  SCIP_CALL( SCIPcopyProb(sourcescip, targetscip, localvarmap, localconsmap, global, name) );
2750  }
2751 
2752  /* copy original or transformed variables and perform fixings if needed */
2753  SCIP_CALL( copyVars(sourcescip, targetscip, localvarmap, localconsmap, fixedvars, fixedvals, nfixedvars, original, global) );
2754 
2755  /* if fixed variables are directly specified or inferred from local bounds, enable constraint compression */
2756  if( useconscompression && (nfixedvars > 0 || !global) )
2757  {
2758  SCIP_CALL( SCIPenableConsCompression(targetscip) );
2759 
2760  /* domain reductions yield a copy that is no longer guaranteed to be valid */
2761  localvalid = FALSE;
2762  }
2763 
2764  /* copy all (original) constraints */
2765  if( original )
2766  {
2767  SCIP_CALL( SCIPcopyOrigConss(sourcescip, targetscip, localvarmap, localconsmap, enablepricing, &consscopyvalid) );
2768  }
2769  else
2770  {
2771  SCIP_CALL( SCIPcopyConss(sourcescip, targetscip, localvarmap, localconsmap, global, enablepricing, &consscopyvalid) );
2772  }
2773 
2774  SCIPdebugMsg(sourcescip, "Copying constraints was%s valid.\n", consscopyvalid ? "" : " not");
2775 
2776  localvalid = localvalid && consscopyvalid;
2777 
2778  /* copy the Benders' decomposition plugins explicitly, because it requires the variable mapping hash map */
2779  SCIP_CALL( SCIPcopyBenders(sourcescip, targetscip, localvarmap, threadsafe, &benderscopyvalid) );
2780 
2781  SCIPdebugMsg(sourcescip, "Copying Benders' decomposition plugins was%s valid.\n", benderscopyvalid ? "" : " not");
2782 
2783  localvalid = localvalid && benderscopyvalid;
2784 
2785  if( uselocalvarmap )
2786  {
2787  /* free hash map */
2788  SCIPhashmapFree(&localvarmap);
2789  }
2790 
2791  if( uselocalconsmap )
2792  {
2793  /* free hash map */
2794  SCIPhashmapFree(&localconsmap);
2795  }
2796 
2797  /* stop time measuring */
2798  SCIPclockStop(sourcescip->stat->copyclock, sourcescip->set);
2799 
2800  /* get time after copying procedure */
2801  copytime = SCIPclockGetTime(sourcescip->stat->copyclock) - startcopytime;
2802 
2803  if( copytime > sourcescip->stat->maxcopytime )
2804  sourcescip->stat->maxcopytime = copytime;
2805  if( copytime < sourcescip->stat->mincopytime )
2806  sourcescip->stat->mincopytime = copytime;
2807 
2808  /* increase copy counter */
2809  ++(sourcescip->stat->ncopies);
2810 
2811  targetscip->concurrent = sourcescip->concurrent;
2812  SCIP_CALL( SCIPsyncstoreRelease(&targetscip->syncstore) );
2813  targetscip->syncstore = sourcescip->syncstore;
2814  SCIP_CALL( SCIPsyncstoreCapture(targetscip->syncstore) );
2815 
2816  /* return the information about a valid copy to the user */
2817  if( valid != NULL )
2818  *valid = localvalid;
2819 
2820  return SCIP_OKAY;
2821 }
2822 
2823 /** copies source SCIP to target SCIP; the copying process is done in the following order:
2824  * 1) copy the plugins
2825  * 2) copy the settings
2826  * 3) create problem data in target-SCIP and copy the problem data of the source-SCIP
2827  * 4) copy all active variables except those that are marked as relaxation-only
2828  * 5) copy all constraints
2829  *
2830  * The source problem depends on the stage of the \p sourcescip - In SCIP_STAGE_PROBLEM, the original problem is copied,
2831  * otherwise, the transformed problem is copied. For an explicit copy of the original problem, use SCIPcopyOrig().
2832  *
2833  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
2834  *
2835  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2836  * Also, 'passmessagehdlr' should be set to FALSE.
2837  * @note the 'threadsafe' parameter should only be set to TRUE if you are absolutely certain that the source and target
2838  * SCIP instances will be solved in parallel. The usual case is to set this to FALSE, since thread safety
2839  * typically incurs a performance cost.
2840  * @note Do not change the source SCIP environment during the copying process
2841  *
2842  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2843  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2844  *
2845  * @pre This method can be called if sourcescip is in one of the following stages:
2846  * - \ref SCIP_STAGE_PROBLEM
2847  * - \ref SCIP_STAGE_TRANSFORMED
2848  * - \ref SCIP_STAGE_INITPRESOLVE
2849  * - \ref SCIP_STAGE_PRESOLVING
2850  * - \ref SCIP_STAGE_EXITPRESOLVE
2851  * - \ref SCIP_STAGE_PRESOLVED
2852  * - \ref SCIP_STAGE_INITSOLVE
2853  * - \ref SCIP_STAGE_SOLVING
2854  * - \ref SCIP_STAGE_SOLVED
2855  *
2856  * @pre This method can be called if targetscip is in one of the following stages:
2857  * - \ref SCIP_STAGE_INIT
2858  * - \ref SCIP_STAGE_FREE
2859  *
2860  * @note sourcescip stage does not get changed
2861  *
2862  * @note targetscip stage does not get changed
2863  *
2864  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2865  */
2867  SCIP* sourcescip, /**< source SCIP data structure */
2868  SCIP* targetscip, /**< target SCIP data structure */
2869  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2870  * target variables, or NULL */
2871  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2872  * target constraints, or NULL */
2873  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
2874  SCIP_Bool global, /**< create a global or a local copy? */
2875  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
2876  * plugins will be copied and activated, and the modifiable flag of
2877  * constraints will be respected. If FALSE, valid will be set to FALSE, when
2878  * there are pricers present */
2879  SCIP_Bool threadsafe, /**< FALSE, if data can be safely shared between the source and target
2880  * SCIP, otherwise TRUE. This is usually set to FALSE */
2881  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
2882  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
2883  )
2884 {
2885  SCIP_VAR** fixedvars = NULL;
2886  SCIP_Real* fixedvals = NULL;
2887  int nfixedvars = 0;
2888  SCIP_Bool original = FALSE;
2889  SCIP_Bool useconscompression = FALSE;
2890 
2891  assert(sourcescip != NULL);
2892  assert(targetscip != NULL);
2893  assert(suffix != NULL);
2894 
2895  /* check stages for both, the source and the target SCIP data structure */
2896  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopy", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2897  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopy", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
2898 
2899  /* copy source SCIP data into target SCIP data structure */
2900  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
2901  useconscompression, global, original, enablepricing, threadsafe, passmessagehdlr, valid) );
2902 
2903  return SCIP_OKAY;
2904 }
2905 
2906 /** copies source SCIP to target SCIP but compresses constraints
2907  *
2908  * constraint compression is performed by removing fixed variables immediately
2909  * during constraint creation if the involved constraint handlers support
2910  * compression
2911  *
2912  * the copying process is done in the following order:
2913  * 1) copy the plugins
2914  * 2) copy the settings
2915  * 3) create problem data in target-SCIP and copy the problem data of the source-SCIP
2916  * 4) copy all active variables except those that are marked as relaxation-only
2917  * a) fix all variable copies specified by \p fixedvars, \p fixedvals, and \p nfixedvars
2918  * b) enable constraint compression
2919  * 5) copy all constraints
2920  *
2921  * The source problem depends on the stage of the \p sourcescip - In SCIP_STAGE_PROBLEM, the original problem is copied,
2922  * otherwise, the transformed problem is copied. For an explicit copy of the original problem, use SCIPcopyOrigConsCompression().
2923  *
2924  * @note: in case that a combination of local bounds and explicit fixing values should be used,
2925  * the fixing value of a variable is preferred if local bounds and fixing value disagree.
2926  *
2927  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
2928  *
2929  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
2930  * Also, 'passmessagehdlr' should be set to FALSE.
2931  * @note the 'threadsafe' parameter should only be set to TRUE if you are absolutely certain that the source and target
2932  * SCIP instances will be solved in parallel. The usual case is to set this to FALSE, since thread safety
2933  * typically incurs a performance cost.
2934  * @note Do not change the source SCIP environment during the copying process
2935  *
2936  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
2937  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
2938  *
2939  * @pre This method can be called if sourcescip is in one of the following stages:
2940  * - \ref SCIP_STAGE_PROBLEM
2941  * - \ref SCIP_STAGE_TRANSFORMED
2942  * - \ref SCIP_STAGE_INITPRESOLVE
2943  * - \ref SCIP_STAGE_PRESOLVING
2944  * - \ref SCIP_STAGE_EXITPRESOLVE
2945  * - \ref SCIP_STAGE_PRESOLVED
2946  * - \ref SCIP_STAGE_INITSOLVE
2947  * - \ref SCIP_STAGE_SOLVING
2948  * - \ref SCIP_STAGE_SOLVED
2949  *
2950  * @pre This method can be called if targetscip is in one of the following stages:
2951  * - \ref SCIP_STAGE_INIT
2952  * - \ref SCIP_STAGE_FREE
2953  *
2954  * @note sourcescip stage does not get changed
2955  *
2956  * @note targetscip stage does not get changed
2957  *
2958  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
2959  */
2961  SCIP* sourcescip, /**< source SCIP data structure */
2962  SCIP* targetscip, /**< target SCIP data structure */
2963  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
2964  * target variables, or NULL */
2965  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
2966  * target constraints, or NULL */
2967  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
2968  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
2969  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
2970  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
2971  SCIP_Bool global, /**< create a global or a local copy? */
2972  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
2973  * plugins will be copied and activated, and the modifiable flag of
2974  * constraints will be respected. If FALSE, valid will be set to FALSE, when
2975  * there are pricers present */
2976  SCIP_Bool threadsafe, /**< FALSE, if data can be safely shared between the source and target
2977  * SCIP, otherwise TRUE. This is usually set to FALSE */
2978  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
2979  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
2980  )
2981 {
2982  SCIP_Bool original = FALSE;
2983  SCIP_Bool useconscompression = TRUE;
2984 
2985  assert(sourcescip != NULL);
2986  assert(targetscip != NULL);
2987  assert(suffix != NULL);
2988 
2989  /* check stages for both, the source and the target SCIP data structure */
2990  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyConsCompression", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
2991  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyConsCompression", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
2992 
2993  /* copy the source problem data */
2994  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
2995  useconscompression, global, original, enablepricing, threadsafe, passmessagehdlr, valid) );
2996 
2997  return SCIP_OKAY;
2998 }
2999 
3000 
3001 /** copies source SCIP original problem to target SCIP; the copying process is done in the following order:
3002  * 1) copy the plugins
3003  * 2) copy the settings
3004  * 3) create problem data in target-SCIP and copy the original problem data of the source-SCIP
3005  * 4) copy all original variables
3006  * 5) copy all original constraints
3007  *
3008  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
3009  *
3010  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3011  * Also, 'passmessagehdlr' should be set to FALSE.
3012  * @note the 'threadsafe' parameter should only be set to TRUE if you are absolutely certain that the source and target
3013  * SCIP instances will be solved in parallel. The usual case is to set this to FALSE, since thread safety
3014  * typically incurs a performance cost.
3015  * @note Do not change the source SCIP environment during the copying process
3016  *
3017  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3018  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3019  *
3020  * @pre This method can be called if sourcescip is in one of the following stages:
3021  * - \ref SCIP_STAGE_PROBLEM
3022  * - \ref SCIP_STAGE_TRANSFORMED
3023  * - \ref SCIP_STAGE_INITPRESOLVE
3024  * - \ref SCIP_STAGE_PRESOLVING
3025  * - \ref SCIP_STAGE_EXITPRESOLVE
3026  * - \ref SCIP_STAGE_PRESOLVED
3027  * - \ref SCIP_STAGE_INITSOLVE
3028  * - \ref SCIP_STAGE_SOLVING
3029  * - \ref SCIP_STAGE_SOLVED
3030  *
3031  * @pre This method can be called if targetscip is in one of the following stages:
3032  * - \ref SCIP_STAGE_INIT
3033  * - \ref SCIP_STAGE_FREE
3034  *
3035  * @note sourcescip stage does not get changed
3036  *
3037  * @note targetscip stage does not get changed
3038  *
3039  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3040  */
3042  SCIP* sourcescip, /**< source SCIP data structure */
3043  SCIP* targetscip, /**< target SCIP data structure */
3044  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3045  * target variables, or NULL */
3046  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3047  * target constraints, or NULL */
3048  const char* suffix, /**< suffix which will be added to the names of the target SCIP, might be empty */
3049  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
3050  * plugins will be copied and activated, and the modifiable flag of
3051  * constraints will be respected. If FALSE, valid will be set to FALSE, when
3052  * there are pricers present */
3053  SCIP_Bool threadsafe, /**< FALSE, if data can be safely shared between the source and target
3054  * SCIP, otherwise TRUE. This is usually set to FALSE */
3055  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
3056  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
3057  )
3058 {
3059  SCIP_VAR** fixedvars = NULL;
3060  SCIP_Real* fixedvals = NULL;
3061  int nfixedvars = 0;
3062  SCIP_Bool global = TRUE;
3063  SCIP_Bool original = TRUE;
3064  SCIP_Bool useconscompression = FALSE;
3065 
3066  assert(sourcescip != NULL);
3067  assert(targetscip != NULL);
3068  assert(suffix != NULL);
3069 
3070  /* check stages for both, the source and the target SCIP data structure */
3071  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyOrig", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
3072  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyOrig", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
3073 
3074  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
3075  useconscompression, global, original, enablepricing, threadsafe, passmessagehdlr, valid) );
3076 
3077  return SCIP_OKAY;
3078 }
3079 
3080 /** copies source SCIP original problem to target SCIP but compresses constraints
3081  *
3082  * constraint compression is performed by removing fixed variables immediately
3083  * during constraint creation if the involved constraint handlers support
3084  * compression
3085  *
3086  * the copying process is done in the following order:
3087  * 1) copy the plugins
3088  * 2) copy the settings
3089  * 3) create problem data in target-SCIP and copy the problem data of the source-SCIP
3090  * 4) copy all original variables
3091  * a) fix all variable copies specified by \p fixedvars, \p fixedvals, and \p nfixedvars
3092  * b) enable constraint compression
3093  * 5) copy all constraints
3094  *
3095  * @note all variables and constraints which are created in the target-SCIP are not (user) captured
3096  *
3097  * @note In a multi thread case, you need to lock the copying procedure from outside with a mutex.
3098  * Also, 'passmessagehdlr' should be set to FALSE.
3099  * @note the 'threadsafe' parameter should only be set to TRUE if you are absolutely certain that the source and target
3100  * SCIP instances will be solved in parallel. The usual case is to set this to FALSE, since thread safety
3101  * typically incurs a performance cost.
3102  * @note Do not change the source SCIP environment during the copying process
3103  *
3104  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
3105  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
3106  *
3107  * @pre This method can be called if sourcescip is in one of the following stages:
3108  * - \ref SCIP_STAGE_PROBLEM
3109  * - \ref SCIP_STAGE_TRANSFORMED
3110  * - \ref SCIP_STAGE_INITPRESOLVE
3111  * - \ref SCIP_STAGE_PRESOLVING
3112  * - \ref SCIP_STAGE_EXITPRESOLVE
3113  * - \ref SCIP_STAGE_PRESOLVED
3114  * - \ref SCIP_STAGE_INITSOLVE
3115  * - \ref SCIP_STAGE_SOLVING
3116  * - \ref SCIP_STAGE_SOLVED
3117  *
3118  * @pre This method can be called if targetscip is in one of the following stages:
3119  * - \ref SCIP_STAGE_INIT
3120  * - \ref SCIP_STAGE_FREE
3121  *
3122  * @note sourcescip stage does not get changed
3123  *
3124  * @note targetscip stage does not get changed
3125  *
3126  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3127  */
3129  SCIP* sourcescip, /**< source SCIP data structure */
3130  SCIP* targetscip, /**< target SCIP data structure */
3131  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
3132  * target variables, or NULL */
3133  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
3134  * target constraints, or NULL */
3135  const char* suffix, /**< optional suffix for problem name inside the target SCIP */
3136  SCIP_VAR** fixedvars, /**< source variables whose copies should be fixed in the target SCIP environment, or NULL */
3137  SCIP_Real* fixedvals, /**< array of fixing values for target SCIP variables, or NULL */
3138  int nfixedvars, /**< number of source variables whose copies should be fixed in the target SCIP environment, or NULL */
3139  SCIP_Bool enablepricing, /**< should pricing be enabled in copied SCIP instance? If TRUE, pricer
3140  * plugins will be copied and activated, and the modifiable flag of
3141  * constraints will be respected. If FALSE, valid will be set to FALSE, when
3142  * there are pricers present */
3143  SCIP_Bool threadsafe, /**< FALSE, if data can be safely shared between the source and target
3144  * SCIP, otherwise TRUE. This is usually set to FALSE */
3145  SCIP_Bool passmessagehdlr, /**< should the message handler be passed */
3146  SCIP_Bool* valid /**< pointer to store whether the copying was valid, or NULL */
3147  )
3148 {
3149  SCIP_Bool original = TRUE;
3150  SCIP_Bool global = TRUE;
3151  SCIP_Bool useconscompression = TRUE;
3152 
3153  assert(sourcescip != NULL);
3154  assert(targetscip != NULL);
3155  assert(suffix != NULL);
3156 
3157  /* check stages for both, the source and the target SCIP data structure */
3158  SCIP_CALL( SCIPcheckStage(sourcescip, "SCIPcopyOrigConsCompression", FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE) );
3159  SCIP_CALL( SCIPcheckStage(targetscip, "SCIPcopyOrigConsCompression", TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
3160 
3161  /* copy the source problem data */
3162  SCIP_CALL( doCopy(sourcescip, targetscip, varmap, consmap, suffix, fixedvars, fixedvals, nfixedvars,
3163  useconscompression, global, original, enablepricing, threadsafe, passmessagehdlr, valid) );
3164 
3165  SCIP_CALL( SCIPsyncstoreRelease(&targetscip->syncstore) );
3166  targetscip->syncstore = sourcescip->syncstore;
3167  SCIP_CALL( SCIPsyncstoreCapture(targetscip->syncstore) );
3168 
3169  return SCIP_OKAY;
3170 }
3171 
3172 /** return updated time limit for a sub-SCIP */
3173 static
3175  SCIP* sourcescip, /**< source SCIP data structure */
3176  SCIP_Real* timelimit /**< pointer to store sub-SCIP time limit */
3177  )
3178 {
3179  SCIP_CALL( SCIPgetRealParam(sourcescip, "limits/time", timelimit) );
3180  if( !SCIPisInfinity(sourcescip, *timelimit) )
3181  (*timelimit) -= SCIPgetSolvingTime(sourcescip);
3182 
3183  return SCIP_OKAY;
3184 }
3185 
3186 /** set updated time limit for a sub-SCIP */
3187 static
3189  SCIP* sourcescip, /**< source SCIP data structure */
3190  SCIP* targetscip /**< target SCIP data structure */
3191  )
3192 {
3193  if( SCIPgetParam(targetscip, "limits/softtime") == NULL )
3194  return SCIP_OKAY;
3195  else
3196  {
3197  SCIP_Real timelimit = -1.0;
3198 
3199  SCIP_CALL( SCIPgetRealParam(sourcescip, "limits/softtime", &timelimit) );
3200  if( !SCIPisNegative(sourcescip, timelimit) )
3201  {
3202  timelimit -= SCIPgetSolvingTime(sourcescip);
3203  timelimit = MAX(0.0, timelimit);
3204  }
3205 
3206  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/softtime", timelimit) );
3207  }
3208  return SCIP_OKAY;
3209 }
3210 
3211 /** return updated memory limit for a sub-SCIP */
3212 static
3214  SCIP* sourcescip, /**< source SCIP data structure */
3215  SCIP_Real* memorylimit /**< pointer to store sub-SCIP memory limit */
3216  )
3217 {
3218  SCIP_CALL( SCIPgetRealParam(sourcescip, "limits/memory", memorylimit) );
3219 
3220  /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
3221  if( !SCIPisInfinity(sourcescip, *memorylimit) )
3222  (*memorylimit) -= (SCIPgetMemUsed(sourcescip) + SCIPgetMemExternEstim(sourcescip))/1048576.0;
3223 
3224  return SCIP_OKAY;
3225 }
3226 
3227 /** checks if there is enough time and memory left for copying the sourcescip into a sub-SCIP and solve the sub-SCIP
3228  *
3229  * This is the case if the time and memory limit that would be passed to the sub-SCIP are larger than 0.0
3230  *
3231  * @pre This method can be called if sourcescip is in one of the following stages:
3232  * - \ref SCIP_STAGE_PROBLEM
3233  * - \ref SCIP_STAGE_TRANSFORMED
3234  * - \ref SCIP_STAGE_INITPRESOLVE
3235  * - \ref SCIP_STAGE_PRESOLVING
3236  * - \ref SCIP_STAGE_EXITPRESOLVE
3237  * - \ref SCIP_STAGE_PRESOLVED
3238  * - \ref SCIP_STAGE_INITSOLVE
3239  * - \ref SCIP_STAGE_SOLVING
3240  * - \ref SCIP_STAGE_SOLVED
3241  *
3242  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3243  */
3245  SCIP* sourcescip, /**< source SCIP data structure */
3246  SCIP_Bool* success /**< pointer to store whether there is time and memory left to copy the
3247  * problem and run the sub-SCIP */
3248  )
3249 {
3250  SCIP_Real timelimit;
3251 
3252  SCIP_CALL( getCopyTimelimit(sourcescip, &timelimit) );
3253 
3254  if( sourcescip->set->misc_avoidmemout )
3255  {
3256  SCIP_Real memorylimit;
3257 
3258  /* try to avoid running into memory limit */
3259  SCIP_CALL( getCopyMemlimit(sourcescip, &memorylimit) );
3260  *success = timelimit > 0.0 && memorylimit > 2.0 * SCIPgetMemExternEstim(sourcescip) / 1048576.0;
3261  }
3262  else
3263  *success = timelimit > 0.0;
3264 
3265  return SCIP_OKAY;
3266 }
3267 
3268 /** copies limits from source SCIP to target SCIP
3269  *
3270  * @note time and memory limit are reduced by the amount already spent in the source SCIP before installing the limit
3271  * in the target SCIP
3272  * @note all other limits are disabled and need to be enabled afterwards, if needed
3273  *
3274  * @pre This method can be called if sourcescip is in one of the following stages:
3275  * - \ref SCIP_STAGE_PROBLEM
3276  * - \ref SCIP_STAGE_TRANSFORMED
3277  * - \ref SCIP_STAGE_INITPRESOLVE
3278  * - \ref SCIP_STAGE_PRESOLVING
3279  * - \ref SCIP_STAGE_EXITPRESOLVE
3280  * - \ref SCIP_STAGE_PRESOLVED
3281  * - \ref SCIP_STAGE_INITSOLVE
3282  * - \ref SCIP_STAGE_SOLVING
3283  * - \ref SCIP_STAGE_SOLVED
3284  *
3285  * See \ref SCIP_Stage "SCIP_STAGE" for a complete list of all possible solving stages.
3286  */
3288  SCIP* sourcescip, /**< source SCIP data structure */
3289  SCIP* targetscip /**< target SCIP data structure */
3290  )
3291 {
3292  SCIP_Real timelimit;
3293  SCIP_Real memorylimit;
3294 
3295  SCIP_CALL( getCopyTimelimit(sourcescip, &timelimit) );
3296  SCIP_CALL( getCopyMemlimit(sourcescip, &memorylimit) );
3297 
3298  /* avoid negative limits */
3299  if( timelimit < 0.0 )
3300  timelimit = 0.0;
3301  if( memorylimit < 0.0 )
3302  memorylimit = 0.0;
3303 
3304  /* set time and memory limit to the adjusted values */
3305  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/time", timelimit) );
3306  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/memory", memorylimit) );
3307 
3308  /* copy and adjust soft time limit (or disable it) */
3309  SCIP_CALL( copySofttimelimit(sourcescip, targetscip) );
3310 
3311  /* disable all other limits */
3312  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/absgap", 0.0) );
3313  SCIP_CALL( SCIPsetIntParam(targetscip, "limits/bestsol", -1) );
3314  SCIP_CALL( SCIPsetRealParam(targetscip, "limits/gap", 0.0) );
3315  SCIP_CALL( SCIPsetLongintParam(targetscip, "limits/nodes", -1LL) );
3316  SCIP_CALL( SCIPsetIntParam(targetscip, "limits/restarts", -1) );
3317  SCIP_CALL( SCIPsetIntParam(targetscip, "limits/solutions", -1) );
3318  SCIP_CALL( SCIPsetLongintParam(targetscip, "limits/stallnodes", -1LL) );
3319  SCIP_CALL( SCIPsetLongintParam(targetscip, "limits/totalnodes", -1LL) );
3320 
3321  return SCIP_OKAY;
3322 }
3323 
3324 /** sets the working limits as well as common search parameters for the auxiliary problem
3325  *
3326  * @note memory and time limits are not affected, and must be set using SCIPcopyLimits() instead
3327  */
3329  SCIP* sourcescip, /**< source SCIP data structure */
3330  SCIP* subscip, /**< target SCIP data structure, often a copy of \p sourcescip */
3331  SCIP_Longint nsubnodes, /**< nodelimit for subscip, or -1 for no limit */
3332  SCIP_Longint nstallnodes, /**< stall node limit for subscip, or -1 for no limit */
3333  int bestsollimit /**< the limit on the number of best solutions found, or -1 for no limit */
3334  )
3335 {
3336  SCIP_Bool useuct;
3337 
3338  assert(sourcescip != NULL);
3339  assert(subscip != NULL);
3340 
3341  /* do not abort subproblem on CTRL-C */
3342  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/catchctrlc", FALSE) );
3343 
3344 #ifdef SCIP_DEBUG
3345  /* for debugging, enable full output */
3346  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 5) );
3347  SCIP_CALL( SCIPsetIntParam(subscip, "display/freq", 100000000) );
3348 #else
3349  /* disable statistic timing inside sub SCIP and output to console */
3350  SCIP_CALL( SCIPsetIntParam(subscip, "display/verblevel", 0) );
3351  SCIP_CALL( SCIPsetBoolParam(subscip, "timing/statistictiming", FALSE) );
3352 #endif
3353 
3354  /* set limits for the subproblem */
3355  SCIP_CALL( SCIPcopyLimits(sourcescip, subscip) );
3356  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nsubnodes) );
3357  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/stallnodes", nstallnodes) );
3358  SCIP_CALL( SCIPsetIntParam(subscip, "limits/bestsol", bestsollimit) );
3359 
3360  /* forbid recursive call of heuristics and separators solving subMIPs */
3361  SCIP_CALL( SCIPsetSubscipsOff(subscip, TRUE) );
3362 
3363  /* disable cutting plane separation */
3365 
3366  /* disable expensive presolving */
3368 
3369  /* use best estimate node selection */
3370  if( SCIPfindNodesel(subscip, "estimate") != NULL && !SCIPisParamFixed(subscip, "nodeselection/estimate/stdpriority") )
3371  {
3372  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/estimate/stdpriority", INT_MAX/4) );
3373  }
3374 
3375  /* activate uct node selection at the top of the tree */
3376  SCIP_CALL( SCIPgetBoolParam(sourcescip, "heuristics/useuctsubscip", &useuct) );
3377  if( useuct && SCIPfindNodesel(subscip, "uct") != NULL && !SCIPisParamFixed(subscip, "nodeselection/uct/stdpriority") )
3378  {
3379  SCIP_CALL( SCIPsetIntParam(subscip, "nodeselection/uct/stdpriority", INT_MAX/2) );
3380  }
3381 
3382  /* use inference branching */
3383  if( SCIPfindBranchrule(subscip, "inference") != NULL && !SCIPisParamFixed(subscip, "branching/inference/priority") )
3384  {
3385  SCIP_CALL( SCIPsetIntParam(subscip, "branching/inference/priority", INT_MAX/4) );
3386  }
3387 
3388  /* enable conflict analysis, disable analysis of boundexceeding LPs, and restrict conflict pool */
3389  if( !SCIPisParamFixed(subscip, "conflict/enable") )
3390  {
3391  SCIP_CALL( SCIPsetBoolParam(subscip, "conflict/enable", TRUE) );
3392  }
3393  if( !SCIPisParamFixed(subscip, "conflict/useboundlp") )
3394  {
3395  SCIP_CALL( SCIPsetCharParam(subscip, "conflict/useboundlp", 'o') );
3396  }
3397  if( !SCIPisParamFixed(subscip, "conflict/maxstoresize") )
3398  {
3399  SCIP_CALL( SCIPsetIntParam(subscip, "conflict/maxstoresize", 100) );
3400  }
3401 
3402  /* speed up sub-SCIP by not checking dual LP feasibility */
3403  SCIP_CALL( SCIPsetBoolParam(subscip, "lp/checkdualfeas", FALSE) );
3404 
3405  return SCIP_OKAY;
3406 }
SCIP_STAT * stat
Definition: struct_scip.h:79
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition: type_lp.h:59
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2090
SCIP_RETCODE SCIPflattenVarAggregationGraph(SCIP *scip, SCIP_VAR *var)
Definition: scip_var.c:1693
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:378
SCIP_Bool SCIPmessagehdlrIsQuiet(SCIP_MESSAGEHDLR *messagehdlr)
Definition: message.c:910
SCIP_RETCODE SCIPsetSeparating(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:958
SCIP_VAR ** SCIPcliqueGetVars(SCIP_CLIQUE *clique)
Definition: implics.c:3377
int SCIPgetNDelayedPoolCuts(SCIP *scip)
Definition: scip_cut.c:695
SCIP_RETCODE SCIPsyncstoreRelease(SCIP_SYNCSTORE **syncstore)
Definition: syncstore.c:87
public methods for SCIP parameter handling
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:365
SCIP_RETCODE SCIPsetCopyPlugins(SCIP_SET *sourceset, SCIP_SET *targetset, SCIP_Bool copyreaders, SCIP_Bool copypricers, SCIP_Bool copyconshdlrs, SCIP_Bool copyconflicthdlrs, SCIP_Bool copypresolvers, SCIP_Bool copyrelaxators, SCIP_Bool copyseparators, SCIP_Bool copycutselectors, SCIP_Bool copypropagators, SCIP_Bool copyheuristics, SCIP_Bool copyeventhdlrs, SCIP_Bool copynodeselectors, SCIP_Bool copybranchrules, SCIP_Bool copydisplays, SCIP_Bool copydialogs, SCIP_Bool copytables, SCIP_Bool copyexprhdlrs, SCIP_Bool copynlpis, SCIP_Bool *allvalid)
Definition: set.c:936
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:8349
SCIP_Real * SCIPvarGetMultaggrScalars(SCIP_VAR *var)
Definition: var.c:17715
SCIP_RETCODE SCIPcopyOrigProb(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *name)
Definition: scip_copy.c:580
SCIP_NLPI * SCIPsetFindNlpi(SCIP_SET *set, const char *name)
Definition: set.c:5195
SCIP_Bool SCIPprobIsConsCompressionEnabled(SCIP_PROB *prob)
Definition: prob.c:2433
public methods for node selector plugins
public methods for memory management
SCIP_RETCODE SCIPaddOrigObjoffset(SCIP *scip, SCIP_Real addval)
Definition: scip_prob.c:1298
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip_cons.c:886
public methods for implications, variable bounds, and cliques
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip_param.c:307
int SCIPconflictstoreGetNConflictsInStore(SCIP_CONFLICTSTORE *conflictstore)
#define SCIP_MAXSTRLEN
Definition: def.h:302
SCIP_RETCODE SCIPsetMessagehdlr(SCIP *scip, SCIP_MESSAGEHDLR *messagehdlr)
Definition: scip_message.c:64
#define SCIP_DECOMPSTORE_CAPA
Definition: dcmp.h:48
SCIP_PRIMAL * origprimal
Definition: struct_scip.h:81
SCIP_RETCODE SCIPaddSolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool *stored)
Definition: scip_sol.c:3025
internal methods for clocks and timing issues
SCIP_VAR ** SCIPvarGetMultaggrVars(SCIP_VAR *var)
Definition: var.c:17703
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:17216
SCIP_RETCODE SCIPcopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip_copy.c:2866
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17979
SCIP_CUT ** SCIPgetDelayedPoolCuts(SCIP *scip)
Definition: scip_cut.c:679
public solving methods
public methods for timing
#define SCIPdebugSolDataCreate(debugsoldata)
Definition: debug.h:278
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:17354
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip_var.c:1248
static SCIP_RETCODE doCopy(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool useconscompression, SCIP_Bool global, SCIP_Bool original, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip_copy.c:2645
SCIP_CONCURRENT * concurrent
Definition: struct_scip.h:110
SCIP_Bool history_allowmerge
Definition: struct_set.h:302
SCIP_RETCODE SCIPconvertCutsToConss(SCIP *scip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, int *ncutsadded)
Definition: scip_copy.c:2063
static SCIP_RETCODE copyVars(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool original, SCIP_Bool global)
Definition: scip_copy.c:946
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1874
void SCIPclockStop(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:360
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4554
SCIP_SOL ** SCIPgetSols(SCIP *scip)
Definition: scip_sol.c:2263
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:17295
#define FALSE
Definition: def.h:96
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3024
void SCIPsetSubscipDepth(SCIP *scip, int newdepth)
Definition: scip_copy.c:2621
char sepa_cutselrestart
Definition: struct_set.h:551
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3287
SCIP_RETCODE SCIPcopyOrig(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip_copy.c:3041
int SCIPgetSubscipDepth(SCIP *scip)
Definition: scip_copy.c:2600
void SCIPclockStart(SCIP_CLOCK *clck, SCIP_SET *set)
Definition: clock.c:290
int SCIPgetNActivePricers(SCIP *scip)
Definition: scip_pricer.c:348
SCIP_Real SCIPinfinity(SCIP *scip)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10788
SCIP_STAGE stage
Definition: struct_set.h:74
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
#define TRUE
Definition: def.h:95
SCIP_Real SCIPcutGetLPActivityQuot(SCIP_CUT *cut)
Definition: cutpool.c:406
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
SCIP_Bool SCIPcliqueIsEquation(SCIP_CLIQUE *clique)
Definition: implics.c:3433
void SCIPnlpiMergeStatistics(SCIP_NLPI *targetnlpi, SCIP_NLPI *sourcenlpi, SCIP_Bool reset)
Definition: nlpi.c:833
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:932
enum SCIP_Varstatus SCIP_VARSTATUS
Definition: type_var.h:57
SCIP_BRANCHRULE * SCIPfindBranchrule(SCIP *scip, const char *name)
Definition: scip_branch.c:297
SCIP_RETCODE SCIPtranslateSubSol(SCIP *scip, SCIP *subscip, SCIP_SOL *subsol, SCIP_HEUR *heur, SCIP_VAR **subvars, SCIP_SOL **newsol)
Definition: scip_copy.c:1408
SCIP_Real SCIPvarGetAggrScalar(SCIP_VAR *var)
Definition: var.c:17667
public methods for problem variables
static SCIP_RETCODE getCopyTimelimit(SCIP *sourcescip, SCIP_Real *timelimit)
Definition: scip_copy.c:3174
const char * SCIPnlpiGetName(SCIP_NLPI *nlpi)
Definition: nlpi.c:722
SCIP_RETCODE SCIPtranslateSubSols(SCIP *scip, SCIP *subscip, SCIP_HEUR *heur, SCIP_VAR **subvars, SCIP_Bool *success, int *solindex)
Definition: scip_copy.c:1448
SCIP_RETCODE SCIPgetOrigVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:2365
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
Definition: scip_message.c:88
SCIP_PROB * transprob
Definition: struct_scip.h:98
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3211
SCIP_CLOCK * copyclock
Definition: struct_stat.h:178
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:136
#define SCIPdebugPrintCons(x, y, z)
Definition: pub_message.h:102
SCIP_Bool SCIPisTransformed(SCIP *scip)
Definition: scip_general.c:575
public methods for SCIP variables
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
Definition: var.c:17749
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition: scip_param.c:603
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:8359
SCIP_RETCODE SCIPcopyPlugins(SCIP *sourcescip, SCIP *targetscip, SCIP_Bool copyreaders, SCIP_Bool copypricers, SCIP_Bool copyconshdlrs, SCIP_Bool copyconflicthdlrs, SCIP_Bool copypresolvers, SCIP_Bool copyrelaxators, SCIP_Bool copyseparators, SCIP_Bool copycutselectors, SCIP_Bool copypropagators, SCIP_Bool copyheuristics, SCIP_Bool copyeventhdlrs, SCIP_Bool copynodeselectors, SCIP_Bool copybranchrules, SCIP_Bool copydisplays, SCIP_Bool copydialogs, SCIP_Bool copytables, SCIP_Bool copyexprhdlrs, SCIP_Bool copynlpis, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip_copy.c:275
#define SCIPdebugMsg
Definition: scip_message.h:78
SCIP_RETCODE SCIPcopyParamSettings(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:2559
SCIP_CUT ** SCIPgetPoolCuts(SCIP *scip)
Definition: scip_cut.c:402
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:8151
SCIP_PROB * origprob
Definition: struct_scip.h:80
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2180
SCIP_RETCODE SCIPcopyBenders(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_Bool threadsafe, SCIP_Bool *valid)
Definition: scip_copy.c:357
public methods for numerical tolerances
internal methods for collecting primal CIP solutions and primal informations
SCIP_RETCODE SCIPconflictstoreCreate(SCIP_CONFLICTSTORE **conflictstore, SCIP_SET *set)
SCIP_Bool SCIPconsIsOriginal(SCIP_CONS *cons)
Definition: cons.c:8389
int SCIPgetNConshdlrs(SCIP *scip)
Definition: scip_cons.c:910
public methods for querying solving statistics
const char * SCIPgetProbName(SCIP *scip)
Definition: scip_prob.c:1075
SCIP_Bool SCIProwIsInLP(SCIP_ROW *row)
Definition: lp.c:17526
SCIP_NLPI ** nlpis
Definition: struct_set.h:107
SCIP_RETCODE SCIPcopyOrigConss(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool enablepricing, SCIP_Bool *valid)
Definition: scip_copy.c:1930
int SCIPgetNFixedVars(SCIP *scip)
Definition: scip_prob.c:2317
SCIP_VAR ** SCIPgetFixedVars(SCIP *scip)
Definition: scip_prob.c:2274
SCIP_RETCODE SCIPaddClique(SCIP *scip, SCIP_VAR **vars, SCIP_Bool *values, int nvars, SCIP_Bool isequation, SCIP_Bool *infeasible, int *nbdchgs)
Definition: scip_var.c:6921
SCIP_RETCODE SCIPenableConsCompression(SCIP *scip)
Definition: scip_copy.c:621
static SCIP_RETCODE getCopyMemlimit(SCIP *sourcescip, SCIP_Real *memorylimit)
Definition: scip_copy.c:3213
SCIP_MEM * mem
Definition: struct_scip.h:71
public methods for managing constraints
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
Definition: scip_prob.c:1250
SCIP_Real mincopytime
Definition: struct_stat.h:141
void SCIPvarMergeHistories(SCIP_VAR *targetvar, SCIP_VAR *othervar, SCIP_STAT *stat)
Definition: var.c:4513
internal methods for storing and manipulating the main problem
#define SCIPerrorMessage
Definition: pub_message.h:64
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4182
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:219
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2778
SCIP_CONSHDLR ** SCIPgetConshdlrs(SCIP *scip)
Definition: scip_cons.c:899
SCIP_SYNCSTORE * syncstore
Definition: struct_scip.h:109
SCIP_RETCODE SCIPfreeProb(SCIP *scip)
Definition: scip_prob.c:702
void SCIPprobEnableConsCompression(SCIP_PROB *prob)
Definition: prob.c:2443
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:17404
SCIP_RETCODE SCIPcopyVars(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool global)
Definition: scip_copy.c:1178
SCIP_RETCODE SCIPaddVarImplication(SCIP *scip, SCIP_VAR *var, SCIP_Bool varfixing, SCIP_VAR *implvar, SCIP_BOUNDTYPE impltype, SCIP_Real implbound, SCIP_Bool *infeasible, int *nbdchgs)
Definition: scip_var.c:6780
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2187
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:429
char sepa_cutselsubscip
Definition: struct_set.h:552
SCIP_RETCODE SCIPcopyCuts(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, int *ncutsadded)
Definition: scip_copy.c:2125
int nbenders
Definition: struct_set.h:158
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:57
SCIP_CONFLICTSTORE * conflictstore
Definition: struct_scip.h:104
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:8090
SCIP_Real SCIPvarGetAggrConstant(SCIP_VAR *var)
Definition: var.c:17679
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
Definition: cons.c:8309
SCIP_CONS ** SCIPgetOrigConss(SCIP *scip)
Definition: scip_prob.c:3169
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:17264
SCIP_Real SCIPclockGetTime(SCIP_CLOCK *clck)
Definition: clock.c:438
SCIP_REOPT * reopt
Definition: struct_scip.h:85
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3058
SCIP_RETCODE SCIPmergeVariableStatistics(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR **sourcevars, SCIP_VAR **targetvars, int nvars)
Definition: scip_copy.c:1265
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
Definition: scip_param.c:250
#define NULL
Definition: lpi_spx1.cpp:164
static SCIP_RETCODE copyCuts(SCIP *sourcescip, SCIP *targetscip, SCIP_CUT **cuts, int ncuts, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, int *ncutsadded)
Definition: scip_copy.c:126
SCIP_PARAM * SCIPgetParam(SCIP *scip, const char *name)
Definition: scip_param.c:234
public methods for problem copies
SCIP_ROW * SCIPcutGetRow(SCIP_CUT *cut)
Definition: cutpool.c:382
public methods for primal CIP solutions
SCIP_RETCODE SCIPcopyOrigVars(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars)
Definition: scip_copy.c:1235
SCIP_Bool misc_avoidmemout
Definition: struct_set.h:401
internal methods for global SCIP settings
internal methods for storing conflicts
static SCIP_RETCODE translateSubSol(SCIP *scip, SCIP *subscip, SCIP_SOL *subsol, SCIP_VAR **subvars, SCIP_Real *solvals)
Definition: scip_copy.c:1368
#define SCIP_CALL(x)
Definition: def.h:394
SCIP main data structure.
int SCIPgetNOrigConss(SCIP *scip)
Definition: scip_prob.c:3142
SCIP_Real SCIPvarGetMultaggrConstant(SCIP_VAR *var)
Definition: var.c:17727
SCIP_Bool SCIPvarIsRelaxationOnly(SCIP_VAR *var)
Definition: var.c:17551
static SCIP_RETCODE copyProb(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool original, SCIP_Bool global, const char *name)
Definition: scip_copy.c:400
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:17305
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8329
SCIP_Bool SCIPsetIsEQ(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6237
SCIP_RETCODE SCIPcaptureCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_cons.c:1084
SCIP_RETCODE SCIPcopyImplicationsCliques(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, SCIP_Bool *infeasible, int *nbdchgs, int *ncopied)
Definition: scip_copy.c:2375
SCIP_Bool SCIProwIsModifiable(SCIP_ROW *row)
Definition: lp.c:17414
SCIP_DEBUGSOLDATA * debugsoldata
Definition: struct_set.h:111
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:17241
SCIP_DECOMPSTORE * decompstore
Definition: struct_scip.h:82
public methods for constraint handler plugins and constraints
SCIP_RETCODE SCIPsetCommonSubscipParams(SCIP *sourcescip, SCIP *subscip, SCIP_Longint nsubnodes, SCIP_Longint nstallnodes, int bestsollimit)
Definition: scip_copy.c:3328
SCIP_RETCODE SCIPcopyConflicts(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool *valid)
Definition: scip_copy.c:2217
SCIP_RETCODE SCIPgetConsCopy(SCIP *sourcescip, SCIP *targetscip, SCIP_CONS *sourcecons, SCIP_CONS **targetcons, SCIP_CONSHDLR *sourceconshdlr, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *name, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode, SCIP_Bool global, SCIP_Bool *valid)
Definition: scip_copy.c:1586
SCIP_RETCODE SCIPcopyConsCompression(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip_copy.c:2960
internal methods for problem variables
the function declarations for the synchronization store
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:124
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:17251
public data structures and miscellaneous methods
SCIP_BOUNDTYPE * SCIPvarGetImplTypes(SCIP_VAR *var, SCIP_Bool varfixing)
Definition: var.c:18233
SCIP_RETCODE SCIPcheckSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *feasible)
Definition: scip_sol.c:3450
#define SCIP_Bool
Definition: def.h:93
int SCIPgetNImplVars(SCIP *scip)
Definition: scip_prob.c:2135
SCIP_Real SCIPgetOrigObjscale(SCIP *scip)
Definition: scip_prob.c:1352
public methods for storing cuts in a cut pool
static SCIP_RETCODE copySofttimelimit(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3188
void SCIPconsSetModifiable(SCIP_CONS *cons, SCIP_Bool modifiable)
Definition: cons.c:6665
SCIP_RETCODE SCIPstatCreate(SCIP_STAT **stat, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_MESSAGEHDLR *messagehdlr)
Definition: stat.c:55
int SCIPvarGetNImpls(SCIP_VAR *var, SCIP_Bool varfixing)
Definition: var.c:18201
SCIP_RETCODE SCIPcopyConss(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, SCIP_Bool enablepricing, SCIP_Bool *valid)
Definition: scip_copy.c:1725
#define MAX(x, y)
Definition: tclique_def.h:92
SCIP_RETCODE SCIPsetCopyParams(SCIP_SET *sourceset, SCIP_SET *targetset, SCIP_MESSAGEHDLR *messagehdlr)
Definition: set.c:1162
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
Definition: scip_message.c:108
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:8110
methods for debugging
SCIP_Bool * SCIPcliqueGetValues(SCIP_CLIQUE *clique)
Definition: implics.c:3389
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:487
public methods for LP management
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
Definition: cons.c:8219
datastructures for block memory pools and memory buffers
SCIP_BENDERS ** benders
Definition: struct_set.h:110
public methods for cuts and aggregation rows
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:985
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8289
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:8259
SCIP_VAR * SCIPvarGetAggrVar(SCIP_VAR *var)
Definition: var.c:17655
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2214
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8276
int SCIPgetNRuns(SCIP *scip)
SCIP_Real maxcopytime
Definition: struct_stat.h:140
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1444
Constraint handler for linear constraints in their most general form, .
SCIP_RETCODE SCIPvarCopy(SCIP_VAR **var, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP *sourcescip, SCIP_VAR *sourcevar, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global)
Definition: var.c:2163
datastructures for problem statistics
int SCIPvarGetMultaggrNVars(SCIP_VAR *var)
Definition: var.c:17691
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Real * SCIPvarGetImplBounds(SCIP_VAR *var, SCIP_Bool varfixing)
Definition: var.c:18247
SCIP * scip
Definition: struct_var.h:288
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2045
int SCIPconshdlrGetNActiveConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4631
public methods for NLP solver interfaces
public methods for variable pricer plugins
SCIP_RETCODE SCIPsetCharParam(SCIP *scip, const char *name, char value)
Definition: scip_param.c:661
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:2000
SCIP_RETCODE SCIPbendersCopyInclude(SCIP_BENDERS *benders, SCIP_SET *sourceset, SCIP_SET *targetset, SCIP_HASHMAP *varmap, SCIP_Bool threadsafe, SCIP_Bool *valid)
Definition: benders.c:927
SCIP_VAR ** SCIPvarGetImplVars(SCIP_VAR *var, SCIP_Bool varfixing)
Definition: var.c:18218
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
internal methods for decompositions and the decomposition store
SCIP_CLIQUE ** SCIPgetCliques(SCIP *scip)
Definition: scip_var.c:7629
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:17261
public methods for branching rule plugins and branching
SCIP_RETCODE SCIPcopyProb(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, const char *name)
Definition: scip_copy.c:527
SCIP_RETCODE SCIPcopyOrigConsCompression(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, const char *suffix, SCIP_VAR **fixedvars, SCIP_Real *fixedvals, int nfixedvars, SCIP_Bool enablepricing, SCIP_Bool threadsafe, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip_copy.c:3128
general public methods
BMS_BLKMEM * probmem
Definition: struct_mem.h:49
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:17045
public methods for solutions
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:100
SCIP_RETCODE SCIPgetVarCopy(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR *sourcevar, SCIP_VAR **targetvar, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, SCIP_Bool *success)
Definition: scip_copy.c:711
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip_prob.c:1676
SCIP_CONS ** SCIPconshdlrGetCheckConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4574
int SCIPgetNConss(SCIP *scip)
Definition: scip_prob.c:3050
SCIP_Bool SCIPisConsCompressionEnabled(SCIP *scip)
Definition: scip_copy.c:660
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1119
SCIP_RETCODE SCIPprobCopy(SCIP_PROB **prob, BMS_BLKMEM *blkmem, SCIP_SET *set, const char *name, SCIP *sourcescip, SCIP_PROB *sourceprob, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global)
Definition: prob.c:201
SCIP_SET * set
Definition: struct_scip.h:72
public methods for message output
int SCIPgetNCliques(SCIP *scip)
Definition: scip_var.c:7575
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:126
SCIP_NODESEL * SCIPfindNodesel(SCIP *scip, const char *name)
Definition: scip_nodesel.c:234
datastructures for problem variables
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17383
SCIP_Real sepa_minactivityquot
Definition: struct_set.h:546
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:75
#define SCIP_Real
Definition: def.h:186
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:8339
internal methods for problem statistics
SCIP_RETCODE SCIPconflictstoreAddConflict(SCIP_CONFLICTSTORE *conflictstore, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_TREE *tree, SCIP_PROB *transprob, SCIP_REOPT *reopt, SCIP_CONS *cons, SCIP_CONFTYPE conftype, SCIP_Bool cutoffinvolved, SCIP_Real primalbound)
int SCIPconshdlrGetNCheckConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4617
public methods for message handling
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:8279
int SCIPgetNPoolCuts(SCIP *scip)
Definition: scip_cut.c:420
int nnlpis
Definition: struct_set.h:152
internal methods for constraints and constraint handlers
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:8269
SCIP_RETCODE SCIPconsCopy(SCIP_CONS **cons, SCIP_SET *set, const char *name, SCIP *sourcescip, SCIP_CONSHDLR *sourceconshdlr, SCIP_CONS *sourcecons, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode, SCIP_Bool global, SCIP_Bool *valid)
Definition: cons.c:5960
SCIP_Real SCIPgetOrigObjoffset(SCIP *scip)
Definition: scip_prob.c:1327
#define SCIP_Longint
Definition: def.h:171
SCIP_RETCODE SCIPcheckCopyLimits(SCIP *sourcescip, SCIP_Bool *success)
Definition: scip_copy.c:3244
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17429
SCIP_OBJSENSE SCIPgetObjsense(SCIP *scip)
Definition: scip_prob.c:1233
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1263
static SCIP_Bool takeCut(SCIP *scip, SCIP_CUT *cut, char cutsel)
Definition: scip_copy.c:93
void SCIPmergeNLPIStatistics(SCIP *sourcescip, SCIP *targetscip, SCIP_Bool reset)
Definition: scip_copy.c:1330
SCIP_RETCODE SCIPsyncstoreCapture(SCIP_SYNCSTORE *syncstore)
Definition: syncstore.c:122
SCIP_Bool SCIPconsIsConflict(SCIP_CONS *cons)
Definition: cons.c:8239
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17989
int SCIPcliqueGetNVars(SCIP_CLIQUE *clique)
Definition: implics.c:3367
SCIP_RETCODE SCIPprimalCreate(SCIP_PRIMAL **primal)
Definition: primal.c:130
int SCIPcutGetAge(SCIP_CUT *cut)
Definition: cutpool.c:392
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:3106
#define SCIP_CALL_ABORT(x)
Definition: def.h:373
SCIP_VAR * SCIPvarGetTransVar(SCIP_VAR *var)
Definition: var.c:17623
#define SCIPABORT()
Definition: def.h:366
public methods for global and local (sub)problems
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1361
SCIP_Bool SCIPisInRestart(SCIP *scip)
Definition: scip_solve.c:3714
datastructures for global SCIP settings
int SCIPsolGetIndex(SCIP_SOL *sol)
Definition: sol.c:2644
SCIP_RETCODE SCIPdecompstoreCreate(SCIP_DECOMPSTORE **decompstore, BMS_BLKMEM *blkmem, int nslots)
Definition: dcmp.c:499
SCIP_RETCODE SCIPsetSubscipsOff(SCIP *scip, SCIP_Bool quiet)
Definition: scip_param.c:883
int subscipdepth
Definition: struct_stat.h:217
SCIP_RETCODE SCIPconflictstoreGetConflicts(SCIP_CONFLICTSTORE *conflictstore, SCIP_CONS **conflicts, int conflictsize, int *nconflicts)
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip_param.c:545
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
Definition: scip_var.c:1527
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:328
memory allocation routines