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-2021 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 memorylimit;
664 
665  assert(scip != NULL);
666  assert(subscip != NULL);
667 
668  /* set time limit */
669  SCIP_CALL( SCIPgetRealParam(scip, "limits/time", &timelimit) );
670  if( !SCIPisInfinity(scip, timelimit) )
671  {
672  timelimit -= SCIPgetSolvingTime(scip);
673  timelimit += SCIPgetSolvingTime(subscip);
674  }
675 
676  /* substract the memory already used by the main SCIP and the estimated memory usage of external software */
677  /* @todo count memory of other components */
678  SCIP_CALL( SCIPgetRealParam(scip, "limits/memory", &memorylimit) );
679  if( !SCIPisInfinity(scip, memorylimit) )
680  {
681  memorylimit -= SCIPgetMemUsed(scip)/1048576.0;
682  memorylimit -= SCIPgetMemExternEstim(scip)/1048576.0;
683  }
684 
685  /* abort if no time is left or not enough memory to create a copy of SCIP, including external memory usage */
686  if( timelimit <= 0.0 || memorylimit <= 0.0)
687  {
688  SCIPdebugMessage("--> not solved (not enough memory or time left)\n");
689  return SCIP_OKAY;
690  }
691 
692  /* SCIP copy limits will set wrong time limits since it does not take into account time spent already in the
693  * sub-SCIP; nevertheless, we call it to set the memory limit and unset all other limits, if set in the main SCIP
694  */
695  SCIP_CALL( SCIPcopyLimits(scip, subscip) );
696 
697  /* set time and memory limit for the subproblem */
698  SCIP_CALL( SCIPsetRealParam(subscip, "limits/time", timelimit) );
699 
700  /* only set soft time limit if it exists */
701  if( SCIPgetParam(scip, "limits/softtime") != NULL )
702  {
703  SCIP_Real softtimelimit;
704 
705  /* set soft time limit, if specified in main SCIP and if it exists */
706  SCIP_CALL( SCIPgetRealParam(scip, "limits/softtime", &softtimelimit) );
707  if( softtimelimit > -0.5 )
708  {
709  softtimelimit -= SCIPgetSolvingTime(scip);
710  softtimelimit += SCIPgetSolvingTime(subscip);
711  softtimelimit = MAX(softtimelimit, 0.0);
712  }
713 
714  SCIP_CALL( SCIPsetRealParam(subscip, "limits/softtime", softtimelimit) );
715  }
716 
717  /* set gap limit */
718  SCIP_CALL( SCIPsetRealParam(subscip, "limits/gap", gaplimit) );
719 
720  /* set node limit */
721  SCIP_CALL( SCIPsetLongintParam(subscip, "limits/nodes", nodelimit) );
722 
723  /* solve the subproblem */
724  SCIP_CALL( SCIPsolve(subscip) );
725 
726 #ifdef SCIP_MORE_DEBUG
727  SCIP_CALL( SCIPprintBestSol(subscip, NULL, FALSE) );
728  SCIP_CALL( SCIPprintStatistics(subscip, NULL) );
729 #endif
730 
731  return SCIP_OKAY;
732 }
733 
734 /** solve a connected component during presolving and evaluate the result */
735 static
737  SCIP* scip, /**< SCIP main data structure */
738  SCIP_CONSHDLRDATA* conshdlrdata, /**< the components constraint handler data */
739  SCIP* subscip, /**< sub-SCIP to be solved */
740  SCIP_VAR** vars, /**< array of variables copied to this component */
741  SCIP_VAR** subvars, /**< array of sub-SCIP variables corresponding to the vars array */
742  SCIP_CONS** conss, /**< array of constraints copied to this component */
743  int nvars, /**< number of variables copied to this component */
744  int nconss, /**< number of constraints copied to this component */
745  int* ndeletedconss, /**< pointer to store the number of deleted constraints */
746  int* nfixedvars, /**< pointer to store the number of fixed variables */
747  int* ntightenedbounds, /**< pointer to store the number of bound tightenings */
748  SCIP_RESULT* result, /**< pointer to store the result of the component solving */
749  SCIP_Bool* solved /**< pointer to store if the problem was solved to optimality */
750  )
751 {
752  int i;
753 
754  assert(scip != NULL);
755  assert(conshdlrdata != NULL);
756  assert(subscip != NULL);
757  assert(vars != NULL);
758  assert(conss != NULL);
759  assert(ndeletedconss != NULL);
760  assert(nfixedvars != NULL);
761  assert(ntightenedbounds != NULL);
762  assert(result != NULL);
763 
764  *solved = FALSE;
765 
766  SCIP_CALL( solveSubscip(scip, subscip, conshdlrdata->nodelimit, 0.0) );
767 
768  if( SCIPgetStatus(subscip) == SCIP_STATUS_OPTIMAL )
769  {
770  SCIP_SOL* sol;
771  SCIP_VAR* var;
772  SCIP_VAR* subvar;
773  SCIP_Real* fixvals;
774  SCIP_Bool feasible;
775  SCIP_Bool infeasible;
776  SCIP_Bool fixed;
777 
778  sol = SCIPgetBestSol(subscip);
779 
780 #ifdef SCIP_DEBUG
781  SCIP_CALL( SCIPcheckSolOrig(subscip, sol, &feasible, TRUE, TRUE) );
782 #else
783  SCIP_CALL( SCIPcheckSolOrig(subscip, sol, &feasible, FALSE, FALSE) );
784 #endif
785 
786  SCIPdebugMessage("--> solved to optimality: time=%.2f, solution is%s feasible\n", SCIPgetSolvingTime(subscip), feasible ? "" : " not");
787 
788  SCIP_CALL( SCIPallocBufferArray(scip, &fixvals, nvars) );
789 
790  if( feasible )
791  {
792  SCIP_Real glb;
793  SCIP_Real gub;
794 
795  /* get values of variables in the optimal solution */
796  for( i = 0; i < nvars; ++i )
797  {
798  var = vars[i];
799  subvar = subvars[i];
800 
801  /* get global bounds */
802  glb = SCIPvarGetLbGlobal(var);
803  gub = SCIPvarGetUbGlobal(var);
804 
805  if( subvar != NULL )
806  {
807  /* get solution value from optimal solution of the sub-SCIP */
808  fixvals[i] = SCIPgetSolVal(subscip, sol, subvar);
809 
810  assert(SCIPisFeasLE(scip, fixvals[i], SCIPvarGetUbLocal(var)));
811  assert(SCIPisFeasGE(scip, fixvals[i], SCIPvarGetLbLocal(var)));
812 
813  /* checking a solution is done with a relative tolerance of feasibility epsilon, if we really want to
814  * change the bounds of the variables by fixing them, the old bounds must not be violated by more than
815  * the absolute epsilon; therefore, we change the fixing values, if needed, and mark that the solution
816  * has to be checked again
817  */
818  if( SCIPisGT(scip, fixvals[i], gub) )
819  {
820  SCIPdebugMessage("variable <%s> fixval: %f violates global upperbound: %f\n",
821  SCIPvarGetName(var), fixvals[i], gub);
822  fixvals[i] = gub;
823  feasible = FALSE;
824  }
825  else if( SCIPisLT(scip, fixvals[i], glb) )
826  {
827  SCIPdebugMessage("variable <%s> fixval: %f violates global lowerbound: %f\n",
828  SCIPvarGetName(var), fixvals[i], glb);
829  fixvals[i] = glb;
830  feasible = FALSE;
831  }
832  assert(SCIPisLE(scip, fixvals[i], SCIPvarGetUbLocal(var)));
833  assert(SCIPisGE(scip, fixvals[i], SCIPvarGetLbLocal(var)));
834  }
835  else
836  {
837  /* the variable was not copied, so it was cancelled out of constraints during copying;
838  * thus, the variable is not constrained and we fix it to its best bound
839  */
840  if( SCIPisPositive(scip, SCIPvarGetObj(var)) )
841  fixvals[i] = glb;
842  else if( SCIPisNegative(scip, SCIPvarGetObj(var)) )
843  fixvals[i] = gub;
844  else
845  {
846  fixvals[i] = 0.0;
847  fixvals[i] = MIN(fixvals[i], gub);
848  fixvals[i] = MAX(fixvals[i], glb);
849  }
850  }
851  }
852 
853  /* the solution value of at least one variable is feasible with a relative tolerance of feasibility epsilon,
854  * but infeasible with an absolute tolerance of epsilon; try to set the variables to the bounds and check
855  * solution again in the original space (changing the values might now introduce infeasibilities of constraints)
856  */
857  if( !feasible )
858  {
859  SCIP_Real origobj;
860 
861  SCIPdebugMessage("solution violates bounds by more than epsilon, check the corrected solution...\n");
862 
863  origobj = SCIPgetSolOrigObj(subscip, SCIPgetBestSol(subscip));
864 
865  SCIP_CALL( SCIPfreeTransform(subscip) );
866 
867  SCIP_CALL( SCIPcreateOrigSol(subscip, &sol, NULL) );
868 
869  /* set solution values of variables */
870  for( i = 0; i < nvars; ++i )
871  {
872  if( subvars[i] != NULL )
873  {
874  SCIP_CALL( SCIPsetSolVal(subscip, sol, subvars[i], fixvals[i]) );
875  }
876  }
877 
878  /* check the solution; integrality and bounds should be fulfilled and do not have to be checked */
879  SCIP_CALL( SCIPcheckSol(subscip, sol, FALSE, FALSE, FALSE, FALSE, TRUE, &feasible) );
880 
881 #ifndef NDEBUG
882  /* in debug mode, we additionally check integrality and bounds */
883  if( feasible )
884  {
885  SCIP_CALL( SCIPcheckSol(subscip, sol, FALSE, FALSE, TRUE, TRUE, FALSE, &feasible) );
886  assert(feasible);
887  }
888 #endif
889 
890  SCIPdebugMessage("--> corrected solution is%s feasible\n", feasible ? "" : " not");
891 
892  if( !SCIPisFeasEQ(subscip, SCIPsolGetOrigObj(sol), origobj) )
893  {
894  SCIPdebugMessage("--> corrected solution has a different objective value (old=%16.9g, corrected=%16.9g)\n",
895  origobj, SCIPsolGetOrigObj(sol));
896 
897  feasible = FALSE;
898  }
899 
900  SCIP_CALL( SCIPfreeSol(subscip, &sol) );
901  }
902 
903  /* if the solution is feasible, fix variables and delete constraints of the component */
904  if( feasible )
905  {
906  /* fix variables */
907  for( i = 0; i < nvars; ++i )
908  {
909  assert(SCIPisLE(scip, fixvals[i], SCIPvarGetUbLocal(vars[i])));
910  assert(SCIPisGE(scip, fixvals[i], SCIPvarGetLbLocal(vars[i])));
911  assert(SCIPisLE(scip, fixvals[i], SCIPvarGetUbGlobal(vars[i])));
912  assert(SCIPisGE(scip, fixvals[i], SCIPvarGetLbGlobal(vars[i])));
913 
914  SCIP_CALL( SCIPfixVar(scip, vars[i], fixvals[i], &infeasible, &fixed) );
916  assert(!infeasible);
917  assert(fixed);
918  (*nfixedvars)++;
919  }
920 
921  /* delete constraints */
922  for( i = 0; i < nconss; ++i )
923  {
924  SCIP_CALL( SCIPdelCons(scip, conss[i]) );
925  (*ndeletedconss)++;
926  }
927 
928  *result = SCIP_SUCCESS;
929  *solved = TRUE;
930  }
931  }
932 
933  SCIPfreeBufferArray(scip, &fixvals);
934  }
935  else if( SCIPgetStatus(subscip) == SCIP_STATUS_INFEASIBLE )
936  {
937  *result = SCIP_CUTOFF;
938  }
939  else if( SCIPgetStatus(subscip) == SCIP_STATUS_UNBOUNDED || SCIPgetStatus(subscip) == SCIP_STATUS_INFORUNBD )
940  {
941  /* TODO: store unbounded ray in original SCIP data structure */
942  *result = SCIP_UNBOUNDED;
943  }
944  else
945  {
946  SCIPdebugMessage("--> solving interrupted (status=%d, time=%.2f)\n",
947  SCIPgetStatus(subscip), SCIPgetSolvingTime(subscip));
948 
949  /* transfer global fixings to the original problem; we can only do this, if we did not find a solution in the
950  * subproblem, because otherwise, the primal bound might lead to dual reductions that cannot be transferred to
951  * the original problem without also transferring the possibly suboptimal solution (which is currently not
952  * possible)
953  */
954  if( SCIPgetNSols(subscip) == 0 )
955  {
956  SCIP_Bool infeasible;
957  SCIP_Bool tightened;
958  int ntightened;
959 
960  ntightened = 0;
961 
962  for( i = 0; i < nvars; ++i )
963  {
964  if( subvars[i] == NULL )
965  continue;
966 
967  SCIP_CALL( SCIPtightenVarLb(scip, vars[i], SCIPvarGetLbGlobal(subvars[i]), FALSE,
968  &infeasible, &tightened) );
969  assert(!infeasible);
970  if( tightened )
971  ntightened++;
972 
973  SCIP_CALL( SCIPtightenVarUb(scip, vars[i], SCIPvarGetUbGlobal(subvars[i]), FALSE,
974  &infeasible, &tightened) );
975  assert(!infeasible);
976  if( tightened )
977  ntightened++;
978  }
979 
980  *result = SCIP_SUCCESS;
981 
982  *ntightenedbounds += ntightened;
983 
984  SCIPdebugMessage("--> tightened %d bounds of variables due to global bounds in the sub-SCIP\n", ntightened);
985  }
986  }
987 
988  return SCIP_OKAY;
989 }
990 
991 /** (continues) solving a connected component */
992 static
994  COMPONENT* component, /**< component structure */
995  SCIP_Bool lastcomponent, /**< is this the last component to be solved? */
996  SCIP_RESULT* result /**< pointer to store the result of the solving process */
997  )
998 {
999  PROBLEM* problem;
1000  SCIP* scip;
1001  SCIP* subscip;
1002  SCIP_SOL* bestsol;
1003  SCIP_Longint nodelimit;
1004  SCIP_Longint lastnnodes;
1005  SCIP_Real gaplimit;
1006  SCIP_STATUS status;
1007 
1008  assert(component != NULL);
1009 
1010  problem = component->problem;
1011  assert(problem != NULL);
1012 
1013  scip = problem->scip;
1014  assert(scip != NULL);
1015 
1016  subscip = component->subscip;
1017  assert(subscip != NULL);
1018 
1019  *result = SCIP_DIDNOTRUN;
1020 
1021  SCIPdebugMessage("solve component <%s> (ncalls=%d, absgap=%.9g)\n",
1022  SCIPgetProbName(subscip), component->ncalls, component->lastprimalbound - component->lastdualbound);
1023 
1024  bestsol = SCIPgetBestSol(scip);
1025 
1026  /* update best solution of component */
1027  if( bestsol != NULL && SCIPsolGetIndex(bestsol) != component->lastbestsolindex )
1028  {
1029  SCIP_SOL* compsol = component->workingsol;
1030  SCIP_VAR** vars = component->vars;
1031  SCIP_VAR** subvars = component->subvars;
1032  int nvars = component->nvars;
1033  int v;
1034 
1035  component->lastbestsolindex = SCIPsolGetIndex(bestsol);
1036 
1037  /* set solution values of component variables */
1038  for( v = 0; v < nvars; ++v )
1039  {
1040  if( subvars[v] != NULL )
1041  {
1042  SCIP_CALL( SCIPsetSolVal(subscip, compsol, subvars[v], SCIPgetSolVal(scip, bestsol, vars[v])) );
1043  }
1044  }
1045 #ifndef NDEBUG
1046  for( v = 0; v < component->nfixedvars; ++v )
1047  {
1048  if( component->fixedsubvars[v] != NULL )
1049  assert(SCIPisEQ(scip, SCIPgetSolVal(subscip, compsol, component->fixedsubvars[v]),
1050  SCIPvarGetLbGlobal(component->fixedsubvars[v])));
1051  }
1052 #endif
1053 
1054  if( SCIPgetStage(subscip) == SCIP_STAGE_PROBLEM
1055  || SCIPisLT(subscip, SCIPgetSolOrigObj(subscip, compsol), SCIPgetPrimalbound(subscip)) )
1056  {
1057  SCIP_Bool feasible;
1058 
1059  SCIPdebugMessage("checking new solution in component <%s> inherited from problem <%s>: primal bound %.9g --> %.9g\n",
1060  SCIPgetProbName(subscip), problem->name,
1061  SCIPgetStage(subscip) == SCIP_STAGE_PROBLEM ? SCIPinfinity(subscip) : SCIPgetPrimalbound(subscip),
1062  SCIPgetSolOrigObj(subscip, compsol));
1063 
1064  SCIP_CALL( SCIPcheckSolOrig(subscip, compsol, &feasible, FALSE, FALSE) );
1065  if( feasible )
1066  {
1067  SCIPdebugMessage("... feasible, adding solution.\n");
1068 
1069  SCIP_CALL( SCIPaddSol(subscip, compsol, &feasible) );
1070  }
1071 
1072  /* We cannot take the value of compsol as a cutoff bound if it was not feasible; some of the fixed connecting
1073  * variables are different and might not allow for a better solution in this component, but still for far
1074  * better solutions in other components. Therefore, the only cutoffbound we can apply is the cutoffbound
1075  * of the problem reduced by the dual bounds of the other components
1076  */
1077  if( problem->nlowerboundinf == 0 || (problem->nlowerboundinf == 1
1078  && SCIPisInfinity(scip, -component->lastdualbound)) )
1079  {
1080  SCIP_Real newcutoffbound = SCIPgetSolTransObj(scip, bestsol);
1081 
1082  assert(problem->nlowerboundinf > 0 || SCIPisGE(scip, newcutoffbound, problem->lowerbound));
1083 
1084  newcutoffbound = newcutoffbound - problem->lowerbound + component->fixedvarsobjsum;
1085 
1086  if( problem->nlowerboundinf == 0 )
1087  newcutoffbound += component->lastdualbound;
1088 
1089  if( SCIPisSumLT(subscip, newcutoffbound, SCIPgetCutoffbound(subscip)) )
1090  {
1091  SCIPdebugMessage("update cutoff bound to %16.9g\n", newcutoffbound);
1092 
1093  SCIP_CALL( SCIPupdateCutoffbound(subscip, newcutoffbound) );
1094  }
1095  }
1096  }
1097  }
1098 
1099  assert(component->laststatus != SCIP_STATUS_OPTIMAL);
1100 
1101  SCIPdebugMsg(scip, "solve sub-SCIP for component <%s> (ncalls=%d, absgap=%16.9g)\n",
1102  SCIPgetProbName(component->subscip), component->ncalls, component->lastprimalbound - component->lastdualbound);
1103 
1104  if( component->ncalls == 0 )
1105  {
1106  nodelimit = 1LL;
1107  gaplimit = 0.0;
1108 
1109  lastnnodes = 0;
1110  }
1111  else
1112  {
1113  SCIP_Longint mainnodelimit;
1114 
1115  lastnnodes = SCIPgetNNodes(component->subscip);
1116 
1117  SCIP_CALL( SCIPgetLongintParam(scip, "limits/nodes", &mainnodelimit) );
1118 
1119  nodelimit = 2 * lastnnodes;
1120  nodelimit = MAX(nodelimit, 10LL);
1121 
1122  if( mainnodelimit != -1 )
1123  {
1124  assert(mainnodelimit >= lastnnodes);
1125  nodelimit = MIN(nodelimit, mainnodelimit - lastnnodes);
1126  }
1127 
1128  /* set a gap limit of half the current gap (at most 10%) */
1129  if( SCIPgetGap(component->subscip) < 0.2 )
1130  gaplimit = 0.5 * SCIPgetGap(component->subscip);
1131  else
1132  gaplimit = 0.1;
1133 
1134  if( lastcomponent )
1135  gaplimit = 0.0;
1136  }
1137 
1138  SCIP_CALL( solveSubscip(scip, subscip, nodelimit, gaplimit) );
1139 
1140  SCIPaddNNodes(scip, SCIPgetNNodes(subscip) - lastnnodes);
1141 
1143 
1144  status = SCIPgetStatus(subscip);
1145 
1146  component->laststatus = status;
1147  ++component->ncalls;
1148 
1149  SCIPdebugMsg(scip, "--> (status=%d, nodes=%lld, time=%.2f): gap: %12.5g%% absgap: %16.9g\n",
1150  status, SCIPgetNNodes(subscip), SCIPgetSolvingTime(subscip), 100.0*SCIPgetGap(subscip),
1151  SCIPgetPrimalbound(subscip) - SCIPgetDualbound(subscip));
1152 
1153  *result = SCIP_SUCCESS;
1154 
1155  switch( status )
1156  {
1157  case SCIP_STATUS_OPTIMAL:
1158  component->solved = TRUE;
1159  break;
1161  component->solved = TRUE;
1162 
1163  /* the problem is really infeasible */
1164  if( SCIPisInfinity(subscip, SCIPgetPrimalbound(subscip)) )
1165  {
1166  *result = SCIP_CUTOFF;
1167  }
1168  /* the cutoff bound was reached; no solution better than the cutoff bound exists */
1169  else
1170  {
1171  *result = SCIP_SUCCESS;
1172  component->laststatus = SCIP_STATUS_OPTIMAL;
1173  assert(SCIPisLE(subscip, SCIPgetDualbound(subscip), SCIPgetPrimalbound(subscip)));
1174  }
1175  break;
1176  case SCIP_STATUS_UNBOUNDED:
1177  case SCIP_STATUS_INFORUNBD:
1178  /* TODO: store unbounded ray in original SCIP data structure */
1179  *result = SCIP_UNBOUNDED;
1180  component->solved = TRUE;
1181  break;
1183  SCIP_CALL( SCIPinterruptSolve(scip) );
1184  break;
1185  case SCIP_STATUS_TERMINATE:
1186  case SCIP_STATUS_UNKNOWN:
1187  case SCIP_STATUS_NODELIMIT:
1190  case SCIP_STATUS_TIMELIMIT:
1191  case SCIP_STATUS_MEMLIMIT:
1192  case SCIP_STATUS_GAPLIMIT:
1193  case SCIP_STATUS_SOLLIMIT:
1196  default:
1197  break;
1198  }
1199 
1200  /* evaluate call */
1201  if( *result == SCIP_SUCCESS )
1202  {
1203  SCIP_SOL* sol = SCIPgetBestSol(subscip);
1204  SCIP_VAR* var;
1205  SCIP_VAR* subvar;
1206  SCIP_Real newdualbound;
1207  int v;
1208 
1209  /* get dual bound as the minimum of SCIP dual bound and sub-problems dual bound */
1210  newdualbound = SCIPgetDualbound(subscip) - component->fixedvarsobjsum;
1211 
1212  /* update dual bound of problem */
1213  if( !SCIPisEQ(scip, component->lastdualbound, newdualbound) )
1214  {
1215  assert(!SCIPisInfinity(scip, -newdualbound));
1216 
1217  /* first finite dual bound: decrease inf counter and add dual bound to problem dualbound */
1218  if( SCIPisInfinity(scip, -component->lastdualbound) )
1219  {
1220  --problem->nlowerboundinf;
1221  problem->lowerbound += newdualbound;
1222  }
1223  /* increase problem dual bound by dual bound delta */
1224  else
1225  {
1226  problem->lowerbound += (newdualbound - component->lastdualbound);
1227  }
1228 
1229  /* update problem dual bound if all problem components have a finite dual bound */
1230  if( problem->nlowerboundinf == 0 )
1231  {
1232  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",
1233  SCIPgetProbName(subscip), component->lastdualbound, newdualbound, problem->name,
1234  SCIPretransformObj(scip, problem->lowerbound),
1235  problem->nfeascomps == problem->ncomponents ?
1236  (SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound)) /
1237  MAX( ABS( SCIPretransformObj(scip, problem->lowerbound) ), SCIPgetSolOrigObj(scip, problem->bestsol) ) /*lint !e666*/
1238  : SCIPinfinity(scip),
1239  problem->nfeascomps == problem->ncomponents ?
1240  SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound) : SCIPinfinity(scip));
1241  SCIP_CALL( SCIPupdateLocalLowerbound(scip, problem->lowerbound) );
1242  }
1243 
1244  /* store dual bound of this call */
1245  component->lastdualbound = newdualbound;
1246  }
1247 
1248  /* update primal solution of problem */
1249  if( sol != NULL && component->lastsolindex != SCIPsolGetIndex(sol) )
1250  {
1251  component->lastsolindex = SCIPsolGetIndex(sol);
1252 
1253  if( SCIPsolGetHeur(sol) != NULL )
1255  else
1256  SCIPsolSetHeur(problem->bestsol, NULL);
1257 
1258  /* increase counter for feasible problems if no solution was known before */
1259  if( SCIPisInfinity(scip, component->lastprimalbound) )
1260  ++(problem->nfeascomps);
1261 
1262  /* update working best solution in problem */
1263  for( v = 0; v < component->nvars; ++v )
1264  {
1265  var = component->vars[v];
1266  subvar = component->subvars[v];
1267  assert(var != NULL);
1268  assert(SCIPvarIsActive(var));
1269 
1270  if( subvar == NULL )
1271  continue;
1272 
1273  SCIP_CALL( SCIPsetSolVal(scip, problem->bestsol, var, SCIPgetSolVal(subscip, sol, subvar)) );
1274  }
1275 
1276  /* if we have a feasible solution for each component, add the working solution to the main problem */
1277  if( problem->nfeascomps == problem->ncomponents )
1278  {
1279  SCIP_Bool feasible;
1280 #ifdef SCIP_MORE_DEBUG
1281  SCIP_CALL( SCIPcheckSol(scip, problem->bestsol, TRUE, FALSE, TRUE, TRUE, TRUE, &feasible) );
1282  assert(feasible);
1283 #endif
1284  SCIP_CALL( SCIPaddSol(scip, problem->bestsol, &feasible) );
1285 
1286  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",
1287  SCIPgetProbName(subscip), component->lastprimalbound, SCIPgetPrimalbound(subscip), problem->name,
1288  SCIPgetSolOrigObj(scip, problem->bestsol),
1289  problem->nfeascomps == problem->ncomponents ?
1290  (SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound)) /
1291  MAX( ABS( SCIPretransformObj(scip, problem->lowerbound) ),SCIPgetSolOrigObj(scip, problem->bestsol) ) /*lint !e666*/
1292  : SCIPinfinity(scip),
1293  problem->nfeascomps == problem->ncomponents ?
1294  SCIPgetSolOrigObj(scip, problem->bestsol) - SCIPretransformObj(scip, problem->lowerbound) : SCIPinfinity(scip));
1295  }
1296 
1297  /* store primal bound of this call */
1298  component->lastprimalbound = SCIPgetPrimalbound(subscip) - component->fixedvarsobjsum;
1299  }
1300 
1301  /* if the component was solved to optimality, we increase the respective counter and free the subscip */
1302  if( component->laststatus == SCIP_STATUS_OPTIMAL || component->laststatus == SCIP_STATUS_INFEASIBLE ||
1303  component->laststatus == SCIP_STATUS_UNBOUNDED || component->laststatus == SCIP_STATUS_INFORUNBD )
1304  {
1305  ++(problem->nsolvedcomps);
1306  component->solved = TRUE;
1307 
1308  /* free working solution and component */
1309  SCIP_CALL( SCIPfreeSol(subscip, &component->workingsol) );
1310 
1311  SCIP_CALL( SCIPfree(&subscip) );
1312  component->subscip = NULL;
1313  }
1314  }
1315 
1316  return SCIP_OKAY;
1317 }
1318 
1319 /** initialize subproblem structure */
1320 static
1322  SCIP* scip, /**< SCIP data structure */
1323  PROBLEM** problem, /**< pointer to subproblem structure */
1324  SCIP_Real fixedvarsobjsum, /**< objective contribution of all locally fixed variables */
1325  int ncomponents /**< number of independent components */
1326  )
1327 {
1328  char name[SCIP_MAXSTRLEN];
1329  SCIP_VAR** vars;
1330  int nvars;
1331  int v;
1332 
1333  assert(scip != NULL);
1334  assert(problem != NULL);
1335 
1336  vars = SCIPgetVars(scip);
1337  nvars = SCIPgetNVars(scip);
1338 
1340  assert(*problem != NULL);
1341 
1342  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(*problem)->components, ncomponents) );
1343 
1344  /* create a priority queue for the components: we need exactly ncomponents slots in the queue so it should never be
1345  * resized
1346  */
1347  SCIP_CALL( SCIPpqueueCreate(&(*problem)->compqueue, ncomponents, 1.2, componentSort, NULL) );
1348 
1349  (*problem)->scip = scip;
1350  (*problem)->lowerbound = fixedvarsobjsum;
1351  (*problem)->fixedvarsobjsum = fixedvarsobjsum;
1352  (*problem)->ncomponents = 0;
1353  (*problem)->componentssize = ncomponents;
1354  (*problem)->nlowerboundinf = ncomponents;
1355  (*problem)->nfeascomps = 0;
1356  (*problem)->nsolvedcomps = 0;
1357 
1358  if( SCIPgetDepth(scip) == 0 )
1359  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s", SCIPgetProbName(scip));
1360  else
1361  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_node_%" SCIP_LONGINT_FORMAT, SCIPgetProbName(scip), SCIPnodeGetNumber(SCIPgetCurrentNode(scip)));
1362 
1363  SCIP_CALL( SCIPduplicateMemoryArray(scip, &(*problem)->name, name, strlen(name)+1) );
1364 
1365  SCIP_CALL( SCIPcreateSol(scip, &(*problem)->bestsol, NULL) );
1366 
1367  for( v = 0; v < nvars; v++ )
1368  {
1369  if( SCIPisFeasEQ(scip, SCIPvarGetLbLocal(vars[v]), SCIPvarGetUbLocal(vars[v])) )
1370  {
1371  SCIP_CALL( SCIPsetSolVal(scip, (*problem)->bestsol, vars[v],
1372  (SCIPvarGetUbLocal(vars[v]) + SCIPvarGetLbLocal(vars[v]))/2) );
1373  }
1374  }
1375 
1376  SCIPdebugMessage("initialized problem <%s>\n", (*problem)->name);
1377 
1378  return SCIP_OKAY;
1379 }
1380 
1381 /** free subproblem structure */
1382 static
1384  PROBLEM** problem /**< pointer to problem to free */
1385  )
1386 {
1387  SCIP* scip;
1388  int c;
1389 
1390  assert(problem != NULL);
1391  assert(*problem != NULL);
1392 
1393  scip = (*problem)->scip;
1394  assert(scip != NULL);
1395 
1396  /* free best solution */
1397  if( (*problem)->bestsol != NULL )
1398  {
1399  SCIP_CALL( SCIPfreeSol(scip, &(*problem)->bestsol) );
1400  }
1401 
1402  /* free all components */
1403  for( c = (*problem)->ncomponents - 1; c >= 0; --c )
1404  {
1405  SCIP_CALL( freeComponent(&(*problem)->components[c]) );
1406  }
1407  if( (*problem)->components != NULL )
1408  {
1409  SCIPfreeBlockMemoryArray(scip, &(*problem)->components, (*problem)->componentssize);
1410  }
1411 
1412  /* free priority queue */
1413  SCIPpqueueFree(&(*problem)->compqueue);
1414 
1415  /* free problem name */
1416  SCIPfreeMemoryArray(scip, &(*problem)->name);
1417 
1418  /* free PROBLEM struct and set the pointer to NULL */
1420  *problem = NULL;
1421 
1422  return SCIP_OKAY;
1423 }
1424 
1425 /** creates and captures a components constraint */
1426 static
1428  SCIP* scip, /**< SCIP data structure */
1429  SCIP_CONS** cons, /**< pointer to hold the created constraint */
1430  const char* name, /**< name of constraint */
1431  PROBLEM* problem /**< problem to be stored in the constraint */
1432  )
1433 {
1434  SCIP_CONSHDLR* conshdlr;
1435 
1436  /* find the samediff constraint handler */
1437  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
1438  if( conshdlr == NULL )
1439  {
1440  SCIPerrorMessage("components constraint handler not found\n");
1441  return SCIP_PLUGINNOTFOUND;
1442  }
1443 
1444  /* create constraint */
1445  SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, (SCIP_CONSDATA*)problem,
1446  FALSE, FALSE, FALSE, FALSE, TRUE,
1447  TRUE, FALSE, FALSE, FALSE, TRUE) );
1448 
1449  return SCIP_OKAY;
1450 }
1451 
1452 
1453 /** sort the components by size and sort vars and conss arrays by component numbers */
1454 static
1456  SCIP* scip, /**< SCIP data structure */
1457  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1458  SCIP_DIGRAPH* digraph, /**< directed graph */
1459  SCIP_CONS** conss, /**< constraints */
1460  SCIP_VAR** vars, /**< variables */
1461  int* varcomponent, /**< component numbers for the variables */
1462  int* conscomponent, /**< array to store component numbers for the constraints */
1463  int nconss, /**< number of constraints */
1464  int nvars, /**< number of variables */
1465  int* firstvaridxpercons, /**< array with index of first variable in vars array for each constraint */
1466  int* ncompsminsize, /**< pointer to store the number of components not exceeding the minimum size */
1467  int* ncompsmaxsize /**< pointer to store the number of components not exceeding the maximum size */
1468  )
1469 {
1470  SCIP_Real* compsize;
1471  int* permu;
1472  int ncomponents;
1473  int nbinvars;
1474  int nintvars;
1475  int ndiscvars;
1476  int ncontvars;
1477  int minsize;
1478  int v;
1479  int c;
1480 
1481  assert(scip != NULL);
1482  assert(conshdlrdata != NULL);
1483  assert(digraph != NULL);
1484  assert(conss != NULL);
1485  assert(vars != NULL);
1486  assert(firstvaridxpercons != NULL);
1487 
1488  /* compute minimum size of components to solve individually */
1489  minsize = getMinsize(scip, conshdlrdata);
1490 
1491  ncomponents = SCIPdigraphGetNComponents(digraph);
1492  *ncompsminsize = 0;
1493  *ncompsmaxsize = 0;
1494 
1495  /* We want to sort the components in increasing complexity (number of discrete variables,
1496  * integer weighted with factor intfactor, continuous used as tie-breaker).
1497  * Therefore, we now get the variables for each component, count the different variable types
1498  * and compute a size as described above. Then, we rename the components
1499  * such that for i < j, component i has no higher complexity than component j.
1500  */
1501  SCIP_CALL( SCIPallocBufferArray(scip, &compsize, ncomponents) );
1502  SCIP_CALL( SCIPallocBufferArray(scip, &permu, ncomponents) );
1503 
1504  /* get number of variables in the components */
1505  for( c = 0; c < ncomponents; ++c )
1506  {
1507  int* cvars;
1508  int ncvars;
1509 
1510  SCIPdigraphGetComponent(digraph, c, &cvars, &ncvars);
1511  permu[c] = c;
1512  nbinvars = 0;
1513  nintvars = 0;
1514 
1515  for( v = 0; v < ncvars; ++v )
1516  {
1517  /* check whether variable is of binary or integer type */
1518  if( SCIPvarGetType(vars[cvars[v]]) == SCIP_VARTYPE_BINARY )
1519  nbinvars++;
1520  else if( SCIPvarGetType(vars[cvars[v]]) == SCIP_VARTYPE_INTEGER )
1521  nintvars++;
1522  }
1523  ncontvars = ncvars - nintvars - nbinvars;
1524  ndiscvars = (int)(nbinvars + conshdlrdata->intfactor * nintvars);
1525  compsize[c] = ((1000.0 * ndiscvars + (950.0 * ncontvars)/nvars));
1526 
1527  /* component fulfills the maxsize requirement */
1528  if( ndiscvars <= conshdlrdata->maxintvars )
1529  ++(*ncompsmaxsize);
1530 
1531  /* component fulfills the minsize requirement */
1532  if( ncvars >= minsize )
1533  ++(*ncompsminsize);
1534  }
1535 
1536  /* get permutation of component numbers such that the size of the components is increasing */
1537  SCIPsortRealInt(compsize, permu, ncomponents);
1538 
1539  /* now, we need the reverse direction, i.e., for each component number, we store its new number
1540  * such that the components are sorted; for this, we abuse the conscomponent array
1541  */
1542  for( c = 0; c < ncomponents; ++c )
1543  conscomponent[permu[c]] = c;
1544 
1545  /* for each variable, replace the old component number by the new one */
1546  for( c = 0; c < nvars; ++c )
1547  varcomponent[c] = conscomponent[varcomponent[c]];
1548 
1549  SCIPfreeBufferArray(scip, &permu);
1550  SCIPfreeBufferArray(scip, &compsize);
1551 
1552  /* do the mapping from calculated components per variable to corresponding
1553  * constraints and sort the component-arrays for faster finding the
1554  * actual variables and constraints belonging to one component
1555  */
1556  for( c = 0; c < nconss; c++ )
1557  conscomponent[c] = (firstvaridxpercons[c] == -1 ? -1 : varcomponent[firstvaridxpercons[c]]);
1558 
1559  SCIPsortIntPtr(varcomponent, (void**)vars, nvars);
1560  SCIPsortIntPtr(conscomponent, (void**)conss, nconss);
1561 
1562  return SCIP_OKAY;
1563 }
1564 
1565 
1566 
1567 /** create PROBLEM structure for the current node and split it into components */
1568 static
1570  SCIP* scip, /**< SCIP data structure */
1571  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1572  SCIP_Real fixedvarsobjsum, /**< objective contribution of all locally fixed variables */
1573  SCIP_VAR** sortedvars, /**< array of unfixed variables sorted by components */
1574  SCIP_CONS** sortedconss, /**< array of (checked) constraints sorted by components */
1575  int* compstartsvars, /**< start points of components in sortedvars array */
1576  int* compstartsconss, /**< start points of components in sortedconss array */
1577  int ncomponents, /**< number of components */
1578  PROBLEM** problem /**< pointer to store problem structure */
1579  )
1580 {
1581  COMPONENT* component;
1582  SCIP_HASHMAP* consmap;
1583  SCIP_HASHMAP* varmap;
1584  SCIP_VAR** compvars;
1585  SCIP_CONS** compconss;
1586  SCIP_Bool success = TRUE;
1587  int nfixedvars = SCIPgetNVars(scip) - compstartsvars[ncomponents];
1588  int ncompconss;
1589  int comp;
1590 
1591  /* init subproblem data structure */
1592  SCIP_CALL( initProblem(scip, problem, fixedvarsobjsum, ncomponents) );
1593  assert((*problem)->components != NULL);
1594 
1595  /* hashmap mapping from original constraints to constraints in the sub-SCIPs (for performance reasons) */
1596  SCIP_CALL( SCIPhashmapCreate(&consmap, SCIPblkmem(scip), compstartsconss[ncomponents]) );
1597 
1598  /* loop over all components */
1599  for( comp = 0; comp < ncomponents; comp++ )
1600  {
1602  assert((*problem)->ncomponents == comp+1);
1603 
1604  component = &(*problem)->components[comp];
1605 
1606  /* get component variables and store them in component structure */
1607  compvars = &(sortedvars[compstartsvars[comp]]);
1608  component->nvars = compstartsvars[comp + 1 ] - compstartsvars[comp];
1609  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &component->vars, compvars, component->nvars) );
1610  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &component->subvars, component->nvars) );
1611  SCIP_CALL( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), component->nvars + nfixedvars) );
1612 
1613  /* get component constraints */
1614  compconss = &(sortedconss[compstartsconss[comp]]);
1615  ncompconss = compstartsconss[comp + 1] - compstartsconss[comp];
1616 
1617 #ifdef DETAILED_OUTPUT
1618  /* print details about the component including its size */
1619  if( component->nvars > 1 && ncompconss > 1 )
1620  {
1621  int nbinvars = 0;
1622  int nintvars = 0;
1623  int ncontvars = 0;
1624  int i;
1625 
1626  for( i = 0; i < component->nvars; ++i )
1627  {
1628  if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_BINARY )
1629  ++nbinvars;
1630  else if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_INTEGER )
1631  ++nintvars;
1632  else
1633  ++ncontvars;
1634  }
1635  SCIPdebugMsg(scip, "component %d at node %lld, depth %d (%d): %d vars (%d bin, %d int, %d cont), %d conss\n",
1636  comp, SCIPnodeGetNumber(SCIPgetCurrentNode(scip)), SCIPgetDepth(scip), SCIPgetDepth(scip) + conshdlrdata->subscipdepth,
1637  component->nvars, nbinvars, nintvars, ncontvars, ncompconss);
1638  }
1639 #endif
1640  assert(ncompconss > 0 || component->nvars == 1);
1641 
1642  SCIPdebugMsg(scip, "build sub-SCIP for component %d of problem <%s>: %d vars, %d conss\n",
1643  component->number, (*problem)->name, component->nvars, ncompconss);
1644 
1645 #ifndef NDEBUG
1646  {
1647  int i;
1648  for( i = 0; i < component->nvars; ++i )
1649  assert(SCIPvarIsActive(component->vars[i]));
1650  }
1651 #endif
1652 
1653  /* build subscip for component */
1654  SCIP_CALL( componentCreateSubscip(component, conshdlrdata, varmap, consmap, compconss, ncompconss, &success) );
1655 
1656  if( success )
1657  {
1658  SCIP_CALL( componentSetupWorkingSol(component, varmap) );
1659 
1660  /* add component to the priority queue of the problem structure */
1661  SCIP_CALL( SCIPpqueueInsert((*problem)->compqueue, component) );
1662  }
1663 
1664  SCIPhashmapFree(&varmap);
1665 
1666  if( !success )
1667  break;
1668  }
1669 
1670  SCIPhashmapFree(&consmap);
1671 
1672  if( !success )
1673  {
1674  /* free subproblem data structure since not all component could be copied */
1676  }
1677 
1678  return SCIP_OKAY;
1679 }
1680 
1681 /** continue solving a problem */
1682 static
1684  PROBLEM* problem, /**< problem structure */
1685  SCIP_RESULT* result /**< result pointer for the problem solve */
1686  )
1687 {
1688  COMPONENT* component;
1689  SCIP_RESULT subscipresult;
1690 
1691  assert(problem != NULL);
1692 
1693  *result = SCIP_SUCCESS;
1694 
1695  component = (COMPONENT*)SCIPpqueueRemove(problem->compqueue);
1696 
1697  /* continue solving the component */
1698  SCIP_CALL( solveComponent(component, SCIPpqueueNElems(problem->compqueue) == 0, &subscipresult) );
1699 
1700  /* if infeasibility or unboundedness was detected, return this */
1701  if( subscipresult == SCIP_CUTOFF || subscipresult == SCIP_UNBOUNDED )
1702  {
1703  *result = subscipresult;
1704  }
1705  /* the component was not solved to optimality, so we need to re-insert it in the components queue */
1706  else if( !component->solved )
1707  {
1708  SCIP_CALL( SCIPpqueueInsert(problem->compqueue, component) );
1709  *result = SCIP_DELAYNODE;
1710  }
1711  /* no unsolved components are left, so this problem has be completely evaluated and the node can be pruned */
1712  else if( SCIPpqueueNElems(problem->compqueue) == 0 )
1713  *result = SCIP_CUTOFF;
1714  /* there are some unsolved components left, so we delay this node */
1715  else
1716  *result = SCIP_DELAYNODE;
1717 
1718  return SCIP_OKAY;
1719 }
1720 
1721 /*
1722  * Local methods
1723  */
1724 
1725 /** loop over constraints, get active variables and fill directed graph */
1726 static
1728  SCIP* scip, /**< SCIP data structure */
1729  SCIP_DIGRAPH* digraph, /**< directed graph */
1730  SCIP_CONS** conss, /**< constraints */
1731  int nconss, /**< number of constraints */
1732  int* unfixedvarpos, /**< mapping from variable problem index to unfixed var index */
1733  int nunfixedvars, /**< number of unfixed variables */
1734  int* firstvaridxpercons, /**< array to store for each constraint the index in the local vars array
1735  * of the first variable of the constraint */
1736  SCIP_Bool* success /**< flag indicating successful directed graph filling */
1737  )
1738 {
1739  SCIP_VAR** consvars;
1740  int requiredsize;
1741  int nconsvars;
1742  int nvars;
1743  int idx1;
1744  int idx2;
1745  int c;
1746  int v;
1747 
1748  assert(scip != NULL);
1749  assert(digraph != NULL);
1750  assert(conss != NULL);
1751  assert(firstvaridxpercons != NULL);
1752  assert(success != NULL);
1753 
1754  *success = TRUE;
1755 
1756  nconsvars = 0;
1757  requiredsize = 0;
1758  nvars = SCIPgetNVars(scip);
1759 
1760  /* allocate buffer for storing active variables per constraint; size = nvars ensures that it will be big enough */
1761  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nvars) );
1762 
1763  for( c = 0; c < nconss; ++c )
1764  {
1765  /* check for reached timelimit */
1766  if( (c % 1000 == 0) && SCIPisStopped(scip) )
1767  {
1768  *success = FALSE;
1769  break;
1770  }
1771 
1772  /* get number of variables for this constraint */
1773  SCIP_CALL( SCIPgetConsNVars(scip, conss[c], &nconsvars, success) );
1774 
1775  if( !(*success) )
1776  break;
1777 
1778  /* reallocate consvars array, if needed */
1779  if( nconsvars > nvars )
1780  {
1781  nvars = nconsvars;
1782  SCIP_CALL( SCIPreallocBufferArray(scip, &consvars, nvars) );
1783  }
1784 
1785 #ifndef NDEBUG
1786  /* clearing variables array to check for consistency */
1787  if( nconsvars == nvars )
1788  {
1789  BMSclearMemoryArray(consvars, nconsvars);
1790  }
1791  else
1792  {
1793  assert(nconsvars < nvars);
1794  BMSclearMemoryArray(consvars, nconsvars + 1);
1795  }
1796 #endif
1797 
1798  /* get variables for this constraint */
1799  SCIP_CALL( SCIPgetConsVars(scip, conss[c], consvars, nvars, success) );
1800 
1801  if( !(*success) )
1802  {
1803 #ifndef NDEBUG
1804  /* it looks strange if returning the number of variables was successful but not returning the variables */
1805  SCIPwarningMessage(scip, "constraint <%s> returned number of variables but returning variables failed\n", SCIPconsGetName(conss[c]));
1806 #endif
1807  break;
1808  }
1809 
1810 #ifndef NDEBUG
1811  /* check if returned variables are consistent with the number of variables that were returned */
1812  for( v = nconsvars - 1; v >= 0; --v )
1813  assert(consvars[v] != NULL);
1814  if( nconsvars < nvars )
1815  assert(consvars[nconsvars] == NULL);
1816 #endif
1817 
1818  /* transform given variables to active variables */
1819  SCIP_CALL( SCIPgetActiveVars(scip, consvars, &nconsvars, nvars, &requiredsize) );
1820  assert(requiredsize <= nvars);
1821 
1822  firstvaridxpercons[c] = -1;
1823 
1824  /* store the index of the first unfixed variable and add edges to the directed graph */
1825  if( nconsvars > 0 )
1826  {
1827  v = 0;
1828  idx1 = -1;
1829 
1830  /* go through variables until the first unfixed one is reached (which has unfixedvarpos >= 0) */
1831  while( idx1 == -1 && v < nconsvars )
1832  {
1833  idx1 = SCIPvarGetProbindex(consvars[v]);
1834  assert(idx1 >= 0);
1835  idx1 = unfixedvarpos[idx1];
1836  assert(idx1 < nunfixedvars);
1837  ++v;
1838  }
1839 
1840  if( idx1 >= 0 )
1841  {
1842  /* save index of the first variable for later component assignment */
1843  firstvaridxpercons[c] = idx1;
1844 
1845  /* create sparse directed graph; sparse means to add only those edges necessary for component calculation,
1846  * i.e., add edges from the first variable to all others
1847  */
1848  for(; v < nconsvars; ++v )
1849  {
1850  idx2 = SCIPvarGetProbindex(consvars[v]);
1851  assert(idx2 >= 0);
1852  idx2 = unfixedvarpos[idx2];
1853  assert(idx2 < nunfixedvars);
1854 
1855  /* variable is fixed */
1856  if( idx2 < 0 )
1857  continue;
1858 
1859  /* we add only one directed edge, because the other direction is automatically added for component computation */
1860  SCIP_CALL( SCIPdigraphAddArc(digraph, idx1, idx2, NULL) );
1861  }
1862  }
1863  }
1864  }
1865 
1866  SCIPfreeBufferArray(scip, &consvars);
1867 
1868  return SCIP_OKAY;
1869 }
1870 
1871 /** search for components in the problem */
1872 static
1874  SCIP* scip, /**< SCIP main data structure */
1875  SCIP_CONSHDLRDATA* conshdlrdata, /**< the components constraint handler data */
1876  SCIP_Real* fixedvarsobjsum, /**< objective contribution of all locally fixed variables, or NULL if
1877  * fixed variables should not be disregarded */
1878  SCIP_VAR** sortedvars, /**< array to store variables sorted by components, should have enough size
1879  * for all variables */
1880  SCIP_CONS** sortedconss, /**< array to store (checked) constraints sorted by components, should have
1881  * enough size for all constraints */
1882  int* compstartsvars, /**< start points of components in sortedvars array */
1883  int* compstartsconss, /**< start points of components in sortedconss array */
1884  int* nsortedvars, /**< pointer to store the number of variables belonging to any component */
1885  int* nsortedconss, /**< pointer to store the number of (checked) constraints in components */
1886  int* ncomponents, /**< pointer to store the number of components */
1887  int* ncompsminsize, /**< pointer to store the number of components not exceeding the minimum size */
1888  int* ncompsmaxsize /**< pointer to store the number of components not exceeding the maximum size */
1889 
1890  )
1891 {
1892  SCIP_CONS** tmpconss;
1893  SCIP_VAR** vars;
1894  SCIP_Bool success;
1895  int ntmpconss;
1896  int nvars;
1897  int c;
1898 
1899  assert(scip != NULL);
1900  assert(conshdlrdata != NULL);
1901  assert(sortedvars != NULL);
1902  assert(sortedconss != NULL);
1903  assert(compstartsvars != NULL);
1904  assert(compstartsconss != NULL);
1905  assert(nsortedvars != NULL);
1906  assert(nsortedconss != NULL);
1907  assert(ncomponents != NULL);
1908  assert(ncompsminsize != NULL);
1909  assert(ncompsmaxsize != NULL);
1910 
1911  vars = SCIPgetVars(scip);
1912  nvars = SCIPgetNVars(scip);
1913 
1914  if( fixedvarsobjsum != NULL )
1915  *fixedvarsobjsum = 0.0;
1916 
1917  *ncomponents = 0;
1918  *ncompsminsize = 0;
1919  *ncompsmaxsize = 0;
1920 
1921  /* collect checked constraints for component detection */
1922  ntmpconss = SCIPgetNConss(scip);
1923  tmpconss = SCIPgetConss(scip);
1924  (*nsortedconss) = 0;
1925  for( c = 0; c < ntmpconss; c++ )
1926  {
1927  sortedconss[(*nsortedconss)] = tmpconss[c];
1928  (*nsortedconss)++;
1929  }
1930 
1931  if( nvars > 1 && *nsortedconss > 1 )
1932  {
1933  int* unfixedvarpos;
1934  int* firstvaridxpercons;
1935  int* varlocks;
1936  int nunfixedvars = 0;
1937  int v;
1938 
1939  /* arrays for storing the first variable in each constraint (for later component assignment), the number of
1940  * variable locks, and the positions in the sortedvars array for all unfixed variables
1941  */
1942  SCIP_CALL( SCIPallocBufferArray(scip, &firstvaridxpercons, *nsortedconss) );
1943  SCIP_CALL( SCIPallocBufferArray(scip, &varlocks, nvars) );
1944  SCIP_CALL( SCIPallocBufferArray(scip, &unfixedvarpos, nvars) );
1945 
1946  /* count number of varlocks for each variable (up + down locks) and multiply it by 2;
1947  * that value is used as an estimate of the number of arcs incident to the variable's node in the digraph
1948  * to be safe, we double this value
1949  */
1950  for( v = 0; v < nvars; ++v )
1951  {
1952  /* variable is not fixed or we do not want to disregard fixed variables */
1953  if( (fixedvarsobjsum == NULL) || SCIPisLT(scip, SCIPvarGetLbLocal(vars[v]), SCIPvarGetUbLocal(vars[v])) )
1954  {
1955  assert(nunfixedvars <= v);
1956  sortedvars[nunfixedvars] = vars[v];
1957  varlocks[nunfixedvars] = 4 * (SCIPvarGetNLocksDownType(vars[v], SCIP_LOCKTYPE_MODEL)
1959  unfixedvarpos[v] = nunfixedvars;
1960  ++nunfixedvars;
1961  }
1962  /* variable is fixed; update the objective sum of all fixed variables */
1963  else
1964  {
1965  unfixedvarpos[v] = -1;
1966  (*fixedvarsobjsum) += SCIPvarGetObj(vars[v]) * SCIPvarGetLbLocal(vars[v]);
1967  }
1968  }
1969  *nsortedvars = nunfixedvars;
1970 
1971  if( nunfixedvars > 0 )
1972  {
1973  SCIP_DIGRAPH* digraph;
1974 
1975  /* create and fill directed graph */
1976  SCIP_CALL( SCIPcreateDigraph(scip, &digraph, nunfixedvars) );
1977  SCIP_CALL( SCIPdigraphSetSizes(digraph, varlocks) );
1978  SCIP_CALL( fillDigraph(scip, digraph, sortedconss, *nsortedconss, unfixedvarpos, nunfixedvars, firstvaridxpercons, &success) );
1979 
1980  if( success )
1981  {
1982  int* varcomponent;
1983  int* conscomponent;
1984 
1985  SCIP_CALL( SCIPallocBufferArray(scip, &varcomponent, nunfixedvars) );
1986  SCIP_CALL( SCIPallocBufferArray(scip, &conscomponent, MAX(nunfixedvars,*nsortedconss)) );
1987 
1988  /* compute independent components */
1989  SCIP_CALL( SCIPdigraphComputeUndirectedComponents(digraph, 1, varcomponent, ncomponents) );
1990 
1991  if( *ncomponents > 1 )
1992  {
1993  int nconss = *nsortedconss;
1994  int i;
1995 
1996  nvars = *nsortedvars;
1997 
1999  "cons components found %d undirected components at node %lld, depth %d (%d)\n",
2000  *ncomponents, SCIPnodeGetNumber(SCIPgetCurrentNode(scip)), SCIPgetDepth(scip), SCIPgetDepth(scip) + conshdlrdata->subscipdepth);
2001 
2002  /* sort components by size and sort variables and constraints by component number */
2003  SCIP_CALL( sortComponents(scip, conshdlrdata, digraph, sortedconss, sortedvars, varcomponent, conscomponent, nconss, *nsortedvars,
2004  firstvaridxpercons, ncompsminsize, ncompsmaxsize) );
2005 
2006  /* determine start indices of components in sortedvars and sortedconss array */
2007  i = 0;
2008 
2009  while( i < nconss && conscomponent[i] == -1 )
2010  ++i;
2011 
2012  for( c = 0; c < *ncomponents + 1; ++c )
2013  {
2014  assert(i == nconss || conscomponent[i] >= c);
2015 
2016  compstartsconss[c] = i;
2017 
2018  while( i < nconss && conscomponent[i] == c )
2019  ++i;
2020  }
2021 
2022  for( c = 0, i = 0; c < *ncomponents + 1; ++c )
2023  {
2024  assert(i == nvars || varcomponent[i] >= c);
2025 
2026  compstartsvars[c] = i;
2027 
2028  while( i < nvars && varcomponent[i] == c )
2029  ++i;
2030  }
2031 
2032 #ifndef NDEBUG
2033  for( c = 0; c < *ncomponents; ++c )
2034  {
2035  for( i = compstartsconss[c]; i < compstartsconss[c+1]; ++i )
2036  assert(conscomponent[i] == c);
2037  for( i = compstartsvars[c]; i < compstartsvars[c+1]; ++i )
2038  assert(varcomponent[i] == c);
2039  }
2040 #endif
2041  }
2042 
2043  SCIPfreeBufferArray(scip, &conscomponent);
2044  SCIPfreeBufferArray(scip, &varcomponent);
2045  }
2046 
2047  SCIPdigraphFree(&digraph);
2048  }
2049 
2050  SCIPfreeBufferArray(scip, &unfixedvarpos);
2051  SCIPfreeBufferArray(scip, &varlocks);
2052  SCIPfreeBufferArray(scip, &firstvaridxpercons);
2053  }
2054 
2055  return SCIP_OKAY;
2056 }
2057 
2058 
2059 /*
2060  * Callback methods of constraint handler
2061  */
2062 
2063 /** copy method for constraint handler plugins (called when SCIP copies plugins) */
2064 static
2065 SCIP_DECL_CONSHDLRCOPY(conshdlrCopyComponents)
2066 { /*lint --e{715}*/
2067  assert(scip != NULL);
2068  assert(conshdlr != NULL);
2069  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2070 
2071  /* call inclusion method of constraint handler */
2073 
2074  *valid = TRUE;
2075 
2076  return SCIP_OKAY;
2077 }
2078 
2079 /** destructor of constraint handler to free user data (called when SCIP is exiting) */
2080 static
2081 SCIP_DECL_CONSFREE(conshdlrFreeComponents)
2082 { /*lint --e{715}*/
2083  SCIP_CONSHDLRDATA* conshdlrdata;
2084 
2085  /* free constraint handler data */
2086  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2087  assert(conshdlrdata != NULL);
2088 
2089  SCIPfreeBlockMemory(scip, &conshdlrdata);
2090  SCIPconshdlrSetData(conshdlr, NULL);
2091 
2092  return SCIP_OKAY;
2093 }
2094 
2095 /** domain propagation method of constraint handler */
2096 static
2097 SCIP_DECL_CONSPROP(consPropComponents)
2098 { /*lint --e{715}*/
2099  PROBLEM* problem;
2100  SCIP_CONSHDLRDATA* conshdlrdata;
2101  SCIP_Longint nodelimit;
2102 
2103  assert(conshdlr != NULL);
2104  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2105  assert(result != NULL);
2106  assert(SCIPconshdlrGetNActiveConss(conshdlr) >= 0);
2107  assert(SCIPconshdlrGetNActiveConss(conshdlr) <= 1);
2108 
2109  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2110  assert(conshdlrdata != NULL);
2111 
2112  *result = SCIP_DIDNOTRUN;
2113 
2114  /* do not try to detect independent components if the depth is too high */
2115  if( SCIPgetDepth(scip) + conshdlrdata->subscipdepth > conshdlrdata->maxdepth
2116  && SCIPconshdlrGetNActiveConss(conshdlr) == 0 )
2117  return SCIP_OKAY;
2118 
2119  /* don't run in probing or in repropagation */
2120  if( SCIPinProbing(scip) || SCIPinRepropagation(scip) )
2121  return SCIP_OKAY;
2122 
2123  /* do not run, if not all variables are explicitly known */
2124  if( SCIPgetNActivePricers(scip) > 0 )
2125  return SCIP_OKAY;
2126 
2127  /* we do not want to run, if there are no variables left */
2128  if( SCIPgetNVars(scip) == 0 )
2129  return SCIP_OKAY;
2130 
2131  /* check for a reached timelimit */
2132  if( SCIPisStopped(scip) )
2133  return SCIP_OKAY;
2134 
2135  /* the components constraint handler does kind of dual reductions */
2136  if( !SCIPallowStrongDualReds(scip) || !SCIPallowWeakDualReds(scip) )
2137  return SCIP_OKAY;
2138 
2139  problem = NULL;
2140  *result = SCIP_DIDNOTFIND;
2141 
2142  /* the current node already has a components constraint storing a problem split into individual components */
2143  if( SCIPconshdlrGetNActiveConss(conshdlr) >= 1 )
2144  {
2145  assert(SCIPconshdlrGetNActiveConss(conshdlr) == 1);
2146 
2147  problem = (PROBLEM*)SCIPconsGetData(SCIPconshdlrGetConss(conshdlr)[0]);
2148  }
2149  /* no components constraint at the current node, search for components */
2150  else
2151  {
2153  SCIP_VAR** sortedvars;
2154  SCIP_CONS** sortedconss;
2155  int* compstartsvars;
2156  int* compstartsconss;
2157  int nsortedvars;
2158  int nsortedconss;
2159  int ncomponents;
2160  int ncompsminsize;
2161  int ncompsmaxsize;
2162 
2163  assert(SCIPconshdlrGetNActiveConss(conshdlr) == 0);
2164 
2165  /* allocate memory for sorted components */
2166  SCIP_CALL( SCIPallocBufferArray(scip, &sortedvars, SCIPgetNVars(scip)) );
2167  SCIP_CALL( SCIPallocBufferArray(scip, &sortedconss, SCIPgetNConss(scip)) );
2168  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsvars, SCIPgetNVars(scip) + 1) );
2169  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsconss, SCIPgetNVars(scip) + 1) );
2170 
2171  /* search for components */
2172  SCIP_CALL( findComponents(scip, conshdlrdata, &fixedvarsobjsum, sortedvars, sortedconss, compstartsvars,
2173  compstartsconss, &nsortedvars, &nsortedconss, &ncomponents, &ncompsminsize, &ncompsmaxsize) );
2174 
2175  if( ncompsminsize > 1 )
2176  {
2177  SCIP_CONS* cons;
2178 
2179  SCIPdebugMsg(scip, "found %d components (%d fulfulling the minsize requirement) at node %lld at depth %d (%d)\n",
2180  ncomponents, ncompsminsize, SCIPnodeGetNumber(SCIPgetCurrentNode(scip)), SCIPgetDepth(scip),
2181  SCIPgetDepth(scip) + conshdlrdata->subscipdepth);
2182 
2183  /* if there are components with size smaller than the limit, we merge them with the smallest component */
2184  if( ncomponents > ncompsminsize )
2185  {
2186  int minsize;
2187  int size;
2188  int c;
2189  int m = 0;
2190 
2191  /* compute minimum size of components to solve individually */
2192  minsize = getMinsize(scip, conshdlrdata);
2193 
2194  for( c = 0; c < ncomponents; ++c )
2195  {
2196  size = compstartsvars[c+1] - compstartsvars[c];
2197 
2198  if( size >= minsize )
2199  {
2200  ++m;
2201  compstartsvars[m] = compstartsvars[c+1];
2202  compstartsconss[m] = compstartsconss[c+1];
2203  }
2204  /* the last component is too small */
2205  else if( c == ncomponents - 1 )
2206  {
2207  assert(m == ncompsminsize);
2208  compstartsvars[m] = compstartsvars[c+1];
2209  compstartsconss[m] = compstartsconss[c+1];
2210  }
2211  }
2212  assert(m == ncompsminsize);
2213  assert(compstartsvars[m] == nsortedvars);
2214  assert(compstartsconss[m] == nsortedconss);
2215 
2216  ncomponents = m;
2217  }
2218 
2219  SCIP_CALL( createAndSplitProblem(scip, conshdlrdata, fixedvarsobjsum, sortedvars, sortedconss, compstartsvars,
2220  compstartsconss, ncomponents, &problem) );
2221 
2222  /* if the problem is not NULL, copying worked fine */
2223  if( problem != NULL )
2224  {
2225  SCIP_CALL( createConsComponents(scip, &cons, problem->name, problem) );
2226  SCIP_CALL( SCIPaddConsNode(scip, SCIPgetCurrentNode(scip), cons, NULL) );
2227  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
2228  }
2229  }
2230 
2231  SCIPfreeBufferArray(scip, &compstartsconss);
2232  SCIPfreeBufferArray(scip, &compstartsvars);
2233  SCIPfreeBufferArray(scip, &sortedconss);
2234  SCIPfreeBufferArray(scip, &sortedvars);
2235  }
2236 
2237  /* (continue to) solve the problem
2238  *
2239  * If the problem was not solved to optimality yet, the result code is set to SCIP_DELAYNODE, so that after the
2240  * propagation is finished, the node is put back into the queue of open nodes and solving the components of the
2241  * problem will be continued when the node is focused and propagated the next time.
2242  * However, if we are at the root node, we continue solving the problem until it is solved or some limit is reached
2243  * since there are no other nodes to process and we want to avoid calling other propagation methods or heuristics
2244  * again and again
2245  */
2246  SCIP_CALL( SCIPgetLongintParam(scip, "limits/nodes", &nodelimit) );
2247  if( nodelimit == -1 )
2248  nodelimit = SCIP_LONGINT_MAX;
2249 
2250  do
2251  {
2252  if( problem != NULL )
2253  {
2254  SCIP_CALL( solveProblem(problem, result) );
2255  }
2256  } while( *result == SCIP_DELAYNODE && SCIPgetDepth(scip) == 0 && !SCIPisStopped(scip) && SCIPgetNNodes(scip) < nodelimit);
2257 
2258  return SCIP_OKAY;
2259 }
2260 
2261 /** presolving method of constraint handler */
2262 static
2263 SCIP_DECL_CONSPRESOL(consPresolComponents)
2264 { /*lint --e{715}*/
2265  SCIP_CONSHDLRDATA* conshdlrdata;
2266  SCIP_VAR** sortedvars;
2267  SCIP_CONS** sortedconss;
2268  int* compstartsvars;
2269  int* compstartsconss;
2270  int nsortedvars;
2271  int nsortedconss;
2272  int ncomponents;
2273  int ncompsminsize;
2274  int ncompsmaxsize;
2275  int nvars;
2276 
2277  assert(conshdlr != NULL);
2278  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2279  assert(result != NULL);
2280  assert(SCIPconshdlrGetNActiveConss(conshdlr) >= 0);
2281  assert(SCIPconshdlrGetNActiveConss(conshdlr) <= 1);
2282 
2283  conshdlrdata = SCIPconshdlrGetData(conshdlr);
2284  assert(conshdlrdata != NULL);
2285 
2286  *result = SCIP_DIDNOTRUN;
2287 
2288  if( SCIPgetStage(scip) != SCIP_STAGE_PRESOLVING || SCIPinProbing(scip) )
2289  return SCIP_OKAY;
2290 
2291  /* do not run, if not all variables are explicitly known */
2292  if( SCIPgetNActivePricers(scip) > 0 )
2293  return SCIP_OKAY;
2294 
2295  nvars = SCIPgetNVars(scip);
2296 
2297  /* we do not want to run, if there are no variables left */
2298  if( nvars == 0 )
2299  return SCIP_OKAY;
2300 
2301  /* only call the components presolving, if presolving would be stopped otherwise */
2302  if( !SCIPisPresolveFinished(scip) )
2303  return SCIP_OKAY;
2304 
2305  /* the components constraint handler does kind of dual reductions */
2306  if( !SCIPallowStrongDualReds(scip) || !SCIPallowWeakDualReds(scip) )
2307  return SCIP_OKAY;
2308 
2309  /* check for a reached timelimit */
2310  if( SCIPisStopped(scip) )
2311  return SCIP_OKAY;
2312 
2313  *result = SCIP_DIDNOTFIND;
2314 
2315  assert(SCIPconshdlrGetNActiveConss(conshdlr) == 0);
2316 
2317  /* allocate memory for sorted components */
2318  SCIP_CALL( SCIPallocBufferArray(scip, &sortedvars, SCIPgetNVars(scip)) );
2319  SCIP_CALL( SCIPallocBufferArray(scip, &sortedconss, SCIPgetNConss(scip)) );
2320  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsvars, SCIPgetNVars(scip) + 1) );
2321  SCIP_CALL( SCIPallocBufferArray(scip, &compstartsconss, SCIPgetNVars(scip) + 1) );
2322 
2323  /* search for components */
2324  SCIP_CALL( findComponents(scip, conshdlrdata, NULL, sortedvars, sortedconss, compstartsvars,
2325  compstartsconss, &nsortedvars, &nsortedconss, &ncomponents, &ncompsminsize, &ncompsmaxsize) );
2326 
2327  if( ncompsmaxsize > 0 )
2328  {
2329  char name[SCIP_MAXSTRLEN];
2330  SCIP* subscip;
2331  SCIP_HASHMAP* consmap;
2332  SCIP_HASHMAP* varmap;
2333  SCIP_VAR** compvars;
2334  SCIP_VAR** subvars;
2335  SCIP_CONS** compconss;
2336  SCIP_Bool success;
2337  SCIP_Bool solved;
2338  int nsolved = 0;
2339  int ncompvars;
2340  int ncompconss;
2341  int comp;
2342 
2343  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",
2344  ncomponents, ncompsmaxsize, SCIPgetNVars(scip), SCIPgetNBinVars(scip), SCIPgetNIntVars(scip), SCIPgetNContVars(scip) + SCIPgetNImplVars(scip), SCIPgetNConss(scip));
2345 
2346  /* build subscip */
2347  SCIP_CALL( createSubscip(scip, conshdlrdata, &subscip) );
2348 
2349  if( subscip == NULL )
2350  goto TERMINATE;
2351 
2352  SCIP_CALL( SCIPsetBoolParam(subscip, "misc/usesmalltables", TRUE) );
2353  SCIP_CALL( SCIPsetIntParam(subscip, "constraints/" CONSHDLR_NAME "/propfreq", -1) );
2354 
2355  /* hashmap mapping from original constraints to constraints in the sub-SCIPs (for performance reasons) */
2356  SCIP_CALL( SCIPhashmapCreate(&consmap, SCIPblkmem(scip), nsortedconss) );
2357 
2358  SCIP_CALL( SCIPallocBufferArray(scip, &subvars, nsortedvars) );
2359 
2360  /* loop over all components */
2361  for( comp = 0; comp < ncompsmaxsize && !SCIPisStopped(scip); comp++ )
2362  {
2363 #ifdef WITH_DEBUG_SOLUTION
2364  if( SCIPgetStage(subscip) > SCIP_STAGE_INIT )
2365  {
2366  SCIP_CALL( SCIPfree(&subscip) );
2367  SCIP_CALL( createSubscip(scip, conshdlrdata, &subscip) );
2368  }
2369 #endif
2370  /* get component variables */
2371  compvars = &(sortedvars[compstartsvars[comp]]);
2372  ncompvars = compstartsvars[comp + 1 ] - compstartsvars[comp];
2373 
2374  /* get component constraints */
2375  compconss = &(sortedconss[compstartsconss[comp]]);
2376  ncompconss = compstartsconss[comp + 1] - compstartsconss[comp];
2377 
2378  /* if we have an unlocked variable, let duality fixing do the job! */
2379  if( ncompconss == 0 )
2380  {
2381  assert(ncompvars == 1);
2382  continue;
2383  }
2384 
2385  SCIP_CALL( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), ncompvars) );
2386 #ifdef DETAILED_OUTPUT
2387  {
2388  int nbinvars = 0;
2389  int nintvars = 0;
2390  int ncontvars = 0;
2391  int i;
2392 
2393  for( i = 0; i < ncompvars; ++i )
2394  {
2395  if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_BINARY )
2396  ++nbinvars;
2397  else if( SCIPvarGetType(compvars[i]) == SCIP_VARTYPE_INTEGER )
2398  ++nintvars;
2399  else
2400  ++ncontvars;
2401  }
2402  SCIPdebugMsg(scip, "solve component %d: %d vars (%d bin, %d int, %d cont), %d conss\n",
2403  comp, ncompvars, nbinvars, nintvars, ncontvars, ncompconss);
2404  }
2405 #endif
2406 #ifndef NDEBUG
2407  {
2408  int i;
2409  for( i = 0; i < ncompvars; ++i )
2410  assert(SCIPvarIsActive(compvars[i]));
2411  }
2412 #endif
2413 
2414  /* get name of the original problem and add "comp_nr" */
2415  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_comp_%d", SCIPgetProbName(scip), comp);
2416 
2417  SCIP_CALL( copyToSubscip(scip, subscip, name, compvars, subvars,
2418  compconss, varmap, consmap, ncompvars, ncompconss, &success) );
2419 
2420  if( !success )
2421  {
2422  SCIPhashmapFree(&varmap);
2423  continue;
2424  }
2425 
2426  /* set up debug solution */
2427 #ifdef WITH_DEBUG_SOLUTION
2428  if( SCIPdebugSolIsEnabled(scip) )
2429  {
2430  SCIP_SOL* debugsol;
2431  SCIP_Real val;
2432  int i;
2433 
2434  SCIP_CALL( SCIPdebugGetSol(scip, &debugsol) );
2435 
2436  /* set solution values in the debug solution if it is available */
2437  if( debugsol != NULL )
2438  {
2439  SCIPdebugSolEnable(subscip);
2440 
2441  for( i = 0; i < ncompvars; ++i )
2442  {
2443  if( subvars[i] != NULL )
2444  {
2445  SCIP_CALL( SCIPdebugGetSolVal(scip, compvars[i], &val) );
2446  SCIP_CALL( SCIPdebugAddSolVal(subscip, subvars[i], val) );
2447  }
2448  }
2449  }
2450  }
2451 #endif
2452 
2453  /* solve the subproblem and evaluate the result, i.e. apply fixings of variables and remove constraints */
2454  SCIP_CALL( solveAndEvalSubscip(scip, conshdlrdata, subscip, compvars, subvars, compconss,
2455  ncompvars, ncompconss, ndelconss, nfixedvars, nchgbds, result, &solved) );
2456 
2457  /* free variable hash map */
2458  SCIPhashmapFree(&varmap);
2459 
2460  if( solved )
2461  ++nsolved;
2462 
2463  /* if the component is unbounded or infeasible, this holds for the complete problem as well */
2464  if( *result == SCIP_UNBOUNDED || *result == SCIP_CUTOFF )
2465  break;
2466  /* if there is only one component left, let's solve this in the main SCIP */
2467  else if( nsolved == ncomponents - 1 )
2468  break;
2469  }
2470 
2471  SCIPfreeBufferArray(scip, &subvars);
2472  SCIPhashmapFree(&consmap);
2473 
2474  SCIP_CALL( SCIPfree(&subscip) );
2475  }
2476 
2477  TERMINATE:
2478  SCIPfreeBufferArray(scip, &compstartsconss);
2479  SCIPfreeBufferArray(scip, &compstartsvars);
2480  SCIPfreeBufferArray(scip, &sortedconss);
2481  SCIPfreeBufferArray(scip, &sortedvars);
2482 
2483  return SCIP_OKAY;
2484 }
2485 
2486 /** frees specific constraint data */
2487 static
2488 SCIP_DECL_CONSDELETE(consDeleteComponents)
2489 { /*lint --e{715}*/
2490  assert(conshdlr != NULL);
2491  assert(strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0);
2492  assert(consdata != NULL);
2493  assert(*consdata != NULL);
2494 
2495  SCIP_CALL( freeProblem((PROBLEM**) consdata) );
2496 
2497  return SCIP_OKAY;
2498 }
2499 
2500 /** constraint enforcing method of constraint handler for relaxation solutions */
2501 static
2502 SCIP_DECL_CONSENFORELAX(consEnforelaxComponents)
2503 { /*lint --e{715}*/
2504  assert(result != NULL );
2505 
2506  /* no enforcement is performed, but the callback is needed for all constraint handlers with needscons = FALSE */
2507  *result = SCIP_FEASIBLE;
2508 
2509  return SCIP_OKAY;
2510 }
2511 
2512 /** variable rounding lock method of constraint handler */
2513 static
2514 SCIP_DECL_CONSLOCK(consLockComponents)
2515 { /*lint --e{715}*/
2516  return SCIP_OKAY;
2517 }
2518 
2519 #ifndef NDEBUG
2520 /** solving process initialization method of constraint handler (called when branch and bound process is about to begin) */
2521 static
2522 SCIP_DECL_CONSINITSOL(consInitsolComponents)
2523 { /*lint --e{715}*/
2524  assert(nconss == 0);
2525 
2526  return SCIP_OKAY;
2527 }
2528 #endif
2529 
2530 #define consEnfolpComponents NULL
2531 #define consEnfopsComponents NULL
2532 #define consCheckComponents NULL
2534 /**@name Interface methods
2535  *
2536  * @{
2537  */
2538 
2539 /** creates the components constraint handler and includes it in SCIP */
2541  SCIP* scip /**< SCIP data structure */
2542  )
2543 {
2544  SCIP_CONSHDLRDATA* conshdlrdata;
2545  SCIP_CONSHDLR* conshdlr;
2546 
2547  /* create components propagator data */
2548  SCIP_CALL( SCIPallocBlockMemory(scip, &conshdlrdata) );
2549  conshdlrdata->subscipdepth = 0;
2550 
2551  /* include constraint handler */
2555  conshdlrdata) );
2556  assert(conshdlr != NULL);
2557 
2558  SCIP_CALL( SCIPsetConshdlrProp(scip, conshdlr, consPropComponents,
2560  SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolComponents,
2562 
2563  SCIP_CALL( SCIPsetConshdlrFree(scip, conshdlr, conshdlrFreeComponents) );
2564  SCIP_CALL( SCIPsetConshdlrEnforelax(scip, conshdlr, consEnforelaxComponents) );
2565 #ifndef NDEBUG
2566  SCIP_CALL( SCIPsetConshdlrInitsol(scip, conshdlr, consInitsolComponents) );
2567 #endif
2568  SCIP_CALL( SCIPsetConshdlrCopy(scip, conshdlr, conshdlrCopyComponents, NULL) );
2569  SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteComponents) );
2570 
2571  SCIP_CALL( SCIPaddIntParam(scip,
2572  "constraints/" CONSHDLR_NAME "/maxdepth",
2573  "maximum depth of a node to run components detection (-1: disable component detection during solving)",
2574  &conshdlrdata->maxdepth, FALSE, DEFAULT_MAXDEPTH, -1, INT_MAX, NULL, NULL) );
2575  SCIP_CALL( SCIPaddIntParam(scip,
2576  "constraints/" CONSHDLR_NAME "/maxintvars",
2577  "maximum number of integer (or binary) variables to solve a subproblem during presolving (-1: unlimited)",
2578  &conshdlrdata->maxintvars, TRUE, DEFAULT_MAXINTVARS, -1, INT_MAX, NULL, NULL) );
2579  SCIP_CALL( SCIPaddIntParam(scip,
2580  "constraints/" CONSHDLR_NAME "/minsize",
2581  "minimum absolute size (in terms of variables) to solve a component individually during branch-and-bound",
2582  &conshdlrdata->minsize, TRUE, DEFAULT_MINSIZE, 0, INT_MAX, NULL, NULL) );
2584  "constraints/" CONSHDLR_NAME "/minrelsize",
2585  "minimum relative size (in terms of variables) to solve a component individually during branch-and-bound",
2586  &conshdlrdata->minrelsize, TRUE, DEFAULT_MINRELSIZE, 0.0, 1.0, NULL, NULL) );
2588  "constraints/" CONSHDLR_NAME "/nodelimit",
2589  "maximum number of nodes to be solved in subproblems during presolving",
2590  &conshdlrdata->nodelimit, FALSE, DEFAULT_NODELIMIT, -1LL, SCIP_LONGINT_MAX, NULL, NULL) );
2592  "constraints/" CONSHDLR_NAME "/intfactor",
2593  "the weight of an integer variable compared to binary variables",
2594  &conshdlrdata->intfactor, FALSE, DEFAULT_INTFACTOR, 0.0, SCIP_REAL_MAX, NULL, NULL) );
2596  "constraints/" CONSHDLR_NAME "/feastolfactor",
2597  "factor to increase the feasibility tolerance of the main SCIP in all sub-SCIPs, default value 1.0",
2598  &conshdlrdata->feastolfactor, TRUE, DEFAULT_FEASTOLFACTOR, 0.0, 1000000.0, NULL, NULL) );
2599 
2600  return SCIP_OKAY;
2601 }
2602 
2603 /**@} */
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:5177
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:8617
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:3435
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:279
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:5294
public solving methods
SCIP_Real SCIPgetGap(SCIP *scip)
SCIP_EXPORT SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
Definition: tree.c:7438
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_PARAM * SCIPgetParam(SCIP *scip, const char *name)
Definition: scip_param.c:225
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:2555
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:370
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:275
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:276
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:1827
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:8250
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:274
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2031
#define CONSHDLR_DESC
#define SCIPdebugSolIsEnabled(scip)
Definition: debug.h:279
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:8590
#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:277
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:3357
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