Scippy

SCIP

Solving Constraint Integer Programs

debug.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2021 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file debug.c
17  * @ingroup OTHER_CFILES
18  * @brief methods for debugging
19  * @author Tobias Achterberg
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include <stdio.h>
25 #include <string.h>
26 #include <assert.h>
27 #if defined(_WIN32) || defined(_WIN64)
28 #else
29 #include <strings.h> /*lint --e{766}*/
30 #endif
31 
32 #include "scip/def.h"
33 #include "blockmemshell/memory.h"
34 #include "scip/set.h"
35 #include "scip/lp.h"
36 #include "scip/var.h"
37 #include "scip/prob.h"
38 #include "scip/tree.h"
39 #include "scip/scip.h"
40 #include "scip/debug.h"
41 #include "scip/pub_message.h"
42 #include "scip/pub_misc.h"
43 #include "scip/struct_scip.h"
44 
45 #ifdef WITH_DEBUG_SOLUTION
46 
47 #define SCIP_HASHSIZE_DEBUG 500 /**< minimum size of hash map for storing whether a solution is valid for the node */
48 
49 struct SCIP_DebugSolData
50 {
51  char** solnames; /**< variable names in the solution */
52  SCIP_Real* solvals; /**< solution value array (only nonzero entries) */
53  int nsolvals; /**< number of entries in the debug solution */
54  int solsize; /**< size of the array entries */
55  SCIP_SOL* debugsol; /**< a debug solution */
56  SCIP_STAGE debugsolstage; /**< solving stage of debug solution */
57  SCIP_HASHMAP* solinnode; /**< maps nodes to bools, storing whether the solution is valid for the node */
58  SCIP_Bool falseptr; /**< pointer to value FALSE used for hashmap */
59  SCIP_Bool trueptr; /**< pointer to value TRUE used for hashmap */
60  SCIP_Bool solisachieved; /**< means if current best solution is better than the given debug solution */
61  SCIP_Real debugsolval; /**< objective value for debug solution */
62  SCIP_Bool debugsoldisabled; /**< flag indicating if debugging of solution was disabled or not */
63  SCIP_Bool warningprinted; /**< flag indicating if a warning was already printed */
64 };
65 
66 
67 /** creates debug solution data */
69  SCIP_DEBUGSOLDATA** debugsoldata /**< pointer to debug solution data */
70  )
71 {
72  assert(debugsoldata != NULL);
73 
74  SCIP_ALLOC( BMSallocMemory(debugsoldata) );
75 
76  (*debugsoldata)->solnames = NULL;
77  (*debugsoldata)->solvals = NULL;
78  (*debugsoldata)->nsolvals = 0;
79  (*debugsoldata)->solsize = 0;
80  (*debugsoldata)->debugsol = NULL;
81  (*debugsoldata)->debugsolstage = SCIP_STAGE_INIT;
82  (*debugsoldata)->solinnode = NULL;
83  (*debugsoldata)->falseptr = FALSE;
84  (*debugsoldata)->trueptr = TRUE;
85  (*debugsoldata)->solisachieved = FALSE;
86  (*debugsoldata)->debugsolval = 0.0;
87  (*debugsoldata)->debugsoldisabled = TRUE;
88  (*debugsoldata)->warningprinted = FALSE;
89 
90  return SCIP_OKAY;
91 }
92 
93 #ifdef SCIP_MORE_DEBUG
94 /** comparison method for sorting variables w.r.t. to their name */
95 static
96 SCIP_DECL_SORTPTRCOMP(sortVarsAfterNames)
97 {
98  return strcmp(SCIPvarGetName((SCIP_VAR*)elem1), SCIPvarGetName((SCIP_VAR*)elem2));
99 }
100 #endif
101 
102 /* checks whether the parameter is specified */
103 static
104 SCIP_Bool debugSolutionAvailable(
105  SCIP_SET* set /**< global SCIP settings */
106  )
107 {
108  SCIP_DEBUGSOLDATA* debugsoldata;
109 
110  assert(set != NULL);
111 
112  debugsoldata = SCIPsetGetDebugSolData(set);
113 
114  /* check whether a debug solution is specified */
115  if( strcmp(set->misc_debugsol, "-") == 0 )
116  {
117  if( !debugsoldata->warningprinted )
118  {
119  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "SCIP is compiled with 'DEBUGSOL=true' but no debug solution is given:\n ");
120  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "*** Please set the parameter 'misc/debugsol' and reload the problem again to use the debugging-mechanism ***\n\n");
121  debugsoldata->warningprinted = TRUE;
122  }
123  return FALSE;
124  }
125  else
126  {
127  debugsoldata->warningprinted = FALSE;
128  return TRUE;
129  }
130 }
131 
132 /** reads solution from given file into given arrays */
133 static
134 SCIP_RETCODE readSolfile(
135  SCIP_SET* set, /**< global SCIP settings */
136  const char* solfilename, /**< solution filename to read */
137  SCIP_SOL** debugsolptr,
138  SCIP_Real* debugsolvalptr,
139  SCIP_STAGE* debugsolstageptr,
140  char*** names, /**< pointer to store the array of variable names */
141  SCIP_Real** vals, /**< pointer to store the array of solution values */
142  int* nvals, /**< pointer to store the number of non-zero elements */
143  int* valssize /**< pointer to store the length of the variable names and solution values arrays */
144  )
145 {
146  SCIP_VAR** vars;
147  SCIP_Real* solvalues;
148  SCIP_FILE* file;
149  SCIP_SOL* debugsol;
150  SCIP_Real debugsolval;
151  int nonvalues;
152  int nfound;
153  int i;
154  SCIP_Bool unknownvariablemessage;
155 
156  assert(set != NULL);
157  assert(solfilename != NULL);
158  assert(names != NULL);
159  assert(*names == NULL);
160  assert(vals != NULL);
161  assert(*vals == NULL);
162  assert(nvals != NULL);
163  assert(valssize != NULL);
164 
165  printf("***** debug: reading solution file <%s>\n", solfilename);
166 
167  /* open solution file */
168  file = SCIPfopen(solfilename, "r");
169  if( file == NULL )
170  {
171  SCIPerrorMessage("cannot open solution file <%s> specified in scip/debug.h\n", solfilename);
172  SCIPprintSysError(solfilename);
173  return SCIP_NOFILE;
174  }
175 
176  /* read data */
177  nonvalues = 0;
178  *valssize = 0;
179  unknownvariablemessage = FALSE;
180 
181  while( !SCIPfeof(file) )
182  {
183  char buf[SCIP_MAXSTRLEN];
184  char name[SCIP_MAXSTRLEN];
185  char objstring[SCIP_MAXSTRLEN];
186  char valuestring[SCIP_MAXSTRLEN];
187  SCIP_VAR* var;
188  SCIP_Real val;
189  int nread;
190 
191  if( SCIPfgets(buf, SCIP_MAXSTRLEN, file) == NULL )
192  {
193  if( SCIPfeof(file) )
194  break;
195  else
196  return SCIP_READERROR;
197  }
198 
199  /* there are some lines which may preceed the solution information */
200  if( strncasecmp(buf, "solution status:", 16) == 0 || strncasecmp(buf, "objective value:", 16) == 0 ||
201  strncasecmp(buf, "Log started", 11) == 0 || strncasecmp(buf, "Variable Name", 13) == 0 ||
202  strncasecmp(buf, "All other variables", 19) == 0 || strncasecmp(buf, "\n", 1) == 0 ||
203  strncasecmp(buf, "NAME", 4) == 0 || strncasecmp(buf, "ENDATA", 6) == 0 ) /* allow parsing of SOL-format on the MIPLIB 2003 pages */
204  {
205  ++nonvalues;
206  continue;
207  }
208 
209  /* cppcheck-suppress invalidscanf */
210  nread = sscanf(buf, "%s %s %s\n", name, valuestring, objstring);
211  if( nread < 2 )
212  {
213  printf("invalid input line %d in solution file <%s>: <%s>\n", *nvals + nonvalues, solfilename, name);
214  SCIPfclose(file);
215  return SCIP_READERROR;
216  }
217 
218  /* find the variable */
219  var = SCIPfindVar(set->scip, name);
220  if( var == NULL )
221  {
222  if( !unknownvariablemessage )
223  {
224  SCIPverbMessage(set->scip, SCIP_VERBLEVEL_NORMAL, NULL, "unknown variable <%s> in line %d of solution file <%s>\n",
225  name, *nvals + nonvalues, solfilename);
226  SCIPverbMessage(set->scip, SCIP_VERBLEVEL_NORMAL, NULL, " (further unknown variables are ignored)\n");
227  unknownvariablemessage = TRUE;
228  }
229  continue;
230  }
231 
232  /* cast the value, check first for inv(alid) or inf(inite) ones that need special treatment */
233  if( strncasecmp(valuestring, "inv", 3) == 0 )
234  continue;
235  else if( strncasecmp(valuestring, "+inf", 4) == 0 || strncasecmp(valuestring, "inf", 3) == 0 )
236  val = SCIPsetInfinity(set);
237  else if( strncasecmp(valuestring, "-inf", 4) == 0 )
238  val = -SCIPsetInfinity(set);
239  else
240  {
241  /* cppcheck-suppress invalidscanf */
242  nread = sscanf(valuestring, "%lf", &val);
243  if( nread != 1 )
244  {
245  SCIPerrorMessage("Invalid solution value <%s> for variable <%s> in line %d of solution file <%s>.\n",
246  valuestring, name, *nvals + nonvalues, solfilename);
247  SCIPfclose(file);
248  return SCIP_READERROR;
249  }
250  }
251 
252  /* allocate memory */
253  if( *nvals >= *valssize )
254  {
255  *valssize = MAX(2 * *valssize, (*nvals)+1);
256  SCIP_ALLOC( BMSreallocMemoryArray(names, *valssize) );
257  SCIP_ALLOC( BMSreallocMemoryArray(vals, *valssize) );
258  }
259  assert(*nvals < *valssize);
260 
261  /* store solution value in sorted list */
262  for( i = *nvals; i > 0 && strcmp(name, (*names)[i-1]) < 0; --i )
263  {
264  (*names)[i] = (*names)[i-1];
265  (*vals)[i] = (*vals)[i-1];
266  }
267  SCIP_ALLOC( BMSduplicateMemoryArray(&(*names)[i], name, strlen(name)+1) );
268  SCIPdebugMsg(set->scip, "found variable <%s>: value <%g>\n", (*names)[i], val);
269  (*vals)[i] = val;
270  (*nvals)++;
271  }
272 
273  /* get memory for SCIP solution */
274  SCIP_ALLOC( BMSallocMemoryArray(&vars, *valssize) );
275  SCIP_ALLOC( BMSallocMemoryArray(&solvalues, *valssize) );
276 
277  debugsolval = 0.0;
278  nfound = 0;
279 
280  /* get solution value */
281  for( i = 0; i < *nvals; ++i)
282  {
283  SCIP_VAR* var;
284  var = SCIPfindVar(set->scip, (*names)[i]);
285  if( var != NULL )
286  {
287  vars[nfound] = var;
288  solvalues[nfound] = (*vals)[i];
289  ++nfound;
290  debugsolval += (*vals)[i] * SCIPvarGetObj(var);
291  }
292  }
293  SCIPdebugMsg(set->scip, "Debug Solution value is %g.\n", debugsolval);
294 
295 #ifdef SCIP_MORE_DEBUG
296  SCIPsortPtrReal((void**)vars, solvalues, sortVarsAfterNames, nfound);
297 
298  for( i = 0; i < nfound - 1; ++i)
299  {
300  assert(strcmp(SCIPvarGetName(vars[i]), SCIPvarGetName(vars[i + 1])) != 0);
301  }
302 #endif
303 
304  if( debugsolptr != NULL )
305  {
306  /* create SCIP solution */
307  SCIP_CALL( SCIPcreateOrigSol(set->scip, &debugsol, NULL) );
308  *debugsolstageptr = SCIPgetStage(set->scip);
309 
310  /* set SCIP solution values */
311  SCIP_CALL( SCIPsetSolVals(set->scip, debugsol, nfound, vars, solvalues ) );
312  }
313 
314  BMSfreeMemoryArray(&vars);
315  BMSfreeMemoryArray(&solvalues);
316 
317  if( debugsolptr != NULL )
318  *debugsolptr = debugsol;
319 
320  if( debugsolvalptr != NULL )
321  *debugsolvalptr = debugsolval;
322 
323  /* close file */
324  SCIPfclose(file);
325 
326  printf("***** debug: read %d non-zero entries (%d variables found)\n", *nvals, nfound);
327 
328  return SCIP_OKAY;
329 }
330 
331 /** reads feasible solution to check from file */
332 static
333 SCIP_RETCODE readSolution(
334  SCIP_SET* set /**< global SCIP settings */
335  )
336 {
337  SCIP_DEBUGSOLDATA* debugsoldata;
338 
339  assert(set != NULL);
340 
341  debugsoldata = SCIPsetGetDebugSolData(set);
342 
343  /* check whether a debug solution is available */
344  if( !debugSolutionAvailable(set) )
345  return SCIP_OKAY;
346 
347  if( debugsoldata == NULL || debugsoldata->nsolvals > 0 )
348  return SCIP_OKAY;
349 
350  SCIP_CALL( readSolfile(set, set->misc_debugsol, &debugsoldata->debugsol, &debugsoldata->debugsolval,
351  &debugsoldata->debugsolstage, &(debugsoldata->solnames), &(debugsoldata->solvals), &(debugsoldata->nsolvals),
352  &(debugsoldata->solsize)) );
353 
354  return SCIP_OKAY;
355 }
356 
357 /** gets value of given variable in debugging solution */
358 static
359 SCIP_RETCODE getSolutionValue(
360  SCIP_SET* set, /**< global SCIP settings */
361  SCIP_VAR* var, /**< variable to get solution value for */
362  SCIP_Real* val /**< pointer to store solution value */
363  )
364 {
365  SCIP_VAR* solvar;
366  SCIP_DEBUGSOLDATA* debugsoldata;
367  SCIP_Real scalar;
368  SCIP_Real constant;
369  const char* name;
370  int left;
371  int right;
372  int middle;
373  int cmp;
374 
375  assert(set != NULL);
376  assert(var != NULL);
377  assert(val != NULL);
378 
379  /* check whether a debug solution is available */
380  if( !debugSolutionAvailable(set) )
381  return SCIP_OKAY;
382 
383  debugsoldata = SCIPsetGetDebugSolData(set);
384  assert(debugsoldata != NULL);
385 
386  /* allow retrieving solution values only if referring to the SCIP instance that is debugged */
387  if( !SCIPdebugSolIsEnabled(set->scip) )
388  {
389  *val = SCIP_UNKNOWN;
390  return SCIP_OKAY;
391  }
392 
393  SCIP_CALL( readSolution(set) );
394  SCIPsetDebugMsg(set, "Now handling variable <%s>, which has status %d, is of type %d, and was deleted: %d, negated: %d, transformed: %d\n",
396 
397  /* ignore deleted variables */
398  if( SCIPvarIsDeleted(var) )
399  {
400  SCIPsetDebugMsg(set, "**** unknown solution value for deleted variable <%s>\n", SCIPvarGetName(var));
401  *val = SCIP_UNKNOWN;
402  return SCIP_OKAY;
403  }
404 
405  /* retransform variable onto original variable space */
406  solvar = var;
407  scalar = 1.0;
408  constant = 0.0;
409  if( SCIPvarIsNegated(solvar) )
410  {
411  scalar = -1.0;
412  constant = SCIPvarGetNegationConstant(solvar);
413  solvar = SCIPvarGetNegationVar(solvar);
414  }
415 
416  if( SCIPvarIsTransformed(solvar) )
417  {
418  SCIP_CALL( SCIPvarGetOrigvarSum(&solvar, &scalar, &constant) );
419  if( solvar == NULL )
420  {
421  /* if no original counterpart, then maybe someone added a value for the transformed variable, so search for var (or its negation) */
422  SCIPsetDebugMsg(set, "variable <%s> has no original counterpart\n", SCIPvarGetName(var));
423  solvar = var;
424  scalar = 1.0;
425  constant = 0.0;
426  if( SCIPvarIsNegated(solvar) )
427  {
428  scalar = -1.0;
429  constant = SCIPvarGetNegationConstant(solvar);
430  solvar = SCIPvarGetNegationVar(solvar);
431  }
432  }
433  }
434 
435  /* perform a binary search for the variable */
436  name = SCIPvarGetName(solvar);
437  left = 0;
438  right = debugsoldata->nsolvals-1;
439  while( left <= right )
440  {
441  middle = (left+right)/2;
442  cmp = strcmp(name, debugsoldata->solnames[middle]);
443  if( cmp < 0 )
444  right = middle-1;
445  else if( cmp > 0 )
446  left = middle+1;
447  else
448  {
449  *val = scalar * debugsoldata->solvals[middle] + constant;
450 
451  if( SCIPsetIsFeasLT(set, *val, SCIPvarGetLbGlobal(var)) || SCIPsetIsFeasGT(set, *val, SCIPvarGetUbGlobal(var)) )
452  {
453  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "invalid solution value %.15g for variable <%s>[%.15g,%.15g]\n",
454  *val, SCIPvarGetName(var), SCIPvarGetLbGlobal(var), SCIPvarGetUbGlobal(var));
455  }
456 
457  return SCIP_OKAY;
458  }
459  }
460  *val = constant;
461 
462  if( SCIPsetIsFeasLT(set, *val, SCIPvarGetLbGlobal(var)) || SCIPsetIsFeasGT(set, *val, SCIPvarGetUbGlobal(var)) )
463  {
464  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "invalid solution value %.15g for variable <%s>[%.15g,%.15g]\n",
465  *val, SCIPvarGetName(var), SCIPvarGetLbGlobal(var), SCIPvarGetUbGlobal(var));
466  }
467 
468  return SCIP_OKAY;
469 }
470 
471 /** gets pointer to the debug solution */
472 SCIP_RETCODE SCIPdebugGetSol(
473  SCIP* scip, /**< SCIP data structure */
474  SCIP_SOL** sol /**< buffer to store pointer to the debug solution */
475  )
476 {
477  SCIP_DEBUGSOLDATA* debugsoldata;
478 
479  debugsoldata = SCIPsetGetDebugSolData(scip->set);
480  assert(scip != NULL);
481  assert(sol != NULL);
482 
483  *sol = NULL;
484 
485  /* check whether a debug solution is available */
486  if( !debugSolutionAvailable(scip->set) )
487  return SCIP_OKAY;
488 
489  SCIP_CALL( readSolution(scip->set) );
490 
491  if( debugsoldata->debugsol == NULL )
492  return SCIP_ERROR;
493 
494  *sol = debugsoldata->debugsol;
495 
496  return SCIP_OKAY;
497 }
498 
499 /** gets value for a variable in the debug solution
500  *
501  * if no value is stored for the variable, gives 0.0
502  */
504  SCIP* scip, /**< SCIP data structure */
505  SCIP_VAR* var, /**< variable for which to get the value */
506  SCIP_Real* val /**< buffer to store solution value */
507  )
508 {
509  SCIP_CALL( getSolutionValue(scip->set, var, val) );
510 
511  return SCIP_OKAY;
512 }
513 
514 /** returns whether the debug solution is worse than the best known solution or if the debug solution was found */
515 static
516 SCIP_Bool debugSolIsAchieved(
517  SCIP_SET* set /**< global SCIP settings */
518  )
519 {
520  SCIP_SOL* bestsol;
521  SCIP* scip;
522  SCIP_DEBUGSOLDATA* debugsoldata;
523 
524  /* check whether a debug solution is available */
525  if( !debugSolutionAvailable(set) )
526  return SCIP_OKAY;
527 
528  assert(set != NULL);
529  debugsoldata = SCIPsetGetDebugSolData(set);
530 
531  assert(debugsoldata != NULL);
532 
533  if( debugsoldata->solisachieved )
534  return TRUE;
535 
536  assert(set != NULL);
537 
538  scip = set->scip;
539  assert(scip != NULL);
540 
541  bestsol = SCIPgetBestSol(scip);
542 
543  if( bestsol != NULL )
544  {
545  SCIP_Real solvalue;
546 
547  /* don't check solution while in problem creation stage */
548  if( SCIPsetGetStage(set) == SCIP_STAGE_PROBLEM )
549  return TRUE;
550 
551  solvalue = SCIPgetSolOrigObj(scip, bestsol);
552 
553  /* make sure a debug solution has been read, so we do not compare against the initial debugsolval == 0 */
554  SCIP_CALL( readSolution(set) );
555 
556  if( (SCIPgetObjsense(scip) == SCIP_OBJSENSE_MINIMIZE && SCIPsetIsLE(set, solvalue, debugsoldata->debugsolval))
557  || (SCIPgetObjsense(scip) == SCIP_OBJSENSE_MAXIMIZE && SCIPsetIsGE(set, solvalue, debugsoldata->debugsolval)) )
558  debugsoldata->solisachieved = TRUE;
559  }
560 
561  return debugsoldata->solisachieved;
562 }
563 
564 /** returns whether the solution is contained in node's subproblem */
565 static
566 SCIP_RETCODE isSolutionInNode(
567  BMS_BLKMEM* blkmem, /**< block memory */
568  SCIP_SET* set, /**< global SCIP settings */
569  SCIP_NODE* node, /**< local node where this bound change was applied */
570  SCIP_Bool* solcontained /**< pointer to store whether the solution is contained in node's subproblem */
571  )
572 {
573  SCIP_Bool* boolptr;
574  SCIP_DEBUGSOLDATA* debugsoldata;
575 
576  assert(set != NULL);
577  assert(blkmem != NULL);
578  assert(node != NULL);
579  assert(solcontained != NULL);
580 
581  /* check whether a debug solution is available */
582  if( !debugSolutionAvailable(set) )
583  return SCIP_OKAY;
584 
585  debugsoldata = SCIPsetGetDebugSolData(set);
586  assert(debugsoldata != NULL);
587 
588  if( debugsoldata ->debugsoldisabled )
589  {
590  *solcontained = FALSE;
591  return SCIP_OKAY;
592  }
593 
594  /* generate the hashmap */
595  if( debugsoldata->solinnode == NULL )
596  {
597  SCIP_CALL( SCIPhashmapCreate(&debugsoldata->solinnode, blkmem, SCIP_HASHSIZE_DEBUG) );
598  }
599 
600  /* check, whether we know already whether the solution is contained in the given node */
601  boolptr = (SCIP_Bool*)SCIPhashmapGetImage(debugsoldata->solinnode, (void*)node);
602  if( boolptr != NULL )
603  {
604  if( boolptr != &debugsoldata->falseptr && boolptr != &debugsoldata->trueptr )
605  {
606  SCIPerrorMessage("wrong value in node hashmap\n");
607  SCIPABORT();
608  return SCIP_ERROR;
609  }
610  *solcontained = *boolptr;
611  return SCIP_OKAY;
612  }
613 
614  /* if the solution is not contained in the parent of the node, it cannot be contained in the current node */
615  *solcontained = TRUE;
616  if( node->parent != NULL )
617  {
618  SCIP_CALL( isSolutionInNode(blkmem, set, node->parent, solcontained) );
619  }
620 
621  if( *solcontained )
622  {
623  /* check whether the bound changes at the current node remove the debugging solution from the subproblem */
624  if( node->domchg != NULL )
625  {
626  SCIP_DOMCHGBOUND* domchgbound;
627  SCIP_BOUNDCHG* boundchgs;
628  int i;
629 
630  domchgbound = &node->domchg->domchgbound;
631  boundchgs = domchgbound->boundchgs;
632  for( i = 0; i < (int)domchgbound->nboundchgs && *solcontained; ++i )
633  {
634  SCIP_Real varsol;
635 
636  /* get solution value of variable */
637  SCIP_CALL( getSolutionValue(set, boundchgs[i].var, &varsol) );
638 
639  if( varsol != SCIP_UNKNOWN ) /*lint !e777*/
640  {
641  /* compare the bound change with the solution value */
642  if( SCIPboundchgGetBoundtype(&boundchgs[i]) == SCIP_BOUNDTYPE_LOWER )
643  *solcontained = SCIPsetIsFeasGE(set, varsol, boundchgs[i].newbound);
644  else
645  *solcontained = SCIPsetIsFeasLE(set, varsol, boundchgs[i].newbound);
646 
647  if( !(*solcontained) && SCIPboundchgGetBoundchgtype(&boundchgs[i]) != SCIP_BOUNDCHGTYPE_BRANCHING )
648  {
649  SCIPerrorMessage("debugging solution was cut off in local node %p at depth %d by inference <%s>[%.15g] %s %.15g\n",
650  node, SCIPnodeGetDepth(node), SCIPvarGetName(boundchgs[i].var), varsol,
651  SCIPboundchgGetBoundtype(&boundchgs[i]) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=", boundchgs[i].newbound);
652  SCIPABORT();
653  }
654  }
655  else if( SCIPboundchgGetBoundchgtype(&boundchgs[i]) == SCIP_BOUNDCHGTYPE_BRANCHING )
656  {
657  /* we branched on a variable were we don't know the solution: no debugging can be applied in this subtree */
658  *solcontained = FALSE;
659  }
660  }
661  }
662  }
663 
664  /* remember the status of the current node */
665  SCIP_CALL( SCIPhashmapSetImage(debugsoldata->solinnode, (void*)node, *solcontained ? (void*)(&debugsoldata->trueptr) : (void*)(&debugsoldata->falseptr)) );
666 
667  return SCIP_OKAY;
668 }
669 
670 /** frees the debug solution */
672  SCIP_SET* set
673  )
674 {
675  SCIP_DEBUGSOLDATA* debugsoldata;
676 
677  debugsoldata = SCIPsetGetDebugSolData(set);
678  assert(debugsoldata != NULL);
679 
680  if( debugsoldata->debugsol != NULL && ((SCIPgetStage(set->scip) > SCIP_STAGE_PROBLEM && debugsoldata->debugsolstage > SCIP_STAGE_PROBLEM)
681  || (SCIPgetStage(set->scip) <= SCIP_STAGE_PROBLEM && debugsoldata->debugsolstage <= SCIP_STAGE_PROBLEM)) )
682  {
683  SCIP_CALL( SCIPfreeSol(set->scip, &debugsoldata->debugsol) );
684  }
685 
686  return SCIP_OKAY;
687 }
688 
689 /** resets the data structure after restart */
691  SCIP_SET* set
692  )
693 {
694  SCIP_DEBUGSOLDATA* debugsoldata;
695 
696  assert(set != NULL);
697 
698  debugsoldata = SCIPsetGetDebugSolData(set);
699  assert(debugsoldata != NULL);
700 
701  if( debugsoldata->solinnode != NULL )
702  {
703  SCIP_CALL( SCIPhashmapRemoveAll(debugsoldata->solinnode) );
704  }
705 
706  return SCIP_OKAY;
707 }
708 
709 /** frees all debugging solution data */
711  SCIP_SET* set /**< global SCIP settings */
712  )
713 {
714  int s;
715 
716  SCIP_DEBUGSOLDATA* debugsoldata;
717  assert(set != NULL);
718 
719  debugsoldata = SCIPsetGetDebugSolData(set);
720  assert(debugsoldata != NULL);
721 
722  for( s = debugsoldata->nsolvals - 1; s >= 0; --s )
723  BMSfreeMemoryArrayNull(&(debugsoldata->solnames[s]));
724 
725  BMSfreeMemoryArrayNull(&debugsoldata->solnames);
726  BMSfreeMemoryArrayNull(&debugsoldata->solvals);
727 
728  debugsoldata->nsolvals = 0;
729  debugsoldata->debugsolval= 0.0;
730  debugsoldata->solisachieved = FALSE;
731 
732  if( debugsoldata->solinnode != NULL)
733  SCIPhashmapFree(&debugsoldata->solinnode);
734 
735  /* free the debug solution */
736  SCIP_CALL( SCIPdebugFreeSol(set) );
737 
738  BMSfreeMemoryNull(&debugsoldata);
739 
740  set->debugsoldata = NULL;
741 
742  return SCIP_OKAY;
743 }
744 
745 /** checks for validity of the debugging solution in given constraints */
747  SCIP* scip, /**< SCIP data structure */
748  SCIP_CONS** conss, /**< constraints to check for validity */
749  int nconss /**< number of given constraints */
750  )
751 {
752  SCIP_RESULT result;
753  int c;
754 
755  SCIP_DEBUGSOLDATA* debugsoldata;
756  assert(scip->set != NULL);
757 
758  /* check if we are in the original problem and not in a sub MIP */
759  if( !SCIPdebugSolIsEnabled(scip) )
760  return SCIP_OKAY;
761 
762  /* check whether a debug solution is available */
763  if( !debugSolutionAvailable(scip->set) )
764  return SCIP_OKAY;
765 
766  debugsoldata = SCIPsetGetDebugSolData(scip->set);
767 
768  assert(conss != NULL || nconss == 0);
769  assert(debugsoldata->debugsol != NULL);
770 
771  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug
772  * solution
773  */
774  if( debugSolIsAchieved(scip->set) )
775  return SCIP_OKAY;
776 
777  result = SCIP_FEASIBLE;
778 
779  /* checking each given constraint against the debugging solution */
780  for( c = nconss - 1; c >= 0; --c )
781  {
782  assert(conss[c] != NULL);
783 
784  if( !SCIPconsIsActive(conss[c]) )
785  continue;
786 
787  assert(SCIPconsGetActiveDepth(conss[c]) <= SCIPgetDepth(scip));
788 
789  /* if the cons is only locally valid, check whether the debugging solution is contained in the local subproblem */
790  if( SCIPconsIsLocal(conss[c]) )
791  {
792  SCIP_Bool solcontained;
793 
794  SCIP_CALL( isSolutionInNode(SCIPblkmem(scip), scip->set, SCIPgetCurrentNode(scip), &solcontained) );
795  if( !solcontained )
796  return SCIP_OKAY;
797  }
798 
799  SCIP_CALL( SCIPcheckCons(scip, conss[c], debugsoldata->debugsol, TRUE, TRUE, TRUE, &result) );
800 
801  SCIPdebugMsg(scip, " -> checking of constraint %s returned result <%d>\n", SCIPconsGetName(conss[c]), result);
802 
803  if( result != SCIP_FEASIBLE )
804  {
805  SCIPerrorMessage("constraint %s violates the debugging solution\n", SCIPconsGetName(conss[c]));
806  SCIPABORT();
807  }
808  }
809 
810  return SCIP_OKAY;
811 }
812 
813 /** checks whether given row is valid for the debugging solution */
815  SCIP_SET* set, /**< global SCIP settings */
816  SCIP_ROW* row /**< row to check for validity */
817  )
818 {
819  SCIP_COL** cols;
820  SCIP_Real* vals;
821  SCIP_Real lhs;
822  SCIP_Real rhs;
823  int nnonz;
824  int i;
825  SCIP_Real minactivity;
826  SCIP_Real maxactivity;
827  SCIP_Real solval;
828 
829  assert(set != NULL);
830  assert(row != NULL);
831 
832  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
833  if( !SCIPdebugSolIsEnabled(set->scip) )
834  return SCIP_OKAY;
835 
836  /* check whether a debug solution is available */
837  if( !debugSolutionAvailable(set) )
838  return SCIP_OKAY;
839 
840  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
841  if( debugSolIsAchieved(set) )
842  return SCIP_OKAY;
843 
844  /* if the row is only locally valid, check whether the debugging solution is contained in the local subproblem */
845  if( SCIProwIsLocal(row) )
846  {
847  SCIP_Bool solcontained;
848 
849  SCIP_CALL( isSolutionInNode(SCIPblkmem(set->scip), set, SCIPgetCurrentNode(set->scip), &solcontained) );
850  if( !solcontained )
851  return SCIP_OKAY;
852  }
853 
854  cols = SCIProwGetCols(row);
855  vals = SCIProwGetVals(row);
856  nnonz = SCIProwGetNNonz(row);
857  lhs = SCIProwGetLhs(row);
858  rhs = SCIProwGetRhs(row);
859 
860  /* calculate row's activity on debugging solution */
861  minactivity = SCIProwGetConstant(row);
862  maxactivity = minactivity;
863  for( i = 0; i < nnonz; ++i )
864  {
865  SCIP_VAR* var;
866 
867  /* get solution value of variable in debugging solution */
868  var = SCIPcolGetVar(cols[i]);
869  SCIP_CALL( getSolutionValue(set, var, &solval) );
870 
871  if( solval != SCIP_UNKNOWN ) /*lint !e777*/
872  {
873  minactivity += vals[i] * solval;
874  maxactivity += vals[i] * solval;
875  }
876  else if( vals[i] > 0.0 )
877  {
878  minactivity += vals[i] * SCIPvarGetLbGlobal(var);
879  maxactivity += vals[i] * SCIPvarGetUbGlobal(var);
880  }
881  else if( vals[i] < 0.0 )
882  {
883  minactivity += vals[i] * SCIPvarGetUbGlobal(var);
884  maxactivity += vals[i] * SCIPvarGetLbGlobal(var);
885  }
886  }
887  SCIPsetDebugMsg(set, "debugging solution on row <%s>: %g <= [%g,%g] <= %g\n",
888  SCIProwGetName(row), lhs, minactivity, maxactivity, rhs);
889 
890  /* check row for violation, using absolute LP feasibility tolerance (as LP solver should do) */
891  if( maxactivity + SCIPgetLPFeastol(set->scip) < lhs || minactivity - SCIPgetLPFeastol(set->scip) > rhs )
892  {
893  printf("***** debug: row <%s> violates debugging solution (lhs=%.15g, rhs=%.15g, activity=[%.15g,%.15g], local=%u, lpfeastol=%g)\n",
894  SCIProwGetName(row), lhs, rhs, minactivity, maxactivity, SCIProwIsLocal(row), SCIPgetLPFeastol(set->scip));
895  SCIProwPrint(row, SCIPgetMessagehdlr(set->scip), NULL);
896 
897  /* output row with solution values */
898  printf("\n\n");
899  printf("***** debug: violated row <%s>:\n", SCIProwGetName(row));
900  printf(" %.15g <= %.15g", lhs, SCIProwGetConstant(row));
901  for( i = 0; i < nnonz; ++i )
902  {
903  /* get solution value of variable in debugging solution */
904  SCIP_CALL( getSolutionValue(set, SCIPcolGetVar(cols[i]), &solval) );
905  printf(" %+.15g<%s>[%.15g]", vals[i], SCIPvarGetName(SCIPcolGetVar(cols[i])), solval);
906  }
907  printf(" <= %.15g\n", rhs);
908 
909  SCIPABORT();
910  }
911 
912  return SCIP_OKAY;
913 }
914 
915 /** checks whether given global lower bound is valid for the debugging solution */
917  SCIP* scip, /**< SCIP data structure */
918  SCIP_VAR* var, /**< problem variable */
919  SCIP_Real lb /**< lower bound */
920  )
921 {
922  SCIP_Real varsol;
923 
924  assert(scip != NULL);
925  assert(var != NULL);
926 
927  /* check if we are in the original problem and not in a sub MIP */
928  if( !SCIPdebugSolIsEnabled(scip) )
929  return SCIP_OKAY;
930 
931  /* check whether a debug solution is available */
932  if( !debugSolutionAvailable(scip->set) )
933  return SCIP_OKAY;
934 
935  if( SCIPgetStage(scip) == SCIP_STAGE_PROBLEM )
936  return SCIP_OKAY;
937 
938  /* skip unused relaxation-only variables
939  * Relaxation-only variables are not part of any constraints or the original problem and thus there is no need to check their solution value.
940  * However, for relaxation-only variables that are still in use for the current solve round and for which a debug solution value has been set,
941  * checking against the debug solution value is helpful. If they not in use anymore, they will be captured only by the transformed problem
942  * and they may get fixed to some arbitrary value, e.g., in dual fixing.
943  * Thus, we skip checking bound changes on unused relaxation-only variables.
944  */
945  if( SCIPvarIsRelaxationOnly(var) && SCIPvarGetNUses(var) == 1 )
946  return SCIP_OKAY;
947 
948  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
949  if( debugSolIsAchieved(scip->set) )
950  return SCIP_OKAY;
951 
952  /* get solution value of variable */
953  SCIP_CALL( getSolutionValue(scip->set, var, &varsol) );
954  SCIPdebugMsg(scip, "debugging solution on lower bound of <%s>[%g] >= %g\n", SCIPvarGetName(var), varsol, lb);
955 
956  /* check validity of debugging solution */
957  if( varsol != SCIP_UNKNOWN && SCIPisFeasLT(scip, varsol, lb) ) /*lint !e777*/
958  {
959  SCIPerrorMessage("invalid global lower bound: <%s>[%.15g] >= %.15g\n", SCIPvarGetName(var), varsol, lb);
960  SCIPABORT();
961  }
962 
963  return SCIP_OKAY;
964 }
965 
966 /** checks whether given global upper bound is valid for the debugging solution */
968  SCIP* scip, /**< SCIP data structure */
969  SCIP_VAR* var, /**< problem variable */
970  SCIP_Real ub /**< upper bound */
971  )
972 {
973  SCIP_Real varsol;
974 
975  assert(scip != NULL);
976  assert(var != NULL);
977 
978  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
979  if( !SCIPdebugSolIsEnabled(scip) )
980  return SCIP_OKAY;
981 
982  /* check whether a debug solution is available */
983  if( !debugSolutionAvailable(scip->set) )
984  return SCIP_OKAY;
985 
986  if( SCIPgetStage(scip) == SCIP_STAGE_PROBLEM )
987  return SCIP_OKAY;
988 
989  /* skip unused relaxation-only variables, see also comment in SCIPdebugCheckLbGlobal() */
990  if( SCIPvarIsRelaxationOnly(var) && SCIPvarGetNUses(var) == 1 )
991  return SCIP_OKAY;
992 
993  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
994  if( debugSolIsAchieved(scip->set) )
995  return SCIP_OKAY;
996 
997  /* get solution value of variable */
998  SCIP_CALL( getSolutionValue(scip->set, var, &varsol) );
999  SCIPdebugMsg(scip, "debugging solution on upper bound of <%s>[%g] <= %g\n", SCIPvarGetName(var), varsol, ub);
1000 
1001  /* check validity of debugging solution */
1002  if( varsol != SCIP_UNKNOWN && SCIPisFeasGT(scip, varsol, ub) ) /*lint !e777*/
1003  {
1004  SCIPerrorMessage("invalid global upper bound: <%s>[%.15g] <= %.15g\n", SCIPvarGetName(var), varsol, ub);
1005  SCIPABORT();
1006  }
1007 
1008  return SCIP_OKAY;
1009 }
1010 
1011 /** checks whether given local bound implication is valid for the debugging solution */
1013  BMS_BLKMEM* blkmem, /**< block memory */
1014  SCIP_SET* set, /**< global SCIP settings */
1015  SCIP_NODE* node, /**< local node where this bound change was applied */
1016  SCIP_VAR* var, /**< problem variable */
1017  SCIP_Real newbound, /**< new value for bound */
1018  SCIP_BOUNDTYPE boundtype /**< type of bound: lower or upper bound */
1019  )
1020 {
1021  SCIP_Real varsol;
1022  SCIP_Bool solcontained;
1023 
1024  assert(set != NULL);
1025  assert(blkmem != NULL);
1026  assert(node != NULL);
1027  assert(var != NULL);
1028 
1029  /* in case we are in probing or diving we have to avoid checking the solution */
1030  if( SCIPlpDiving(set->scip->lp) || SCIPtreeProbing(set->scip->tree) )
1031  return SCIP_OKAY;
1032 
1033  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1034  if( !SCIPdebugSolIsEnabled(set->scip) )
1035  return SCIP_OKAY;
1036 
1037  /* check whether a debug solution is available */
1038  if( !debugSolutionAvailable(set) )
1039  return SCIP_OKAY;
1040 
1041  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1042  if( debugSolIsAchieved(set) )
1043  return SCIP_OKAY;
1044 
1045  /* check whether the debugging solution is contained in the local subproblem */
1046  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solcontained) );
1047  if( !solcontained )
1048  return SCIP_OKAY;
1049 
1050  /* get solution value of variable */
1051  SCIP_CALL( getSolutionValue(set, var, &varsol) );
1052 
1053  /* check validity of debugging solution */
1054  if( varsol != SCIP_UNKNOWN ) /*lint !e777*/
1055  {
1056  if( boundtype == SCIP_BOUNDTYPE_LOWER && SCIPsetIsFeasLT(set, varsol, newbound) )
1057  {
1058  SCIPerrorMessage("invalid local lower bound implication: <%s>[%.15g] >= %.15g\n", SCIPvarGetName(var), varsol, newbound);
1059  SCIPABORT();
1060  }
1061  if( boundtype == SCIP_BOUNDTYPE_UPPER && SCIPsetIsFeasGT(set, varsol, newbound) )
1062  {
1063  SCIPerrorMessage("invalid local upper bound implication: <%s>[%.15g] <= %.15g\n", SCIPvarGetName(var), varsol, newbound);
1064  SCIPABORT();
1065  }
1066  }
1067 
1068  return SCIP_OKAY;
1069 }
1070 
1071 /** informs solution debugger, that the given node will be freed */
1073  BMS_BLKMEM* blkmem, /**< block memory */
1074  SCIP_SET* set, /**< global SCIP settings */
1075  SCIP_NODE* node /**< node that will be freed */
1076  )
1077 {
1078  SCIP_DEBUGSOLDATA* debugsoldata;
1079 
1080  assert(set != NULL);
1081  assert(blkmem != NULL);
1082  assert(node != NULL);
1083 
1084  debugsoldata = SCIPsetGetDebugSolData(set);
1085  assert(debugsoldata != NULL);
1086 
1087  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1088  if( !SCIPdebugSolIsEnabled(set->scip) )
1089  return SCIP_OKAY;
1090 
1091  /* check whether a debug solution is available */
1092  if( !debugSolutionAvailable(set) )
1093  return SCIP_OKAY;
1094 
1095  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1096  if( debugSolIsAchieved(set) )
1097  return SCIP_OKAY;
1098 
1099  /* check if a solution will be cutoff in tree */
1102  {
1103  SCIP_Bool solisinnode;
1104 
1105  solisinnode = FALSE;
1106 
1107  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solisinnode) );
1108  /* wrong node will be cutoff */
1109  if( solisinnode )
1110  {
1111  SCIPerrorMessage("debugging solution was cut off in local node #%" SCIP_LONGINT_FORMAT " (%p) at depth %d\n",
1112  node->number, node, SCIPnodeGetDepth(node));
1113  SCIPABORT();
1114  }
1115  }
1116 
1117  /* remove node from the hash map */
1118  if( debugsoldata->solinnode != NULL )
1119  {
1120  SCIP_CALL( SCIPhashmapRemove(debugsoldata->solinnode, (void*)node) );
1121  }
1122 
1123  return SCIP_OKAY;
1124 }
1125 
1126 /** checks whether global lower bound does not exceed debuging solution value */
1128  BMS_BLKMEM* blkmem, /**< block memory */
1129  SCIP_SET* set /**< global SCIP settings */
1130  )
1131 {
1132  SCIP_DEBUGSOLDATA* debugsoldata;
1133  SCIP_Real treelowerbound;
1134 
1135  assert(set != NULL);
1136  assert(blkmem != NULL);
1137 
1138  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1139  if( !SCIPdebugSolIsEnabled(set->scip) )
1140  return SCIP_OKAY;
1141 
1142  /* check whether a debug solution is available */
1143  if( !debugSolutionAvailable(set) )
1144  return SCIP_OKAY;
1145 
1147  return SCIP_OKAY;
1148 
1150  return SCIP_OKAY;
1151 
1152  /* if there are no leaves then SCIPtreeGetLowerbound() will return infintiy */
1153  if( SCIPgetNLeaves(set->scip) <= 0 )
1154  return SCIP_OKAY;
1155 
1156  debugsoldata = SCIPsetGetDebugSolData(set);
1157  assert(debugsoldata != NULL);
1158 
1159  /* make sure a debug solution has been read */
1160  if( debugsoldata->debugsol == NULL )
1161  {
1162  SCIP_CALL( readSolution(set) );
1163  }
1164 
1165  /* get global lower bound of tree (do not use SCIPgetLowerbound() since this adjusts the value using the primal bound) */
1166  treelowerbound = SCIPtreeGetLowerbound(set->scip->tree, set);
1167  treelowerbound = SCIPprobExternObjval(set->scip->transprob, set->scip->origprob, set, treelowerbound);
1168 
1169  if( (SCIPgetObjsense(set->scip) == SCIP_OBJSENSE_MINIMIZE && SCIPsetIsGT(set, treelowerbound, SCIPsolGetOrigObj(debugsoldata->debugsol)))
1170  || (SCIPgetObjsense(set->scip) == SCIP_OBJSENSE_MAXIMIZE && SCIPsetIsLT(set, treelowerbound, SCIPsolGetOrigObj(debugsoldata->debugsol))) )
1171  {
1172  SCIPerrorMessage("global lower bound %g is larger than the value of the debugging solution %g.\n", treelowerbound, SCIPsolGetOrigObj(debugsoldata->debugsol));
1173  SCIPABORT();
1174  }
1175 
1176  return SCIP_OKAY;
1177 }
1178 
1179 /** checks whether local lower bound does not exceed debuging solution value */
1181  BMS_BLKMEM* blkmem, /**< block memory */
1182  SCIP_SET* set, /**< global SCIP settings */
1183  SCIP_NODE* node /**< node that will be freed */
1184  )
1185 {
1186  SCIP_DEBUGSOLDATA* debugsoldata;
1187  SCIP_Bool solisinnode;
1188 
1189  assert(set != NULL);
1190  assert(blkmem != NULL);
1191 
1192  /* exit if we do not have a node to check */
1193  if( node == NULL )
1194  return SCIP_OKAY;
1195 
1196  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1197  if( !SCIPdebugSolIsEnabled(set->scip) )
1198  return SCIP_OKAY;
1199 
1200  /* check whether a debug solution is available */
1201  if( !debugSolutionAvailable(set) )
1202  return SCIP_OKAY;
1203 
1204  if( SCIPgetStage(set->scip) <= SCIP_STAGE_INITSOLVE )
1205  return SCIP_OKAY;
1206 
1208  return SCIP_OKAY;
1209 
1210  debugsoldata = SCIPsetGetDebugSolData(set);
1211  assert(debugsoldata != NULL);
1212 
1213  /* make sure a debug solution has been read */
1214  if( debugsoldata->debugsol == NULL )
1215  {
1216  SCIP_CALL( readSolution(set) );
1217  }
1218 
1219  /* check local lower bound */
1220  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solisinnode) );
1221 
1222  /* if we are in a node that contains the given debug solution, the lower bound should not exceed the solution's objective */
1223  if( solisinnode )
1224  {
1225  SCIP_Real localbound;
1226 
1227  localbound = SCIPnodeGetLowerbound(node);
1228  localbound = SCIPprobExternObjval(set->scip->transprob, set->scip->origprob, set, localbound);
1229 
1230  if( (SCIPgetObjsense(set->scip) == SCIP_OBJSENSE_MINIMIZE && SCIPsetIsGT(set, localbound, SCIPsolGetOrigObj(debugsoldata->debugsol)))
1231  || (SCIPgetObjsense(set->scip) == SCIP_OBJSENSE_MAXIMIZE && SCIPsetIsLT(set, localbound, SCIPsolGetOrigObj(debugsoldata->debugsol))) )
1232  {
1233  SCIPerrorMessage("local lower bound %g of node #%" SCIP_LONGINT_FORMAT " at depth %d is larger than the value of the debugging solution %g contained in this node.\n",
1234  localbound, node->number, SCIPnodeGetDepth(node), SCIPsolGetOrigObj(debugsoldata->debugsol));
1235  SCIPABORT();
1236  }
1237  }
1238 
1239  return SCIP_OKAY;
1240 }
1241 
1242 /** checks whether given variable bound is valid for the debugging solution */
1244  SCIP_SET* set, /**< global SCIP settings */
1245  SCIP_VAR* var, /**< problem variable x in x <= b*z + d or x >= b*z + d */
1246  SCIP_BOUNDTYPE vbtype, /**< type of variable bound (LOWER or UPPER) */
1247  SCIP_VAR* vbvar, /**< variable z in x <= b*z + d or x >= b*z + d */
1248  SCIP_Real vbcoef, /**< coefficient b in x <= b*z + d or x >= b*z + d */
1249  SCIP_Real vbconstant /**< constant d in x <= b*z + d or x >= b*z + d */
1250  )
1251 {
1252  SCIP_Real varsol;
1253  SCIP_Real vbvarsol;
1254  SCIP_Real vb;
1255 
1256  assert(set != NULL);
1257  assert(var != NULL);
1258 
1259  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1260  if( !SCIPdebugSolIsEnabled(set->scip) )
1261  return SCIP_OKAY;
1262 
1263  /* check whether a debug solution is available */
1264  if( !debugSolutionAvailable(set) )
1265  return SCIP_OKAY;
1266 
1267  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1268  if( debugSolIsAchieved(set) )
1269  return SCIP_OKAY;
1270 
1271  /* get solution value of variables */
1272  SCIP_CALL( getSolutionValue(set, var, &varsol) );
1273  SCIP_CALL( getSolutionValue(set, vbvar, &vbvarsol) );
1274 
1275  /* check validity of debugging solution */
1276  if( varsol != SCIP_UNKNOWN && vbvarsol != SCIP_UNKNOWN ) /*lint !e777*/
1277  {
1278  vb = vbcoef * vbvarsol + vbconstant;
1279  if( (vbtype == SCIP_BOUNDTYPE_LOWER && SCIPsetIsFeasLT(set, varsol, vb))
1280  || (vbtype == SCIP_BOUNDTYPE_UPPER && SCIPsetIsFeasGT(set, varsol, vb)) )
1281  {
1282  SCIPerrorMessage("invalid variable bound: <%s>[%.15g] %s %.15g<%s>[%.15g] %+.15g\n",
1283  SCIPvarGetName(var), varsol, vbtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=", vbcoef,
1284  SCIPvarGetName(vbvar), vbvarsol, vbconstant);
1285  SCIPABORT();
1286  }
1287  }
1288 
1289  return SCIP_OKAY;
1290 }
1291 
1292 /** checks whether given implication is valid for the debugging solution */
1294  SCIP_SET* set, /**< global SCIP settings */
1295  SCIP_VAR* var, /**< problem variable */
1296  SCIP_Bool varfixing, /**< FALSE if y should be added in implications for x == 0, TRUE for x == 1 */
1297  SCIP_VAR* implvar, /**< variable y in implication y <= b or y >= b */
1298  SCIP_BOUNDTYPE impltype, /**< type of implication y <= b (SCIP_BOUNDTYPE_UPPER) or y >= b (SCIP_BOUNDTYPE_LOWER) */
1299  SCIP_Real implbound /**< bound b in implication y <= b or y >= b */
1300  )
1301 {
1302  SCIP_Real solval;
1303 
1304  assert(set != NULL);
1305  assert(var != NULL);
1306  assert(SCIPvarGetType(var) == SCIP_VARTYPE_BINARY);
1307 
1308  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1309  if( !SCIPdebugSolIsEnabled(set->scip) )
1310  return SCIP_OKAY;
1311 
1312  /* check whether a debug solution is available */
1313  if( !debugSolutionAvailable(set) )
1314  return SCIP_OKAY;
1315 
1316  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1317  if( debugSolIsAchieved(set) )
1318  return SCIP_OKAY;
1319 
1320  /* get solution value of variable */
1321  SCIP_CALL( getSolutionValue(set, var, &solval) );
1322  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1323  return SCIP_OKAY;
1324  assert(SCIPsetIsFeasZero(set, solval) || SCIPsetIsFeasEQ(set, solval, 1.0));
1325 
1326  /* check, whether the implication applies for the debugging solution */
1327  if( (solval > 0.5) != varfixing )
1328  return SCIP_OKAY;
1329 
1330  /* get solution value of implied variable */
1331  SCIP_CALL( getSolutionValue(set, implvar, &solval) );
1332  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1333  return SCIP_OKAY;
1334 
1335  if( impltype == SCIP_BOUNDTYPE_LOWER )
1336  {
1337  if( SCIPsetIsFeasLT(set, solval, implbound) )
1338  {
1339  SCIPerrorMessage("invalid implication <%s> == %d -> <%s> >= %.15g (variable has value %.15g in solution)\n",
1340  SCIPvarGetName(var), varfixing, SCIPvarGetName(implvar), implbound, solval);
1341  SCIPABORT();
1342  }
1343  }
1344  else
1345  {
1346  if( SCIPsetIsFeasGT(set, solval, implbound) )
1347  {
1348  SCIPerrorMessage("invalid implication <%s> == %d -> <%s> <= %.15g (variable has value %.15g in solution)\n",
1349  SCIPvarGetName(var), varfixing, SCIPvarGetName(implvar), implbound, solval);
1350  SCIPABORT();
1351  }
1352  }
1353 
1354  return SCIP_OKAY;
1355 }
1356 
1357 /** checks whether given (multi)-aggregation is valid for the debugging solution */
1359  SCIP_SET* set, /**< global SCIP settings */
1360  SCIP_VAR* var, /**< problem variable */
1361  SCIP_VAR** aggrvars, /**< variables y_i in aggregation x = a_1*y_1 + ... + a_n*y_n + c */
1362  SCIP_Real* scalars, /**< multipliers a_i in aggregation x = a_1*y_1 + ... + a_n*y_n + c */
1363  SCIP_Real constant, /**< constant shift c in aggregation x = a_1*y_1 + ... + a_n*y_n + c */
1364  int naggrvars /**< number n of variables in aggregation x = a_1*y_1 + ... + a_n*y_n + c */
1365  )
1366 {
1367  SCIP_Real solval;
1368  SCIP_Real val;
1369  int i;
1370 
1371  assert(set != NULL);
1372  assert(var != NULL);
1373  assert(aggrvars != NULL);
1374  assert(scalars != NULL);
1375  assert(naggrvars >= 1);
1376 
1377  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1378  if( !SCIPdebugSolIsEnabled(set->scip) )
1379  return SCIP_OKAY;
1380 
1381  /* check whether a debug solution is available */
1382  if( !debugSolutionAvailable(set) )
1383  return SCIP_OKAY;
1384 
1385  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1386  if( debugSolIsAchieved(set) )
1387  return SCIP_OKAY;
1388 
1389  /* get solution value of x variable */
1390  SCIP_CALL( getSolutionValue(set, var, &solval) );
1391 
1392  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1393  return SCIP_OKAY;
1394 
1395  val = constant;
1396 
1397  for( i = 0; i < naggrvars; i++ )
1398  {
1399  SCIP_Real aggrsolval;
1400 
1401  /* get solution value of y variable */
1402  SCIP_CALL( getSolutionValue(set, aggrvars[i], &aggrsolval) );
1403 
1404  if( aggrsolval == SCIP_UNKNOWN ) /*lint !e777*/
1405  return SCIP_OKAY;
1406 
1407  val += scalars[i] * aggrsolval;
1408  }
1409 
1410  /* print debug message if the aggregation violates the debugging solution */
1411  if( !SCIPsetIsRelEQ(set, solval, val) )
1412  {
1413  if( naggrvars == 1 )
1414  {
1415  SCIP_Real aggrsolval;
1416 
1417  /* get solution value of y variable */
1418  SCIP_CALL( getSolutionValue(set, aggrvars[0], &aggrsolval) );
1419 
1420  SCIPerrorMessage("aggregation <%s>[%g] = %g<%s>[%g] + %g violates debugging solution (expected %g)\n",
1421  SCIPvarGetName(var), solval, scalars[0], SCIPvarGetName(aggrvars[0]), aggrsolval, constant, val);
1422  }
1423  else
1424  {
1425  SCIPerrorMessage("multi-aggregation <%s>[%g] = ... %d vars ... + %g violates debugging solution (expected %g)\n",
1426  SCIPvarGetName(var), solval, naggrvars, constant, val);
1427  }
1428  SCIPABORT();
1429  }
1430 
1431  return SCIP_OKAY;
1432 }
1433 
1434 /** check whether given clique is valid for the debugging solution */
1436  SCIP_SET* set, /**< global SCIP settings */
1437  SCIP_VAR** vars, /**< binary variables in the clique: at most one can be set to the given value */
1438  SCIP_Bool* values, /**< values of the variables in the clique; NULL to use TRUE for all vars */
1439  int nvars /**< number of variables in the clique */
1440  )
1441 {
1442  SCIP_Real solval;
1443  int pos1;
1444  int pos2;
1445  int v;
1446 
1447  assert(set != NULL);
1448  assert(vars != NULL);
1449 
1450  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1451  if( !SCIPdebugSolIsEnabled(set->scip) )
1452  return SCIP_OKAY;
1453 
1454  /* check whether a debug solution is available */
1455  if( !debugSolutionAvailable(set) )
1456  return SCIP_OKAY;
1457 
1458  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1459  if( debugSolIsAchieved(set) )
1460  return SCIP_OKAY;
1461 
1462  pos1 = -1;
1463  pos2 = -1;
1464 
1465  for( v = 0; v < nvars; ++v )
1466  {
1467  assert(vars[v] != NULL);
1468  assert(SCIPvarIsBinary(vars[v]));
1469 
1470  /* get solution value of variable */
1471  SCIP_CALL( getSolutionValue(set, vars[v], &solval) );
1472 
1473  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1474  continue;
1475 
1476  assert(SCIPsetIsFeasZero(set, solval) || SCIPsetIsFeasEQ(set, solval, 1.0));
1477 
1478  /* negated solution value if negated variable is in clique */
1479  if( values != NULL && values[v] == 0 )
1480  solval = 1.0 - solval;
1481 
1482  if( SCIPsetIsFeasEQ(set, solval, 1.0) )
1483  {
1484  if( pos1 == -1 )
1485  pos1 = v;
1486  else
1487  {
1488  assert(pos2 == -1);
1489  pos2 = v;
1490  break;
1491  }
1492  }
1493  }
1494 
1495  /* print debug message if the clique violates the debugging solution */
1496  if( pos2 != -1 )
1497  {
1498  assert(pos1 != -1);
1499  SCIPerrorMessage("clique violates debugging solution, (at least) variable <%s%s> and variable <%s%s> are both one in the debugging solution\n",
1500  (values == NULL || values[pos1]) ? "" : "~", SCIPvarGetName(vars[pos1]), (values == NULL || values[pos2]) ? "" : "~", SCIPvarGetName(vars[pos2]));
1501  SCIPABORT();
1502  }
1503 
1504  return SCIP_OKAY;
1505 }
1506 
1507 /** check, whether at least one literals is TRUE in the debugging solution */
1508 static
1509 SCIP_Bool debugCheckBdchginfos(
1510  SCIP_SET* set, /**< global SCIP settings */
1511  SCIP_BDCHGINFO** bdchginfos, /**< bound change informations of the conflict set */
1512  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict, or NULL */
1513  int nbdchginfos /**< number of bound changes in the conflict set */
1514  )
1515 {
1516  SCIP_Real solval;
1517  int i;
1518 
1519  /* check whether a debug solution is available */
1520  if( !debugSolutionAvailable(set) )
1521  return SCIP_OKAY;
1522 
1523  assert(SCIPdebugSolIsEnabled(set->scip));
1524 
1525  solval = 0.0;
1526  /* check, whether at least one literals is TRUE in the debugging solution */
1527  for( i = 0; i < nbdchginfos; ++i )
1528  {
1529  SCIP_BDCHGINFO* bdchginfo;
1530  SCIP_VAR* var;
1531  SCIP_Real newbound;
1532 
1533  bdchginfo = bdchginfos[i];
1534  assert(bdchginfo != NULL);
1535 
1536  var = SCIPbdchginfoGetVar(bdchginfo);
1537  assert(var != NULL);
1538 
1539  if( relaxedbds != NULL )
1540  newbound = relaxedbds[i];
1541  else
1542  newbound = SCIPbdchginfoGetNewbound(bdchginfo);
1543 
1544  SCIP_CALL( getSolutionValue(set, var, &solval) );
1545 
1546  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1547  return TRUE;
1548 
1550  {
1551  assert(SCIPsetIsLE(set, newbound, SCIPbdchginfoGetNewbound(bdchginfo)));
1552 
1554  {
1555  if( SCIPsetIsLE(set, solval, newbound) )
1556  return TRUE;
1557  }
1558  else
1559  {
1560  if( SCIPsetIsLT(set, solval, newbound) )
1561  return TRUE;
1562  }
1563  }
1564  else
1565  {
1566  assert(SCIPsetIsGE(set, newbound, SCIPbdchginfoGetNewbound(bdchginfo)));
1567 
1569  {
1570  if( SCIPsetIsGE(set, solval, newbound) )
1571  return TRUE;
1572  }
1573  else
1574  {
1575  if( SCIPsetIsGT(set, solval, newbound) )
1576  return TRUE;
1577  }
1578  }
1579  }
1580 
1581  return FALSE;
1582 }
1583 
1584 /** print bound change information */
1585 static
1586 SCIP_RETCODE printBdchginfo(
1587  SCIP_SET* set, /**< global SCIP settings */
1588  SCIP_BDCHGINFO * bdchginfo, /**< bound change information */
1589  SCIP_Real relaxedbd /**< array with relaxed bounds which are efficient to create a valid conflict, or NULL */
1590  )
1591 {
1592  SCIP_Real solval;
1593 
1594  /* check whether a debug solution is available */
1595  if( !debugSolutionAvailable(set) )
1596  return SCIP_OKAY;
1597 
1598  /* get solution value within the debug solution */
1599  SCIP_CALL( getSolutionValue(set, SCIPbdchginfoGetVar(bdchginfo), &solval) );
1600 
1601  printf(" <%s>[%.15g] %s %g(%g)", SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)), solval,
1602  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
1603  SCIPbdchginfoGetNewbound(bdchginfo), relaxedbd);
1604 
1605  return SCIP_OKAY;
1606 }
1607 
1608 
1609 /** print bound change information */
1610 static
1611 SCIP_RETCODE printBdchginfos(
1612  SCIP_SET* set, /**< global SCIP settings */
1613  SCIP_BDCHGINFO** bdchginfos, /**< bound change information array */
1614  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict, or NULL */
1615  int nbdchginfos /**< number of bound changes in the conflict set */
1616  )
1617 {
1618  int i;
1619 
1620  /* check whether a debug solution is available */
1621  if( !debugSolutionAvailable(set) )
1622  return SCIP_OKAY;
1623 
1624  for( i = 0; i < nbdchginfos; ++i )
1625  {
1626  SCIP_BDCHGINFO* bdchginfo;
1627 
1628  bdchginfo = bdchginfos[i];
1629  assert(bdchginfo != NULL);
1630 
1631  printBdchginfo(set, bdchginfo, relaxedbds != NULL ? relaxedbds[i] : SCIPbdchginfoGetNewbound(bdchginfo));
1632  }
1633 
1634  return SCIP_OKAY;
1635 }
1636 
1637 /** checks whether given conflict is valid for the debugging solution */
1639  BMS_BLKMEM* blkmem, /**< block memory */
1640  SCIP_SET* set, /**< global SCIP settings */
1641  SCIP_NODE* node, /**< node where the conflict clause is added */
1642  SCIP_BDCHGINFO** bdchginfos, /**< bound change informations of the conflict set */
1643  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict */
1644  int nbdchginfos /**< number of bound changes in the conflict set */
1645  )
1646 {
1647  SCIP_Bool solcontained;
1648 
1649  assert(set != NULL);
1650  assert(blkmem != NULL);
1651  assert(node != NULL);
1652  assert(nbdchginfos == 0 || bdchginfos != NULL);
1653 
1654  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1655  if( !SCIPdebugSolIsEnabled(set->scip) )
1656  return SCIP_OKAY;
1657 
1658  /* check whether a debug solution is available */
1659  if( !debugSolutionAvailable(set) )
1660  return SCIP_OKAY;
1661 
1662  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1663  if( debugSolIsAchieved(set) )
1664  return SCIP_OKAY;
1665 
1666  /* check whether the debugging solution is contained in the local subproblem */
1667  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solcontained) );
1668  if( !solcontained )
1669  return SCIP_OKAY;
1670 
1671  /* check, whether at least one literals is TRUE in the debugging solution */
1672  if( debugCheckBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) )
1673  return SCIP_OKAY;
1674 
1675  SCIPerrorMessage("invalid conflict set:");
1676 
1677  /* print bound changes which are already part of the conflict set */
1678  SCIP_CALL( printBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) );
1679 
1680  printf("\n");
1681  SCIPABORT();
1682 
1683  return SCIP_OKAY; /*lint !e527*/
1684 }
1685 
1686 /** checks whether given conflict graph frontier is valid for the debugging solution */
1688  BMS_BLKMEM* blkmem, /**< block memory */
1689  SCIP_SET* set, /**< global SCIP settings */
1690  SCIP_NODE* node, /**< node where the conflict clause is added */
1691  SCIP_BDCHGINFO* bdchginfo, /**< bound change info which got resolved, or NULL */
1692  SCIP_BDCHGINFO** bdchginfos, /**< bound change informations of the conflict set */
1693  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict */
1694  int nbdchginfos, /**< number of bound changes in the conflict set */
1695  SCIP_PQUEUE* bdchgqueue, /**< unprocessed conflict bound changes */
1696  SCIP_PQUEUE* forcedbdchgqueue /**< unprocessed conflict bound changes that must be resolved */
1697  )
1698 {
1699  SCIP_BDCHGINFO** bdchgqueued;
1700  SCIP_BDCHGINFO** forcedbdchgqueued;
1701  SCIP_Bool solcontained;
1702  int nbdchgqueued;
1703  int nforcedbdchgqueued;
1704 
1705  assert(set != NULL);
1706  assert(blkmem != NULL);
1707  assert(node != NULL);
1708  assert(nbdchginfos == 0 || bdchginfos != NULL);
1709 
1710  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1711  if( !SCIPdebugSolIsEnabled(set->scip) )
1712  return SCIP_OKAY;
1713 
1714  /* check whether a debug solution is available */
1715  if( !debugSolutionAvailable(set) )
1716  return SCIP_OKAY;
1717 
1718  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1719  if( debugSolIsAchieved(set) )
1720  return SCIP_OKAY;
1721 
1722  /* check whether the debugging solution is contained in the local subproblem */
1723  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solcontained) );
1724  if( !solcontained )
1725  return SCIP_OKAY;
1726 
1727  /* check, whether one literals is TRUE in the debugging solution */
1728  if( debugCheckBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) )
1729  return SCIP_OKAY;
1730 
1731  /* get the elements of the bound change queue */
1732  bdchgqueued = (SCIP_BDCHGINFO**)SCIPpqueueElems(bdchgqueue);
1733  nbdchgqueued = SCIPpqueueNElems(bdchgqueue);
1734 
1735  /* check, whether one literals is TRUE in the debugging solution */
1736  if( debugCheckBdchginfos(set, bdchgqueued, NULL, nbdchgqueued) )
1737  return SCIP_OKAY;
1738 
1739  /* get the elements of the bound change queue */
1740  forcedbdchgqueued = (SCIP_BDCHGINFO**)SCIPpqueueElems(forcedbdchgqueue);
1741  nforcedbdchgqueued = SCIPpqueueNElems(forcedbdchgqueue);
1742 
1743  /* check, whether one literals is TRUE in the debugging solution */
1744  if( debugCheckBdchginfos(set, forcedbdchgqueued, NULL, nforcedbdchgqueued) )
1745  return SCIP_OKAY;
1746 
1747  SCIPerrorMessage("invalid conflict frontier");
1748 
1749  if( bdchginfo != NULL )
1750  {
1751  printf(" (after resolving bound change ");
1752  printBdchginfo(set, bdchginfo, SCIPbdchginfoGetNewbound(bdchginfo));
1753  printf(")");
1754  }
1755  printf(":");
1756 
1757  /* print bound changes which are already part of the conflict set */
1758  SCIP_CALL( printBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) );
1759 
1760  /* print bound changes which are queued */
1761  SCIP_CALL( printBdchginfos(set, bdchgqueued, NULL, nbdchgqueued) );
1762 
1763  /* print bound changes which are queued in the force queue */
1764  SCIP_CALL( printBdchginfos(set, forcedbdchgqueued, NULL, nforcedbdchgqueued) );
1765 
1766  printf("\n");
1767  SCIPABORT();
1768 
1769  return SCIP_OKAY; /*lint !e527*/
1770 }
1771 
1772 /** check whether the debugging solution is valid in the current node */
1774  SCIP* scip, /**< SCIP data structure */
1775  SCIP_Bool* isvalidinsubtree /**< pointer to store whether the solution is valid in the current
1776  * subtree */
1777  )
1778 {
1779  SCIP_Bool solcontained;
1780 
1781  *isvalidinsubtree = FALSE;
1782 
1783  assert(scip->set != NULL);
1784 
1785  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1786  if( !SCIPdebugSolIsEnabled(scip) )
1787  return SCIP_OKAY;
1788 
1789  /* check whether a debug solution is available */
1790  if( !debugSolutionAvailable(scip->set) )
1791  return SCIP_OKAY;
1792 
1793  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1794  if( debugSolIsAchieved(scip->set) )
1795  return SCIP_OKAY;
1796 
1797  /* check whether the debugging solution is contained in the local subproblem */
1798  SCIP_CALL( isSolutionInNode(SCIPblkmem(scip), scip->set, SCIPgetCurrentNode(scip), &solcontained) );
1799 
1800  if( solcontained )
1801  *isvalidinsubtree = TRUE;
1802 
1803  return SCIP_OKAY;
1804 }
1805 
1806 /** checks whether SCIP data structure is the main SCIP (the one for which debugging is enabled) */
1807 SCIP_Bool SCIPdebugIsMainscip(
1808  SCIP* scip /**< SCIP data structure */
1809  )
1810 {
1811  assert(scip != NULL);
1812 
1813  return SCIPdebugSolIsEnabled(scip);
1814 }
1815 
1816 /** enabling solution debugging mechanism */
1817 void SCIPdebugSolEnable(
1818  SCIP* scip /**< SCIP data structure */
1819  )
1820 {
1821  SCIP_DEBUGSOLDATA* debugsoldata;
1822  assert(scip != NULL);
1823  assert(scip->set != NULL);
1824 
1825  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1826  assert(debugsoldata != NULL);
1827 
1828  debugsoldata->debugsoldisabled = FALSE;
1829 }
1830 
1831 /** disabling solution debugging mechanism */
1832 void SCIPdebugSolDisable(
1833  SCIP* scip /**< SCIP data structure */
1834  )
1835 {
1836  SCIP_DEBUGSOLDATA* debugsoldata;
1837  assert(scip != NULL);
1838  assert(scip->set != NULL);
1839 
1840  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1841  assert(debugsoldata != NULL);
1842 
1843  debugsoldata->debugsoldisabled = TRUE;
1844 }
1845 
1846 /** check if solution debugging mechanism is enabled */
1848  SCIP* scip /**< SCIP data structure */
1849  )
1850 {
1851  SCIP_DEBUGSOLDATA* debugsoldata;
1852  assert(scip != NULL);
1853  assert(scip->set != NULL);
1854 
1855  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1856  assert(debugsoldata != NULL);
1857 
1858  return (!debugsoldata->debugsoldisabled);
1859 }
1860 
1861 /** check if SCIP is compiled with WITH_DEBUG_SOLUTION */
1863 {
1864 #ifdef WITH_DEBUG_SOLUTION
1865  return TRUE;
1866 #else
1867  return FALSE;
1868 #endif
1869 }
1870 
1871 
1872 /** propagator to force finding the debugging solution */
1873 static
1874 SCIP_DECL_PROPEXEC(propExecDebug)
1875 { /*lint --e{715}*/
1876  SCIP_VAR** vars;
1877  int nvars;
1878  int i;
1879 
1880  assert(scip != NULL);
1881  assert(result != NULL);
1882 
1883  *result = SCIP_DIDNOTFIND;
1884 
1885  /* check if we are in the original problem and not in a sub MIP */
1886  if( !SCIPdebugIsMainscip(scip) )
1887  return SCIP_OKAY;
1888 
1889  if( SCIPgetStage(scip) != SCIP_STAGE_SOLVING )
1890  return SCIP_OKAY;
1891 
1892  /* check whether a debug solution is available */
1893  if( !debugSolutionAvailable(scip->set) )
1894  return SCIP_OKAY;
1895 
1896  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1897  if( debugSolIsAchieved(scip->set) )
1898  return SCIP_OKAY;
1899 
1900 #if 1
1901  /* solve at least one LP */
1902  if( SCIPgetNLPIterations(scip) == 0 )
1903  return SCIP_OKAY;
1904 #endif
1905 
1906  vars = SCIPgetOrigVars(scip);
1907  nvars = SCIPgetNOrigVars(scip);
1908  for( i = 0; i < nvars; ++i )
1909  {
1910  SCIP_Real solval;
1911  SCIP_Real lb;
1912  SCIP_Real ub;
1913  SCIP_Bool infeasible;
1914  SCIP_Bool fixed;
1915 
1916  SCIP_CALL( getSolutionValue(scip->set, vars[i], &solval) );
1917  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1918  {
1919  SCIPerrorMessage("original variable without debugging solution value\n");
1920  SCIPABORT();
1921  }
1922 
1923  lb = SCIPvarGetLbGlobal(vars[i]);
1924  ub = SCIPvarGetUbGlobal(vars[i]);
1925  if( SCIPisLT(scip, solval, lb) || SCIPisGT(scip, solval, ub) )
1926  {
1927  SCIPerrorMessage("solution value %.15g of <%s> outside bounds loc=[%.15g,%.15g], glb=[%.15g,%.15g]\n",
1928  solval, SCIPvarGetName(vars[i]), lb, ub, SCIPvarGetLbGlobal(vars[i]), SCIPvarGetUbGlobal(vars[i]));
1929  SCIPABORT();
1930  }
1931 
1932  SCIP_CALL( SCIPfixVar(scip, vars[i], solval, &infeasible, &fixed) );
1933  if( infeasible )
1934  *result = SCIP_CUTOFF;
1935  else if( fixed )
1936  *result = SCIP_REDUCEDDOM;
1937  }
1938 
1939  return SCIP_OKAY;
1940 }
1941 
1942 /** creates the debugging propagator and includes it in SCIP */
1944  SCIP* scip /**< SCIP data structure */
1945  )
1946 {
1947  assert(scip != NULL);
1948 
1949  /* include propagator */
1950  SCIP_CALL( SCIPincludeProp(scip, "debug", "debugging propagator", 99999999, -1, FALSE,
1952  NULL, propExecDebug, NULL, NULL) );
1953 
1954  return SCIP_OKAY;
1955 }
1956 
1957 /** adds a solution value for a new variable in the transformed problem that has no original counterpart
1958  * a value can only be set if no value has been set for this variable before
1959  */
1961  SCIP* scip, /**< SCIP data structure */
1962  SCIP_VAR* var, /**< variable for which to add a value */
1963  SCIP_Real val /**< solution value for variable */
1964  )
1965 {
1966  SCIP_DEBUGSOLDATA* debugsoldata;
1967  SCIP_Real testval;
1968  const char* varname;
1969  int i;
1970 
1971  assert(scip != NULL);
1972  assert(var != NULL);
1973  assert(scip->set != NULL);
1974 
1975  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1976  assert(debugsoldata != NULL);
1977 
1978  /* assert that we are in the SCIP instance that we are debugging and not some different (subSCIP,
1979  * auxiliary CIP, ...)
1980  */
1981  if( !SCIPdebugSolIsEnabled(scip) )
1982  return SCIP_OKAY;
1983 
1984  /* check whether a debug solution is available */
1985  if( !debugSolutionAvailable(scip->set) )
1986  return SCIP_OKAY;
1987 
1988  if( debugsoldata->debugsol == NULL )
1989  {
1990  /* make sure a debug solution has been read, so we do not compare against the initial debugsolval == 0 */
1991  SCIP_CALL( readSolution(scip->set) );
1992  }
1993 
1994  /* allocate memory */
1995  if( debugsoldata->nsolvals >= debugsoldata->solsize )
1996  {
1997  debugsoldata->solsize = MAX(2*debugsoldata->solsize, debugsoldata->nsolvals+1);
1998  SCIP_ALLOC( BMSreallocMemoryArray(&debugsoldata->solnames, debugsoldata->solsize) );
1999  SCIP_ALLOC( BMSreallocMemoryArray(&debugsoldata->solvals, debugsoldata->solsize) );
2000  }
2001  assert(debugsoldata->nsolvals < debugsoldata->solsize);
2002 
2003  /* store solution value in sorted list */
2004  varname = SCIPvarGetName(var);
2005  for( i = debugsoldata->nsolvals; i > 0 && strcmp(varname, debugsoldata->solnames[i-1]) < 0; --i )
2006  {
2007  debugsoldata->solnames[i] = debugsoldata->solnames[i-1];
2008  debugsoldata->solvals[i] = debugsoldata->solvals[i-1];
2009  }
2010  if( i > 0 && strcmp(varname, debugsoldata->solnames[i-1]) == 0 )
2011  {
2012  if( REALABS(debugsoldata->solvals[i-1] - val) > 1e-9 )
2013  {
2014  SCIPerrorMessage("already have stored different debugging solution value (%g) for variable <%s>, cannot store %g\n", debugsoldata->solvals[i-1], varname, val);
2015  return SCIP_ERROR;
2016  }
2017  else
2018  {
2019  SCIPdebugMsg(scip, "already have stored debugging solution value %g for variable <%s>, do not store same value again\n", val, varname);
2020  for( ; i < debugsoldata->nsolvals; ++i )
2021  {
2022  debugsoldata->solnames[i] = debugsoldata->solnames[i+1];
2023  debugsoldata->solvals[i] = debugsoldata->solvals[i+1];
2024  }
2025  return SCIP_OKAY;
2026  }
2027  }
2028 
2029  /* insert new solution value */
2030  SCIP_ALLOC( BMSduplicateMemoryArray(&(debugsoldata->solnames[i]), varname, strlen(varname)+1) );
2031  SCIPdebugMsg(scip, "add variable <%s>: value <%g>\n", debugsoldata->solnames[i], val);
2032  debugsoldata->solvals[i] = val;
2033  debugsoldata->nsolvals++;
2034 
2035  /* update objective function value of debug solution */
2036  debugsoldata->debugsolval += debugsoldata->solvals[i] * SCIPvarGetObj(var);
2037  SCIPdebugMsg(scip, "Debug Solution value is now %g.\n", debugsoldata->debugsolval);
2038 
2040  {
2041  /* add values to SCIP debug solution */
2042  SCIP_CALL( SCIPsetSolVal(scip, debugsoldata->debugsol, var, debugsoldata->solvals[i] ) );
2043  }
2044 
2045  /* get solution value once to produce warning if solution was cut off */
2046  SCIPdebugGetSolVal(scip, var, &testval);
2047 
2048  return SCIP_OKAY;
2049 }
2050 
2051 #else
2052 
2053 /** this is a dummy method to make the SunOS gcc linker happy */
2054 extern void SCIPdummyDebugMethodForSun(void);
2056 {
2057  return;
2058 }
2059 
2060 #endif
2061 
2062 
2063 /*
2064  * debug method for LP interface, to check if the LP interface works correct
2065  */
2066 #ifdef SCIP_DEBUG_LP_INTERFACE
2067 
2068 /* check whether coef is the r-th row of the inverse basis matrix B^-1; this is
2069  * the case if( coef * B ) is the r-th unit vector */
2071  SCIP* scip, /**< SCIP data structure */
2072  int r, /**< row number */
2073  SCIP_Real* coef /**< r-th row of the inverse basis matrix */
2074  )
2075 {
2076  SCIP_Real vecval;
2077  SCIP_Real matrixval;
2078  int* basisind;
2079  int nrows;
2080  int idx;
2081  int i;
2082  int k;
2083 
2084  assert(scip != NULL);
2085 
2086  nrows = SCIPgetNLPRows(scip);
2087 
2088  /* get basic indices for the basic matrix B */
2089  SCIP_CALL( SCIPallocBufferArray(scip, &basisind, nrows) );
2090  SCIP_CALL( SCIPgetLPBasisInd(scip, basisind) );
2091 
2092  /* loop over the columns of B */
2093  for( k = 0; k < nrows; ++k )
2094  {
2095  vecval = 0.0;
2096 
2097  /* indices of basic columns and rows:
2098  * - index i >= 0 corresponds to column i,
2099  * - index i < 0 to row -i-1
2100  */
2101  idx = basisind[k];
2102 
2103  /* check if we have a slack variable; this is the case if idx < 0 */
2104  if( idx >= 0 )
2105  {
2106  /* loop over the rows to compute the corresponding value in the unit vector */
2107  for( i = 0; i < nrows; ++i )
2108  {
2109  SCIP_CALL( SCIPlpiGetCoef(scip->lp->lpi, i, idx, &matrixval) );
2110  vecval += coef[i] * matrixval;
2111  }
2112  }
2113  else
2114  {
2115  assert( idx < 0 );
2116 
2117  /* retransform idx
2118  * - index i >= 0 corresponds to column i,
2119  * - index i < 0 to row -i-1
2120  */
2121  idx = -idx - 1;
2122  assert( idx >= 0 && idx < nrows );
2123 
2124  /* since idx < 0 we are in the case of a slack variable, i.e., the corresponding column
2125  is the idx-unit vector; note that some LP solver return a -idx-unit vector */
2126  /* vecval = REALABS(coef[idx]);*/
2127  vecval = coef[idx];
2128  }
2129 
2130  /* check if vecval fits to the r-th unit vector */
2131  if( k == r && !SCIPisFeasEQ(scip, vecval, 1.0) )
2132  {
2133  /* we expected a 1.0 and found something different */
2134  SCIPmessagePrintWarning(SCIPgetMessagehdlr(scip), "checked SCIPgetLPBInvRow() found value <%g> expected 1.0\n", vecval);
2135  }
2136  else if( k != r && !SCIPisFeasZero(scip, vecval) )
2137  {
2138  /* we expected a 0.0 and found something different */
2139  SCIPmessagePrintWarning(SCIPgetMessagehdlr(scip), "checked SCIPgetLPBInvRow() found value <%g> expected 0.0\n", vecval);
2140  }
2141  }
2142 
2143  SCIPfreeBufferArray(scip, &basisind);
2144 
2145  return SCIP_OKAY;
2146 }
2147 
2148 #endif
2149 
2150 /** checks, if SCIP is in one of the feasible stages */
2151 #ifndef NDEBUG
2153  SCIP* scip, /**< SCIP data structure */
2154  const char* method, /**< method that was called */
2155  SCIP_Bool init, /**< may method be called in the INIT stage? */
2156  SCIP_Bool problem, /**< may method be called in the PROBLEM stage? */
2157  SCIP_Bool transforming, /**< may method be called in the TRANSFORMING stage? */
2158  SCIP_Bool transformed, /**< may method be called in the TRANSFORMED stage? */
2159  SCIP_Bool initpresolve, /**< may method be called in the INITPRESOLVE stage? */
2160  SCIP_Bool presolving, /**< may method be called in the PRESOLVING stage? */
2161  SCIP_Bool exitpresolve, /**< may method be called in the EXITPRESOLE stage? */
2162  SCIP_Bool presolved, /**< may method be called in the PRESOLVED stage? */
2163  SCIP_Bool initsolve, /**< may method be called in the INITSOLVE stage? */
2164  SCIP_Bool solving, /**< may method be called in the SOLVING stage? */
2165  SCIP_Bool solved, /**< may method be called in the SOLVED stage? */
2166  SCIP_Bool exitsolve, /**< may method be called in the EXITSOLVE stage? */
2167  SCIP_Bool freetrans, /**< may method be called in the FREETRANS stage? */
2168  SCIP_Bool freescip /**< may method be called in the FREE stage? */
2169  )
2170 {
2171  assert(scip != NULL);
2172  assert(method != NULL);
2173 
2174  /*SCIPdebugMsg(scip, "called method <%s> at stage %d ------------------------------------------------\n",
2175  method, scip->set->stage);*/
2176 
2177  assert(scip->mem != NULL);
2178  assert(scip->set != NULL);
2179  assert(scip->interrupt != NULL);
2180  assert(scip->dialoghdlr != NULL);
2181  assert(scip->totaltime != NULL);
2182 
2183  switch( scip->set->stage )
2184  {
2185  case SCIP_STAGE_INIT:
2186  assert(scip->stat == NULL);
2187  assert(scip->origprob == NULL);
2188  assert(scip->eventfilter == NULL);
2189  assert(scip->eventqueue == NULL);
2190  assert(scip->branchcand == NULL);
2191  assert(scip->lp == NULL);
2192  assert(scip->nlp == NULL);
2193  assert(scip->primal == NULL);
2194  assert(scip->tree == NULL);
2195  assert(scip->conflict == NULL);
2196  assert(scip->transprob == NULL);
2197  assert(scip->pricestore == NULL);
2198  assert(scip->sepastore == NULL);
2199  assert(scip->cutpool == NULL);
2200  assert(scip->delayedcutpool == NULL);
2201 
2202  if( !init )
2203  {
2204  SCIPerrorMessage("cannot call method <%s> in initialization stage\n", method);
2205  return SCIP_INVALIDCALL;
2206  }
2207  return SCIP_OKAY;
2208 
2209  case SCIP_STAGE_PROBLEM:
2210  assert(scip->stat != NULL);
2211  assert(scip->origprob != NULL);
2212  assert(scip->eventfilter == NULL);
2213  assert(scip->eventqueue == NULL);
2214  assert(scip->branchcand == NULL);
2215  assert(scip->lp == NULL);
2216  assert(scip->nlp == NULL);
2217  assert(scip->primal == NULL);
2218  assert(scip->tree == NULL);
2219  assert(scip->conflict == NULL);
2220  assert(scip->transprob == NULL);
2221  assert(scip->pricestore == NULL);
2222  assert(scip->sepastore == NULL);
2223  assert(scip->cutpool == NULL);
2224  assert(scip->delayedcutpool == NULL);
2225 
2226  if( !problem )
2227  {
2228  SCIPerrorMessage("cannot call method <%s> in problem creation stage\n", method);
2229  return SCIP_INVALIDCALL;
2230  }
2231  return SCIP_OKAY;
2232 
2234  assert(scip->stat != NULL);
2235  assert(scip->origprob != NULL);
2236  assert(scip->eventfilter != NULL);
2237  assert(scip->eventqueue != NULL);
2238  assert(scip->branchcand != NULL);
2239  assert(scip->lp != NULL);
2240  assert(scip->primal != NULL);
2241  assert(scip->tree != NULL);
2242  assert(scip->conflict != NULL);
2243  assert(scip->transprob != NULL);
2244  assert(scip->pricestore == NULL);
2245  assert(scip->sepastore == NULL);
2246  assert(scip->cutpool == NULL);
2247  assert(scip->delayedcutpool == NULL);
2248 
2249  if( !transforming )
2250  {
2251  SCIPerrorMessage("cannot call method <%s> in problem transformation stage\n", method);
2252  return SCIP_INVALIDCALL;
2253  }
2254  return SCIP_OKAY;
2255 
2257  assert(scip->stat != NULL);
2258  assert(scip->origprob != NULL);
2259  assert(scip->eventfilter != NULL);
2260  assert(scip->eventqueue != NULL);
2261  assert(scip->branchcand != NULL);
2262  assert(scip->lp != NULL);
2263  assert(scip->primal != NULL);
2264  assert(scip->tree != NULL);
2265  assert(scip->conflict != NULL);
2266  assert(scip->transprob != NULL);
2267  assert(scip->pricestore == NULL);
2268  assert(scip->sepastore == NULL);
2269  assert(scip->cutpool == NULL);
2270  assert(scip->delayedcutpool == NULL);
2271 
2272  if( !transformed )
2273  {
2274  SCIPerrorMessage("cannot call method <%s> in problem transformed stage\n", method);
2275  return SCIP_INVALIDCALL;
2276  }
2277  return SCIP_OKAY;
2278 
2280  assert(scip->stat != NULL);
2281  assert(scip->origprob != NULL);
2282  assert(scip->eventfilter != NULL);
2283  assert(scip->eventqueue != NULL);
2284  assert(scip->branchcand != NULL);
2285  assert(scip->lp != NULL);
2286  assert(scip->primal != NULL);
2287  assert(scip->tree != NULL);
2288  assert(scip->conflict != NULL);
2289  assert(scip->transprob != NULL);
2290  assert(scip->pricestore == NULL);
2291  assert(scip->sepastore == NULL);
2292  assert(scip->cutpool == NULL);
2293  assert(scip->delayedcutpool == NULL);
2294 
2295  if( !initpresolve )
2296  {
2297  SCIPerrorMessage("cannot call method <%s> in init presolving stage\n", method);
2298  return SCIP_INVALIDCALL;
2299  }
2300  return SCIP_OKAY;
2301 
2302  case SCIP_STAGE_PRESOLVING:
2303  assert(scip->stat != NULL);
2304  assert(scip->origprob != NULL);
2305  assert(scip->eventfilter != NULL);
2306  assert(scip->eventqueue != NULL);
2307  assert(scip->branchcand != NULL);
2308  assert(scip->lp != NULL);
2309  assert(scip->primal != NULL);
2310  assert(scip->tree != NULL);
2311  assert(scip->conflict != NULL);
2312  assert(scip->transprob != NULL);
2313  assert(scip->pricestore == NULL);
2314  assert(scip->sepastore == NULL);
2315  assert(scip->cutpool == NULL);
2316  assert(scip->delayedcutpool == NULL);
2317 
2318  if( !presolving )
2319  {
2320  SCIPerrorMessage("cannot call method <%s> in presolving stage\n", method);
2321  return SCIP_INVALIDCALL;
2322  }
2323  return SCIP_OKAY;
2324 
2326  assert(scip->stat != NULL);
2327  assert(scip->origprob != NULL);
2328  assert(scip->eventfilter != NULL);
2329  assert(scip->eventqueue != NULL);
2330  assert(scip->branchcand != NULL);
2331  assert(scip->lp != NULL);
2332  assert(scip->primal != NULL);
2333  assert(scip->tree != NULL);
2334  assert(scip->conflict != NULL);
2335  assert(scip->transprob != NULL);
2336  assert(scip->pricestore == NULL);
2337  assert(scip->sepastore == NULL);
2338  assert(scip->cutpool == NULL);
2339  assert(scip->delayedcutpool == NULL);
2340 
2341  if( !exitpresolve )
2342  {
2343  SCIPerrorMessage("cannot call method <%s> in exit presolving stage\n", method);
2344  return SCIP_INVALIDCALL;
2345  }
2346  return SCIP_OKAY;
2347 
2348  case SCIP_STAGE_PRESOLVED:
2349  assert(scip->stat != NULL);
2350  assert(scip->origprob != NULL);
2351  assert(scip->eventfilter != NULL);
2352  assert(scip->eventqueue != NULL);
2353  assert(scip->branchcand != NULL);
2354  assert(scip->lp != NULL);
2355  assert(scip->primal != NULL);
2356  assert(scip->tree != NULL);
2357  assert(scip->conflict != NULL);
2358  assert(scip->transprob != NULL);
2359  assert(scip->pricestore == NULL);
2360  assert(scip->sepastore == NULL);
2361  assert(scip->cutpool == NULL);
2362  assert(scip->delayedcutpool == NULL);
2363 
2364  if( !presolved )
2365  {
2366  SCIPerrorMessage("cannot call method <%s> in problem presolved stage\n", method);
2367  return SCIP_INVALIDCALL;
2368  }
2369  return SCIP_OKAY;
2370 
2371  case SCIP_STAGE_INITSOLVE:
2372  assert(scip->stat != NULL);
2373  assert(scip->origprob != NULL);
2374  assert(scip->eventfilter != NULL);
2375  assert(scip->eventqueue != NULL);
2376  assert(scip->branchcand != NULL);
2377  assert(scip->lp != NULL);
2378  assert(scip->primal != NULL);
2379  assert(scip->tree != NULL);
2380  assert(scip->transprob != NULL);
2381 
2382  if( !initsolve )
2383  {
2384  SCIPerrorMessage("cannot call method <%s> in init solve stage\n", method);
2385  return SCIP_INVALIDCALL;
2386  }
2387  return SCIP_OKAY;
2388 
2389  case SCIP_STAGE_SOLVING:
2390  assert(scip->stat != NULL);
2391  assert(scip->origprob != NULL);
2392  assert(scip->eventfilter != NULL);
2393  assert(scip->eventqueue != NULL);
2394  assert(scip->branchcand != NULL);
2395  assert(scip->lp != NULL);
2396  assert(scip->primal != NULL);
2397  assert(scip->tree != NULL);
2398  assert(scip->conflict != NULL);
2399  assert(scip->transprob != NULL);
2400  assert(scip->pricestore != NULL);
2401  assert(scip->sepastore != NULL);
2402  assert(scip->cutpool != NULL);
2403  assert(scip->delayedcutpool != NULL);
2404 
2405  if( !solving )
2406  {
2407  SCIPerrorMessage("cannot call method <%s> in solving stage\n", method);
2408  return SCIP_INVALIDCALL;
2409  }
2410  return SCIP_OKAY;
2411 
2412  case SCIP_STAGE_SOLVED:
2413  assert(scip->stat != NULL);
2414  assert(scip->origprob != NULL);
2415  assert(scip->eventfilter != NULL);
2416  assert(scip->eventqueue != NULL);
2417  assert(scip->branchcand != NULL);
2418  assert(scip->lp != NULL);
2419  assert(scip->primal != NULL);
2420  assert(scip->tree != NULL);
2421  assert(scip->conflict != NULL);
2422  assert(scip->transprob != NULL);
2423  assert(scip->pricestore != NULL);
2424  assert(scip->sepastore != NULL);
2425  assert(scip->cutpool != NULL);
2426  assert(scip->delayedcutpool != NULL);
2427 
2428  if( !solved )
2429  {
2430  SCIPerrorMessage("cannot call method <%s> in problem solved stage\n", method);
2431  return SCIP_INVALIDCALL;
2432  }
2433  return SCIP_OKAY;
2434 
2435  case SCIP_STAGE_EXITSOLVE:
2436  assert(scip->stat != NULL);
2437  assert(scip->origprob != NULL);
2438  assert(scip->eventfilter != NULL);
2439  assert(scip->eventqueue != NULL);
2440  assert(scip->branchcand != NULL);
2441  assert(scip->lp != NULL);
2442  assert(scip->primal != NULL);
2443  assert(scip->tree != NULL);
2444  assert(scip->transprob != NULL);
2445 
2446  if( !exitsolve )
2447  {
2448  SCIPerrorMessage("cannot call method <%s> in solve deinitialization stage\n", method);
2449  return SCIP_INVALIDCALL;
2450  }
2451  return SCIP_OKAY;
2452 
2453  case SCIP_STAGE_FREETRANS:
2454  assert(scip->stat != NULL);
2455  assert(scip->origprob != NULL);
2456  assert(scip->pricestore == NULL);
2457  assert(scip->sepastore == NULL);
2458  assert(scip->cutpool == NULL);
2459  assert(scip->delayedcutpool == NULL);
2460 
2461  if( !freetrans )
2462  {
2463  SCIPerrorMessage("cannot call method <%s> in free transformed problem stage\n", method);
2464  return SCIP_INVALIDCALL;
2465  }
2466  return SCIP_OKAY;
2467 
2468  case SCIP_STAGE_FREE:
2469  if( !freescip )
2470  {
2471  SCIPerrorMessage("cannot call method <%s> in free stage\n", method);
2472  return SCIP_INVALIDCALL;
2473  }
2474  return SCIP_OKAY;
2475 
2476  default:
2477  /* note that this is in an internal SCIP error since all SCIP stages are covert in the switch above */
2478  SCIPerrorMessage("invalid SCIP stage <%d>\n", scip->set->stage);
2479  return SCIP_ERROR;
2480  }
2481 }
2482 #endif
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_STAT * stat
Definition: struct_scip.h:70
SCIP_RETCODE SCIPincludeProp(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Bool delay, SCIP_PROPTIMING timingmask, int presolpriority, int presolmaxrounds, SCIP_PRESOLTIMING presoltiming, SCIP_DECL_PROPCOPY((*propcopy)), SCIP_DECL_PROPFREE((*propfree)), SCIP_DECL_PROPINIT((*propinit)), SCIP_DECL_PROPEXIT((*propexit)), SCIP_DECL_PROPINITPRE((*propinitpre)), SCIP_DECL_PROPEXITPRE((*propexitpre)), SCIP_DECL_PROPINITSOL((*propinitsol)), SCIP_DECL_PROPEXITSOL((*propexitsol)), SCIP_DECL_PROPPRESOL((*proppresol)), SCIP_DECL_PROPEXEC((*propexec)), SCIP_DECL_PROPRESPROP((*propresprop)), SCIP_PROPDATA *propdata)
Definition: scip_prop.c:53
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition: type_lp.h:50
SCIP_RETCODE SCIPcreateOrigSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:557
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:977
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:17265
SCIP_EXPORT SCIP_Bool SCIPvarIsTransformed(SCIP_VAR *var)
Definition: var.c:17159
SCIP_EXPORT SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:17172
SCIP_Bool SCIPsetIsLE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6045
SCIP_Bool SCIPsetIsFeasZero(SCIP_SET *set, SCIP_Real val)
Definition: set.c:6495
SCIP_EXPORT int SCIPvarGetNUses(SCIP_VAR *var)
Definition: var.c:17027
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1213
SCIP_Bool SCIPlpDiving(SCIP_LP *lp)
Definition: lp.c:17684
#define SCIPdebugRemoveNode(blkmem, set, node)
Definition: debug.h:264
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:140
internal methods for branch and bound tree
SCIP_CONFLICT * conflict
Definition: struct_scip.h:87
int SCIPgetNLPRows(SCIP *scip)
Definition: scip_lp.c:596
#define SCIPdebugFreeDebugData(set)
Definition: debug.h:258
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8316
SCIP_STATUS SCIPgetStatus(SCIP *scip)
Definition: scip_general.c:467
SCIP_Bool SCIPsetIsFeasEQ(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6385
#define SCIP_MAXSTRLEN
Definition: def.h:279
SCIP_BOUNDCHG * boundchgs
Definition: struct_var.h:125
#define SCIPdebugCheckImplic(set, var, varfixing, implvar, impltype, implbound)
Definition: debug.h:268
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:17077
SCIP_EVENTQUEUE * eventqueue
Definition: struct_scip.h:80
SCIP_CLOCK * totaltime
Definition: struct_scip.h:67
#define SCIPdebugSolDataCreate(debugsoldata)
Definition: debug.h:255
SCIP_PRIMAL * primal
Definition: struct_scip.h:85
SCIP_CUTPOOL * delayedcutpool
Definition: struct_scip.h:97
SCIP_Real SCIPsetInfinity(SCIP_SET *set)
Definition: set.c:5852
unsigned int nboundchgs
Definition: struct_var.h:123
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:17122
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
Definition: scip_tree.c:81
SCIP_EXPORT SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:17197
#define SCIPdebugCheckClique(set, vars, values, nvars)
Definition: debug.h:270
SCIP_BRANCHCAND * branchcand
Definition: struct_scip.h:81
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:8138
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:216
#define FALSE
Definition: def.h:73
SCIP_EXPORT SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17515
SCIP_EXPORT int SCIPnodeGetDepth(SCIP_NODE *node)
Definition: tree.c:7448
SCIP_STAGE stage
Definition: struct_set.h:63
SCIP_EXPORT SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17182
#define TRUE
Definition: def.h:72
#define SCIPdebugCheckRow(set, row)
Definition: debug.h:260
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
int SCIPpqueueNElems(SCIP_PQUEUE *pqueue)
Definition: misc.c:1468
SCIP_EXPORT SCIP_Bool SCIPvarIsTransformedOrigvar(SCIP_VAR *var)
Definition: var.c:12632
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3201
#define SCIPdebugCheckLocalLowerbound(blkmem, set, node)
Definition: debug.h:266
#define BMSallocMemoryArray(ptr, num)
Definition: memory.h:115
SCIP_EXPORT void SCIPsortPtrReal(void **ptrarray, SCIP_Real *realarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
SCIP_EXPORT SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:17136
SCIP_PROB * transprob
Definition: struct_scip.h:89
SCIP_EXPORT SCIP_RETCODE SCIPlpiGetCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real *val)
Definition: lpi_clp.cpp:1762
SCIP_EXPORT SCIP_Real SCIPnodeGetLowerbound(SCIP_NODE *node)
Definition: tree.c:7458
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:123
#define SCIP_DECL_PROPEXEC(x)
Definition: type_prop.h:208
#define SCIPdebugCheckVbound(set, var, vbtype, vbvar, vbcoef, vbconstant)
Definition: debug.h:267
#define SCIPdebugMsg
Definition: scip_message.h:69
internal methods for LP management
Definition: heur_padm.c:125
SCIP_PROB * origprob
Definition: struct_scip.h:71
SCIP_Longint number
Definition: struct_tree.h:134
#define SCIP_PRESOLTIMING_FAST
Definition: type_timing.h:43
SCIP_DIALOGHDLR * dialoghdlr
Definition: struct_scip.h:65
SCIP_Bool SCIPsetIsGE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6081
#define SCIPdebugCheckConflict(blkmem, set, node, bdchginfos, relaxedbds, nliterals)
Definition: debug.h:271
SCIP_PRICESTORE * pricestore
Definition: struct_scip.h:92
SCIP_EXPORT SCIP_Bool SCIPvarIsRelaxationOnly(SCIP_VAR *var)
Definition: var.c:17304
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
Definition: fileio.c:144
struct SCIP_DebugSolData SCIP_DEBUGSOLDATA
Definition: debug.h:50
SCIP_Bool SCIPsetIsLT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6027
SCIP_MEM * mem
Definition: struct_scip.h:62
SCIP_DOMCHG * domchg
Definition: struct_tree.h:150
SCIP_RETCODE SCIPcheckCons(SCIP *scip, SCIP_CONS *cons, SCIP_SOL *sol, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool printreason, SCIP_RESULT *result)
Definition: scip_cons.c:2072
SCIP_Bool SCIPtreeProbing(SCIP_TREE *tree)
Definition: tree.c:8280
SCIP_EXPORT const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:17017
#define SCIPdebugIncludeProp(scip)
Definition: debug.h:273
#define BMSfreeMemoryArray(ptr)
Definition: memory.h:139
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:17102
internal methods for storing and manipulating the main problem
#define SCIPerrorMessage
Definition: pub_message.h:55
SCIP_EVENTFILTER * eventfilter
Definition: struct_scip.h:79
SCIP_INTERRUPT * interrupt
Definition: struct_scip.h:64
SCIP_EXPORT SCIP_BOUNDCHGTYPE SCIPboundchgGetBoundchgtype(SCIP_BOUNDCHG *boundchg)
Definition: var.c:16934
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPdebugCheckInference(blkmem, set, node, var, newbound, boundtype)
Definition: debug.h:263
SCIP_Bool SCIPisInRestart(SCIP *scip)
Definition: scip_solve.c:3567
SCIP_Bool SCIPsetIsRelEQ(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6864
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2152
int SCIPfeof(SCIP_FILE *stream)
Definition: fileio.c:218
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:48
struct SCIP_File SCIP_FILE
Definition: pub_fileio.h:34
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
Definition: fileio.c:191
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:17112
#define SCIPdebugCheckAggregation(set, var, aggrvars, scalars, constant, naggrvars)
Definition: debug.h:269
void SCIPmessagePrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
Definition: message.c:418
#define NULL
Definition: lpi_spx1.cpp:155
SCIP_OBJSENSE SCIPgetObjsense(SCIP *scip)
Definition: scip_prob.c:1223
#define REALABS(x)
Definition: def.h:187
#define SCIP_PROPTIMING_ALWAYS
Definition: type_timing.h:64
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:370
SCIP main data structure.
SCIP_Bool SCIPsetIsFeasGE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6473
void SCIPdummyDebugMethodForSun(void)
Definition: debug.c:2055
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip_prob.c:2426
#define SCIPdebugCheckBInvRow(scip, r, coef)
Definition: debug.h:300
#define SCIPdebugCheckLbGlobal(scip, var, lb)
Definition: debug.h:261
SCIP_LPI * lpi
Definition: struct_lp.h:286
#define SCIPdebugGetSolVal(scip, var, val)
Definition: debug.h:275
void SCIProwPrint(SCIP_ROW *row, SCIP_MESSAGEHDLR *messagehdlr, FILE *file)
Definition: lp.c:5287
SCIP_EXPORT SCIP_Real SCIPvarGetNegationConstant(SCIP_VAR *var)
Definition: var.c:17504
SCIP_Bool SCIPsetIsFeasLE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6429
#define SCIPdebugCheckUbGlobal(scip, var, ub)
Definition: debug.h:262
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:135
SCIP_CUTPOOL * cutpool
Definition: struct_scip.h:96
#define SCIPdebugCheckConss(scip, conss, nconss)
Definition: debug.h:259
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
internal methods for problem variables
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:111
#define SCIP_UNKNOWN
Definition: def.h:184
SCIP_SEPASTORE * sepastore
Definition: struct_scip.h:93
public data structures and miscellaneous methods
SCIP_EXPORT SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
Definition: var.c:17493
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip_sol.c:1255
SCIP_Real SCIPgetLPFeastol(SCIP *scip)
Definition: scip_lp.c:419
int SCIPgetDepth(SCIP *scip)
Definition: scip_tree.c:638
#define SCIP_Bool
Definition: def.h:70
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3014
SCIP_EXPORT SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17677
#define SCIPdebugSolIsValidInSubtree(scip, isvalidinsubtree)
Definition: debug.h:276
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
Definition: scip_message.c:91
#define SCIPdebugCheckGlobalLowerbound(blkmem, set)
Definition: debug.h:265
#define MAX(x, y)
Definition: tclique_def.h:83
SCIP_VAR ** SCIPgetOrigVars(SCIP *scip)
Definition: scip_prob.c:2399
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:17156
#define SCIPdebugCheckConflictFrontier(blkmem, set, node, bdchginfo, bdchginfos, relaxedbds, nliterals, bdchgqueue, forcedbdchgqueue)
Definition: debug.h:272
methods for debugging
#define SCIPsetDebugMsg
Definition: set.h:1721
SCIP_EXPORT SCIP_BOUNDTYPE SCIPbdchginfoGetBoundtype(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:18289
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip_var.c:8250
SCIP_EXPORT SCIP_Bool SCIPvarIsDeleted(SCIP_VAR *var)
Definition: var.c:17238
SCIP_RETCODE SCIPhashmapRemoveAll(SCIP_HASHMAP *hashmap)
Definition: misc.c:3573
SCIP_Bool SCIPsetIsFeasLT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6407
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16906
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
Definition: scip_prob.c:2679
SCIP_EXPORT SCIP_Real SCIPsolGetOrigObj(SCIP_SOL *sol)
Definition: sol.c:2541
SCIP_Real * r
Definition: circlepacking.c:50
#define SCIPdebugReset(set)
Definition: debug.h:257
SCIP_DOMCHGBOUND domchgbound
Definition: struct_var.h:153
SCIP_EXPORT SCIP_VAR * SCIPbdchginfoGetVar(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:18269
int SCIPconsGetActiveDepth(SCIP_CONS *cons)
Definition: cons.c:8127
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_NODE * parent
Definition: struct_tree.h:148
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
void ** SCIPpqueueElems(SCIP_PQUEUE *pqueue)
Definition: misc.c:1479
static const SCIP_Real scalars[]
Definition: lp.c:5731
#define SCIP_DECL_SORTPTRCOMP(x)
Definition: type_misc.h:172
SCIP_EXPORT SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17667
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
int SCIPgetNLeaves(SCIP *scip)
Definition: scip_tree.c:262
#define BMSfreeMemoryNull(ptr)
Definition: memory.h:138
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
SCIP_Bool SCIPsetIsGT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6063
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3048
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:8077
#define SCIPdebugSolDisable(scip)
Definition: debug.h:278
#define SCIP_Real
Definition: def.h:163
enum SCIP_Stage SCIP_STAGE
Definition: type_set.h:50
SCIP_DEBUGSOLDATA * SCIPsetGetDebugSolData(SCIP_SET *set)
Definition: set.c:5744
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:17215
SCIP_NLP * nlp
Definition: struct_scip.h:83
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPwithDebugSol(void)
Definition: debug.h:280
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_EXPORT SCIP_RETCODE SCIPvarGetOrigvarSum(SCIP_VAR **var, SCIP_Real *scalar, SCIP_Real *constant)
Definition: var.c:12545
#define BMSallocMemory(ptr)
Definition: memory.h:111
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:119
SCIP_RETCODE SCIPgetLPBasisInd(SCIP *scip, int *basisind)
Definition: scip_lp.c:656
void SCIPprintSysError(const char *message)
Definition: misc.c:10513
#define SCIPdebugAddSolVal(scip, var, val)
Definition: debug.h:274
SCIP_Bool SCIPsetIsFeasGT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6451
SCIP_TREE * tree
Definition: struct_scip.h:86
#define SCIPdebugSolIsEnabled(scip)
Definition: debug.h:279
SCIP_STAGE SCIPsetGetStage(SCIP_SET *set)
Definition: set.c:2924
SCIP_Real SCIPprobExternObjval(SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_SET *set, SCIP_Real objval)
Definition: prob.c:2082
SCIP_EXPORT SCIP_NODETYPE SCIPnodeGetType(SCIP_NODE *node)
Definition: tree.c:7428
SCIP_Real SCIPtreeGetLowerbound(SCIP_TREE *tree, SCIP_SET *set)
Definition: tree.c:7251
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:17166
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:429
int SCIPfclose(SCIP_FILE *fp)
Definition: fileio.c:223
SCIP_EXPORT SCIP_BOUNDTYPE SCIPboundchgGetBoundtype(SCIP_BOUNDCHG *boundchg)
Definition: var.c:16944
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip_general.c:356
SCIP_LP * lp
Definition: struct_scip.h:82
#define SCIP_ALLOC(x)
Definition: def.h:381
#define SCIPdebugSolEnable(scip)
Definition: debug.h:277
#define SCIPABORT()
Definition: def.h:342
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2305
#define SCIPdebugFreeSol(set)
Definition: debug.h:256
SCIP_RETCODE SCIPhashmapRemove(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3379
SCIP_RETCODE SCIPhashmapSetImage(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:3263
SCIP_EXPORT SCIP_Real SCIPbdchginfoGetNewbound(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:18259
SCIP callable library.
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1436
memory allocation routines