Scippy

SCIP

Solving Constraint Integer Programs

cons_components.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-2020 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file cons_components.c
17  * @ingroup DEFPLUGINS_CONS
18  * @brief constraint handler for handling independent components
19  * @author Gerald Gamrath
20  *
21  * This constraint handler looks for independent components.
22  */
23 /*#define DETAILED_OUTPUT*/
24 /*#define SCIP_DEBUG*/
25 /*#define SCIP_MORE_DEBUG*/
26 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
27 
28 #include "blockmemshell/memory.h"
29 #include "scip/cons_components.h"
30 #include "scip/debug.h"
31 #include "scip/pub_cons.h"
32 #include "scip/pub_heur.h"
33 #include "scip/pub_message.h"
34 #include "scip/pub_misc.h"
35 #include "scip/pub_misc_sort.h"
36 #include "scip/pub_sol.h"
37 #include "scip/pub_tree.h"
38 #include "scip/pub_var.h"
39 #include "scip/scip_cons.h"
40 #include "scip/scip_copy.h"
42 #include "scip/scip_general.h"
43 #include "scip/scip_heur.h"
44 #include "scip/scip_mem.h"
45 #include "scip/scip_message.h"
46 #include "scip/scip_numerics.h"
47 #include "scip/scip_param.h"
48 #include "scip/scip_pricer.h"
49 #include "scip/scip_prob.h"
50 #include "scip/scip_probing.h"
51 #include "scip/scip_sol.h"
52 #include "scip/scip_solve.h"
53 #include "scip/scip_solvingstats.h"
54 #include "scip/scip_timing.h"
55 #include "scip/scip_tree.h"
56 #include "scip/scip_var.h"
57 #include <string.h>
58 
59 #define CONSHDLR_NAME "components"
60 #define CONSHDLR_DESC "independent components constraint handler"
61 #define CONSHDLR_ENFOPRIORITY 0 /**< priority of the constraint handler for constraint enforcing */
62 #define CONSHDLR_CHECKPRIORITY -9999999 /**< priority of the constraint handler for checking feasibility */
63 #define CONSHDLR_EAGERFREQ -1 /**< frequency for using all instead of only the useful constraints in separation,
64  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
65 #define CONSHDLR_NEEDSCONS FALSE /**< should the constraint handler be skipped, if no constraints are available? */
66 
67 #define CONSHDLR_PROPFREQ 1 /**< frequency for propagating domains; zero means only preprocessing propagation */
68 #define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
69 #define CONSHDLR_DELAYPROP TRUE /**< should propagation method be delayed, if other propagators found reductions? */
70 
71 #define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_FINAL /**< presolving timing of the constraint handler (fast, medium, or exhaustive) */
72 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP /**< propagation timing mask of the constraint handler*/
73 
74 #define DEFAULT_MAXDEPTH -1 /**< maximum depth of a node to run components detection (-1: disable component detection during solving) */
75 #define DEFAULT_MAXINTVARS 500 /**< maximum number of integer (or binary) variables to solve a subproblem directly in presolving (-1: no solving) */
76 #define DEFAULT_MINSIZE 50 /**< minimum absolute size (in terms of variables) to solve a component individually during branch-and-bound */
77 #define DEFAULT_MINRELSIZE 0.1 /**< minimum relative size (in terms of variables) to solve a component individually during branch-and-bound */
78 #define DEFAULT_NODELIMIT 10000LL /**< maximum number of nodes to be solved in subproblems during presolving */
79 #define DEFAULT_INTFACTOR 1.0 /**< the weight of an integer variable compared to binary variables */
80 #define DEFAULT_FEASTOLFACTOR 1.0 /**< default value for parameter to increase the feasibility tolerance in all sub-SCIPs */
81 
82 /*
83  * Data structures
84  */
85 
86 /** data related to one problem (see below) */
87 typedef struct Problem PROBLEM;
88 
89 /** data related to one component */
90 typedef struct Component
91 {
92  PROBLEM* problem; /**< the problem this component belongs to */
93  SCIP* subscip; /**< sub-SCIP representing the component */
94  SCIP_SOL* workingsol; /**< working solution for transferring solutions into the sub-SCIP */
95  SCIP_VAR** vars; /**< variables belonging to this component (in complete problem) */
96  SCIP_VAR** subvars; /**< variables belonging to this component (in subscip) */
97  SCIP_VAR** fixedvars; /**< variables in the original SCIP which were copied while copying the component's
98  * constraints, but do not count to the subvars, because they were locally fixed */
99  SCIP_VAR** fixedsubvars; /**< variables in the sub-SCIP which were copied while copying the component's
100  * constraints, but do not count to the subvars, because they were locally fixed */
101  SCIP_Real fixedvarsobjsum; /**< objective contribution of all locally fixed variables */
102  SCIP_Real lastdualbound; /**< dual bound after last optimization call for this component */
103  SCIP_Real lastprimalbound; /**< primal bound after last optimization call for this component */
104  SCIP_STATUS laststatus; /**< solution status of last optimization call for the sub-SCIP of this component */
105  SCIP_Bool solved; /**< was this component solved already? */
106  int ncalls; /**< number of optimization calls for this component */
107  int lastsolindex; /**< index of best solution after last optimization call for this component */
108  int lastbestsolindex; /**< index of last best solution transferred to this component from the main problem */
109  int nvars; /**< number of variables belonging to this component */
110  int nfixedvars; /**< number of fixed variables copied during constraint copying */
111  int fixedvarssize; /**< size of fixedvars and fixedsubvars arrays */
112  int number; /**< component number */
114 
115 /** data related to one problem
116  * (corresponding to one node in the branch-and-bound tree and consisting of multiple components)
117  */
118 struct Problem
119 {
120  SCIP* scip; /**< the SCIP instance this problem belongs to */
121  COMPONENT* components; /**< independent components into which the problem can be divided */
122  SCIP_PQUEUE* compqueue; /**< priority queue for components */
123  SCIP_SOL* bestsol; /**< best solution found so far for the problem */
124  char* name; /**< name of the problem */
125  SCIP_Real fixedvarsobjsum; /**< objective contribution of all locally fixed variables */
126  SCIP_Real lowerbound; /**< lower bound of the problem */
127  int ncomponents; /**< number of independent components into which the problem can be divided */
128  int componentssize; /**< size of components array */
129  int nfeascomps; /**< number of components for which a feasible solution was found */
130  int nsolvedcomps; /**< number of components solved to optimality */
131  int nlowerboundinf; /**< number of components with lower bound equal to -infinity */
132 };
133 
134 
135 /** constraint handler data */
136 struct SCIP_ConshdlrData
137 {
138  SCIP_Longint nodelimit; /**< maximum number of nodes to be solved in subproblems */
139  SCIP_Real intfactor; /**< the weight of an integer variable compared to binary variables */
140  SCIP_Real feastolfactor; /**< parameter to increase the feasibility tolerance in all sub-SCIPs */
141  int maxintvars; /**< maximum number of integer (or binary) variables to solve a subproblem
142  * directly (-1: no solving) */
143  int maxdepth; /**< maximum depth of a node to run components detection (-1: disable
144  * component detection during solving) */
145  int minsize; /**< minimum absolute size (in terms of variables) to solve a component
146  * individually during branch-and-bound */
147  SCIP_Real minrelsize; /**< minimum relative size (in terms of variables) to solve a component
148  * individually during branch-and-bound */
149  int subscipdepth; /**< depth offset of the current (sub-)problem compared to the original
150  * problem */
151 };
152 
153 
154 /** comparison method for sorting components */
155 static
156 SCIP_DECL_SORTPTRCOMP(componentSort)
157 {
158  SCIP* scip;
159  COMPONENT* comp1;
160  COMPONENT* comp2;
161  SCIP_Real gap1;
162  SCIP_Real gap2;
163 
164  assert(elem1 != NULL);
165  assert(elem2 != NULL);
166 
167  comp1 = (COMPONENT*)elem1;
168  comp2 = (COMPONENT*)elem2;
169 
170  if( comp1->ncalls == 0 )
171  if( comp2->ncalls == 0 )
172  return comp1->number - comp2->number;
173  else
174  return -1;
175  else if( comp2->ncalls == 0 )
176  return 1;
177 
178  /* the main sorting criterion is the absolute gap; however, we devide it by the number of solving calls for this
179  * component to diversify the search if one component does not improve
180  * @todo investigate other sorting criteria
181  */
182  gap1 = SQR(comp1->lastprimalbound - comp1->lastdualbound) / comp1->ncalls;
183  gap2 = SQR(comp2->lastprimalbound - comp2->lastdualbound) / comp2->ncalls;
184 
185  assert(comp1->problem != NULL);
186  assert(comp1->problem == comp2->problem);
187  assert(comp1->problem->scip == comp2->problem->scip);
188 
189  scip = comp1->problem->scip;
190  assert(scip != NULL);
191 
192  if( SCIPisFeasGT(scip, gap1, gap2) )
193  return -1;
194  else if( SCIPisFeasLT(scip, gap1, gap2) )
195  return +1;
196  else
197  return comp1->number - comp2->number;
198 }
199 
200 /** returns minimum size of components to be solved individually during the branch-and-bound search */
201 static
202 int getMinsize(
203  SCIP* scip, /**< main SCIP data structure */
204  SCIP_CONSHDLRDATA* conshdlrdata /**< constraint handler data */
205  )
206 {
207  int minsize;
208 
209  assert(conshdlrdata != NULL);
210 
211  minsize = (int)(conshdlrdata->minrelsize * SCIPgetNVars(scip));
212  minsize = MAX(minsize, conshdlrdata->minsize);
213 
214  return minsize;
215 }
216 
217 /** initialize component structure */
218 static
220  PROBLEM* problem /**< subproblem structure */
221  )
222 {
223  COMPONENT* component;
224  SCIP* scip;
225 
226  assert(problem != NULL);
227  assert(problem->ncomponents < problem->componentssize);
228 
229  scip = problem->scip;
230  assert(scip != NULL);
231 
232  component = &problem->components[problem->ncomponents];
233 
234  component->problem = problem;
235  component->subscip = NULL;
236  component->workingsol = NULL;
237  component->vars = NULL;
238  component->subvars = NULL;
239  component->fixedvars = NULL;
240  component->fixedsubvars = NULL;
241  component->fixedvarsobjsum = 0.0;
242  component->lastdualbound = -SCIPinfinity(scip);
243  component->lastprimalbound = SCIPinfinity(scip);
244  component->laststatus = SCIP_STATUS_UNKNOWN;
245  component->solved = FALSE;
246  component->ncalls = 0;
247  component->lastsolindex = -1;
248  component->lastbestsolindex = -1;
249  component->nvars = 0;
250  component->nfixedvars = 0;
251  component->fixedvarssize = 0;
252  component->number = problem->ncomponents;
253 
254  ++problem->ncomponents;
255 
256  return SCIP_OKAY;
257 }
258 
259 /** free component structure */
260 static
262  COMPONENT* component /**< pointer to component structure */
263  )
264 {
265  PROBLEM* problem;
266  SCIP* scip;
267 
268  assert(component != NULL);
269 
270  problem = component->problem;
271  assert(problem != NULL);
272 
273  scip = problem->scip;
274  assert(scip != NULL);
275 
276  SCIPdebugMsg(scip, "freeing component %d of problem <%s>\n", component->number, component->problem->name);
277 
278  assert((component->vars != NULL) == (component->subvars != NULL));
279  if( component->vars != NULL )
280  {
281  SCIPfreeBlockMemoryArray(scip, &component->vars, component->nvars);
282  SCIPfreeBlockMemoryArray(scip, &component->subvars, component->nvars);
283  }
284 
285  assert((component->fixedvars != NULL) == (component->fixedsubvars != NULL));
286  if( component->fixedvars != NULL )
287  {
288  SCIPfreeBlockMemoryArray(scip, &component->fixedsubvars, component->fixedvarssize);
289  SCIPfreeBlockMemoryArray(scip, &component->fixedvars, component->fixedvarssize);
290  }
291 
292  /* free sub-SCIP belonging to this component and the working solution */
293  if( component->subscip != NULL )
294  {
295  if( component->workingsol != NULL )
296  {
297  SCIP_CALL( SCIPfreeSol(component->subscip, &component->workingsol) );
298  }
299 
300  SCIP_CALL( SCIPfree(&component->subscip) );
301  }
302 
303  return SCIP_OKAY;
304 }
305 
306 
307 /** create the working solution for a given component, store fixed variables and the corresponding objective offset */
308 static
310  COMPONENT* component, /**< component structure */
311  SCIP_HASHMAP* varmap /**< variable hashmap */
312  )
313 {
314  SCIP* subscip;
315 
316  assert(component != NULL);
317 
318  subscip = component->subscip;
319  assert(subscip != NULL);
320  assert(SCIPgetStage(subscip) == SCIP_STAGE_PROBLEM);
321 
322  /* the solution should live in the primal, not the origprimal, of the sub-SCIP, so we need to transform it first */
323  SCIP_CALL( SCIPtransformProb(subscip) );
324  SCIP_CALL( SCIPcreateOrigSol(subscip, &(component->workingsol), NULL) );
325 
326  /* the number of variables was increased by copying the constraints */
327  if( SCIPgetNOrigVars(subscip) > component->nvars )
328  {
329  PROBLEM* problem;
330  SCIP* scip;
331  SCIP_VAR** sourcevars;
332  SCIP_VAR* subvar;
333  int nsourcevars;
334  int nnewvars;
335  int idx = 0;
336  int nvars;
337  int v;
338 
339  problem = component->problem;
340  assert(problem != NULL);
341 
342  scip = problem->scip;
343  assert(scip != NULL);
344 
345  sourcevars = SCIPgetVars(scip);
346  nsourcevars = SCIPgetNVars(scip);
347  nnewvars = SCIPgetNOrigVars(subscip);
348  nvars = component->nvars;
349 
350  component->fixedvarssize = nnewvars - nvars;
351  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &component->fixedvars, component->fixedvarssize) );
352  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &component->fixedsubvars, component->fixedvarssize) );
353 
354  for( v = 0; v < nsourcevars; ++v )
355  {
356  subvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, sourcevars[v]);
357  if( subvar != NULL && SCIPvarGetIndex(subvar) >= nvars )
358  {
359  /* the variable is either locally fixed or could be an inactive variable present in a constraint
360  * for which an aggregation constraint linking it to the active variable was created in the subscip
361  */
362  assert(SCIPisZero(subscip, SCIPvarGetObj(subvar)) ||
363  SCIPisEQ(subscip, SCIPvarGetLbGlobal(subvar), SCIPvarGetUbGlobal(subvar)));
364 
365  /* variable is gloablly fixed in sub-SCIP, so it was locally fixed in the main-SCIP */
366  if( SCIPisEQ(subscip, SCIPvarGetLbGlobal(subvar), SCIPvarGetUbGlobal(subvar)) )
367  {
368  assert(SCIPisEQ(scip, SCIPvarGetLbLocal(sourcevars[v]), SCIPvarGetUbLocal(sourcevars[v])));
369 
370  component->fixedvarsobjsum += SCIPvarGetLbGlobal(subvar) * SCIPvarGetObj(subvar);
371  component->fixedvars[idx] = sourcevars[v];
372  component->fixedsubvars[idx] = subvar;
373  ++idx;
374 
375  SCIP_CALL( SCIPsetSolVal(subscip, component->workingsol, subvar, SCIPvarGetLbGlobal(subvar)) );
376  }
377  /* inactive variable */
378  else
379  {
380  assert(SCIPisZero(subscip, SCIPvarGetObj(subvar)));
381  }
382  }
383  else
384  {
385  assert(subvar == NULL || SCIPisLT(scip, SCIPvarGetLbGlobal(sourcevars[v]), SCIPvarGetUbGlobal(sourcevars[v])));
386  assert(subvar == NULL || SCIPisLT(subscip, SCIPvarGetLbGlobal(subvar), SCIPvarGetUbGlobal(subvar)));
387  }
388  }
389  component->nfixedvars = idx;
390  assert(component->nfixedvars <= component->fixedvarssize);
391  SCIPdebugMsg(scip, "%d locally fixed variables have been copied, objective contribution: %g\n",
392  component->nfixedvars, component->fixedvarsobjsum);
393  }
394 
395  /* set up debug solution */
396 #ifdef WITH_DEBUG_SOLUTION
397  if( SCIPdebugSolIsEnabled(component->problem->scip) )
398  {
399  PROBLEM* problem;
400  SCIP* scip;
401  SCIP_Bool isvalid = FALSE;
402 
403  problem = component->problem;
404  assert(problem != NULL);
405 
406  scip = problem->scip;
407  assert(scip != NULL);
408 
409  SCIP_CALL( SCIPdebugSolIsValidInSubtree(scip, &isvalid) );
410 
411  if( isvalid )
412  {
413  SCIP_Real val;
414  int i;
415 
416  SCIPdebugSolEnable(component->subscip);
417 
418  for( i = 0; i < component->nvars; ++i )
419  {
420  if( component->subvars[i] != NULL )
421  {
422  SCIP_CALL( SCIPdebugGetSolVal(scip, component->vars[i], &val) );
423  SCIP_CALL( SCIPdebugAddSolVal(component->subscip, component->subvars[i], val) );
424  }
425  }
426  for( i = 0; i < component->nfixedvars; ++i )
427  {
428  if( component->fixedsubvars[i] != NULL )
429  {
430  SCIP_CALL( SCIPdebugGetSolVal(scip, component->fixedvars[i], &val) );
431  SCIP_CALL( SCIPdebugAddSolVal(component->subscip, component->fixedsubvars[i], val) );
432  }
433  }
434  }
435  }
436 #endif
437 
438  return SCIP_OKAY;
439 }
440 
441 /** create a sub-SCIP for the given variables and constraints */
442 static
444  SCIP* scip, /**< main SCIP data structure */
445  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
446  SCIP** subscip /**< pointer to store created sub-SCIP */
447  )
448 {
449  SCIP_Bool success;
450 
451  assert(conshdlrdata != NULL);
452 
453  /* create a new SCIP instance */
454  SCIP_CALL( SCIPcreate(subscip) );
455 
456  /* copy plugins, we omit pricers (because we do not run if there are active pricers) and dialogs */
457 #ifdef SCIP_MORE_DEBUG /* we print statistics later, so we need to copy statistics tables */
458  SCIP_CALL( SCIPcopyPlugins(scip, *subscip, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE,
459  TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, &success) );
460 #else
461  SCIP_CALL( SCIPcopyPlugins(scip, *subscip, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE,
462  TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, &success) );
463 #endif
464 
465  /* the plugins were successfully copied */
466  if( success )
467  {
468  SCIP_CONSHDLR* newconshdlr;
469  SCIP_CONSHDLRDATA* newconshdlrdata;
470 #ifdef WITH_DEBUG_SOLUTION
471  SCIP_Bool isvalid = FALSE;
472 #endif
473 
474  /* copy parameter settings */
475  SCIP_CALL( SCIPcopyParamSettings(scip, *subscip) );
476 
477  /* some general settings should not be fixed */
478  assert(!SCIPisParamFixed(*subscip, "limits/solutions"));
479  assert(!SCIPisParamFixed(*subscip, "limits/bestsol"));
480  assert(!SCIPisParamFixed(*subscip, "misc/usevartable"));
481  assert(!SCIPisParamFixed(*subscip, "misc/useconstable"));
482  assert(!SCIPisParamFixed(*subscip, "numerics/feastol"));
483  assert(!SCIPisParamFixed(*subscip, "misc/usesmalltables"));
484 
485  /* disable solution limits */
486  SCIP_CALL( SCIPsetIntParam(*subscip, "limits/solutions", -1) );
487  SCIP_CALL( SCIPsetIntParam(*subscip, "limits/bestsol", -1) );
488 
489  /* reduce the effort spent for hash tables; however, if the debug solution is enabled and valid in this subtree,
490  * hash tables are needed for installing the debug solution
491  */
492 #ifdef WITH_DEBUG_SOLUTION
493  SCIP_CALL( SCIPdebugSolIsValidInSubtree(scip, &isvalid) );
494  if( !isvalid && SCIPgetStage(scip) > SCIP_STAGE_PRESOLVING )
495 #endif
496  {
497  SCIP_CALL( SCIPsetBoolParam(*subscip, "misc/usevartable", FALSE) );
498  SCIP_CALL( SCIPsetBoolParam(*subscip, "misc/useconstable", FALSE) );
499  }
500 
501  /* disable presolving */
503 
504  /* disable component presolving and fix the parameter */
505  SCIP_CALL( SCIPsetIntParam(*subscip, "constraints/" CONSHDLR_NAME "/maxprerounds", 0) );
506  SCIP_CALL( SCIPfixParam(*subscip, "constraints/" CONSHDLR_NAME "/maxprerounds") );
507 
508  /* find the components constraint handler in the sub-SCIP and inform it about the actual depth in the tree */
509  newconshdlr = SCIPfindConshdlr(*subscip, CONSHDLR_NAME);
510  assert(newconshdlr != NULL);
511 
512  newconshdlrdata = SCIPconshdlrGetData(newconshdlr);
513  assert(newconshdlrdata != NULL);
514  newconshdlrdata->subscipdepth = conshdlrdata->subscipdepth + SCIPgetDepth(scip);
515 
516  /* disable output, unless in extended debug mode */
517 #ifndef SCIP_MORE_DEBUG
518  SCIP_CALL( SCIPsetIntParam(*subscip, "display/verblevel", 0) );
519 #endif
520  }
521  else
522  {
523  SCIP_CALL( SCIPfree(subscip) );
524  *subscip = NULL;
525  }
526 
527  return SCIP_OKAY;
528 }
529 
530 /** copies the given variables and constraints to the given sub-SCIP */
531 static
533  SCIP* scip, /**< source SCIP */
534  SCIP* subscip, /**< target SCIP */
535  const char* name, /**< name for copied problem */
536  SCIP_VAR** vars, /**< array of variables to copy */
537  SCIP_VAR** subvars, /**< array to fill with copied vars */
538  SCIP_CONS** conss, /**< constraint to copy */
539  SCIP_HASHMAP* varmap, /**< hashmap used for the copy process of variables */
540  SCIP_HASHMAP* consmap, /**< hashmap used for the copy process of constraints */
541  int nvars, /**< number of variables to copy */
542  int nconss, /**< number of constraints to copy */
543  SCIP_Bool* success /**< pointer to store whether copying was successful */
544  )
545 {
546  SCIP_CONS* newcons;
547  int i;
548 
549  assert(scip != NULL);
550  assert(subscip != NULL);
551  assert(vars != NULL);
552  assert(subvars != NULL);
553  assert(conss != NULL);
554  assert(varmap != NULL);
555  assert(consmap != NULL);
556  assert(success != NULL);
557 
558  *success = TRUE;
559 
560  /* create problem in sub-SCIP */
561  SCIP_CALL( SCIPcopyProb(scip, subscip, varmap, consmap, FALSE, name) );
562 
563  /* copy variables */
564  for( i = 0; i < nvars; ++i )
565  {
566  SCIP_CALL( SCIPgetVarCopy(scip, subscip, vars[i], &subvars[i], varmap, consmap, FALSE, success) );
567 
568  /* abort if variable was not successfully copied */
569  if( !(*success) )
570  return SCIP_OKAY;
571  }
572 
573  /* copy constraints */
574  for( i = 0; i < nconss; ++i )
575  {
576  assert(!SCIPconsIsModifiable(conss[i]));
577 
578  /* copy the constraint */
579  SCIP_CALL( SCIPgetConsCopy(scip, subscip, conss[i], &newcons, SCIPconsGetHdlr(conss[i]), varmap, consmap, NULL,
580  SCIPconsIsInitial(conss[i]), SCIPconsIsSeparated(conss[i]), SCIPconsIsEnforced(conss[i]),
581  SCIPconsIsChecked(conss[i]), SCIPconsIsPropagated(conss[i]), FALSE, FALSE,
582  SCIPconsIsDynamic(conss[i]), SCIPconsIsRemovable(conss[i]), FALSE, FALSE, success) );
583 
584  /* abort if constraint was not successfully copied */
585  if( !(*success) )
586  return SCIP_OKAY;
587 
588  SCIP_CALL( SCIPaddCons(subscip, newcons) );
589  SCIP_CALL( SCIPreleaseCons(subscip, &newcons) );
590  }
591 
592  return SCIP_OKAY;
593 }
594 
595 /** create the sub-SCIP for a given component */
596 static
598  COMPONENT* component, /**< component structure */
599  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
600  SCIP_HASHMAP* varmap, /**< variable hashmap used to improve performance */
601  SCIP_HASHMAP* consmap, /**< constraint hashmap used to improve performance */
602  SCIP_CONS** conss, /**< constraints contained in this component */
603  int nconss, /**< number of constraints contained in this component */
604  SCIP_Bool* success /**< pointer to store whether the copying process was successful */
605  )
606 {
607  char name[SCIP_MAXSTRLEN];
608  PROBLEM* problem;
609  SCIP* scip;
610  int minsize;
611 
612  assert(component != NULL);
613  assert(consmap != NULL);
614  assert(conss != NULL);
615  assert(success != NULL);
616  assert(component->nvars > 0);
617 
618  problem = component->problem;
619  assert(problem != NULL);
620 
621  scip = problem->scip;
622  assert(scip != NULL);
623 
624  (*success) = TRUE;
625 
626  SCIP_CALL( createSubscip(scip, conshdlrdata, &component->subscip) );
627 
628  if( component->subscip != NULL )
629  {
630  /* get minimum size of components to solve individually and set the parameter in the sub-SCIP */
631  minsize = getMinsize(scip, conshdlrdata);
632 
633  SCIP_CALL( SCIPsetIntParam(component->subscip, "constraints/" CONSHDLR_NAME "/minsize", minsize) );
634 
635  /* get name of the original problem and add "comp_nr" */
636  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_comp_%d", problem->name, component->number);
637 
638  SCIP_CALL( copyToSubscip(scip, component->subscip, name, component->vars, component->subvars,
639  conss, varmap, consmap, component->nvars, nconss, success) );
640 
641  if( !(*success) )
642  {
643  SCIP_CALL( SCIPfree(&component->subscip) );
644  component->subscip = NULL;
645  }
646  }
647  else
648  (*success) = FALSE;
649 
650  return SCIP_OKAY;
651 }
652 
653 /** solve a given sub-SCIP up to the given limits */
654 static
656  SCIP* scip, /**< main SCIP */
657  SCIP* subscip, /**< sub-SCIP to solve */
658  SCIP_Longint nodelimit, /**< node limit */
659  SCIP_Real gaplimit /**< gap limit */
660  )
661 {
662  SCIP_Real timelimit;
663  SCIP_Real softtimelimit;
664  SCIP_Real memorylimit;
665 
666  assert(scip != NULL);
667  assert(subscip != NULL);
668 
669  /* set time limit */
670  SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
671  if( !SCIPisInfinity(scip, timelimit) )
672  {
673  timelimit -= SCIPgetSolvingTime(scip);
674  timelimit += SCIPgetSolvingTime(subscip);
675  }
676 
677  /* set soft time limit, if specified in main SCIP */
678  SCIP_CALL( SCIPgetRealParam(scip, "limits/softtime", &softtimelimit) );
679  if( softtimelimit > -0.5 )
680  {
681  softtimelimit -= SCIPgetSolvingTime(scip);
682  softtimelimit += SCIPgetSolvingTime(subscip);
683  softtimelimit = MAX(softtimelimit, 0.0);
684  }
685 
686  /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
687  /* @todo count memory of other components */
688  SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
689  if( !SCIPisInfinity(scip, memorylimit) )
690  {
691  memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
692  memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
693  }
694 
695  /* abort if no time is left or not enough memory to create a copy of SCIP, including external memory usage */
696  if( timelimit <= 0.0 || memorylimit <= 0.0)
697  {
698  SCIPdebugMessage("--> not solved (not enough memory or time left)\n");
699  return SCIP_OKAY;
700  }
701 
702  /* SCIP copy limits will set wrong time limits since it does not take into account time spent already in the
703  * sub-SCIP; nevertheless, we call it to set the memory limit and unset all other limits, if set in the main SCIP
704  */
705  SCIP_CALL( SCIPcopyLimits(scip, subscip) );
706 
707  /* set time and memory limit for the subproblem */
708  SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
709  SCIP_CALL( SCIPsetRealParam(subscip, "limits/softtime", softtimelimit) );
710 
711  /* set gap limit */
712  SCIP_CALL( SCIPsetRealParam(subscip, "limits/gap", gaplimit) );
713 
714  /* set node limit */
715  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nodelimit) );
716 
717  /* solve the subproblem */
718  SCIP_CALL( SCIPsolve(subscip) );
719 
720 #ifdef SCIP_MORE_DEBUG
721  SCIP_CALL( SCIPprintBestSol(subscip, NULL, FALSE) );
722  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
723 #endif
724 
725  return SCIP_OKAY;
726 }
727 
728 /** solve a connected component during presolving and evaluate the result */
729 static
731  SCIP* scip, /**< SCIP main data structure */
732  SCIP_CONSHDLRDATA* conshdlrdata, /**< the components constraint handler data */
733  SCIP* subscip, /**< sub-SCIP to be solved */
734  SCIP_VAR** vars, /**< array of variables copied to this component */
735  SCIP_VAR** subvars, /**< array of sub-SCIP variables corresponding to the vars array */
736  SCIP_CONS** conss, /**< array of constraints copied to this component */
737  int nvars, /**< number of variables copied to this component */
738  int nconss, /**< number of constraints copied to this component */
739  int* ndeletedconss, /**< pointer to store the number of deleted constraints */
740  int* nfixedvars, /**< pointer to store the number of fixed variables */
741  int* ntightenedbounds, /**< pointer to store the number of bound tightenings */
742  SCIP_RESULT* result, /**< pointer to store the result of the component solving */
743  SCIP_Bool* solved /**< pointer to store if the problem was solved to optimality */
744  )
745 {
746  int i;
747 
748  assert(scip != NULL);
749  assert(conshdlrdata != NULL);
750  assert(subscip != NULL);
751  assert(vars != NULL);
752  assert(conss != NULL);
753  assert(ndeletedconss != NULL);
754  assert(nfixedvars != NULL);
755  assert(ntightenedbounds != NULL);
756  assert(result != NULL);
757 
758  *solved = FALSE;
759 
760  SCIP_CALL( solveSubscip(scip, subscip, conshdlrdata->nodelimit, 0.0) );
761 
762  if( SCIPgetStatus(subscip) == SCIP_STATUS_OPTIMAL )
763  {
764  SCIP_SOL* sol;
765  SCIP_VAR* var;
766  SCIP_VAR* subvar;
767  SCIP_Real* fixvals;
768  SCIP_Bool feasible;
769  SCIP_Bool infeasible;
770  SCIP_Bool fixed;
771 
772  sol = SCIPgetBestSol(subscip);
773 
774 #ifdef SCIP_DEBUG
775  SCIP_CALL( SCIPcheckSolOrig(subscip, sol, &feasible, TRUE, TRUE) );
776 #else
777  SCIP_CALL( SCIPcheckSolOrig(subscip, sol, &feasible, FALSE, FALSE) );
778 #endif
779 
780  SCIPdebugMessage("--> solved to optimality: time=%.2f, solution is%s feasible\n", SCIPgetSolvingTime(subscip), feasible ? "" : " not");
781 
782  SCIP_CALL( SCIPallocBufferArray(scip, &fixvals, nvars) );
783 
784  if( feasible )
785  {
786  SCIP_Real glb;
787  SCIP_Real gub;
788 
789  /* get values of variables in the optimal solution */
790  for( i = 0; i < nvars; ++i )
791  {
792  var = vars[i];
793  subvar = subvars[i];
794 
795  /* get global bounds */
796  glb = SCIPvarGetLbGlobal(var);
797  gub = SCIPvarGetUbGlobal(var);
798 
799  if( subvar != NULL )
800  {
801  /* get solution value from optimal solution of the sub-SCIP */
802  fixvals[i] = SCIPgetSolVal(subscip, sol, subvar);
803 
804  assert(SCIPisFeasLE(scip, fixvals[i], SCIPvarGetUbLocal(var)));
805  assert(SCIPisFeasGE(scip, fixvals[i], SCIPvarGetLbLocal(var)));
806 
807  /* checking a solution is done with a relative tolerance of feasibility epsilon, if we really want to
808  * change the bounds of the variables by fixing them, the old bounds must not be violated by more than
809  * the absolute epsilon; therefore, we change the fixing values, if needed, and mark that the solution
810  * has to be checked again
811  */
812  if( SCIPisGT(scip, fixvals[i], gub) )
813  {
814  SCIPdebugMessage("variable <%s> fixval: %f violates global upperbound: %f\n",
815  SCIPvarGetName(var), fixvals[i], gub);
816  fixvals[i] = gub;
817  feasible = FALSE;
818  }
819  else if( SCIPisLT(scip, fixvals[i], glb) )
820  {
821  SCIPdebugMessage("variable <%s> fixval: %f violates global lowerbound: %f\n",
822  SCIPvarGetName(var), fixvals[i], glb);
823  fixvals[i] = glb;
824  feasible = FALSE;
825  }
826  assert(SCIPisLE(scip, fixvals[i], SCIPvarGetUbLocal(var)));
827  assert(SCIPisGE(scip, fixvals[i], SCIPvarGetLbLocal(var)));
828  }
829  else
830  {
831  /* the variable was not copied, so it was cancelled out of constraints during copying;
832  * thus, the variable is not constrained and we fix it to its best bound
833  */
834  if( SCIPisPositive(scip, SCIPvarGetObj(var)) )
835  fixvals[i] = glb;
836  else if( SCIPisNegative(scip, SCIPvarGetObj(var)) )
837  fixvals[i] = gub;
838  else
839  {
840  fixvals[i] = 0.0;
841  fixvals[i] = MIN(fixvals[i], gub);
842  fixvals[i] = MAX(fixvals[i], glb);
843  }
844  }
845  }
846 
847  /* the solution value of at least one variable is feasible with a relative tolerance of feasibility epsilon,
848  * but infeasible with an absolute tolerance of epsilon; try to set the variables to the bounds and check
849  * solution again in the original space (changing the values might now introduce infeasibilities of constraints)
850  */
851  if( !feasible )
852  {
853  SCIP_Real origobj;
854 
855  SCIPdebugMessage("solution violates bounds by more than epsilon, check the corrected solution...\n");
856 
857  origobj = SCIPgetSolOrigObj(subscip, SCIPgetBestSol(subscip));
858 
859  SCIP_CALL( SCIPfreeTransform(subscip) );
860 
861  SCIP_CALL( SCIPcreateOrigSol(subscip, &sol, NULL) );
862 
863  /* set solution values of variables */
864  for( i = 0; i < nvars; ++i )
865  {
866  if( subvars[i] != NULL )
867  {
868  SCIP_CALL( SCIPsetSolVal(subscip, sol, subvars[i], fixvals[i]) );
869  }
870  }
871 
872  /* check the solution; integrality and bounds should be fulfilled and do not have to be checked */
873  SCIP_CALL( SCIPcheckSol(subscip, sol, FALSE, FALSE, FALSE, FALSE, TRUE, &feasible) );
874 
875 #ifndef NDEBUG
876  /* in debug mode, we additionally check integrality and bounds */
877  if( feasible )
878  {
879  SCIP_CALL( SCIPcheckSol(subscip, sol, FALSE, FALSE, TRUE, TRUE, FALSE, &feasible) );
880  assert(feasible);
881  }
882 #endif
883 
884  SCIPdebugMessage("--> corrected solution is%s feasible\n", feasible ? "" : " not");
885 
886  if( !SCIPisFeasEQ(subscip, SCIPsolGetOrigObj(sol), origobj) )
887  {
888  SCIPdebugMessage("--> corrected solution has a different objective value (old=%16.9g, corrected=%16.9g)\n",
889  origobj, SCIPsolGetOrigObj(sol));
890 
891  feasible = FALSE;
892  }
893 
894  SCIP_CALL( SCIPfreeSol(subscip, &sol) );
895  }
896 
897  /* if the solution is feasible, fix variables and delete constraints of the component */
898  if( feasible )
899  {
900  /* fix variables */
901  for( i = 0; i < nvars; ++i )
902  {
903  assert(SCIPisLE(scip, fixvals[i], SCIPvarGetUbLocal(vars[i])));
904  assert(SCIPisGE(scip, fixvals[i], SCIPvarGetLbLocal(vars[i])));
905  assert(SCIPisLE(scip, fixvals[i], SCIPvarGetUbGlobal(vars[i])));
906  assert(SCIPisGE(scip, fixvals[i], SCIPvarGetLbGlobal(vars[i])));
907 
908  SCIP_CALL( SCIPfixVar(scip, vars[i], fixvals[i], &infeasible, &fixed) );
910  assert(!infeasible);
911  assert(fixed);
912  (*nfixedvars)++;
913  }
914 
915  /* delete constraints */
916  for( i = 0; i < nconss; ++i )
917  {
918  SCIP_CALL( SCIPdelCons(scip, conss[i]) );
919  (*ndeletedconss)++;
920  }
921 
922  *result = SCIP_SUCCESS;
923  *solved = TRUE;
924  }
925  }
926 
927  SCIPfreeBufferArray(scip, &fixvals);
928  }
929  else if( SCIPgetStatus(subscip) == SCIP_STATUS_INFEASIBLE )
930  {
931  *result = SCIP_CUTOFF;
932  }
933  else if( SCIPgetStatus(subscip) == SCIP_STATUS_UNBOUNDED || SCIPgetStatus(subscip) == SCIP_STATUS_INFORUNBD )
934  {
935  /* TODO: store unbounded ray in original SCIP data structure */
936  *result = SCIP_UNBOUNDED;
937  }
938  else
939  {
940  SCIPdebugMessage("--> solving interrupted (status=%d, time=%.2f)\n",
941  SCIPgetStatus(subscip), SCIPgetSolvingTime(subscip));
942 
943  /* transfer global fixings to the original problem; we can only do this, if we did not find a solution in the
944  * subproblem, because otherwise, the primal bound might lead to dual reductions that cannot be transferred to
945  * the original problem without also transferring the possibly suboptimal solution (which is currently not
946  * possible)
947  */
948  if( SCIPgetNSols(subscip) == 0 )
949  {
950  SCIP_Bool infeasible;
951  SCIP_Bool tightened;
952  int ntightened;
953 
954  ntightened = 0;
955 
956  for( i = 0; i < nvars; ++i )
957  {
958  if( subvars[i] == NULL )
959  continue;
960 
961  SCIP_CALL( SCIPtightenVarLb(scip, vars[i], SCIPvarGetLbGlobal(subvars[i]), FALSE,
962  &infeasible, &tightened) );
963  assert(!infeasible);
964  if( tightened )
965  ntightened++;
966 
967  SCIP_CALL( SCIPtightenVarUb(scip, vars[i], SCIPvarGetUbGlobal(subvars[i]), FALSE,
968  &infeasible, &tightened) );
969  assert(!infeasible);
970  if( tightened )
971  ntightened++;
972  }
973 
974  *result = SCIP_SUCCESS;
975 
976  *ntightenedbounds += ntightened;
977 
978  SCIPdebugMessage("--> tightened %d bounds of variables due to global bounds in the sub-SCIP\n", ntightened);
979  }
980  }
981 
982  return SCIP_OKAY;
983 }
984 
985 /** (continues) solving a connected component */
986 static
988  COMPONENT* component, /**< component structure */
989  SCIP_Bool lastcomponent, /**< is this the last component to be solved? */
990  SCIP_RESULT* result /**< pointer to store the result of the solving process */
991  )
992 {
993  PROBLEM* problem;
994  SCIP* scip;
995  SCIP* subscip;
996  SCIP_SOL* bestsol;
997  SCIP_Longint nodelimit;
998  SCIP_Longint lastnnodes;
999  SCIP_Real gaplimit;
1000  SCIP_STATUS status;
1001 
1002  assert(component != NULL);
1003 
1004  problem = component->problem;
1005  assert(problem != NULL);
1006 
1007  scip = problem->scip;
1008  assert(scip != NULL);
1009 
1010  subscip = component->subscip;
1011  assert(subscip != NULL);
1012 
1013  *result = SCIP_DIDNOTRUN;
1014 
1015  SCIPdebugMessage("solve component <%s> (ncalls=%d, absgap=%.9g)\n",
1016  SCIPgetProbName(subscip), component->ncalls, component->lastprimalbound - component->lastdualbound);
1017 
1018  bestsol = SCIPgetBestSol(scip);
1019 
1020  /* update best solution of component */
1021  if( bestsol != NULL && SCIPsolGetIndex(bestsol) != component->lastbestsolindex )
1022  {
1023  SCIP_SOL* compsol = component->workingsol;
1024  SCIP_VAR** vars = component->vars;
1025  SCIP_VAR** subvars = component->subvars;
1026  int nvars = component->nvars;
1027  int v;
1028 
1029  component->lastbestsolindex = SCIPsolGetIndex(bestsol);
1030 
1031  /* set solution values of component variables */
1032  for( v = 0; v < nvars; ++v )
1033  {
1034  if( subvars[v] != NULL )
1035  {
1036  SCIP_CALL( SCIPsetSolVal(subscip, compsol, subvars[v], SCIPgetSolVal(scip, bestsol, vars[v])) );
1037  }
1038  }
1039 #ifndef NDEBUG
1040  for( v = 0; v < component->nfixedvars; ++v )
1041  {
1042  if( component->fixedsubvars[v] != NULL )
1043  assert(SCIPisEQ(scip, SCIPgetSolVal(subscip, compsol, component->fixedsubvars[v]),
1044  SCIPvarGetLbGlobal(component->fixedsubvars[v])));
1045  }
1046 #endif
1047 
1048  if( SCIPgetStage(subscip) == SCIP_STAGE_PROBLEM
1049  || SCIPisLT(subscip, SCIPgetSolOrigObj(subscip, compsol), SCIPgetPrimalbound(subscip)) )
1050  {
1051  SCIP_Bool feasible;
1052 
1053  SCIPdebugMessage("checking new solution in component <%s> inherited from problem <%s>: primal bound %.9g --> %.9g\n",
1054  SCIPgetProbName(subscip), problem->name,
1055  SCIPgetStage(subscip) == SCIP_STAGE_PROBLEM ? SCIPinfinity(subscip) : SCIPgetPrimalbound(subscip),
1056  SCIPgetSolOrigObj(subscip, compsol));
1057 
1058  SCIP_CALL( SCIPcheckSolOrig(subscip, compsol, &feasible, FALSE, FALSE) );
1059  if( feasible )
1060  {
1061  SCIPdebugMessage("... feasible, adding solution.\n");
1062 
1063  SCIP_CALL( SCIPaddSol(subscip, compsol, &feasible) );
1064  }
1065 
1066  /* We cannot take the value of compsol as a cutoff bound if it was not feasible; some of the fixed connecting
1067  * variables are different and might not allow for a better solution in this component, but still for far
1068  * better solutions in other components. Therefore, the only cutoffbound we can apply is the cutoffbound
1069  * of the problem reduced by the dual bounds of the other components
1070  */
1071  if( problem->nlowerboundinf == 0 || (problem->nlowerboundinf == 1
1072  && SCIPisInfinity(scip, -component->lastdualbound)) )
1073  {
1074  SCIP_Real newcutoffbound = SCIPgetSolTransObj(scip, bestsol);
1075 
1076  assert(problem->nlowerboundinf > 0 || SCIPisGE(scip, newcutoffbound, problem->lowerbound));
1077 
1078  newcutoffbound = newcutoffbound - problem->lowerbound + component->fixedvarsobjsum;
1079 
1080  if( problem->nlowerboundinf == 0 )
1081  newcutoffbound += component->lastdualbound;
1082 
1083  if( SCIPisSumLT(subscip, newcutoffbound, SCIPgetCutoffbound(subscip)) )
1084  {
1085  SCIPdebugMessage("update cutoff bound to %16.9g\n", newcutoffbound);
1086 
1087  SCIP_CALL( SCIPupdateCutoffbound(subscip, newcutoffbound) );
1088  }
1089  }
1090  }
1091  }
1092 
1093  assert(component->laststatus != SCIP_STATUS_OPTIMAL);
1094 
1095  SCIPdebugMsg(scip, "solve sub-SCIP for component <%s> (ncalls=%d, absgap=%16.9g)\n",
1096  SCIPgetProbName(component->subscip), component->ncalls, component->lastprimalbound - component->lastdualbound);
1097 
1098  if( component->ncalls == 0 )
1099  {
1100  nodelimit = 1LL;
1101  gaplimit = 0.0;
1102 
1103  lastnnodes = 0;
1104  }
1105  else
1106  {
1107  SCIP_Longint mainnodelimit;
1108 
1109  lastnnodes = SCIPgetNNodes(component->subscip);
1110 
1111  SCIP_CALL( SCIPgetLongintParam(scip, "limits/nodes", &mainnodelimit) );
1112 
1113  nodelimit = 2 * lastnnodes;
1114  nodelimit = MAX(nodelimit, 10LL);
1115 
1116  if( mainnodelimit != -1 )
1117  {
1118  assert(mainnodelimit >= lastnnodes);
1119  nodelimit = MIN(nodelimit, mainnodelimit - lastnnodes);
1120  }
1121 
1122  /* set a gap limit of half the current gap (at most 10%) */
1123  if( SCIPgetGap(component->subscip) < 0.2 )
1124  gaplimit = 0.5 * SCIPgetGap(component->subscip);
1125  else
1126  gaplimit = 0.1;
1127 
1128  if( lastcomponent )
1129  gaplimit = 0.0;
1130  }
1131 
1132  SCIP_CALL( solveSubscip(scip, subscip, nodelimit, gaplimit) );
1133 
1134  SCIPaddNNodes(scip, SCIPgetNNodes(subscip) - lastnnodes);
1135 
1137 
1138  status = SCIPgetStatus(subscip);
1139 
1140  component->laststatus = status;
1141  ++component->ncalls;
1142 
1143  SCIPdebugMsg(scip, "--> (status=%d, nodes=%lld, time=%.2f): gap: %12.5g%% absgap: %16.9g\n",
1144  status, SCIPgetNNodes(subscip), SCIPgetSolvingTime(subscip), 100.0*SCIPgetGap(subscip),
1145  SCIPgetPrimalbound(subscip) - SCIPgetDualbound(subscip));
1146 
1147  *result = SCIP_SUCCESS;
1148 
1149  switch( status )
1150  {
1151  case SCIP_STATUS_OPTIMAL:
1152  component->solved = TRUE;
1153  break;
1155  component->solved = TRUE;
1156 
1157  /* the problem is really infeasible */
1158  if( SCIPisInfinity(subscip, SCIPgetPrimalbound(subscip)) )
1159  {
1160  *result = SCIP_CUTOFF;
1161  }
1162  /* the cutoff bound was reached; no solution better than the cutoff bound exists */
1163  else
1164  {
1165  *result = SCIP_SUCCESS;
1166  component->laststatus = SCIP_STATUS_OPTIMAL;
1167  assert(SCIPisLE(subscip, SCIPgetDualbound(subscip), SCIPgetPrimalbound(subscip)));
1168  }
1169  break;
1170  case SCIP_STATUS_UNBOUNDED:
1171  case SCIP_STATUS_INFORUNBD:
1172  /* TODO: store unbounded ray in original SCIP data structure */
1173  *result = SCIP_UNBOUNDED;
1174  component->solved = TRUE;
1175  break;
1177  SCIP_CALL( SCIPinterruptSolve(scip) );
1178  break;
1179  case SCIP_STATUS_TERMINATE:
1180  case SCIP_STATUS_UNKNOWN:
1181  case SCIP_STATUS_NODELIMIT:
1184  case SCIP_STATUS_TIMELIMIT:
1185  case SCIP_STATUS_MEMLIMIT:
1186  case SCIP_STATUS_GAPLIMIT:
1187  case SCIP_STATUS_SOLLIMIT:
1190  default:
1191  break;
1192  }
1193 
1194  /* evaluate call */
1195  if( *result == SCIP_SUCCESS )
1196  {
1197  SCIP_SOL* sol = SCIPgetBestSol(subscip);
1198  SCIP_VAR* var;
1199  SCIP_VAR* subvar;
1200  SCIP_Real newdualbound;
1201  int v;
1202 
1203  /* get dual bound as the minimum of SCIP dual bound and sub-problems dual bound */
1204  newdualbound = SCIPgetDualbound(subscip) - component->fixedvarsobjsum;
1205 
1206  /* update dual bound of problem */
1207  if( !SCIPisEQ(scip, component->lastdualbound, newdualbound) )
1208  {
1209  assert(!SCIPisInfinity(scip, -newdualbound));
1210 
1211  /* first finite dual bound: decrease inf counter and add dual bound to problem dualbound */
1212  if( SCIPisInfinity(scip, -component->lastdualbound) )
1213  {
1214  --problem->nlowerboundinf;
1215  problem->lowerbound += newdualbound;
1216  }
1217  /* increase problem dual bound by dual bound delta */
1218  else
1219  {
1220  problem->lowerbound += (newdualbound - component->lastdualbound);
1221  }
1222 
1223  /* update problem dual bound if all problem components have a finite dual bound */
1224  if( problem->nlowerboundinf == 0 )
1225  {
1226  SCIPdebugMessage("component <%s>: dual bound increased from %16.9g to %16.9g, new dual bound of problem <%s>: %16.9g (gap: %16.9g, absgap: %16.9g)\n",
1227  SCIPgetProbName(subscip), component->lastdualbound, newdualbound, problem->name,
1228  SCIPretransformObj(scip, problem->lowerbound),
1229  problem->nfeascomps == problem->ncomponents ?
1230  (SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound)) /
1231  MAX( ABS( SCIPretransformObj(scip, problem->lowerbound) ), SCIPgetSolOrigObj(scip, problem->bestsol) ) /*lint !e666*/
1232  : SCIPinfinity(scip),
1233  problem->nfeascomps == problem->ncomponents ?
1234  SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound) : SCIPinfinity(scip));
1235  SCIP_CALL( SCIPupdateLocalLowerbound(scip, problem->lowerbound) );
1236  }
1237 
1238  /* store dual bound of this call */
1239  component->lastdualbound = newdualbound;
1240  }
1241 
1242  /* update primal solution of problem */
1243  if( sol != NULL && component->lastsolindex != SCIPsolGetIndex(sol) )
1244  {
1245  component->lastsolindex = SCIPsolGetIndex(sol);
1246 
1247  if( SCIPsolGetHeur(sol) != NULL )
1249  else
1250  SCIPsolSetHeur(problem->bestsol, NULL);
1251 
1252  /* increase counter for feasible problems if no solution was known before */
1253  if( SCIPisInfinity(scip, component->lastprimalbound) )
1254  ++(problem->nfeascomps);
1255 
1256  /* update working best solution in problem */
1257  for( v = 0; v < component->nvars; ++v )
1258  {
1259  var = component->vars[v];
1260  subvar = component->subvars[v];
1261  assert(var != NULL);
1262  assert(SCIPvarIsActive(var));
1263 
1264  if( subvar == NULL )
1265  continue;
1266 
1267  SCIP_CALL( SCIPsetSolVal(scip, problem->bestsol, var, SCIPgetSolVal(subscip, sol, subvar)) );
1268  }
1269 
1270  /* if we have a feasible solution for each component, add the working solution to the main problem */
1271  if( problem->nfeascomps == problem->ncomponents )
1272  {
1273  SCIP_Bool feasible;
1274 #ifdef SCIP_MORE_DEBUG
1275  SCIP_CALL( SCIPcheckSol(scip, problem->bestsol, TRUE, FALSE, TRUE, TRUE, TRUE, &feasible) );
1276  assert(feasible);
1277 #endif
1278  SCIP_CALL( SCIPaddSol(scip, problem->bestsol, &feasible) );
1279 
1280  SCIPdebugMessage("component <%s>: primal bound decreased from %16.9g to %16.9g, new primal bound of problem <%s>: %16.9g (gap: %16.9g, absgap: %16.9g)\n",
1281  SCIPgetProbName(subscip), component->lastprimalbound, SCIPgetPrimalbound(subscip), problem->name,
1282  SCIPgetSolOrigObj(scip, problem->bestsol),
1283  problem->nfeascomps == problem->ncomponents ?
1284  (SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound)) /
1285  MAX( ABS( SCIPretransformObj(scip, problem->lowerbound) ),SCIPgetSolOrigObj(scip, problem->bestsol) ) /*lint !e666*/
1286  : SCIPinfinity(scip),
1287  problem->nfeascomps == problem->ncomponents ?
1288  SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound) : SCIPinfinity(scip));
1289  }
1290 
1291  /* store primal bound of this call */
1292  component->lastprimalbound = SCIPgetPrimalbound(subscip) - component->fixedvarsobjsum;
1293  }
1294 
1295  /* if the component was solved to optimality, we increase the respective counter and free the subscip */
1296  if( component->laststatus == SCIP_STATUS_OPTIMAL || component->laststatus == SCIP_STATUS_INFEASIBLE ||
1297  component->laststatus == SCIP_STATUS_UNBOUNDED || component->laststatus == SCIP_STATUS_INFORUNBD )
1298  {
1299  ++(problem->nsolvedcomps);
1300  component->solved = TRUE;
1301 
1302  /* free working solution and component */
1303  SCIP_CALL( SCIPfreeSol(subscip, &component->workingsol) );
1304 
1305  SCIP_CALL( SCIPfree(&subscip) );
1306  component->subscip = NULL;
1307  }
1308  }
1309 
1310  return SCIP_OKAY;
1311 }
1312 
1313 /** initialize subproblem structure */
1314 static
1316  SCIP* scip, /**< SCIP data structure */
1317  PROBLEM** problem, /**< pointer to subproblem structure */
1318  SCIP_Real fixedvarsobjsum, /**< objective contribution of all locally fixed variables */
1319  int ncomponents /**< number of independent components */
1320  )
1321 {
1322  char name[SCIP_MAXSTRLEN];
1323  SCIP_VAR** vars;
1324  int nvars;
1325  int v;
1326 
1327  assert(scip != NULL);
1328  assert(problem != NULL);
1329 
1330  vars = SCIPgetVars(scip);
1331  nvars = SCIPgetNVars(scip);
1332 
1334  assert(*problem != NULL);
1335 
1336  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*problem)->components, ncomponents) );
1337 
1338  /* create a priority queue for the components: we need exactly ncomponents slots in the queue so it should never be
1339  * resized
1340  */
1341  SCIP_CALL( SCIPpqueueCreate(&(*problem)->compqueue, ncomponents, 1.2, componentSort, NULL) );
1342 
1343  (*problem)->scip = scip;
1344  (*problem)->lowerbound = fixedvarsobjsum;
1345  (*problem)->fixedvarsobjsum = fixedvarsobjsum;
1346  (*problem)->ncomponents = 0;
1347  (*problem)->componentssize = ncomponents;
1348  (*problem)->nlowerboundinf = ncomponents;
1349  (*problem)->nfeascomps = 0;
1350  (*problem)->nsolvedcomps = 0;
1351 
1352  if( SCIPgetDepth(scip) == 0 )
1353  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", SCIPgetProbName(scip));
1354  else
1355  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_node_%" SCIP_LONGINT_FORMAT, SCIPgetProbName(scip), SCIPnodeGetNumber(SCIPgetCurrentNode(scip)));
1356 
1357  SCIP_CALL( SCIPduplicateMemoryArray(scip, &(*problem)->name, name, strlen(name)+1) );
1358 
1359  SCIP_CALL( SCIPcreateSol(scip, &(*problem)->bestsol, NULL) );
1360 
1361  for( v = 0; v < nvars; v++ )
1362  {
1363  if( SCIPisFeasEQ(scip, SCIPvarGetLbLocal(vars[v]), SCIPvarGetUbLocal(vars[v])) )
1364  {
1365  SCIP_CALL( SCIPsetSolVal(scip, (*problem)->bestsol, vars[v],
1366  (SCIPvarGetUbLocal(vars[v]) + SCIPvarGetLbLocal(vars[v]))/2) );
1367  }
1368  }
1369 
1370  SCIPdebugMessage("initialized problem <%s>\n", (*problem)->name);
1371 
1372  return SCIP_OKAY;
1373 }
1374 
1375 /** free subproblem structure */
1376 static
1378  PROBLEM** problem /**< pointer to problem to free */
1379  )
1380 {
1381  SCIP* scip;
1382  int c;
1383 
1384  assert(problem != NULL);
1385  assert(*problem != NULL);
1386 
1387  scip = (*problem)->scip;
1388  assert(scip != NULL);
1389 
1390  /* free best solution */
1391  if( (*problem)->bestsol != NULL )
1392  {
1393  SCIP_CALL( SCIPfreeSol(scip, &(*problem)->bestsol) );
1394  }
1395 
1396  /* free all components */
1397  for( c = (*problem)->ncomponents - 1; c >= 0; --c )
1398  {
1399  SCIP_CALL( freeComponent(&(*problem)->components[c]) );
1400  }
1401  if( (*problem)->components != NULL )
1402  {
1403  SCIPfreeBlockMemoryArray(scip, &(*problem)->components, (*problem)->componentssize);
1404  }
1405 
1406  /* free priority queue */
1407  SCIPpqueueFree(&(*problem)->compqueue);
1408 
1409  /* free problem name */
1410  SCIPfreeMemoryArray(scip, &(*problem)->name);
1411 
1412  /* free PROBLEM struct and set the pointer to NULL */
1414  *problem = NULL;
1415 
1416  return SCIP_OKAY;
1417 }
1418 
1419 /** creates and captures a components constraint */
1420 static
1422  SCIP* scip, /**< SCIP data structure */
1423  SCIP_CONS** cons, /**< pointer to hold the created constraint */
1424  const char* name, /**< name of constraint */
1425  PROBLEM* problem /**< problem to be stored in the constraint */
1426  )
1427 {
1428  SCIP_CONSHDLR* conshdlr;
1429 
1430  /* find the samediff constraint handler */
1431  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
1432  if( conshdlr == NULL )
1433  {
1434  SCIPerrorMessage("components constraint handler not found\n");
1435  return SCIP_PLUGINNOTFOUND;
1436  }
1437 
1438  /* create constraint */
1439  SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, (SCIP_CONSDATA*)problem,
1440  FALSE, FALSE, FALSE, FALSE, TRUE,
1441  TRUE, FALSE, FALSE, FALSE, TRUE) );
1442 
1443  return SCIP_OKAY;
1444 }
1445 
1446 
1447 /** sort the components by size and sort vars and conss arrays by component numbers */
1448 static
1450  SCIP* scip, /**< SCIP data structure */
1451  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1452  SCIP_DIGRAPH* digraph, /**< directed graph */
1453  SCIP_CONS** conss, /**< constraints */
1454  SCIP_VAR** vars, /**< variables */
1455  int* varcomponent, /**< component numbers for the variables */
1456  int* conscomponent, /**< array to store component numbers for the constraints */
1457  int nconss, /**< number of constraints */
1458  int nvars, /**< number of variables */
1459  int* firstvaridxpercons, /**< array with index of first variable in vars array for each constraint */
1460  int* ncompsminsize, /**< pointer to store the number of components not exceeding the minimum size */
1461  int* ncompsmaxsize /**< pointer to store the number of components not exceeding the maximum size */
1462  )
1463 {
1464  SCIP_Real* compsize;
1465  int* permu;
1466  int ncomponents;
1467  int nbinvars;
1468  int nintvars;
1469  int ndiscvars;
1470  int ncontvars;
1471  int minsize;
1472  int v;
1473  int c;
1474 
1475  assert(scip != NULL);
1476  assert(conshdlrdata != NULL);
1477  assert(digraph != NULL);
1478  assert(conss != NULL);
1479  assert(vars != NULL);
1480  assert(firstvaridxpercons != NULL);
1481 
1482  /* compute minimum size of components to solve individually */
1483  minsize = getMinsize(scip, conshdlrdata);
1484 
1485  ncomponents = SCIPdigraphGetNComponents(digraph);
1486  *ncompsminsize = 0;
1487  *ncompsmaxsize = 0;
1488 
1489  /* We want to sort the components in increasing complexity (number of discrete variables,
1490  * integer weighted with factor intfactor, continuous used as tie-breaker).
1491  * Therefore, we now get the variables for each component, count the different variable types
1492  * and compute a size as described above. Then, we rename the components
1493  * such that for i < j, component i has no higher complexity than component j.
1494  */
1495  SCIP_CALL( SCIPallocBufferArray(scip, &compsize, ncomponents) );
1496  SCIP_CALL( SCIPallocBufferArray(scip, &permu, ncomponents) );
1497 
1498  /* get number of variables in the components */
1499  for( c = 0; c < ncomponents; ++c )
1500  {
1501  int* cvars;
1502  int ncvars;
1503 
1504  SCIPdigraphGetComponent(digraph, c, &cvars, &ncvars);
1505  permu[c] = c;
1506  nbinvars = 0;
1507  nintvars = 0;
1508 
1509  for( v = 0; v < ncvars; ++v )
1510  {
1511  /* check whether variable is of binary or integer type */
1512  if( SCIPvarGetType(vars[cvars[v]]) == SCIP_VARTYPE_BINARY )
1513  nbinvars++;
1514  else if( SCIPvarGetType(vars[cvars[v]]) == SCIP_VARTYPE_INTEGER )
1515  nintvars++;
1516  }
1517  ncontvars = ncvars - nintvars - nbinvars;
1518  ndiscvars = (int)(nbinvars + conshdlrdata->intfactor * nintvars);
1519  compsize[c] = ((1000.0 * ndiscvars + (950.0 * ncontvars)/nvars));
1520 
1521  /* component fulfills the maxsize requirement */
1522  if( ndiscvars <= conshdlrdata->maxintvars )
1523  ++(*ncompsmaxsize);
1524 
1525  /* component fulfills the minsize requirement */
1526  if( ncvars >= minsize )
1527  ++(*ncompsminsize);
1528  }
1529 
1530  /* get permutation of component numbers such that the size of the components is increasing */
1531  SCIPsortRealInt(compsize, permu, ncomponents);
1532 
1533  /* now, we need the reverse direction, i.e., for each component number, we store its new number
1534  * such that the components are sorted; for this, we abuse the conscomponent array
1535  */
1536  for( c = 0; c < ncomponents; ++c )
1537  conscomponent[permu[c]] = c;
1538 
1539  /* for each variable, replace the old component number by the new one */
1540  for( c = 0; c < nvars; ++c )
1541  varcomponent[c] = conscomponent[varcomponent[c]];
1542 
1543  SCIPfreeBufferArray(scip, &permu);
1544  SCIPfreeBufferArray(scip, &compsize);
1545 
1546  /* do the mapping from calculated components per variable to corresponding
1547  * constraints and sort the component-arrays for faster finding the
1548  * actual variables and constraints belonging to one component
1549  */
1550  for( c = 0; c < nconss; c++ )
1551  conscomponent[c] = (firstvaridxpercons[c] == -1 ? -1 : varcomponent[firstvaridxpercons[c]]);
1552 
1553  SCIPsortIntPtr(varcomponent, (void**)vars, nvars);
1554  SCIPsortIntPtr(conscomponent, (void**)conss, nconss);
1555 
1556  return SCIP_OKAY;
1557 }
1558 
1559 
1560 
1561 /** create PROBLEM structure for the current node and split it into components */
1562 static
1564  SCIP* scip, /**< SCIP data structure */
1565  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1566  SCIP_Real fixedvarsobjsum, /**< objective contribution of all locally fixed variables */
1567  SCIP_VAR** sortedvars, /**< array of unfixed variables sorted by components */
1568  SCIP_CONS** sortedconss, /**< array of (checked) constraints sorted by components */
1569  int* compstartsvars, /**< start points of components in sortedvars array */
1570  int* compstartsconss, /**< start points of components in sortedconss array */
1571  int ncomponents, /**< number of components */
1572  PROBLEM** problem /**< pointer to store problem structure */
1573  )
1574 {
1575  COMPONENT* component;
1576  SCIP_HASHMAP* consmap;
1577  SCIP_HASHMAP* varmap;
1578  SCIP_VAR** compvars;
1579  SCIP_CONS** compconss;
1580  SCIP_Bool success = TRUE;
1581  int nfixedvars = SCIPgetNVars(scip) - compstartsvars[ncomponents];
1582  int ncompconss;
1583  int comp;
1584 
1585  /* init subproblem data structure */
1586  SCIP_CALL( initProblem(scip, problem, fixedvarsobjsum, ncomponents) );
1587  assert((*problem)->components != NULL);
1588 
1589  /* hashmap mapping from original constraints to constraints in the sub-SCIPs (for performance reasons) */
1590  SCIP_CALL( SCIPhashmapCreate(&consmap, SCIPblkmem(scip), compstartsconss[ncomponents]) );
1591 
1592  /* loop over all components */
1593  for( comp = 0; comp < ncomponents; comp++ )
1594  {
1596  assert((*problem)->ncomponents == comp+1);
1597 
1598  component = &(*problem)->components[comp];
1599 
1600  /* get component variables and store them in component structure */
1601  compvars = &(sortedvars[compstartsvars[comp]]);
1602  component->nvars = compstartsvars[comp + 1 ] - compstartsvars[comp];
1603  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &component->vars, compvars, component->nvars) );
1604  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &component->subvars, component->nvars) );
1605  SCIP_CALL( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), component->nvars + nfixedvars) );
1606 
1607  /* get component constraints */
1608  compconss = &(sortedconss[compstartsconss[comp]]);
1609  ncompconss = compstartsconss[comp + 1] - compstartsconss[comp];
1610 
1611 #ifdef DETAILED_OUTPUT
1612  /* print details about the component including its size */
1613  if( component->nvars > 1 && ncompconss > 1 )
1614  {
1615  int nbinvars = 0;
1616  int nintvars = 0;
1617  int ncontvars = 0;
1618  int i;
1619 
1620  for( i = 0; i < component->nvars; ++i )
1621  {
1622  if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_BINARY )
1623  ++nbinvars;
1624  else if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_INTEGER )
1625  ++nintvars;
1626  else
1627  ++ncontvars;
1628  }
1629  SCIPdebugMsg(scip, "component %d at node %lld, depth %d (%d): %d vars (%d bin, %d int, %d cont), %d conss\n",
1630  comp, SCIPnodeGetNumber(SCIPgetCurrentNode(scip)), SCIPgetDepth(scip), SCIPgetDepth(scip) + conshdlrdata->subscipdepth,
1631  component->nvars, nbinvars, nintvars, ncontvars, ncompconss);
1632  }
1633 #endif
1634  assert(ncompconss > 0 || component->nvars == 1);
1635 
1636  SCIPdebugMsg(scip, "build sub-SCIP for component %d of problem <%s>: %d vars, %d conss\n",
1637  component->number, (*problem)->name, component->nvars, ncompconss);
1638 
1639 #ifndef NDEBUG
1640  {
1641  int i;
1642  for( i = 0; i < component->nvars; ++i )
1643  assert(SCIPvarIsActive(component->vars[i]));
1644  }
1645 #endif
1646 
1647  /* build subscip for component */
1648  SCIP_CALL( componentCreateSubscip(component, conshdlrdata, varmap, consmap, compconss, ncompconss, &success) );
1649 
1650  if( success )
1651  {
1652  SCIP_CALL( componentSetupWorkingSol(component, varmap) );
1653 
1654  /* add component to the priority queue of the problem structure */
1655  SCIP_CALL( SCIPpqueueInsert((*problem)->compqueue, component) );
1656  }
1657 
1658  SCIPhashmapFree(&varmap);
1659 
1660  if( !success )
1661  break;
1662  }
1663 
1664  SCIPhashmapFree(&consmap);
1665 
1666  if( !success )
1667  {
1668  /* free subproblem data structure since not all component could be copied */
1670  }
1671 
1672  return SCIP_OKAY;
1673 }
1674 
1675 /** continue solving a problem */
1676 static
1678  PROBLEM* problem, /**< problem structure */
1679  SCIP_RESULT* result /**< result pointer for the problem solve */
1680  )
1681 {
1682  COMPONENT* component;
1683  SCIP_RESULT subscipresult;
1684 
1685  assert(problem != NULL);
1686 
1687  *result = SCIP_SUCCESS;
1688 
1689  component = (COMPONENT*)SCIPpqueueRemove(problem->compqueue);
1690 
1691  /* continue solving the component */
1692  SCIP_CALL( solveComponent(component, SCIPpqueueNElems(problem->compqueue) == 0, &subscipresult) );
1693 
1694  /* if infeasibility or unboundedness was detected, return this */
1695  if( subscipresult == SCIP_CUTOFF || subscipresult == SCIP_UNBOUNDED )
1696  {
1697  *result = subscipresult;
1698  }
1699  /* the component was not solved to optimality, so we need to re-insert it in the components queue */
1700  else if( !component->solved )
1701  {
1702  SCIP_CALL( SCIPpqueueInsert(problem->compqueue, component) );
1703  *result = SCIP_DELAYNODE;
1704  }
1705  /* no unsolved components are left, so this problem has be completely evaluated and the node can be pruned */
1706  else if( SCIPpqueueNElems(problem->compqueue) == 0 )
1707  *result = SCIP_CUTOFF;
1708  /* there are some unsolved components left, so we delay this node */
1709  else
1710  *result = SCIP_DELAYNODE;
1711 
1712  return SCIP_OKAY;
1713 }
1714 
1715 /*
1716  * Local methods
1717  */
1718 
1719 /** loop over constraints, get active variables and fill directed graph */
1720 static
1722  SCIP* scip, /**< SCIP data structure */
1723  SCIP_DIGRAPH* digraph, /**< directed graph */
1724  SCIP_CONS** conss, /**< constraints */
1725  int nconss, /**< number of constraints */
1726  int* unfixedvarpos, /**< mapping from variable problem index to unfixed var index */
1727  int nunfixedvars, /**< number of unfixed variables */
1728  int* firstvaridxpercons, /**< array to store for each constraint the index in the local vars array
1729  * of the first variable of the constraint */
1730  SCIP_Bool* success /**< flag indicating successful directed graph filling */
1731  )
1732 {
1733  SCIP_VAR** consvars;
1734  int requiredsize;
1735  int nconsvars;
1736  int nvars;
1737  int idx1;
1738  int idx2;
1739  int c;
1740  int v;
1741 
1742  assert(scip != NULL);
1743  assert(digraph != NULL);
1744  assert(conss != NULL);
1745  assert(firstvaridxpercons != NULL);
1746  assert(success != NULL);
1747 
1748  *success = TRUE;
1749 
1750  nconsvars = 0;
1751  requiredsize = 0;
1752  nvars = SCIPgetNVars(scip);
1753 
1754  /* allocate buffer for storing active variables per constraint; size = nvars ensures that it will be big enough */
1755  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nvars) );
1756 
1757  for( c = 0; c < nconss; ++c )
1758  {
1759  /* check for reached timelimit */
1760  if( (c % 1000 == 0) && SCIPisStopped(scip) )
1761  {
1762  *success = FALSE;
1763  break;
1764  }
1765 
1766  /* get number of variables for this constraint */
1767  SCIP_CALL( SCIPgetConsNVars(scip, conss[c], &nconsvars, success) );
1768 
1769  if( !(*success) )
1770  break;
1771 
1772  /* reallocate consvars array, if needed */
1773  if( nconsvars > nvars )
1774  {
1775  nvars = nconsvars;
1776  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, nvars) );
1777  }
1778 
1779 #ifndef NDEBUG
1780  /* clearing variables array to check for consistency */
1781  if( nconsvars == nvars )
1782  {
1783  BMSclearMemoryArray(consvars, nconsvars);
1784  }
1785  else
1786  {
1787  assert(nconsvars < nvars);
1788  BMSclearMemoryArray(consvars, nconsvars + 1);
1789  }
1790 #endif
1791 
1792  /* get variables for this constraint */
1793  SCIP_CALL( SCIPgetConsVars(scip, conss[c], consvars, nvars, success) );
1794 
1795  if( !(*success) )
1796  {
1797 #ifndef NDEBUG
1798  /* it looks strange if returning the number of variables was successful but not returning the variables */
1799  SCIPwarningMessage(scip, "constraint <%s> returned number of variables but returning variables failed\n", SCIPconsGetName(conss[c]));
1800 #endif
1801  break;
1802  }
1803 
1804 #ifndef NDEBUG
1805  /* check if returned variables are consistent with the number of variables that were returned */
1806  for( v = nconsvars - 1; v >= 0; --v )
1807  assert(consvars[v] != NULL);
1808  if( nconsvars < nvars )
1809  assert(consvars[nconsvars] == NULL);
1810 #endif
1811 
1812  /* transform given variables to active variables */
1813  SCIP_CALL( SCIPgetActiveVars(scip, consvars, &nconsvars, nvars, &requiredsize) );
1814  assert(requiredsize <= nvars);
1815 
1816  firstvaridxpercons[c] = -1;
1817 
1818  /* store the index of the first unfixed variable and add edges to the directed graph */
1819  if( nconsvars > 0 )
1820  {
1821  v = 0;
1822  idx1 = -1;
1823 
1824  /* go through variables until the first unfixed one is reached (which has unfixedvarpos >= 0) */
1825  while( idx1 == -1 && v < nconsvars )
1826  {
1827  idx1 = SCIPvarGetProbindex(consvars[v]);
1828  assert(idx1 >= 0);
1829  idx1 = unfixedvarpos[idx1];
1830  assert(idx1 < nunfixedvars);
1831  ++v;
1832  }
1833 
1834  if( idx1 >= 0 )
1835  {
1836  /* save index of the first variable for later component assignment */
1837  firstvaridxpercons[c] = idx1;
1838 
1839  /* create sparse directed graph; sparse means to add only those edges necessary for component calculation,
1840  * i.e., add edges from the first variable to all others
1841  */
1842  for(; v < nconsvars; ++v )
1843  {
1844  idx2 = SCIPvarGetProbindex(consvars[v]);
1845  assert(idx2 >= 0);
1846  idx2 = unfixedvarpos[idx2];
1847  assert(idx2 < nunfixedvars);
1848 
1849  /* variable is fixed */
1850  if( idx2 < 0 )
1851  continue;
1852 
1853  /* we add only one directed edge, because the other direction is automatically added for component computation */
1854  SCIP_CALL( SCIPdigraphAddArc(digraph, idx1, idx2, NULL) );
1855  }
1856  }
1857  }
1858  }
1859 
1860  SCIPfreeBufferArray(scip, &consvars);
1861 
1862  return SCIP_OKAY;
1863 }
1864 
1865 /** search for components in the problem */
1866 static
1868  SCIP* scip, /**< SCIP main data structure */
1869  SCIP_CONSHDLRDATA* conshdlrdata, /**< the components constraint handler data */
1870  SCIP_Real* fixedvarsobjsum, /**< objective contribution of all locally fixed variables, or NULL if
1871  * fixed variables should not be disregarded */
1872  SCIP_VAR** sortedvars, /**< array to store variables sorted by components, should have enough size
1873  * for all variables */
1874  SCIP_CONS** sortedconss, /**< array to store (checked) constraints sorted by components, should have
1875  * enough size for all constraints */
1876  int* compstartsvars, /**< start points of components in sortedvars array */
1877  int* compstartsconss, /**< start points of components in sortedconss array */
1878  int* nsortedvars, /**< pointer to store the number of variables belonging to any component */
1879  int* nsortedconss, /**< pointer to store the number of (checked) constraints in components */
1880  int* ncomponents, /**< pointer to store the number of components */
1881  int* ncompsminsize, /**< pointer to store the number of components not exceeding the minimum size */
1882  int* ncompsmaxsize /**< pointer to store the number of components not exceeding the maximum size */
1883 
1884  )
1885 {
1886  SCIP_CONS** tmpconss;
1887  SCIP_VAR** vars;
1888  SCIP_Bool success;
1889  int ntmpconss;
1890  int nvars;
1891  int c;
1892 
1893  assert(scip != NULL);
1894  assert(conshdlrdata != NULL);
1895  assert(sortedvars != NULL);
1896  assert(sortedconss != NULL);
1897  assert(compstartsvars != NULL);
1898  assert(compstartsconss != NULL);
1899  assert(nsortedvars != NULL);
1900  assert(nsortedconss != NULL);
1901  assert(ncomponents != NULL);
1902  assert(ncompsminsize != NULL);
1903  assert(ncompsmaxsize != NULL);
1904 
1905  vars = SCIPgetVars(scip);
1906  nvars = SCIPgetNVars(scip);
1907 
1908  if( fixedvarsobjsum != NULL )
1909  *fixedvarsobjsum = 0.0;
1910 
1911  *ncomponents = 0;
1912  *ncompsminsize = 0;
1913  *ncompsmaxsize = 0;
1914 
1915  /* collect checked constraints for component detection */
1916  ntmpconss = SCIPgetNConss(scip);
1917  tmpconss = SCIPgetConss(scip);
1918  (*nsortedconss) = 0;
1919  for( c = 0; c < ntmpconss; c++ )
1920  {
1921  sortedconss[(*nsortedconss)] = tmpconss[c];
1922  (*nsortedconss)++;
1923  }
1924 
1925  if( nvars > 1 && *nsortedconss > 1 )
1926  {
1927  int* unfixedvarpos;
1928  int* firstvaridxpercons;
1929  int* varlocks;
1930  int nunfixedvars = 0;
1931  int v;
1932 
1933  /* arrays for storing the first variable in each constraint (for later component assignment), the number of
1934  * variable locks, and the positions in the sortedvars array for all unfixed variables
1935  */
1936  SCIP_CALL( SCIPallocBufferArray(scip, &firstvaridxpercons, *nsortedconss) );
1937  SCIP_CALL( SCIPallocBufferArray(scip, &varlocks, nvars) );
1938  SCIP_CALL( SCIPallocBufferArray(scip, &unfixedvarpos, nvars) );
1939 
1940  /* count number of varlocks for each variable (up + down locks) and multiply it by 2;
1941  * that value is used as an estimate of the number of arcs incident to the variable's node in the digraph
1942  * to be safe, we double this value
1943  */
1944  for( v = 0; v < nvars; ++v )
1945  {
1946  /* variable is not fixed or we do not want to disregard fixed variables */
1947  if( (fixedvarsobjsum == NULL) || SCIPisLT(scip, SCIPvarGetLbLocal(vars[v]), SCIPvarGetUbLocal(vars[v])) )
1948  {
1949  assert(nunfixedvars <= v);
1950  sortedvars[nunfixedvars] = vars[v];
1951  varlocks[nunfixedvars] = 4 * (SCIPvarGetNLocksDownType(vars[v], SCIP_LOCKTYPE_MODEL)
1953  unfixedvarpos[v] = nunfixedvars;
1954  ++nunfixedvars;
1955  }
1956  /* variable is fixed; update the objective sum of all fixed variables */
1957  else
1958  {
1959  unfixedvarpos[v] = -1;
1960  (*fixedvarsobjsum) += SCIPvarGetObj(vars[v]) * SCIPvarGetLbLocal(vars[v]);
1961  }
1962  }
1963  *nsortedvars = nunfixedvars;
1964 
1965  if( nunfixedvars > 0 )
1966  {
1967  SCIP_DIGRAPH* digraph;
1968 
1969  /* create and fill directed graph */
1970  SCIP_CALL( SCIPcreateDigraph(scip, &digraph, nunfixedvars) );
1971  SCIP_CALL( SCIPdigraphSetSizes(digraph, varlocks) );
1972  SCIP_CALL( fillDigraph(scip, digraph, sortedconss, *nsortedconss, unfixedvarpos, nunfixedvars, firstvaridxpercons, &success) );
1973 
1974  if( success )
1975  {
1976  int* varcomponent;
1977  int* conscomponent;
1978 
1979  SCIP_CALL( SCIPallocBufferArray(scip, &varcomponent, nunfixedvars) );
1980  SCIP_CALL( SCIPallocBufferArray(scip, &conscomponent, MAX(nunfixedvars,*nsortedconss)) );
1981 
1982  /* compute independent components */
1983  SCIP_CALL( SCIPdigraphComputeUndirectedComponents(digraph, 1, varcomponent, ncomponents) );
1984 
1985  if( *ncomponents > 1 )
1986  {
1987  int nconss = *nsortedconss;
1988  int i;
1989 
1990  nvars = *nsortedvars;
1991 
1993  "cons components found %d undirected components at node %lld, depth %d (%d)\n",
1994  *ncomponents, SCIPnodeGetNumber(SCIPgetCurrentNode(scip)), SCIPgetDepth(scip), SCIPgetDepth(scip) + conshdlrdata->subscipdepth);
1995 
1996  /* sort components by size and sort variables and constraints by component number */
1997  SCIP_CALL( sortComponents(scip, conshdlrdata, digraph, sortedconss, sortedvars, varcomponent, conscomponent, nconss, *nsortedvars,
1998  firstvaridxpercons, ncompsminsize, ncompsmaxsize) );
1999 
2000  /* determine start indices of components in sortedvars and sortedconss array */
2001  i = 0;
2002 
2003  while( i < nconss && conscomponent[i] == -1 )
2004  ++i;
2005 
2006  for( c = 0; c < *ncomponents + 1; ++c )
2007  {
2008  assert(i == nconss || conscomponent[i] >= c);
2009 
2010  compstartsconss[c] = i;
2011 
2012  while( i < nconss && conscomponent[i] == c )
2013  ++i;
2014  }
2015 
2016  for( c = 0, i = 0; c < *ncomponents + 1; ++c )
2017  {
2018  assert(i == nvars || varcomponent[i] >= c);
2019 
2020  compstartsvars[c] = i;
2021 
2022  while( i < nvars && varcomponent[i] == c )
2023  ++i;
2024  }
2025 
2026 #ifndef NDEBUG
2027  for( c = 0; c < *ncomponents; ++c )
2028  {
2029  for( i = compstartsconss[c]; i < compstartsconss[c+1]; ++i )
2030  assert(conscomponent[i] == c);
2031  for( i = compstartsvars[c]; i < compstartsvars[c+1]; ++i )
2032  assert(varcomponent[i] == c);
2033  }
2034 #endif
2035  }
2036 
2037  SCIPfreeBufferArray(scip, &conscomponent);
2038  SCIPfreeBufferArray(scip, &varcomponent);
2039  }
2040 
2041  SCIPdigraphFree(&digraph);
2042  }
2043 
2044  SCIPfreeBufferArray(scip, &unfixedvarpos);
2045  SCIPfreeBufferArray(scip, &varlocks);
2046  SCIPfreeBufferArray(scip, &firstvaridxpercons);
2047  }
2048 
2049  return SCIP_OKAY;
2050 }
2051 
2052 
2053 /*
2054  * Callback methods of constraint handler
2055  */
2056 
2057 /** copy method for constraint handler plugins (called when SCIP copies plugins) */
2058 static
2059 SCIP_DECL_CONSHDLRCOPY(conshdlrCopyComponents)
2060 { /*lint --e{715}*/
2061  assert(scip != NULL);
2062  assert(conshdlr != NULL);
2063  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2064 
2065  /* call inclusion method of constraint handler */
2067 
2068  *valid = TRUE;
2069 
2070  return SCIP_OKAY;
2071 }
2072 
2073 /** destructor of constraint handler to free user data (called when SCIP is exiting) */
2074 static
2075 SCIP_DECL_CONSFREE(conshdlrFreeComponents)
2076 { /*lint --e{715}*/
2077  SCIP_CONSHDLRDATA* conshdlrdata;
2078 
2079  /* free constraint handler data */
2080  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2081  assert(conshdlrdata != NULL);
2082 
2083  SCIPfreeBlockMemory(scip, &conshdlrdata);
2084  SCIPconshdlrSetData(conshdlr, NULL);
2085 
2086  return SCIP_OKAY;
2087 }
2088 
2089 /** domain propagation method of constraint handler */
2090 static
2091 SCIP_DECL_CONSPROP(consPropComponents)
2092 { /*lint --e{715}*/
2093  PROBLEM* problem;
2094  SCIP_CONSHDLRDATA* conshdlrdata;
2095  SCIP_Longint nodelimit;
2096 
2097  assert(conshdlr != NULL);
2098  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2099  assert(result != NULL);
2100  assert(SCIPconshdlrGetNActiveConss(conshdlr) >= 0);
2101  assert(SCIPconshdlrGetNActiveConss(conshdlr) <= 1);
2102 
2103  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2104  assert(conshdlrdata != NULL);
2105 
2106  *result = SCIP_DIDNOTRUN;
2107 
2108  /* do not try to detect independent components if the depth is too high */
2109  if( SCIPgetDepth(scip) + conshdlrdata->subscipdepth > conshdlrdata->maxdepth
2110  && SCIPconshdlrGetNActiveConss(conshdlr) == 0 )
2111  return SCIP_OKAY;
2112 
2113  /* don't run in probing or in repropagation */
2114  if( SCIPinProbing(scip) || SCIPinRepropagation(scip) )
2115  return SCIP_OKAY;
2116 
2117  /* do not run, if not all variables are explicitly known */
2118  if( SCIPgetNActivePricers(scip) > 0 )
2119  return SCIP_OKAY;
2120 
2121  /* we do not want to run, if there are no variables left */
2122  if( SCIPgetNVars(scip) == 0 )
2123  return SCIP_OKAY;
2124 
2125  /* check for a reached timelimit */
2126  if( SCIPisStopped(scip) )
2127  return SCIP_OKAY;
2128 
2129  /* the components constraint handler does kind of dual reductions */
2130  if( !SCIPallowStrongDualReds(scip) || !SCIPallowWeakDualReds(scip) )
2131  return SCIP_OKAY;
2132 
2133  problem = NULL;
2134  *result = SCIP_DIDNOTFIND;
2135 
2136  /* the current node already has a components constraint storing a problem split into individual components */
2137  if( SCIPconshdlrGetNActiveConss(conshdlr) >= 1 )
2138  {
2139  assert(SCIPconshdlrGetNActiveConss(conshdlr) == 1);
2140 
2141  problem = (PROBLEM*)SCIPconsGetData(SCIPconshdlrGetConss(conshdlr)[0]);
2142  }
2143  /* no components constraint at the current node, search for components */
2144  else
2145  {
2147  SCIP_VAR** sortedvars;
2148  SCIP_CONS** sortedconss;
2149  int* compstartsvars;
2150  int* compstartsconss;
2151  int nsortedvars;
2152  int nsortedconss;
2153  int ncomponents;
2154  int ncompsminsize;
2155  int ncompsmaxsize;
2156 
2157  assert(SCIPconshdlrGetNActiveConss(conshdlr) == 0);
2158 
2159  /* allocate memory for sorted components */
2160  SCIP_CALL( SCIPallocBufferArray(scip, &sortedvars, SCIPgetNVars(scip)) );
2161  SCIP_CALL( SCIPallocBufferArray(scip, &sortedconss, SCIPgetNConss(scip)) );
2162  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsvars, SCIPgetNVars(scip) + 1) );
2163  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsconss, SCIPgetNVars(scip) + 1) );
2164 
2165  /* search for components */
2166  SCIP_CALL( findComponents(scip, conshdlrdata, &fixedvarsobjsum, sortedvars, sortedconss, compstartsvars,
2167  compstartsconss, &nsortedvars, &nsortedconss, &ncomponents, &ncompsminsize, &ncompsmaxsize) );
2168 
2169  if( ncompsminsize > 1 )
2170  {
2171  SCIP_CONS* cons;
2172 
2173  SCIPdebugMsg(scip, "found %d components (%d fulfulling the minsize requirement) at node %lld at depth %d (%d)\n",
2174  ncomponents, ncompsminsize, SCIPnodeGetNumber(SCIPgetCurrentNode(scip)), SCIPgetDepth(scip),
2175  SCIPgetDepth(scip) + conshdlrdata->subscipdepth);
2176 
2177  /* if there are components with size smaller than the limit, we merge them with the smallest component */
2178  if( ncomponents > ncompsminsize )
2179  {
2180  int minsize;
2181  int size;
2182  int c;
2183  int m = 0;
2184 
2185  /* compute minimum size of components to solve individually */
2186  minsize = getMinsize(scip, conshdlrdata);
2187 
2188  for( c = 0; c < ncomponents; ++c )
2189  {
2190  size = compstartsvars[c+1] - compstartsvars[c];
2191 
2192  if( size >= minsize )
2193  {
2194  ++m;
2195  compstartsvars[m] = compstartsvars[c+1];
2196  compstartsconss[m] = compstartsconss[c+1];
2197  }
2198  /* the last component is too small */
2199  else if( c == ncomponents - 1 )
2200  {
2201  assert(m == ncompsminsize);
2202  compstartsvars[m] = compstartsvars[c+1];
2203  compstartsconss[m] = compstartsconss[c+1];
2204  }
2205  }
2206  assert(m == ncompsminsize);
2207  assert(compstartsvars[m] == nsortedvars);
2208  assert(compstartsconss[m] == nsortedconss);
2209 
2210  ncomponents = m;
2211  }
2212 
2213  SCIP_CALL( createAndSplitProblem(scip, conshdlrdata, fixedvarsobjsum, sortedvars, sortedconss, compstartsvars,
2214  compstartsconss, ncomponents, &problem) );
2215 
2216  /* if the problem is not NULL, copying worked fine */
2217  if( problem != NULL )
2218  {
2219  SCIP_CALL( createConsComponents(scip, &cons, problem->name, problem) );
2220  SCIP_CALL( SCIPaddConsNode(scip, SCIPgetCurrentNode(scip), cons, NULL) );
2221  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
2222  }
2223  }
2224 
2225  SCIPfreeBufferArray(scip, &compstartsconss);
2226  SCIPfreeBufferArray(scip, &compstartsvars);
2227  SCIPfreeBufferArray(scip, &sortedconss);
2228  SCIPfreeBufferArray(scip, &sortedvars);
2229  }
2230 
2231  /* (continue to) solve the problem
2232  *
2233  * If the problem was not solved to optimality yet, the result code is set to SCIP_DELAYNODE, so that after the
2234  * propagation is finished, the node is put back into the queue of open nodes and solving the components of the
2235  * problem will be continued when the node is focused and propagated the next time.
2236  * However, if we are at the root node, we continue solving the problem until it is solved or some limit is reached
2237  * since there are no other nodes to process and we want to avoid calling other propagation methods or heuristics
2238  * again and again
2239  */
2240  SCIP_CALL( SCIPgetLongintParam(scip, "limits/nodes", &nodelimit) );
2241  if( nodelimit == -1 )
2242  nodelimit = SCIP_LONGINT_MAX;
2243 
2244  do
2245  {
2246  if( problem != NULL )
2247  {
2248  SCIP_CALL( solveProblem(problem, result) );
2249  }
2250  } while( *result == SCIP_DELAYNODE && SCIPgetDepth(scip) == 0 && !SCIPisStopped(scip) && SCIPgetNNodes(scip) < nodelimit);
2251 
2252  return SCIP_OKAY;
2253 }
2254 
2255 /** presolving method of constraint handler */
2256 static
2257 SCIP_DECL_CONSPRESOL(consPresolComponents)
2258 { /*lint --e{715}*/
2259  SCIP_CONSHDLRDATA* conshdlrdata;
2260  SCIP_VAR** sortedvars;
2261  SCIP_CONS** sortedconss;
2262  int* compstartsvars;
2263  int* compstartsconss;
2264  int nsortedvars;
2265  int nsortedconss;
2266  int ncomponents;
2267  int ncompsminsize;
2268  int ncompsmaxsize;
2269  int nvars;
2270 
2271  assert(conshdlr != NULL);
2272  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2273  assert(result != NULL);
2274  assert(SCIPconshdlrGetNActiveConss(conshdlr) >= 0);
2275  assert(SCIPconshdlrGetNActiveConss(conshdlr) <= 1);
2276 
2277  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2278  assert(conshdlrdata != NULL);
2279 
2280  *result = SCIP_DIDNOTRUN;
2281 
2282  if( SCIPgetStage(scip) != SCIP_STAGE_PRESOLVING || SCIPinProbing(scip) )
2283  return SCIP_OKAY;
2284 
2285  /* do not run, if not all variables are explicitly known */
2286  if( SCIPgetNActivePricers(scip) > 0 )
2287  return SCIP_OKAY;
2288 
2289  nvars = SCIPgetNVars(scip);
2290 
2291  /* we do not want to run, if there are no variables left */
2292  if( nvars == 0 )
2293  return SCIP_OKAY;
2294 
2295  /* only call the components presolving, if presolving would be stopped otherwise */
2296  if( !SCIPisPresolveFinished(scip) )
2297  return SCIP_OKAY;
2298 
2299  /* the components constraint handler does kind of dual reductions */
2300  if( !SCIPallowStrongDualReds(scip) || !SCIPallowWeakDualReds(scip) )
2301  return SCIP_OKAY;
2302 
2303  /* check for a reached timelimit */
2304  if( SCIPisStopped(scip) )
2305  return SCIP_OKAY;
2306 
2307  *result = SCIP_DIDNOTFIND;
2308 
2309  assert(SCIPconshdlrGetNActiveConss(conshdlr) == 0);
2310 
2311  /* allocate memory for sorted components */
2312  SCIP_CALL( SCIPallocBufferArray(scip, &sortedvars, SCIPgetNVars(scip)) );
2313  SCIP_CALL( SCIPallocBufferArray(scip, &sortedconss, SCIPgetNConss(scip)) );
2314  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsvars, SCIPgetNVars(scip) + 1) );
2315  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsconss, SCIPgetNVars(scip) + 1) );
2316 
2317  /* search for components */
2318  SCIP_CALL( findComponents(scip, conshdlrdata, NULL, sortedvars, sortedconss, compstartsvars,
2319  compstartsconss, &nsortedvars, &nsortedconss, &ncomponents, &ncompsminsize, &ncompsmaxsize) );
2320 
2321  if( ncompsmaxsize > 0 )
2322  {
2323  char name[SCIP_MAXSTRLEN];
2324  SCIP* subscip;
2325  SCIP_HASHMAP* consmap;
2326  SCIP_HASHMAP* varmap;
2327  SCIP_VAR** compvars;
2328  SCIP_VAR** subvars;
2329  SCIP_CONS** compconss;
2330  SCIP_Bool success;
2331  SCIP_Bool solved;
2332  int nsolved = 0;
2333  int ncompvars;
2334  int ncompconss;
2335  int comp;
2336 
2337  SCIPdebugMsg(scip, "found %d components (%d with small size) during presolving; overall problem size: %d vars (%d int, %d bin, %d cont), %d conss\n",
2338  ncomponents, ncompsmaxsize, SCIPgetNVars(scip), SCIPgetNBinVars(scip), SCIPgetNIntVars(scip), SCIPgetNContVars(scip) + SCIPgetNImplVars(scip), SCIPgetNConss(scip));
2339 
2340  /* build subscip */
2341  SCIP_CALL( createSubscip(scip, conshdlrdata, &subscip) );
2342 
2343  if( subscip == NULL )
2344  goto TERMINATE;
2345 
2346  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/usesmalltables", TRUE) );
2347  SCIP_CALL( SCIPsetIntParam(subscip, "constraints/" CONSHDLR_NAME "/propfreq", -1) );
2348 
2349  /* hashmap mapping from original constraints to constraints in the sub-SCIPs (for performance reasons) */
2350  SCIP_CALL( SCIPhashmapCreate(&consmap, SCIPblkmem(scip), nsortedconss) );
2351 
2352  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nsortedvars) );
2353 
2354  /* loop over all components */
2355  for( comp = 0; comp < ncompsmaxsize && !SCIPisStopped(scip); comp++ )
2356  {
2357 #ifdef WITH_DEBUG_SOLUTION
2358  if( SCIPgetStage(subscip) > SCIP_STAGE_INIT )
2359  {
2360  SCIP_CALL( SCIPfree(&subscip) );
2361  SCIP_CALL( createSubscip(scip, conshdlrdata, &subscip) );
2362  }
2363 #endif
2364  /* get component variables */
2365  compvars = &(sortedvars[compstartsvars[comp]]);
2366  ncompvars = compstartsvars[comp + 1 ] - compstartsvars[comp];
2367 
2368  /* get component constraints */
2369  compconss = &(sortedconss[compstartsconss[comp]]);
2370  ncompconss = compstartsconss[comp + 1] - compstartsconss[comp];
2371 
2372  /* if we have an unlocked variable, let duality fixing do the job! */
2373  if( ncompconss == 0 )
2374  {
2375  assert(ncompvars == 1);
2376  continue;
2377  }
2378 
2379  SCIP_CALL( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), ncompvars) );
2380 #ifdef DETAILED_OUTPUT
2381  {
2382  int nbinvars = 0;
2383  int nintvars = 0;
2384  int ncontvars = 0;
2385  int i;
2386 
2387  for( i = 0; i < ncompvars; ++i )
2388  {
2389  if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_BINARY )
2390  ++nbinvars;
2391  else if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_INTEGER )
2392  ++nintvars;
2393  else
2394  ++ncontvars;
2395  }
2396  SCIPdebugMsg(scip, "solve component %d: %d vars (%d bin, %d int, %d cont), %d conss\n",
2397  comp, ncompvars, nbinvars, nintvars, ncontvars, ncompconss);
2398  }
2399 #endif
2400 #ifndef NDEBUG
2401  {
2402  int i;
2403  for( i = 0; i < ncompvars; ++i )
2404  assert(SCIPvarIsActive(compvars[i]));
2405  }
2406 #endif
2407 
2408  /* get name of the original problem and add "comp_nr" */
2409  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_comp_%d", SCIPgetProbName(scip), comp);
2410 
2411  SCIP_CALL( copyToSubscip(scip, subscip, name, compvars, subvars,
2412  compconss, varmap, consmap, ncompvars, ncompconss, &success) );
2413 
2414  if( !success )
2415  {
2416  SCIPhashmapFree(&varmap);
2417  continue;
2418  }
2419 
2420  /* set up debug solution */
2421 #ifdef WITH_DEBUG_SOLUTION
2422  if( SCIPdebugSolIsEnabled(scip) )
2423  {
2424  SCIP_SOL* debugsol;
2425  SCIP_Real val;
2426  int i;
2427 
2428  SCIP_CALL( SCIPdebugGetSol(scip, &debugsol) );
2429 
2430  /* set solution values in the debug solution if it is available */
2431  if( debugsol != NULL )
2432  {
2433  SCIPdebugSolEnable(subscip);
2434 
2435  for( i = 0; i < ncompvars; ++i )
2436  {
2437  if( subvars[i] != NULL )
2438  {
2439  SCIP_CALL( SCIPdebugGetSolVal(scip, compvars[i], &val) );
2440  SCIP_CALL( SCIPdebugAddSolVal(subscip, subvars[i], val) );
2441  }
2442  }
2443  }
2444  }
2445 #endif
2446 
2447  /* solve the subproblem and evaluate the result, i.e. apply fixings of variables and remove constraints */
2448  SCIP_CALL( solveAndEvalSubscip(scip, conshdlrdata, subscip, compvars, subvars, compconss,
2449  ncompvars, ncompconss, ndelconss, nfixedvars, nchgbds, result, &solved) );
2450 
2451  /* free variable hash map */
2452  SCIPhashmapFree(&varmap);
2453 
2454  if( solved )
2455  ++nsolved;
2456 
2457  /* if the component is unbounded or infeasible, this holds for the complete problem as well */
2458  if( *result == SCIP_UNBOUNDED || *result == SCIP_CUTOFF )
2459  break;
2460  /* if there is only one component left, let's solve this in the main SCIP */
2461  else if( nsolved == ncomponents - 1 )
2462  break;
2463  }
2464 
2465  SCIPfreeBufferArray(scip, &subvars);
2466  SCIPhashmapFree(&consmap);
2467 
2468  SCIP_CALL( SCIPfree(&subscip) );
2469  }
2470 
2471  TERMINATE:
2472  SCIPfreeBufferArray(scip, &compstartsconss);
2473  SCIPfreeBufferArray(scip, &compstartsvars);
2474  SCIPfreeBufferArray(scip, &sortedconss);
2475  SCIPfreeBufferArray(scip, &sortedvars);
2476 
2477  return SCIP_OKAY;
2478 }
2479 
2480 /** frees specific constraint data */
2481 static
2482 SCIP_DECL_CONSDELETE(consDeleteComponents)
2483 { /*lint --e{715}*/
2484  assert(conshdlr != NULL);
2485  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2486  assert(consdata != NULL);
2487  assert(*consdata != NULL);
2488 
2489  SCIP_CALL( freeProblem((PROBLEM**) consdata) );
2490 
2491  return SCIP_OKAY;
2492 }
2493 
2494 /** constraint enforcing method of constraint handler for relaxation solutions */
2495 static
2496 SCIP_DECL_CONSENFORELAX(consEnforelaxComponents)
2497 { /*lint --e{715}*/
2498  assert(result != NULL );
2499 
2500  /* no enforcement is performed, but the callback is needed for all constraint handlers with needscons = FALSE */
2501  *result = SCIP_FEASIBLE;
2502 
2503  return SCIP_OKAY;
2504 }
2505 
2506 /** variable rounding lock method of constraint handler */
2507 static
2508 SCIP_DECL_CONSLOCK(consLockComponents)
2509 { /*lint --e{715}*/
2510  return SCIP_OKAY;
2511 }
2512 
2513 #ifndef NDEBUG
2514 /** solving process initialization method of constraint handler (called when branch and bound process is about to begin) */
2515 static
2516 SCIP_DECL_CONSINITSOL(consInitsolComponents)
2517 { /*lint --e{715}*/
2518  assert(nconss == 0);
2519 
2520  return SCIP_OKAY;
2521 }
2522 #endif
2523 
2524 #define consEnfolpComponents NULL
2525 #define consEnfopsComponents NULL
2526 #define consCheckComponents NULL
2528 /**@name Interface methods
2529  *
2530  * @{
2531  */
2532 
2533 /** creates the components constraint handler and includes it in SCIP */
2535  SCIP* scip /**< SCIP data structure */
2536  )
2537 {
2538  SCIP_CONSHDLRDATA* conshdlrdata;
2539  SCIP_CONSHDLR* conshdlr;
2540 
2541  /* create components propagator data */
2542  SCIP_CALL( SCIPallocBlockMemory(scip, &conshdlrdata) );
2543  conshdlrdata->subscipdepth = 0;
2544 
2545  /* include constraint handler */
2549  conshdlrdata) );
2550  assert(conshdlr != NULL);
2551 
2552  SCIP_CALL( SCIPsetConshdlrProp(scip, conshdlr, consPropComponents,
2554  SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolComponents,
2556 
2557  SCIP_CALL( SCIPsetConshdlrFree(scip, conshdlr, conshdlrFreeComponents) );
2558  SCIP_CALL( SCIPsetConshdlrEnforelax(scip, conshdlr, consEnforelaxComponents) );
2559 #ifndef NDEBUG
2560  SCIP_CALL( SCIPsetConshdlrInitsol(scip, conshdlr, consInitsolComponents) );
2561 #endif
2562  SCIP_CALL( SCIPsetConshdlrCopy(scip, conshdlr, conshdlrCopyComponents, NULL) );
2563  SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteComponents) );
2564 
2565  SCIP_CALL( SCIPaddIntParam(scip,
2566  "constraints/" CONSHDLR_NAME "/maxdepth",
2567  "maximum depth of a node to run components detection (-1: disable component detection during solving)",
2568  &conshdlrdata->maxdepth, FALSE, DEFAULT_MAXDEPTH, -1, INT_MAX, NULL, NULL) );
2569  SCIP_CALL( SCIPaddIntParam(scip,
2570  "constraints/" CONSHDLR_NAME "/maxintvars",
2571  "maximum number of integer (or binary) variables to solve a subproblem during presolving (-1: unlimited)",
2572  &conshdlrdata->maxintvars, TRUE, DEFAULT_MAXINTVARS, -1, INT_MAX, NULL, NULL) );
2573  SCIP_CALL( SCIPaddIntParam(scip,
2574  "constraints/" CONSHDLR_NAME "/minsize",
2575  "minimum absolute size (in terms of variables) to solve a component individually during branch-and-bound",
2576  &conshdlrdata->minsize, TRUE, DEFAULT_MINSIZE, 0, INT_MAX, NULL, NULL) );
2578  "constraints/" CONSHDLR_NAME "/minrelsize",
2579  "minimum relative size (in terms of variables) to solve a component individually during branch-and-bound",
2580  &conshdlrdata->minrelsize, TRUE, DEFAULT_MINRELSIZE, 0.0, 1.0, NULL, NULL) );
2582  "constraints/" CONSHDLR_NAME "/nodelimit",
2583  "maximum number of nodes to be solved in subproblems during presolving",
2584  &conshdlrdata->nodelimit, FALSE, DEFAULT_NODELIMIT, -1LL, SCIP_LONGINT_MAX, NULL, NULL) );
2586  "constraints/" CONSHDLR_NAME "/intfactor",
2587  "the weight of an integer variable compared to binary variables",
2588  &conshdlrdata->intfactor, FALSE, DEFAULT_INTFACTOR, 0.0, SCIP_REAL_MAX, NULL, NULL) );
2590  "constraints/" CONSHDLR_NAME "/feastolfactor",
2591  "factor to increase the feasibility tolerance of the main SCIP in all sub-SCIPs, default value 1.0",
2592  &conshdlrdata->feastolfactor, TRUE, DEFAULT_FEASTOLFACTOR, 0.0, 1000000.0, NULL, NULL) );
2593 
2594  return SCIP_OKAY;
2595 }
2596 
2597 /**@} */
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:97
#define CONSHDLR_ENFOPRIORITY
void * SCIPpqueueRemove(SCIP_PQUEUE *pqueue)
Definition: misc.c:1434
SCIP_RETCODE SCIPcreateOrigSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:557
void SCIPconshdlrSetData(SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons.c:4197
int SCIPgetNContVars(SCIP *scip)
Definition: scip_prob.c:2166
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:977
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
#define DEFAULT_MAXINTVARS
SCIP_RETCODE SCIPprintDisplayLine(SCIP *scip, FILE *file, SCIP_VERBLEVEL verblevel, SCIP_Bool endline)
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:687
void SCIPpqueueFree(SCIP_PQUEUE **pqueue)
Definition: misc.c:1263
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip_mem.h:80
SCIP_RETCODE SCIPcreateDigraph(SCIP *scip, SCIP_DIGRAPH **digraph, int nnodes)
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip_cons.c:877
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1429
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1213
int SCIPdigraphGetNComponents(SCIP_DIGRAPH *digraph)
Definition: misc.c:8186
public methods for SCIP parameter handling
public methods for branch and bound tree
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:65
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE freeProblem(PROBLEM **problem)
SCIP_RETCODE SCIPtightenVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip_var.c:5184
SCIP_RETCODE SCIPcreateCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_CONSHDLR *conshdlr, SCIP_CONSDATA *consdata, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: scip_cons.c:934
SCIP_Bool SCIPallowWeakDualReds(SCIP *scip)
Definition: scip_var.c:8624
SCIP_EXPORT int SCIPvarGetNLocksUpType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3250
public methods for memory management
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
Definition: scip_cons.c:308
SCIP_STATUS SCIPgetStatus(SCIP *scip)
Definition: scip_general.c:467
SCIP_RETCODE SCIPinterruptSolve(SCIP *scip)
Definition: scip_solve.c:3407
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8276
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:69
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
Definition: scip_cons.c:166
static SCIP_DECL_CONSENFORELAX(consEnforelaxComponents)
#define SCIP_MAXSTRLEN
Definition: def.h:273
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:123
static SCIP_DECL_CONSDELETE(consDeleteComponents)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1353
SCIP_RETCODE SCIPtightenVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip_var.c:5301
public solving methods
SCIP_Real SCIPgetGap(SCIP *scip)
SCIP_EXPORT SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
Definition: tree.c:7429
public methods for timing
SCIP_RETCODE SCIPtransformProb(SCIP *scip)
Definition: scip_solve.c:357
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:1534
#define DEFAULT_INTFACTOR
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
Definition: scip_tree.c:81
int SCIPgetNConss(SCIP *scip)
Definition: scip_prob.c:3036
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:1986
SCIP_Real SCIPgetSolvingTime(SCIP *scip)
Definition: scip_timing.c:360
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:216
#define FALSE
Definition: def.h:73
static SCIP_RETCODE solveSubscip(SCIP *scip, SCIP *subscip, SCIP_Longint nodelimit, SCIP_Real gaplimit)
#define CONSHDLR_EAGERFREQ
SCIP_EXPORT SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17515
SCIP_EXPORT SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
Definition: sol.c:2604
static int getMinsize(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata)
SCIP_EXPORT SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17182
#define TRUE
Definition: def.h:72
SCIP_CONS ** SCIPgetConss(SCIP *scip)
Definition: scip_prob.c:3082
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
int SCIPpqueueNElems(SCIP_PQUEUE *pqueue)
Definition: misc.c:1468
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:8246
SCIP_RETCODE SCIPsetConshdlrDelete(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELETE((*consdelete)))
Definition: scip_cons.c:563
SCIP_RETCODE SCIPsolve(SCIP *scip)
Definition: scip_solve.c:2527
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
void SCIPdigraphFree(SCIP_DIGRAPH **digraph)
Definition: misc.c:7470
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3201
int SCIPgetNImplVars(SCIP *scip)
Definition: scip_prob.c:2121
SCIP_EXPORT SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:17340
public methods for problem variables
PROBLEM * problem
SCIP_RETCODE SCIPupdateLocalLowerbound(SCIP *scip, SCIP_Real newbound)
Definition: scip_prob.c:3690
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:95
SCIP_Longint SCIPgetMemUsed(SCIP *scip)
Definition: scip_mem.c:91
#define SCIPdebugMessage
Definition: pub_message.h:87
SCIP_Real lastprimalbound
SCIP_RETCODE SCIPsetConshdlrPresol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRESOL((*conspresol)), int maxprerounds, SCIP_PRESOLTIMING presoltiming)
Definition: scip_cons.c:525
#define DEFAULT_MAXDEPTH
#define SCIP_LONGINT_MAX
Definition: def.h:149
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
SCIP_Bool SCIPinRepropagation(SCIP *scip)
Definition: scip_tree.c:136
constraint handler for handling independent components
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:78
static SCIP_RETCODE freeComponent(COMPONENT *component)
public methods for SCIP variables
#define SCIPdebugMsg
Definition: scip_message.h:69
SCIP_Real SCIPgetCutoffbound(SCIP *scip)
SCIP_RETCODE SCIPgetConsNVars(SCIP *scip, SCIP_CONS *cons, int *nvars, SCIP_Bool *success)
Definition: scip_cons.c:2558
static SCIP_RETCODE solveAndEvalSubscip(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP *subscip, SCIP_VAR **vars, SCIP_VAR **subvars, SCIP_CONS **conss, int nvars, int nconss, int *ndeletedconss, int *nfixedvars, int *ntightenedbounds, SCIP_RESULT *result, SCIP_Bool *solved)
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
Definition: scip_cons.c:357
SCIP_RETCODE SCIPcopyProb(SCIP *sourcescip, SCIP *targetscip, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, const char *name)
Definition: scip_copy.c:513
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
#define consEnfopsComponents
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2076
public methods for numerical tolerances
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
Definition: scip_heur.c:249
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:320
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2837
public methods for querying solving statistics
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2206
SCIP_RETCODE SCIPprintBestSol(SCIP *scip, FILE *file, SCIP_Bool printzeros)
Definition: scip_sol.c:2371
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
void SCIPaddNNodes(SCIP *scip, SCIP_Longint nnodes)
SCIP_RETCODE SCIPsetRealParam(SCIP *scip, const char *name, SCIP_Real value)
Definition: scip_param.c:619
public methods for the branch-and-bound tree
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:697
static SCIP_DECL_CONSLOCK(consLockComponents)
SCIP_Bool solved
SCIP_Longint SCIPgetNNodes(SCIP *scip)
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:92
#define CONSHDLR_CHECKPRIORITY
#define CONSHDLR_NAME
SCIP_RETCODE SCIPdigraphComputeUndirectedComponents(SCIP_DIGRAPH *digraph, int minsize, int *components, int *ncomponents)
Definition: misc.c:7991
static SCIP_RETCODE copyToSubscip(SCIP *scip, SCIP *subscip, const char *name, SCIP_VAR **vars, SCIP_VAR **subvars, SCIP_CONS **conss, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, int nvars, int nconss, SCIP_Bool *success)
SCIP_RETCODE SCIPcreate(SCIP **scip)
Definition: scip_general.c:283
public methods for managing constraints
SCIP_VAR ** subvars
SCIP_RETCODE SCIPcopyParamSettings(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:2507
SCIP_Real lastdualbound
SCIP_EXPORT const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:17017
SCIP_EXPORT void SCIPsolSetHeur(SCIP_SOL *sol, SCIP_HEUR *heur)
Definition: sol.c:2649
#define CONSHDLR_PRESOLTIMING
#define SCIPerrorMessage
Definition: pub_message.h:55
SCIP_RETCODE SCIPfixParam(SCIP *scip, const char *name)
Definition: scip_param.c:358
static SCIP_DECL_CONSHDLRCOPY(conshdlrCopyComponents)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisPresolveFinished(SCIP *scip)
Definition: scip_general.c:596
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1941
SCIP_RETCODE SCIPsetConshdlrInitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITSOL((*consinitsol)))
Definition: scip_cons.c:429
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
#define CONSHDLR_MAXPREROUNDS
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_STATUS laststatus
SCIP_Bool SCIPinProbing(SCIP *scip)
Definition: scip_probing.c:88
#define NULL
Definition: lpi_spx1.cpp:155
public methods for problem copies
public methods for primal CIP solutions
#define CONSHDLR_DELAYPROP
static SCIP_RETCODE componentSetupWorkingSol(COMPONENT *component, SCIP_HASHMAP *varmap)
SCIP_CONSDATA * SCIPconsGetData(SCIP_CONS *cons)
Definition: cons.c:8107
#define SCIP_CALL(x)
Definition: def.h:364
void SCIPdigraphGetComponent(SCIP_DIGRAPH *digraph, int compidx, int **nodes, int *nnodes)
Definition: misc.c:8199
SCIP_RETCODE SCIPsetPresolving(SCIP *scip, SCIP_PARAMSETTING paramsetting, SCIP_Bool quiet)
Definition: scip_param.c:948
struct Component COMPONENT
static SCIP_DECL_SORTPTRCOMP(componentSort)
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip_prob.c:2426
#define SCIPdebugGetSolVal(scip, var, val)
Definition: debug.h:257
struct SCIP_ConsData SCIP_CONSDATA
Definition: type_cons.h:56
public methods for primal heuristic plugins and divesets
public methods for constraint handler plugins and constraints
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip_param.c:298
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:8346
SCIP_RETCODE SCIPaddConsNode(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode)
Definition: scip_prob.c:3317
static SCIP_DECL_CONSPRESOL(consPresolComponents)
SCIP_VAR ** vars
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
SCIP_Real SCIPinfinity(SCIP *scip)
public data structures and miscellaneous methods
static SCIP_RETCODE solveComponent(COMPONENT *component, SCIP_Bool lastcomponent, SCIP_RESULT *result)
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:638
SCIP_EXPORT void SCIPsortRealInt(SCIP_Real *realarray, int *intarray, int len)
static SCIP_RETCODE findComponents(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_Real *fixedvarsobjsum, SCIP_VAR **sortedvars, SCIP_CONS **sortedconss, int *compstartsvars, int *compstartsconss, int *nsortedvars, int *nsortedconss, int *ncomponents, int *ncompsminsize, int *ncompsmaxsize)
#define SCIP_Bool
Definition: def.h:70
static SCIP_RETCODE createConsComponents(SCIP *scip, SCIP_CONS **cons, const char *name, PROBLEM *problem)
#define DEFAULT_MINSIZE
char * name
Definition: struct_cons.h:40
SCIP_Bool SCIPisSumLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
const char * SCIPgetProbName(SCIP *scip)
Definition: scip_prob.c:1065
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3014
SCIP_RETCODE SCIPincludeConshdlrComponents(SCIP *scip)
static SCIP_RETCODE fillDigraph(SCIP *scip, SCIP_DIGRAPH *digraph, SCIP_CONS **conss, int nconss, int *unfixedvarpos, int nunfixedvars, int *firstvaridxpercons, SCIP_Bool *success)
SCIP_RETCODE SCIPsetConshdlrCopy(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSCOPY((*conscopy)))
Definition: scip_cons.c:332
enum SCIP_Status SCIP_STATUS
Definition: type_stat.h:58
#define DEFAULT_FEASTOLFACTOR
#define consCheckComponents
SCIP_EXPORT SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17677
SCIP_Bool SCIPisParamFixed(SCIP *scip, const char *name)
Definition: scip_param.c:210
static SCIP_RETCODE initComponent(PROBLEM *problem)
struct Problem PROBLEM
#define SCIPdebugSolIsValidInSubtree(scip, isvalidinsubtree)
Definition: debug.h:258
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4187
#define MAX(x, y)
Definition: tclique_def.h:83
SCIP_RETCODE SCIPgetActiveVars(SCIP *scip, SCIP_VAR **vars, int *nvars, int varssize, int *requiredsize)
Definition: scip_var.c:1834
methods for debugging
SCIP_EXPORT int SCIPsolGetIndex(SCIP_SOL *sol)
Definition: sol.c:2635
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
#define CONSHDLR_PROPFREQ
static SCIP_DECL_CONSPROP(consPropComponents)
SCIP_RETCODE SCIPupdateCutoffbound(SCIP *scip, SCIP_Real cutoffbound)
SCIP_RETCODE SCIPprintStatistics(SCIP *scip, FILE *file)
int SCIPconshdlrGetNActiveConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4616
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:8256
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8257
SCIP_RETCODE SCIPdigraphSetSizes(SCIP_DIGRAPH *digraph, int *sizes)
Definition: misc.c:7446
int SCIPgetNActivePricers(SCIP *scip)
Definition: scip_pricer.c:339
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:8336
SCIP_RETCODE SCIPcopyLimits(SCIP *sourcescip, SCIP *targetscip)
Definition: scip_copy.c:3228
SCIP_EXPORT SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17723
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:130
SCIP_RETCODE SCIPcheckSolOrig(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *feasible, SCIP_Bool printreason, SCIP_Bool completely)
Definition: scip_sol.c:3498
public methods for variable pricer plugins
SCIP_EXPORT int SCIPvarGetNLocksDownType(SCIP_VAR *var, SCIP_LOCKTYPE locktype)
Definition: var.c:3193
#define SCIP_REAL_MAX
Definition: def.h:164
SCIP_EXPORT SCIP_Real SCIPsolGetOrigObj(SCIP_SOL *sol)
Definition: sol.c:2541
SCIP_EXPORT SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17733
SCIP_RETCODE SCIPsetLongintParam(SCIP *scip, const char *name, SCIP_Longint value)
Definition: scip_param.c:561
methods for sorting joint arrays of various types
general public methods
SCIP_VAR ** fixedvars
SCIP_RETCODE SCIPpqueueCreate(SCIP_PQUEUE **pqueue, int initsize, SCIP_Real sizefac, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), SCIP_DECL_PQUEUEELEMCHGPOS((*elemchgpos)))
Definition: misc.c:1236
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for solutions
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:8266
static SCIP_RETCODE componentCreateSubscip(COMPONENT *component, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_CONS **conss, int nconss, SCIP_Bool *success)
static SCIP_RETCODE sortComponents(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *digraph, SCIP_CONS **conss, SCIP_VAR **vars, int *varcomponent, int *conscomponent, int nconss, int nvars, int *firstvaridxpercons, int *ncompsminsize, int *ncompsmaxsize)
SCIP_EXPORT SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17667
public methods for the probing mode
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_SOL * workingsol
SCIP_Real fixedvarsobjsum
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4539
public methods for message output
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1483
static SCIP_DECL_CONSINITSOL(consInitsolComponents)
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10604
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:74
#define DEFAULT_MINRELSIZE
SCIP_EXPORT void SCIPvarMarkDeleteGlobalStructures(SCIP_VAR *var)
Definition: var.c:17274
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3048
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:8077
static SCIP_RETCODE createAndSplitProblem(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_Real fixedvarsobjsum, SCIP_VAR **sortedvars, SCIP_CONS **sortedconss, int *compstartsvars, int *compstartsconss, int ncomponents, PROBLEM **problem)
#define SCIP_Real
Definition: def.h:163
static SCIP_RETCODE solveProblem(PROBLEM *problem, SCIP_RESULT *result)
SCIP_Real SCIPretransformObj(SCIP *scip, SCIP_Real obj)
Definition: scip_sol.c:1568
SCIP_RETCODE SCIPgetLongintParam(SCIP *scip, const char *name, SCIP_Longint *value)
Definition: scip_param.c:279
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:8097
SCIP * subscip
SCIP_RETCODE SCIPaddSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *stored)
Definition: scip_sol.c:2926
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for message handling
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define DEFAULT_NODELIMIT
public methods for data structures
SCIP_Real SCIPgetPrimalbound(SCIP *scip)
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 copypropagators, SCIP_Bool copyheuristics, SCIP_Bool copyeventhdlrs, SCIP_Bool copynodeselectors, SCIP_Bool copybranchrules, SCIP_Bool copydisplays, SCIP_Bool copydialogs, SCIP_Bool copytables, SCIP_Bool copynlpis, SCIP_Bool passmessagehdlr, SCIP_Bool *valid)
Definition: scip_copy.c:265
#define SCIP_Longint
Definition: def.h:148
SCIP_RETCODE SCIPsetBoolParam(SCIP *scip, const char *name, SCIP_Bool value)
Definition: scip_param.c:445
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4167
#define SCIPdebugAddSolVal(scip, var, val)
Definition: debug.h:256
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2031
#define CONSHDLR_DESC
#define SCIPdebugSolIsEnabled(scip)
Definition: debug.h:261
SCIP_RETCODE SCIPaddLongintParam(SCIP *scip, const char *name, const char *desc, SCIP_Longint *valueptr, SCIP_Bool isadvanced, SCIP_Longint defaultvalue, SCIP_Longint minvalue, SCIP_Longint maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:102
SCIP_EXPORT int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:17360
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_prob.c:2764
int lastbestsolindex
static SCIP_RETCODE initProblem(SCIP *scip, PROBLEM **problem, SCIP_Real fixedvarsobjsum, int ncomponents)
struct SCIP_ConshdlrData SCIP_CONSHDLRDATA
Definition: type_cons.h:55
SCIP_VAR ** fixedsubvars
static SCIP_DECL_CONSFREE(conshdlrFreeComponents)
#define CONSHDLR_NEEDSCONS
SCIP_Bool SCIPallowStrongDualReds(SCIP *scip)
Definition: scip_var.c:8597
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:122
public methods for primal heuristics
SCIP_RETCODE SCIPfree(SCIP **scip)
Definition: scip_general.c:315
SCIP_Longint SCIPgetMemExternEstim(SCIP *scip)
Definition: scip_mem.c:117
#define CONSHDLR_PROP_TIMING
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip_cons.c:1110
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:356
SCIP_RETCODE SCIPsetConshdlrProp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPROP((*consprop)), int propfreq, SCIP_Bool delayprop, SCIP_PROPTIMING proptiming)
Definition: scip_cons.c:266
#define SCIPdebugSolEnable(scip)
Definition: debug.h:259
SCIP_RETCODE SCIPgetConsVars(SCIP *scip, SCIP_CONS *cons, SCIP_VAR **vars, int varssize, SCIP_Bool *success)
Definition: scip_cons.c:2514
public methods for global and local (sub)problems
SCIP_Real SCIPgetDualbound(SCIP *scip)
#define consEnfolpComponents
static SCIP_RETCODE createSubscip(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP **subscip)
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2305
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
Definition: cons.c:8296
SCIP_RETCODE SCIPsetIntParam(SCIP *scip, const char *name, int value)
Definition: scip_param.c:503
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:3441
SCIP_EXPORT void SCIPsortIntPtr(int *intarray, void **ptrarray, int len)
SCIP_EXPORT int SCIPvarGetIndex(SCIP_VAR *var)
Definition: var.c:17350
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:8326
SCIP_RETCODE SCIPdigraphAddArc(SCIP_DIGRAPH *digraph, int startnode, int endnode, void *data)
Definition: misc.c:7564
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:115
SCIP_RETCODE SCIPfreeTransform(SCIP *scip)
Definition: scip_solve.c:3329
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1436
SCIP_RETCODE SCIPpqueueInsert(SCIP_PQUEUE *pqueue, void *elem)
Definition: misc.c:1335
memory allocation routines