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