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-2018 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file debug.c
17  * @brief methods for debugging
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <stdio.h>
24 #include <string.h>
25 #include <assert.h>
26 #if defined(_WIN32) || defined(_WIN64)
27 #else
28 #include <strings.h> /*lint --e{766}*/
29 #endif
30 
31 #include "scip/def.h"
32 #include "blockmemshell/memory.h"
33 #include "scip/set.h"
34 #include "scip/lp.h"
35 #include "scip/var.h"
36 #include "scip/prob.h"
37 #include "scip/tree.h"
38 #include "scip/scip.h"
39 #include "scip/debug.h"
40 #include "scip/pub_message.h"
41 #include "scip/pub_misc.h"
42 #include "scip/struct_scip.h"
43 
44 #ifdef WITH_DEBUG_SOLUTION
45 
46 #define SCIP_HASHSIZE_DEBUG 500 /**< minimum size of hash map for storing whether a solution is valid for the node */
47 
48 struct SCIP_DebugSolData
49 {
50  char** solnames; /**< variable names in the solution */
51  SCIP_Real* solvals; /**< solution value array (only nonzero entries) */
52  int nsolvals; /**< number of entries in the debug solution */
53  int solsize; /**< size of the array entries */
54  SCIP_SOL* debugsol; /**< a debug solution */
55  SCIP_STAGE debugsolstage; /**< solving stage of debug solution */
56  SCIP_HASHMAP* solinnode; /**< maps nodes to bools, storing whether the solution is valid for the node */
57  SCIP_Bool falseptr; /**< pointer to value FALSE used for hashmap */
58  SCIP_Bool trueptr; /**< pointer to value TRUE used for hashmap */
59  SCIP_Bool solisachieved; /**< means if current best solution is better than the given debug solution */
60  SCIP_Real debugsolval; /**< objective value for debug solution */
61  SCIP_Bool debugsoldisabled; /**< flag indicating if debugging of solution was disabled or not */
62  SCIP_Bool warningprinted; /**< flag indicating if a warning was already printed */
63 };
64 
65 
66 /** creates debug solution data */
68  SCIP_DEBUGSOLDATA** debugsoldata /**< pointer to debug solution data */
69  )
70 {
71  assert(debugsoldata != NULL);
72 
73  SCIP_ALLOC( BMSallocMemory(debugsoldata) );
74 
75  (*debugsoldata)->solnames = NULL;
76  (*debugsoldata)->solvals = NULL;
77  (*debugsoldata)->nsolvals = 0;
78  (*debugsoldata)->solsize = 0;
79  (*debugsoldata)->debugsol = NULL;
80  (*debugsoldata)->debugsolstage = SCIP_STAGE_INIT;
81  (*debugsoldata)->solinnode = NULL;
82  (*debugsoldata)->falseptr = FALSE;
83  (*debugsoldata)->trueptr = TRUE;
84  (*debugsoldata)->solisachieved = FALSE;
85  (*debugsoldata)->debugsolval = 0.0;
86  (*debugsoldata)->debugsoldisabled = TRUE;
87  (*debugsoldata)->warningprinted = FALSE;
88 
89  return SCIP_OKAY;
90 }
91 
92 #ifdef SCIP_MORE_DEBUG
93 /** comparison method for sorting variables w.r.t. to their name */
94 static
95 SCIP_DECL_SORTPTRCOMP(sortVarsAfterNames)
96 {
97  return strcmp(SCIPvarGetName((SCIP_VAR*)elem1), SCIPvarGetName((SCIP_VAR*)elem2));
98 }
99 #endif
100 
101 /* checks whether the parameter is specified */
102 static
103 SCIP_Bool debugSolutionAvailable(
104  SCIP_SET* set /**< global SCIP settings */
105  )
106 {
107  SCIP_DEBUGSOLDATA* debugsoldata;
108 
109  assert(set != NULL);
110 
111  debugsoldata = SCIPsetGetDebugSolData(set);
112 
113  /* check whether a debug solution is specified */
114  if( strcmp(set->misc_debugsol, "-") == 0 )
115  {
116  if( !debugsoldata->warningprinted )
117  {
118  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "SCIP is compiled with 'DEBUGSOL=true' but no debug solution is given:\n ");
119  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "*** Please set the parameter 'misc/debugsol' and reload the problem again to use the debugging-mechanism ***\n\n");
120  debugsoldata->warningprinted = TRUE;
121  }
122  return FALSE;
123  }
124  else
125  {
126  debugsoldata->warningprinted = FALSE;
127  return TRUE;
128  }
129 }
130 
131 /** reads solution from given file into given arrays */
132 static
133 SCIP_RETCODE readSolfile(
134  SCIP_SET* set, /**< global SCIP settings */
135  const char* solfilename, /**< solution filename to read */
136  SCIP_SOL** debugsolptr,
137  SCIP_Real* debugsolvalptr,
138  SCIP_STAGE* debugsolstageptr,
139  char*** names, /**< pointer to store the array of variable names */
140  SCIP_Real** vals, /**< pointer to store the array of solution values */
141  int* nvals, /**< pointer to store the number of non-zero elements */
142  int* valssize /**< pointer to store the length of the variable names and solution values arrays */
143  )
144 {
145  SCIP_VAR** vars;
146  SCIP_Real* solvalues;
147  SCIP_FILE* file;
148  SCIP_SOL* debugsol;
149  SCIP_Real debugsolval;
150  int nonvalues;
151  int nfound;
152  int i;
153  SCIP_Bool unknownvariablemessage;
154 
155  assert(set != NULL);
156  assert(solfilename != NULL);
157  assert(names != NULL);
158  assert(*names == NULL);
159  assert(vals != NULL);
160  assert(*vals == NULL);
161  assert(nvals != NULL);
162  assert(valssize != NULL);
163 
164  printf("***** debug: reading solution file <%s>\n", solfilename);
165 
166  /* open solution file */
167  file = SCIPfopen(solfilename, "r");
168  if( file == NULL )
169  {
170  SCIPerrorMessage("cannot open solution file <%s> specified in scip/debug.h\n", solfilename);
171  SCIPprintSysError(solfilename);
172  return SCIP_NOFILE;
173  }
174 
175  /* read data */
176  nonvalues = 0;
177  *valssize = 0;
178  unknownvariablemessage = FALSE;
179 
180  while( !SCIPfeof(file) )
181  {
182  char buf[SCIP_MAXSTRLEN];
183  char name[SCIP_MAXSTRLEN];
184  char objstring[SCIP_MAXSTRLEN];
185  char valuestring[SCIP_MAXSTRLEN];
186  SCIP_VAR* var;
187  SCIP_Real val;
188  int nread;
189 
190  if( SCIPfgets(buf, SCIP_MAXSTRLEN, file) == NULL )
191  {
192  if( SCIPfeof(file) )
193  break;
194  else
195  return SCIP_READERROR;
196  }
197 
198  /* there are some lines which may preceed the solution information */
199  if( strncasecmp(buf, "solution status:", 16) == 0 || strncasecmp(buf, "objective value:", 16) == 0 ||
200  strncasecmp(buf, "Log started", 11) == 0 || strncasecmp(buf, "Variable Name", 13) == 0 ||
201  strncasecmp(buf, "All other variables", 19) == 0 || strncasecmp(buf, "\n", 1) == 0 ||
202  strncasecmp(buf, "NAME", 4) == 0 || strncasecmp(buf, "ENDATA", 6) == 0 ) /* allow parsing of SOL-format on the MIPLIB 2003 pages */
203  {
204  ++nonvalues;
205  continue;
206  }
207 
208  /* cppcheck-suppress invalidscanf */
209  nread = sscanf(buf, "%s %s %s\n", name, valuestring, objstring);
210  if( nread < 2 )
211  {
212  printf("invalid input line %d in solution file <%s>: <%s>\n", *nvals + nonvalues, solfilename, name);
213  SCIPfclose(file);
214  return SCIP_READERROR;
215  }
216 
217  /* find the variable */
218  var = SCIPfindVar(set->scip, name);
219  if( var == NULL )
220  {
221  if( !unknownvariablemessage )
222  {
223  SCIPverbMessage(set->scip, SCIP_VERBLEVEL_NORMAL, NULL, "unknown variable <%s> in line %d of solution file <%s>\n",
224  name, *nvals + nonvalues, solfilename);
225  SCIPverbMessage(set->scip, SCIP_VERBLEVEL_NORMAL, NULL, " (further unknown variables are ignored)\n");
226  unknownvariablemessage = TRUE;
227  }
228  continue;
229  }
230 
231  /* cast the value, check first for inv(alid) or inf(inite) ones that need special treatment */
232  if( strncasecmp(valuestring, "inv", 3) == 0 )
233  continue;
234  else if( strncasecmp(valuestring, "+inf", 4) == 0 || strncasecmp(valuestring, "inf", 3) == 0 )
235  val = SCIPsetInfinity(set);
236  else if( strncasecmp(valuestring, "-inf", 4) == 0 )
237  val = -SCIPsetInfinity(set);
238  else
239  {
240  /* cppcheck-suppress invalidscanf */
241  nread = sscanf(valuestring, "%lf", &val);
242  if( nread != 1 )
243  {
244  SCIPerrorMessage("Invalid solution value <%s> for variable <%s> in line %d of solution file <%s>.\n",
245  valuestring, name, *nvals + nonvalues, solfilename);
246  SCIPfclose(file);
247  return SCIP_READERROR;
248  }
249  }
250 
251  /* allocate memory */
252  if( *nvals >= *valssize )
253  {
254  *valssize = MAX(2 * *valssize, (*nvals)+1);
255  SCIP_ALLOC( BMSreallocMemoryArray(names, *valssize) );
256  SCIP_ALLOC( BMSreallocMemoryArray(vals, *valssize) );
257  }
258  assert(*nvals < *valssize);
259 
260  /* store solution value in sorted list */
261  for( i = *nvals; i > 0 && strcmp(name, (*names)[i-1]) < 0; --i )
262  {
263  (*names)[i] = (*names)[i-1];
264  (*vals)[i] = (*vals)[i-1];
265  }
266  SCIP_ALLOC( BMSduplicateMemoryArray(&(*names)[i], name, strlen(name)+1) );
267  SCIPdebugMsg(set->scip, "found variable <%s>: value <%g>\n", (*names)[i], val);
268  (*vals)[i] = val;
269  (*nvals)++;
270  }
271 
272  /* get memory for SCIP solution */
273  SCIP_ALLOC( BMSallocMemoryArray(&vars, *valssize) );
274  SCIP_ALLOC( BMSallocMemoryArray(&solvalues, *valssize) );
275 
276  debugsolval = 0.0;
277  nfound = 0;
278 
279  /* get solution value */
280  for( i = 0; i < *nvals; ++i)
281  {
282  SCIP_VAR* var;
283  var = SCIPfindVar(set->scip, (*names)[i]);
284  if( var != NULL )
285  {
286  vars[nfound] = var;
287  solvalues[nfound] = (*vals)[i];
288  ++nfound;
289  debugsolval += (*vals)[i] * SCIPvarGetObj(var);
290  }
291  }
292  SCIPdebugMsg(set->scip, "Debug Solution value is %g.\n", debugsolval);
293 
294 #ifdef SCIP_MORE_DEBUG
295  SCIPsortPtrReal((void**)vars, solvalues, sortVarsAfterNames, nfound);
296 
297  for( i = 0; i < nfound - 1; ++i)
298  {
299  assert(strcmp(SCIPvarGetName(vars[i]), SCIPvarGetName(vars[i + 1])) != 0);
300  }
301 #endif
302 
303  if( debugsolptr != NULL )
304  {
305  /* create SCIP solution */
306  SCIP_CALL( SCIPcreateOrigSol(set->scip, &debugsol, NULL) );
307  *debugsolstageptr = SCIPgetStage(set->scip);
308 
309  /* set SCIP solution values */
310  SCIP_CALL( SCIPsetSolVals(set->scip, debugsol, nfound, vars, solvalues ) );
311  }
312 
313  BMSfreeMemoryArray(&vars);
314  BMSfreeMemoryArray(&solvalues);
315 
316  if( debugsolptr != NULL )
317  *debugsolptr = debugsol;
318 
319  if( debugsolvalptr != NULL )
320  *debugsolvalptr = debugsolval;
321 
322  /* close file */
323  SCIPfclose(file);
324 
325  printf("***** debug: read %d non-zero entries (%d variables found)\n", *nvals, nfound);
326 
327  return SCIP_OKAY;
328 }
329 
330 /** reads feasible solution to check from file */
331 static
332 SCIP_RETCODE readSolution(
333  SCIP_SET* set /**< global SCIP settings */
334  )
335 {
336  SCIP_DEBUGSOLDATA* debugsoldata;
337 
338  assert(set != NULL);
339 
340  debugsoldata = SCIPsetGetDebugSolData(set);
341 
342  /* check whether a debug solution is available */
343  if( !debugSolutionAvailable(set) )
344  return SCIP_OKAY;
345 
346  if( debugsoldata == NULL || debugsoldata->nsolvals > 0 )
347  return SCIP_OKAY;
348 
349  SCIP_CALL( readSolfile(set, set->misc_debugsol, &debugsoldata->debugsol, &debugsoldata->debugsolval,
350  &debugsoldata->debugsolstage, &(debugsoldata->solnames), &(debugsoldata->solvals), &(debugsoldata->nsolvals),
351  &(debugsoldata->solsize)) );
352 
353  return SCIP_OKAY;
354 }
355 
356 /** gets value of given variable in debugging solution */
357 static
358 SCIP_RETCODE getSolutionValue(
359  SCIP_SET* set, /**< global SCIP settings */
360  SCIP_VAR* var, /**< variable to get solution value for */
361  SCIP_Real* val /**< pointer to store solution value */
362  )
363 {
364  SCIP_VAR* solvar;
365  SCIP_DEBUGSOLDATA* debugsoldata;
366  SCIP_Real scalar;
367  SCIP_Real constant;
368  const char* name;
369  int left;
370  int right;
371  int middle;
372  int cmp;
373 
374  assert(set != NULL);
375  assert(var != NULL);
376  assert(val != NULL);
377 
378  /* check whether a debug solution is available */
379  if( !debugSolutionAvailable(set) )
380  return SCIP_OKAY;
381 
382  debugsoldata = SCIPsetGetDebugSolData(set);
383  assert(debugsoldata != NULL);
384 
385  /* allow retrieving solution values only if referring to the SCIP instance that is debugged */
386  if( !SCIPdebugSolIsEnabled(set->scip) )
387  {
388  *val = SCIP_UNKNOWN;
389  return SCIP_OKAY;
390  }
391 
392  SCIP_CALL( readSolution(set) );
393  SCIPsetDebugMsg(set, "Now handling variable <%s>, which has status %d, is of type %d, and was deleted: %d, negated: %d, transformed: %d\n",
395 
396  /* ignore deleted variables */
397  if( SCIPvarIsDeleted(var) )
398  {
399  SCIPsetDebugMsg(set, "**** unknown solution value for deleted variable <%s>\n", SCIPvarGetName(var));
400  *val = SCIP_UNKNOWN;
401  return SCIP_OKAY;
402  }
403 
404  /* retransform variable onto original variable space */
405  solvar = var;
406  scalar = 1.0;
407  constant = 0.0;
408  if( SCIPvarIsNegated(solvar) )
409  {
410  scalar = -1.0;
411  constant = SCIPvarGetNegationConstant(solvar);
412  solvar = SCIPvarGetNegationVar(solvar);
413  }
414 
415  if( SCIPvarIsTransformed(solvar) )
416  {
417  SCIP_CALL( SCIPvarGetOrigvarSum(&solvar, &scalar, &constant) );
418  if( solvar == NULL )
419  {
420  /* if no original counterpart, then maybe someone added a value for the transformed variable, so search for var (or its negation) */
421  SCIPsetDebugMsg(set, "variable <%s> has no original counterpart\n", SCIPvarGetName(var));
422  solvar = var;
423  scalar = 1.0;
424  constant = 0.0;
425  if( SCIPvarIsNegated(solvar) )
426  {
427  scalar = -1.0;
428  constant = SCIPvarGetNegationConstant(solvar);
429  solvar = SCIPvarGetNegationVar(solvar);
430  }
431  }
432  }
433 
434  /* perform a binary search for the variable */
435  name = SCIPvarGetName(solvar);
436  left = 0;
437  right = debugsoldata->nsolvals-1;
438  while( left <= right )
439  {
440  middle = (left+right)/2;
441  cmp = strcmp(name, debugsoldata->solnames[middle]);
442  if( cmp < 0 )
443  right = middle-1;
444  else if( cmp > 0 )
445  left = middle+1;
446  else
447  {
448  *val = scalar * debugsoldata->solvals[middle] + constant;
449 
450  if( SCIPsetIsFeasLT(set, *val, SCIPvarGetLbGlobal(var)) || SCIPsetIsFeasGT(set, *val, SCIPvarGetUbGlobal(var)) )
451  {
452  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "invalid solution value %.15g for variable <%s>[%.15g,%.15g]\n",
453  *val, SCIPvarGetName(var), SCIPvarGetLbGlobal(var), SCIPvarGetUbGlobal(var));
454  }
455 
456  return SCIP_OKAY;
457  }
458  }
459  *val = constant;
460 
461  if( SCIPsetIsFeasLT(set, *val, SCIPvarGetLbGlobal(var)) || SCIPsetIsFeasGT(set, *val, SCIPvarGetUbGlobal(var)) )
462  {
463  SCIPmessagePrintWarning(SCIPgetMessagehdlr(set->scip), "invalid solution value %.15g for variable <%s>[%.15g,%.15g]\n",
464  *val, SCIPvarGetName(var), SCIPvarGetLbGlobal(var), SCIPvarGetUbGlobal(var));
465  }
466 
467  return SCIP_OKAY;
468 }
469 
470 /** gets pointer to the debug solution */
471 SCIP_RETCODE SCIPdebugGetSol(
472  SCIP* scip, /**< SCIP data structure */
473  SCIP_SOL** sol /**< buffer to store pointer to the debug solution */
474  )
475 {
476  SCIP_DEBUGSOLDATA* debugsoldata;
477 
478  debugsoldata = SCIPsetGetDebugSolData(scip->set);
479  assert(scip != NULL);
480  assert(sol != NULL);
481 
482  *sol = NULL;
483 
484  /* check whether a debug solution is available */
485  if( !debugSolutionAvailable(scip->set) )
486  return SCIP_OKAY;
487 
488  SCIP_CALL( readSolution(scip->set) );
489 
490  if( debugsoldata->debugsol == NULL )
491  return SCIP_ERROR;
492 
493  *sol = debugsoldata->debugsol;
494 
495  return SCIP_OKAY;
496 }
497 
498 /** gets value for a variable in the debug solution
499  *
500  * if no value is stored for the variable, gives 0.0
501  */
503  SCIP* scip, /**< SCIP data structure */
504  SCIP_VAR* var, /**< variable for which to get the value */
505  SCIP_Real* val /**< buffer to store solution value */
506  )
507 {
508  SCIP_CALL( getSolutionValue(scip->set, var, val) );
509 
510  return SCIP_OKAY;
511 }
512 
513 /** returns whether the debug solution is worse than the best known solution or if the debug solution was found */
514 static
515 SCIP_Bool debugSolIsAchieved(
516  SCIP_SET* set /**< global SCIP settings */
517  )
518 {
519  SCIP_SOL* bestsol;
520  SCIP* scip;
521  SCIP_DEBUGSOLDATA* debugsoldata;
522 
523  /* check whether a debug solution is available */
524  if( !debugSolutionAvailable(set) )
525  return SCIP_OKAY;
526 
527  assert(set != NULL);
528  debugsoldata = SCIPsetGetDebugSolData(set);
529 
530  assert(debugsoldata != NULL);
531 
532  if( debugsoldata->solisachieved )
533  return TRUE;
534 
535  assert(set != NULL);
536 
537  scip = set->scip;
538  assert(scip != NULL);
539 
540  bestsol = SCIPgetBestSol(scip);
541 
542  if( bestsol != NULL )
543  {
544  SCIP_Real solvalue;
545 
546  /* don't check solution while in problem creation stage */
547  if( SCIPsetGetStage(set) == SCIP_STAGE_PROBLEM )
548  return TRUE;
549 
550  solvalue = SCIPgetSolOrigObj(scip, bestsol);
551 
552  /* make sure a debug solution has been read, so we do not compare against the initial debugsolval == 0 */
553  SCIP_CALL( readSolution(set) );
554 
555  if( (SCIPgetObjsense(scip) == SCIP_OBJSENSE_MINIMIZE && SCIPsetIsLE(set, solvalue, debugsoldata->debugsolval))
556  || (SCIPgetObjsense(scip) == SCIP_OBJSENSE_MAXIMIZE && SCIPsetIsGE(set, solvalue, debugsoldata->debugsolval)) )
557  debugsoldata->solisachieved = TRUE;
558  }
559 
560  return debugsoldata->solisachieved;
561 }
562 
563 /** returns whether the solution is contained in node's subproblem */
564 static
565 SCIP_RETCODE isSolutionInNode(
566  BMS_BLKMEM* blkmem, /**< block memory */
567  SCIP_SET* set, /**< global SCIP settings */
568  SCIP_NODE* node, /**< local node where this bound change was applied */
569  SCIP_Bool* solcontained /**< pointer to store whether the solution is contained in node's subproblem */
570  )
571 {
572  SCIP_Bool* boolptr;
573  SCIP_DEBUGSOLDATA* debugsoldata;
574 
575  assert(set != NULL);
576  assert(blkmem != NULL);
577  assert(node != NULL);
578  assert(solcontained != NULL);
579 
580  /* check whether a debug solution is available */
581  if( !debugSolutionAvailable(set) )
582  return SCIP_OKAY;
583 
584  debugsoldata = SCIPsetGetDebugSolData(set);
585  assert(debugsoldata != NULL);
586 
587  if( debugsoldata ->debugsoldisabled )
588  {
589  *solcontained = FALSE;
590  return SCIP_OKAY;
591  }
592 
593  /* generate the hashmap */
594  if( debugsoldata->solinnode == NULL )
595  {
596  SCIP_CALL( SCIPhashmapCreate(&debugsoldata->solinnode, blkmem, SCIP_HASHSIZE_DEBUG) );
597  }
598 
599  /* check, whether we know already whether the solution is contained in the given node */
600  boolptr = (SCIP_Bool*)SCIPhashmapGetImage(debugsoldata->solinnode, (void*)node);
601  if( boolptr != NULL )
602  {
603  if( boolptr != &debugsoldata->falseptr && boolptr != &debugsoldata->trueptr )
604  {
605  SCIPerrorMessage("wrong value in node hashmap\n");
606  SCIPABORT();
607  return SCIP_ERROR;
608  }
609  *solcontained = *boolptr;
610  return SCIP_OKAY;
611  }
612 
613  /* if the solution is not contained in the parent of the node, it cannot be contained in the current node */
614  *solcontained = TRUE;
615  if( node->parent != NULL )
616  {
617  SCIP_CALL( isSolutionInNode(blkmem, set, node->parent, solcontained) );
618  }
619 
620  if( *solcontained )
621  {
622  /* check whether the bound changes at the current node remove the debugging solution from the subproblem */
623  if( node->domchg != NULL )
624  {
625  SCIP_DOMCHGBOUND* domchgbound;
626  SCIP_BOUNDCHG* boundchgs;
627  int i;
628 
629  domchgbound = &node->domchg->domchgbound;
630  boundchgs = domchgbound->boundchgs;
631  for( i = 0; i < (int)domchgbound->nboundchgs && *solcontained; ++i )
632  {
633  SCIP_Real varsol;
634 
635  /* get solution value of variable */
636  SCIP_CALL( getSolutionValue(set, boundchgs[i].var, &varsol) );
637 
638  if( varsol != SCIP_UNKNOWN ) /*lint !e777*/
639  {
640  /* compare the bound change with the solution value */
641  if( SCIPboundchgGetBoundtype(&boundchgs[i]) == SCIP_BOUNDTYPE_LOWER )
642  *solcontained = SCIPsetIsFeasGE(set, varsol, boundchgs[i].newbound);
643  else
644  *solcontained = SCIPsetIsFeasLE(set, varsol, boundchgs[i].newbound);
645 
646  if( !(*solcontained) && SCIPboundchgGetBoundchgtype(&boundchgs[i]) != SCIP_BOUNDCHGTYPE_BRANCHING )
647  {
648  SCIPerrorMessage("debugging solution was cut off in local node %p at depth %d by inference <%s>[%.15g] %s %.15g\n",
649  node, SCIPnodeGetDepth(node), SCIPvarGetName(boundchgs[i].var), varsol,
650  SCIPboundchgGetBoundtype(&boundchgs[i]) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=", boundchgs[i].newbound);
651  SCIPABORT();
652  }
653  }
654  else if( SCIPboundchgGetBoundchgtype(&boundchgs[i]) == SCIP_BOUNDCHGTYPE_BRANCHING )
655  {
656  /* we branched on a variable were we don't know the solution: no debugging can be applied in this subtree */
657  *solcontained = FALSE;
658  }
659  }
660  }
661  }
662 
663  /* remember the status of the current node */
664  SCIP_CALL( SCIPhashmapSetImage(debugsoldata->solinnode, (void*)node, *solcontained ? (void*)(&debugsoldata->trueptr) : (void*)(&debugsoldata->falseptr)) );
665 
666  return SCIP_OKAY;
667 }
668 
669 /** frees the debug solution */
671  SCIP_SET* set
672  )
673 {
674  SCIP_DEBUGSOLDATA* debugsoldata;
675 
676  debugsoldata = SCIPsetGetDebugSolData(set);
677  assert(debugsoldata != NULL);
678 
679  if( debugsoldata->debugsol != NULL && ((SCIPgetStage(set->scip) > SCIP_STAGE_PROBLEM && debugsoldata->debugsolstage > SCIP_STAGE_PROBLEM)
680  || (SCIPgetStage(set->scip) <= SCIP_STAGE_PROBLEM && debugsoldata->debugsolstage <= SCIP_STAGE_PROBLEM)) )
681  {
682  SCIP_CALL( SCIPfreeSol(set->scip, &debugsoldata->debugsol) );
683  }
684 
685  return SCIP_OKAY;
686 }
687 
688 /** resets the data structure after restart */
690  SCIP_SET* set
691  )
692 {
693  SCIP_DEBUGSOLDATA* debugsoldata;
694 
695  assert(set != NULL);
696 
697  debugsoldata = SCIPsetGetDebugSolData(set);
698  assert(debugsoldata != NULL);
699 
700  if( debugsoldata->solinnode != NULL )
701  {
702  SCIP_CALL( SCIPhashmapRemoveAll(debugsoldata->solinnode) );
703  }
704 
705  return SCIP_OKAY;
706 }
707 
708 /** frees all debugging solution data */
710  SCIP_SET* set /**< global SCIP settings */
711  )
712 {
713  int s;
714 
715  SCIP_DEBUGSOLDATA* debugsoldata;
716  assert(set != NULL);
717 
718  debugsoldata = SCIPsetGetDebugSolData(set);
719  assert(debugsoldata != NULL);
720 
721  for( s = debugsoldata->nsolvals - 1; s >= 0; --s )
722  BMSfreeMemoryArrayNull(&(debugsoldata->solnames[s]));
723 
724  BMSfreeMemoryArrayNull(&debugsoldata->solnames);
725  BMSfreeMemoryArrayNull(&debugsoldata->solvals);
726 
727  debugsoldata->nsolvals = 0;
728  debugsoldata->debugsolval= 0.0;
729  debugsoldata->solisachieved = FALSE;
730 
731  if( debugsoldata->solinnode != NULL)
732  SCIPhashmapFree(&debugsoldata->solinnode);
733 
734  /* free the debug solution */
735  SCIP_CALL( SCIPdebugFreeSol(set) );
736 
737  BMSfreeMemoryNull(&debugsoldata);
738 
739  set->debugsoldata = NULL;
740 
741  return SCIP_OKAY;
742 }
743 
744 /** checks for validity of the debugging solution in given constraints */
746  SCIP* scip, /**< SCIP data structure */
747  SCIP_CONS** conss, /**< constraints to check for validity */
748  int nconss /**< number of given constraints */
749  )
750 {
751  SCIP_RESULT result;
752  int c;
753 
754  SCIP_DEBUGSOLDATA* debugsoldata;
755  assert(scip->set != NULL);
756 
757  /* check if we are in the original problem and not in a sub MIP */
758  if( !SCIPdebugSolIsEnabled(scip) )
759  return SCIP_OKAY;
760 
761  /* check whether a debug solution is available */
762  if( !debugSolutionAvailable(scip->set) )
763  return SCIP_OKAY;
764 
765  debugsoldata = SCIPsetGetDebugSolData(scip->set);
766 
767  assert(conss != NULL || nconss == 0);
768  assert(debugsoldata->debugsol != NULL);
769 
770  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug
771  * solution
772  */
773  if( debugSolIsAchieved(scip->set) )
774  return SCIP_OKAY;
775 
776  result = SCIP_FEASIBLE;
777 
778  /* checking each given constraint against the debugging solution */
779  for( c = nconss - 1; c >= 0; --c )
780  {
781  assert(conss[c] != NULL);
782 
783  if( !SCIPconsIsActive(conss[c]) )
784  continue;
785 
786  assert(SCIPconsGetActiveDepth(conss[c]) <= SCIPgetDepth(scip));
787 
788  /* if the cons is only locally valid, check whether the debugging solution is contained in the local subproblem */
789  if( SCIPconsIsLocal(conss[c]) )
790  {
791  SCIP_Bool solcontained;
792 
793  SCIP_CALL( isSolutionInNode(SCIPblkmem(scip), scip->set, SCIPgetCurrentNode(scip), &solcontained) );
794  if( !solcontained )
795  return SCIP_OKAY;
796  }
797 
798  SCIP_CALL( SCIPcheckCons(scip, conss[c], debugsoldata->debugsol, TRUE, TRUE, TRUE, &result) );
799 
800  SCIPdebugMsg(scip, " -> checking of constraint %s returned result <%d>\n", SCIPconsGetName(conss[c]), result);
801 
802  if( result != SCIP_FEASIBLE )
803  {
804  SCIPerrorMessage("constraint %s violates the debugging solution\n", SCIPconsGetName(conss[c]));
805  SCIPABORT();
806  }
807  }
808 
809  return SCIP_OKAY;
810 }
811 
812 /** checks whether given row is valid for the debugging solution */
814  SCIP_SET* set, /**< global SCIP settings */
815  SCIP_ROW* row /**< row to check for validity */
816  )
817 {
818  SCIP_COL** cols;
819  SCIP_Real* vals;
820  SCIP_Real lhs;
821  SCIP_Real rhs;
822  int nnonz;
823  int i;
824  SCIP_Real minactivity;
825  SCIP_Real maxactivity;
826  SCIP_Real solval;
827 
828  assert(set != NULL);
829  assert(row != NULL);
830 
831  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
832  if( !SCIPdebugSolIsEnabled(set->scip) )
833  return SCIP_OKAY;
834 
835  /* check whether a debug solution is available */
836  if( !debugSolutionAvailable(set) )
837  return SCIP_OKAY;
838 
839  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
840  if( debugSolIsAchieved(set) )
841  return SCIP_OKAY;
842 
843  /* if the row is only locally valid, check whether the debugging solution is contained in the local subproblem */
844  if( SCIProwIsLocal(row) )
845  {
846  SCIP_Bool solcontained;
847 
848  SCIP_CALL( isSolutionInNode(SCIPblkmem(set->scip), set, SCIPgetCurrentNode(set->scip), &solcontained) );
849  if( !solcontained )
850  return SCIP_OKAY;
851  }
852 
853  cols = SCIProwGetCols(row);
854  vals = SCIProwGetVals(row);
855  nnonz = SCIProwGetNNonz(row);
856  lhs = SCIProwGetLhs(row);
857  rhs = SCIProwGetRhs(row);
858 
859  /* calculate row's activity on debugging solution */
860  minactivity = SCIProwGetConstant(row);
861  maxactivity = minactivity;
862  for( i = 0; i < nnonz; ++i )
863  {
864  SCIP_VAR* var;
865 
866  /* get solution value of variable in debugging solution */
867  var = SCIPcolGetVar(cols[i]);
868  SCIP_CALL( getSolutionValue(set, var, &solval) );
869 
870  if( solval != SCIP_UNKNOWN ) /*lint !e777*/
871  {
872  minactivity += vals[i] * solval;
873  maxactivity += vals[i] * solval;
874  }
875  else if( vals[i] > 0.0 )
876  {
877  minactivity += vals[i] * SCIPvarGetLbGlobal(var);
878  maxactivity += vals[i] * SCIPvarGetUbGlobal(var);
879  }
880  else if( vals[i] < 0.0 )
881  {
882  minactivity += vals[i] * SCIPvarGetUbGlobal(var);
883  maxactivity += vals[i] * SCIPvarGetLbGlobal(var);
884  }
885  }
886  SCIPsetDebugMsg(set, "debugging solution on row <%s>: %g <= [%g,%g] <= %g\n",
887  SCIProwGetName(row), lhs, minactivity, maxactivity, rhs);
888 
889  /* check row for violation, using absolute LP feasibility tolerance (as LP solver should do) */
890  if( maxactivity + SCIPsetLpfeastol(set) < lhs || minactivity - SCIPsetLpfeastol(set) > rhs )
891  {
892  printf("***** debug: row <%s> violates debugging solution (lhs=%.15g, rhs=%.15g, activity=[%.15g,%.15g], local=%u, lpfeastol=%g)\n",
893  SCIProwGetName(row), lhs, rhs, minactivity, maxactivity, SCIProwIsLocal(row), SCIPsetLpfeastol(set));
894  SCIProwPrint(row, SCIPgetMessagehdlr(set->scip), NULL);
895 
896  /* output row with solution values */
897  printf("\n\n");
898  printf("***** debug: violated row <%s>:\n", SCIProwGetName(row));
899  printf(" %.15g <= %.15g", lhs, SCIProwGetConstant(row));
900  for( i = 0; i < nnonz; ++i )
901  {
902  /* get solution value of variable in debugging solution */
903  SCIP_CALL( getSolutionValue(set, SCIPcolGetVar(cols[i]), &solval) );
904  printf(" %+.15g<%s>[%.15g]", vals[i], SCIPvarGetName(SCIPcolGetVar(cols[i])), solval);
905  }
906  printf(" <= %.15g\n", rhs);
907 
908  SCIPABORT();
909  }
910 
911  return SCIP_OKAY;
912 }
913 
914 /** checks whether given global lower bound is valid for the debugging solution */
916  SCIP* scip, /**< SCIP data structure */
917  SCIP_VAR* var, /**< problem variable */
918  SCIP_Real lb /**< lower bound */
919  )
920 {
921  SCIP_Real varsol;
922 
923  assert(scip != NULL);
924  assert(var != NULL);
925 
926  /* check if we are in the original problem and not in a sub MIP */
927  if( !SCIPdebugSolIsEnabled(scip) )
928  return SCIP_OKAY;
929 
930  /* check whether a debug solution is available */
931  if( !debugSolutionAvailable(scip->set) )
932  return SCIP_OKAY;
933 
934  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
935  if( debugSolIsAchieved(scip->set) )
936  return SCIP_OKAY;
937 
938  /* get solution value of variable */
939  SCIP_CALL( getSolutionValue(scip->set, var, &varsol) );
940  SCIPdebugMsg(scip, "debugging solution on lower bound of <%s>[%g] >= %g\n", SCIPvarGetName(var), varsol, lb);
941 
942  /* check validity of debugging solution */
943  if( varsol != SCIP_UNKNOWN && SCIPisFeasLT(scip, varsol, lb) ) /*lint !e777*/
944  {
945  SCIPerrorMessage("invalid global lower bound: <%s>[%.15g] >= %.15g\n", SCIPvarGetName(var), varsol, lb);
946  SCIPABORT();
947  }
948 
949  return SCIP_OKAY;
950 }
951 
952 /** checks whether given global upper bound is valid for the debugging solution */
954  SCIP* scip, /**< SCIP data structure */
955  SCIP_VAR* var, /**< problem variable */
956  SCIP_Real ub /**< upper bound */
957  )
958 {
959  SCIP_Real varsol;
960 
961  assert(scip != NULL);
962  assert(var != NULL);
963 
964  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
965  if( !SCIPdebugSolIsEnabled(scip) )
966  return SCIP_OKAY;
967 
968  /* check whether a debug solution is available */
969  if( !debugSolutionAvailable(scip->set) )
970  return SCIP_OKAY;
971 
972  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
973  if( debugSolIsAchieved(scip->set) )
974  return SCIP_OKAY;
975 
976  /* get solution value of variable */
977  SCIP_CALL( getSolutionValue(scip->set, var, &varsol) );
978  SCIPdebugMsg(scip, "debugging solution on upper bound of <%s>[%g] <= %g\n", SCIPvarGetName(var), varsol, ub);
979 
980  /* check validity of debugging solution */
981  if( varsol != SCIP_UNKNOWN && SCIPisFeasGT(scip, varsol, ub) ) /*lint !e777*/
982  {
983  SCIPerrorMessage("invalid global upper bound: <%s>[%.15g] <= %.15g\n", SCIPvarGetName(var), varsol, ub);
984  SCIPABORT();
985  }
986 
987  return SCIP_OKAY;
988 }
989 
990 /** checks whether given local bound implication is valid for the debugging solution */
992  BMS_BLKMEM* blkmem, /**< block memory */
993  SCIP_SET* set, /**< global SCIP settings */
994  SCIP_NODE* node, /**< local node where this bound change was applied */
995  SCIP_VAR* var, /**< problem variable */
996  SCIP_Real newbound, /**< new value for bound */
997  SCIP_BOUNDTYPE boundtype /**< type of bound: lower or upper bound */
998  )
999 {
1000  SCIP_Real varsol;
1001  SCIP_Bool solcontained;
1002 
1003  assert(set != NULL);
1004  assert(blkmem != NULL);
1005  assert(node != NULL);
1006  assert(var != NULL);
1007 
1008  /* in case we are in probing or diving we have to avoid checking the solution */
1009  if( SCIPlpDiving(set->scip->lp) || SCIPtreeProbing(set->scip->tree) )
1010  return SCIP_OKAY;
1011 
1012  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1013  if( !SCIPdebugSolIsEnabled(set->scip) )
1014  return SCIP_OKAY;
1015 
1016  /* check whether a debug solution is available */
1017  if( !debugSolutionAvailable(set) )
1018  return SCIP_OKAY;
1019 
1020  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1021  if( debugSolIsAchieved(set) )
1022  return SCIP_OKAY;
1023 
1024  /* check whether the debugging solution is contained in the local subproblem */
1025  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solcontained) );
1026  if( !solcontained )
1027  return SCIP_OKAY;
1028 
1029  /* get solution value of variable */
1030  SCIP_CALL( getSolutionValue(set, var, &varsol) );
1031 
1032  /* check validity of debugging solution */
1033  if( varsol != SCIP_UNKNOWN ) /*lint !e777*/
1034  {
1035  if( boundtype == SCIP_BOUNDTYPE_LOWER && SCIPsetIsFeasLT(set, varsol, newbound) )
1036  {
1037  SCIPerrorMessage("invalid local lower bound implication: <%s>[%.15g] >= %.15g\n", SCIPvarGetName(var), varsol, newbound);
1038  SCIPABORT();
1039  }
1040  if( boundtype == SCIP_BOUNDTYPE_UPPER && SCIPsetIsFeasGT(set, varsol, newbound) )
1041  {
1042  SCIPerrorMessage("invalid local upper bound implication: <%s>[%.15g] <= %.15g\n", SCIPvarGetName(var), varsol, newbound);
1043  SCIPABORT();
1044  }
1045  }
1046 
1047  return SCIP_OKAY;
1048 }
1049 
1050 /** informs solution debugger, that the given node will be freed */
1052  BMS_BLKMEM* blkmem, /**< block memory */
1053  SCIP_SET* set, /**< global SCIP settings */
1054  SCIP_NODE* node /**< node that will be freed */
1055  )
1056 {
1057  SCIP_DEBUGSOLDATA* debugsoldata;
1058 
1059  assert(set != NULL);
1060  assert(blkmem != NULL);
1061  assert(node != NULL);
1062 
1063  debugsoldata = SCIPsetGetDebugSolData(set);
1064  assert(debugsoldata != NULL);
1065 
1066  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1067  if( !SCIPdebugSolIsEnabled(set->scip) )
1068  return SCIP_OKAY;
1069 
1070  /* check whether a debug solution is available */
1071  if( !debugSolutionAvailable(set) )
1072  return SCIP_OKAY;
1073 
1074  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1075  if( debugSolIsAchieved(set) )
1076  return SCIP_OKAY;
1077 
1078  /* check if a solution will be cutoff in tree */
1079  if( SCIPgetStage(set->scip) != SCIP_STAGE_EXITSOLVE && SCIPgetStage(set->scip) != SCIP_STAGE_EXITPRESOLVE
1080  && SCIPnodeGetType(node) != SCIP_NODETYPE_PROBINGNODE && !SCIPisInRestart(set->scip) )
1081  {
1082  SCIP_Bool solisinnode;
1083 
1084  solisinnode = FALSE;
1085 
1086  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solisinnode) );
1087  /* wrong node will be cutoff */
1088  if( solisinnode )
1089  {
1090  SCIPerrorMessage("debugging solution was cut off in local node #%" SCIP_LONGINT_FORMAT " (%p) at depth %d\n",
1091  node->number, node, SCIPnodeGetDepth(node));
1092  SCIPABORT();
1093  }
1094  }
1095 
1096  /* remove node from the hash map */
1097  if( debugsoldata->solinnode != NULL )
1098  {
1099  SCIP_CALL( SCIPhashmapRemove(debugsoldata->solinnode, (void*)node) );
1100  }
1101 
1102  return SCIP_OKAY;
1103 }
1104 
1105 /** checks whether given variable bound is valid for the debugging solution */
1107  SCIP_SET* set, /**< global SCIP settings */
1108  SCIP_VAR* var, /**< problem variable x in x <= b*z + d or x >= b*z + d */
1109  SCIP_BOUNDTYPE vbtype, /**< type of variable bound (LOWER or UPPER) */
1110  SCIP_VAR* vbvar, /**< variable z in x <= b*z + d or x >= b*z + d */
1111  SCIP_Real vbcoef, /**< coefficient b in x <= b*z + d or x >= b*z + d */
1112  SCIP_Real vbconstant /**< constant d in x <= b*z + d or x >= b*z + d */
1113  )
1114 {
1115  SCIP_Real varsol;
1116  SCIP_Real vbvarsol;
1117  SCIP_Real vb;
1118 
1119  assert(set != NULL);
1120  assert(var != NULL);
1121 
1122  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1123  if( !SCIPdebugSolIsEnabled(set->scip) )
1124  return SCIP_OKAY;
1125 
1126  /* check whether a debug solution is available */
1127  if( !debugSolutionAvailable(set) )
1128  return SCIP_OKAY;
1129 
1130  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1131  if( debugSolIsAchieved(set) )
1132  return SCIP_OKAY;
1133 
1134  /* get solution value of variables */
1135  SCIP_CALL( getSolutionValue(set, var, &varsol) );
1136  SCIP_CALL( getSolutionValue(set, vbvar, &vbvarsol) );
1137 
1138  /* check validity of debugging solution */
1139  if( varsol != SCIP_UNKNOWN && vbvarsol != SCIP_UNKNOWN ) /*lint !e777*/
1140  {
1141  vb = vbcoef * vbvarsol + vbconstant;
1142  if( (vbtype == SCIP_BOUNDTYPE_LOWER && SCIPsetIsFeasLT(set, varsol, vb))
1143  || (vbtype == SCIP_BOUNDTYPE_UPPER && SCIPsetIsFeasGT(set, varsol, vb)) )
1144  {
1145  SCIPerrorMessage("invalid variable bound: <%s>[%.15g] %s %.15g<%s>[%.15g] %+.15g\n",
1146  SCIPvarGetName(var), varsol, vbtype == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=", vbcoef,
1147  SCIPvarGetName(vbvar), vbvarsol, vbconstant);
1148  SCIPABORT();
1149  }
1150  }
1151 
1152  return SCIP_OKAY;
1153 }
1154 
1155 /** checks whether given implication is valid for the debugging solution */
1157  SCIP_SET* set, /**< global SCIP settings */
1158  SCIP_VAR* var, /**< problem variable */
1159  SCIP_Bool varfixing, /**< FALSE if y should be added in implications for x == 0, TRUE for x == 1 */
1160  SCIP_VAR* implvar, /**< variable y in implication y <= b or y >= b */
1161  SCIP_BOUNDTYPE impltype, /**< type of implication y <= b (SCIP_BOUNDTYPE_UPPER) or y >= b (SCIP_BOUNDTYPE_LOWER) */
1162  SCIP_Real implbound /**< bound b in implication y <= b or y >= b */
1163  )
1164 {
1165  SCIP_Real solval;
1166 
1167  assert(set != NULL);
1168  assert(var != NULL);
1169  assert(SCIPvarGetType(var) == SCIP_VARTYPE_BINARY);
1170 
1171  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1172  if( !SCIPdebugSolIsEnabled(set->scip) )
1173  return SCIP_OKAY;
1174 
1175  /* check whether a debug solution is available */
1176  if( !debugSolutionAvailable(set) )
1177  return SCIP_OKAY;
1178 
1179  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1180  if( debugSolIsAchieved(set) )
1181  return SCIP_OKAY;
1182 
1183  /* get solution value of variable */
1184  SCIP_CALL( getSolutionValue(set, var, &solval) );
1185  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1186  return SCIP_OKAY;
1187  assert(SCIPsetIsFeasZero(set, solval) || SCIPsetIsFeasEQ(set, solval, 1.0));
1188 
1189  /* check, whether the implication applies for the debugging solution */
1190  if( (solval > 0.5) != varfixing )
1191  return SCIP_OKAY;
1192 
1193  /* get solution value of implied variable */
1194  SCIP_CALL( getSolutionValue(set, implvar, &solval) );
1195  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1196  return SCIP_OKAY;
1197 
1198  if( impltype == SCIP_BOUNDTYPE_LOWER )
1199  {
1200  if( SCIPsetIsFeasLT(set, solval, implbound) )
1201  {
1202  SCIPerrorMessage("invalid implication <%s> == %d -> <%s> >= %.15g (variable has value %.15g in solution)\n",
1203  SCIPvarGetName(var), varfixing, SCIPvarGetName(implvar), implbound, solval);
1204  SCIPABORT();
1205  }
1206  }
1207  else
1208  {
1209  if( SCIPsetIsFeasGT(set, solval, implbound) )
1210  {
1211  SCIPerrorMessage("invalid implication <%s> == %d -> <%s> <= %.15g (variable has value %.15g in solution)\n",
1212  SCIPvarGetName(var), varfixing, SCIPvarGetName(implvar), implbound, solval);
1213  SCIPABORT();
1214  }
1215  }
1216 
1217  return SCIP_OKAY;
1218 }
1219 
1220 /** check whether given clique is valid for the debugging solution */
1222  SCIP_SET* set, /**< global SCIP settings */
1223  SCIP_VAR** vars, /**< binary variables in the clique: at most one can be set to the given value */
1224  SCIP_Bool* values, /**< values of the variables in the clique; NULL to use TRUE for all vars */
1225  int nvars /**< number of variables in the clique */
1226  )
1227 {
1228  SCIP_Real solval;
1229  int pos1;
1230  int pos2;
1231  int v;
1232 
1233  assert(set != NULL);
1234  assert(vars != NULL);
1235 
1236  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1237  if( !SCIPdebugSolIsEnabled(set->scip) )
1238  return SCIP_OKAY;
1239 
1240  /* check whether a debug solution is available */
1241  if( !debugSolutionAvailable(set) )
1242  return SCIP_OKAY;
1243 
1244  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1245  if( debugSolIsAchieved(set) )
1246  return SCIP_OKAY;
1247 
1248  pos1 = -1;
1249  pos2 = -1;
1250 
1251  for( v = 0; v < nvars; ++v )
1252  {
1253  assert(vars[v] != NULL);
1254  assert(SCIPvarIsBinary(vars[v]));
1255 
1256  /* get solution value of variable */
1257  SCIP_CALL( getSolutionValue(set, vars[v], &solval) );
1258 
1259  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1260  continue;
1261 
1262  assert(SCIPsetIsFeasZero(set, solval) || SCIPsetIsFeasEQ(set, solval, 1.0));
1263 
1264  /* negated solution value if negated variable is in clique */
1265  if( values != NULL && values[v] == 0 )
1266  solval = 1.0 - solval;
1267 
1268  if( SCIPsetIsFeasEQ(set, solval, 1.0) )
1269  {
1270  if( pos1 == -1 )
1271  pos1 = v;
1272  else
1273  {
1274  assert(pos2 == -1);
1275  pos2 = v;
1276  break;
1277  }
1278  }
1279  }
1280 
1281  /* print debug message if the clique violates the debugging solution */
1282  if( pos2 != -1 )
1283  {
1284  assert(pos1 != -1);
1285  SCIPerrorMessage("clique violates debugging solution, (at least) variable <%s%s> and variable <%s%s> are both one in the debugging solution\n",
1286  (values == NULL || values[pos1]) ? "" : "~", SCIPvarGetName(vars[pos1]), (values == NULL || values[pos2]) ? "" : "~", SCIPvarGetName(vars[pos2]));
1287  SCIPABORT();
1288  }
1289 
1290  return SCIP_OKAY;
1291 }
1292 
1293 /** check, whether at least one literals is TRUE in the debugging solution */
1294 static
1295 SCIP_Bool debugCheckBdchginfos(
1296  SCIP_SET* set, /**< global SCIP settings */
1297  SCIP_BDCHGINFO** bdchginfos, /**< bound change informations of the conflict set */
1298  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict, or NULL */
1299  int nbdchginfos /**< number of bound changes in the conflict set */
1300  )
1301 {
1302  SCIP_Real solval;
1303  int i;
1304 
1305  /* check whether a debug solution is available */
1306  if( !debugSolutionAvailable(set) )
1307  return SCIP_OKAY;
1308 
1309  assert(SCIPdebugSolIsEnabled(set->scip));
1310 
1311  solval = 0.0;
1312  /* check, whether at least one literals is TRUE in the debugging solution */
1313  for( i = 0; i < nbdchginfos; ++i )
1314  {
1315  SCIP_BDCHGINFO* bdchginfo;
1316  SCIP_VAR* var;
1317  SCIP_Real newbound;
1318 
1319  bdchginfo = bdchginfos[i];
1320  assert(bdchginfo != NULL);
1321 
1322  var = SCIPbdchginfoGetVar(bdchginfo);
1323  assert(var != NULL);
1324 
1325  if( relaxedbds != NULL )
1326  newbound = relaxedbds[i];
1327  else
1328  newbound = SCIPbdchginfoGetNewbound(bdchginfo);
1329 
1330  SCIP_CALL( getSolutionValue(set, var, &solval) );
1331 
1332  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1333  return TRUE;
1334 
1336  {
1337  assert(SCIPsetIsLE(set, newbound, SCIPbdchginfoGetNewbound(bdchginfo)));
1338 
1340  {
1341  if( SCIPsetIsLE(set, solval, newbound) )
1342  return TRUE;
1343  }
1344  else
1345  {
1346  if( SCIPsetIsLT(set, solval, newbound) )
1347  return TRUE;
1348  }
1349  }
1350  else
1351  {
1352  assert(SCIPsetIsGE(set, newbound, SCIPbdchginfoGetNewbound(bdchginfo)));
1353 
1355  {
1356  if( SCIPsetIsGE(set, solval, newbound) )
1357  return TRUE;
1358  }
1359  else
1360  {
1361  if( SCIPsetIsGT(set, solval, newbound) )
1362  return TRUE;
1363  }
1364  }
1365  }
1366 
1367  return FALSE;
1368 }
1369 
1370 /** print bound change information */
1371 static
1372 SCIP_RETCODE printBdchginfo(
1373  SCIP_SET* set, /**< global SCIP settings */
1374  SCIP_BDCHGINFO * bdchginfo, /**< bound change information */
1375  SCIP_Real relaxedbd /**< array with relaxed bounds which are efficient to create a valid conflict, or NULL */
1376  )
1377 {
1378  SCIP_Real solval;
1379 
1380  /* check whether a debug solution is available */
1381  if( !debugSolutionAvailable(set) )
1382  return SCIP_OKAY;
1383 
1384  /* get solution value within the debug solution */
1385  SCIP_CALL( getSolutionValue(set, SCIPbdchginfoGetVar(bdchginfo), &solval) );
1386 
1387  printf(" <%s>[%.15g] %s %g(%g)", SCIPvarGetName(SCIPbdchginfoGetVar(bdchginfo)), solval,
1388  SCIPbdchginfoGetBoundtype(bdchginfo) == SCIP_BOUNDTYPE_LOWER ? ">=" : "<=",
1389  SCIPbdchginfoGetNewbound(bdchginfo), relaxedbd);
1390 
1391  return SCIP_OKAY;
1392 }
1393 
1394 
1395 /** print bound change information */
1396 static
1397 SCIP_RETCODE printBdchginfos(
1398  SCIP_SET* set, /**< global SCIP settings */
1399  SCIP_BDCHGINFO** bdchginfos, /**< bound change information array */
1400  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict, or NULL */
1401  int nbdchginfos /**< number of bound changes in the conflict set */
1402  )
1403 {
1404  int i;
1405 
1406  /* check whether a debug solution is available */
1407  if( !debugSolutionAvailable(set) )
1408  return SCIP_OKAY;
1409 
1410  for( i = 0; i < nbdchginfos; ++i )
1411  {
1412  SCIP_BDCHGINFO* bdchginfo;
1413 
1414  bdchginfo = bdchginfos[i];
1415  assert(bdchginfo != NULL);
1416 
1417  printBdchginfo(set, bdchginfo, relaxedbds != NULL ? relaxedbds[i] : SCIPbdchginfoGetNewbound(bdchginfo));
1418  }
1419 
1420  return SCIP_OKAY;
1421 }
1422 
1423 /** checks whether given conflict is valid for the debugging solution */
1425  BMS_BLKMEM* blkmem, /**< block memory */
1426  SCIP_SET* set, /**< global SCIP settings */
1427  SCIP_NODE* node, /**< node where the conflict clause is added */
1428  SCIP_BDCHGINFO** bdchginfos, /**< bound change informations of the conflict set */
1429  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict */
1430  int nbdchginfos /**< number of bound changes in the conflict set */
1431  )
1432 {
1433  SCIP_Bool solcontained;
1434 
1435  assert(set != NULL);
1436  assert(blkmem != NULL);
1437  assert(node != NULL);
1438  assert(nbdchginfos == 0 || bdchginfos != NULL);
1439 
1440  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1441  if( !SCIPdebugSolIsEnabled(set->scip) )
1442  return SCIP_OKAY;
1443 
1444  /* check whether a debug solution is available */
1445  if( !debugSolutionAvailable(set) )
1446  return SCIP_OKAY;
1447 
1448  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1449  if( debugSolIsAchieved(set) )
1450  return SCIP_OKAY;
1451 
1452  /* check whether the debugging solution is contained in the local subproblem */
1453  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solcontained) );
1454  if( !solcontained )
1455  return SCIP_OKAY;
1456 
1457  /* check, whether at least one literals is TRUE in the debugging solution */
1458  if( debugCheckBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) )
1459  return SCIP_OKAY;
1460 
1461  SCIPerrorMessage("invalid conflict set:");
1462 
1463  /* print bound changes which are already part of the conflict set */
1464  SCIP_CALL( printBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) );
1465 
1466  printf("\n");
1467  SCIPABORT();
1468 
1469  return SCIP_OKAY; /*lint !e527*/
1470 }
1471 
1472 /** checks whether given conflict graph frontier is valid for the debugging solution */
1474  BMS_BLKMEM* blkmem, /**< block memory */
1475  SCIP_SET* set, /**< global SCIP settings */
1476  SCIP_NODE* node, /**< node where the conflict clause is added */
1477  SCIP_BDCHGINFO* bdchginfo, /**< bound change info which got resolved, or NULL */
1478  SCIP_BDCHGINFO** bdchginfos, /**< bound change informations of the conflict set */
1479  SCIP_Real* relaxedbds, /**< array with relaxed bounds which are efficient to create a valid conflict */
1480  int nbdchginfos, /**< number of bound changes in the conflict set */
1481  SCIP_PQUEUE* bdchgqueue, /**< unprocessed conflict bound changes */
1482  SCIP_PQUEUE* forcedbdchgqueue /**< unprocessed conflict bound changes that must be resolved */
1483  )
1484 {
1485  SCIP_BDCHGINFO** bdchgqueued;
1486  SCIP_BDCHGINFO** forcedbdchgqueued;
1487  SCIP_Bool solcontained;
1488  int nbdchgqueued;
1489  int nforcedbdchgqueued;
1490 
1491  assert(set != NULL);
1492  assert(blkmem != NULL);
1493  assert(node != NULL);
1494  assert(nbdchginfos == 0 || bdchginfos != NULL);
1495 
1496  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1497  if( !SCIPdebugSolIsEnabled(set->scip) )
1498  return SCIP_OKAY;
1499 
1500  /* check whether a debug solution is available */
1501  if( !debugSolutionAvailable(set) )
1502  return SCIP_OKAY;
1503 
1504  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1505  if( debugSolIsAchieved(set) )
1506  return SCIP_OKAY;
1507 
1508  /* check whether the debugging solution is contained in the local subproblem */
1509  SCIP_CALL( isSolutionInNode(blkmem, set, node, &solcontained) );
1510  if( !solcontained )
1511  return SCIP_OKAY;
1512 
1513  /* check, whether one literals is TRUE in the debugging solution */
1514  if( debugCheckBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) )
1515  return SCIP_OKAY;
1516 
1517  /* get the elements of the bound change queue */
1518  bdchgqueued = (SCIP_BDCHGINFO**)SCIPpqueueElems(bdchgqueue);
1519  nbdchgqueued = SCIPpqueueNElems(bdchgqueue);
1520 
1521  /* check, whether one literals is TRUE in the debugging solution */
1522  if( debugCheckBdchginfos(set, bdchgqueued, NULL, nbdchgqueued) )
1523  return SCIP_OKAY;
1524 
1525  /* get the elements of the bound change queue */
1526  forcedbdchgqueued = (SCIP_BDCHGINFO**)SCIPpqueueElems(forcedbdchgqueue);
1527  nforcedbdchgqueued = SCIPpqueueNElems(forcedbdchgqueue);
1528 
1529  /* check, whether one literals is TRUE in the debugging solution */
1530  if( debugCheckBdchginfos(set, forcedbdchgqueued, NULL, nforcedbdchgqueued) )
1531  return SCIP_OKAY;
1532 
1533  SCIPerrorMessage("invalid conflict frontier");
1534 
1535  if( bdchginfo != NULL )
1536  {
1537  printf(" (after resolving bound change ");
1538  printBdchginfo(set, bdchginfo, SCIPbdchginfoGetNewbound(bdchginfo));
1539  printf(")");
1540  }
1541  printf(":");
1542 
1543  /* print bound changes which are already part of the conflict set */
1544  SCIP_CALL( printBdchginfos(set, bdchginfos, relaxedbds, nbdchginfos) );
1545 
1546  /* print bound changes which are queued */
1547  SCIP_CALL( printBdchginfos(set, bdchgqueued, NULL, nbdchgqueued) );
1548 
1549  /* print bound changes which are queued in the force queue */
1550  SCIP_CALL( printBdchginfos(set, forcedbdchgqueued, NULL, nforcedbdchgqueued) );
1551 
1552  printf("\n");
1553  SCIPABORT();
1554 
1555  return SCIP_OKAY; /*lint !e527*/
1556 }
1557 
1558 /** check whether the debugging solution is valid in the current node */
1560  SCIP* scip, /**< SCIP data structure */
1561  SCIP_Bool* isvalidinsubtree /**< pointer to store whether the solution is valid in the current
1562  * subtree */
1563  )
1564 {
1565  SCIP_Bool solcontained;
1566 
1567  *isvalidinsubtree = FALSE;
1568 
1569  assert(scip->set != NULL);
1570 
1571  /* when debugging was disabled the solution is not defined to be not valid in the current subtree */
1572  if( !SCIPdebugSolIsEnabled(scip) )
1573  return SCIP_OKAY;
1574 
1575  /* check whether a debug solution is available */
1576  if( !debugSolutionAvailable(scip->set) )
1577  return SCIP_OKAY;
1578 
1579  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1580  if( debugSolIsAchieved(scip->set) )
1581  return SCIP_OKAY;
1582 
1583  /* check whether the debugging solution is contained in the local subproblem */
1584  SCIP_CALL( isSolutionInNode(SCIPblkmem(scip), scip->set, SCIPgetCurrentNode(scip), &solcontained) );
1585 
1586  if( solcontained )
1587  *isvalidinsubtree = TRUE;
1588 
1589  return SCIP_OKAY;
1590 }
1591 
1592 /** checks whether SCIP data structure is the main SCIP (the one for which debugging is enabled) */
1593 SCIP_Bool SCIPdebugIsMainscip(
1594  SCIP* scip /**< SCIP data structure */
1595  )
1596 {
1597  assert(scip != NULL);
1598 
1599  return SCIPdebugSolIsEnabled(scip);
1600 }
1601 
1602 /** enabling solution debugging mechanism */
1603 void SCIPdebugSolEnable(
1604  SCIP* scip /**< SCIP data structure */
1605  )
1606 {
1607  SCIP_DEBUGSOLDATA* debugsoldata;
1608  assert(scip != NULL);
1609  assert(scip->set != NULL);
1610 
1611  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1612  assert(debugsoldata != NULL);
1613 
1614  debugsoldata->debugsoldisabled = FALSE;
1615 }
1616 
1617 /** disabling solution debugging mechanism */
1618 void SCIPdebugSolDisable(
1619  SCIP* scip /**< SCIP data structure */
1620  )
1621 {
1622  SCIP_DEBUGSOLDATA* debugsoldata;
1623  assert(scip != NULL);
1624  assert(scip->set != NULL);
1625 
1626  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1627  assert(debugsoldata != NULL);
1628 
1629  debugsoldata->debugsoldisabled = TRUE;
1630 }
1631 
1632 /** check if solution debugging mechanism is enabled */
1634  SCIP* scip /**< SCIP data structure */
1635  )
1636 {
1637  SCIP_DEBUGSOLDATA* debugsoldata;
1638  assert(scip != NULL);
1639  assert(scip->set != NULL);
1640 
1641  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1642  assert(debugsoldata != NULL);
1643 
1644  return (!debugsoldata->debugsoldisabled);
1645 }
1646 
1647 /** propagator to force finding the debugging solution */
1648 static
1649 SCIP_DECL_PROPEXEC(propExecDebug)
1650 { /*lint --e{715}*/
1651  SCIP_VAR** vars;
1652  int nvars;
1653  int i;
1654 
1655  assert(scip != NULL);
1656  assert(result != NULL);
1657 
1658  *result = SCIP_DIDNOTFIND;
1659 
1660  /* check if we are in the original problem and not in a sub MIP */
1661  if( !SCIPdebugIsMainscip(scip) )
1662  return SCIP_OKAY;
1663 
1664  if( SCIPgetStage(scip) != SCIP_STAGE_SOLVING )
1665  return SCIP_OKAY;
1666 
1667  /* check whether a debug solution is available */
1668  if( !debugSolutionAvailable(scip->set) )
1669  return SCIP_OKAY;
1670 
1671  /* check if the incumbent solution is at least as good as the debug solution, so we can stop to check the debug solution */
1672  if( debugSolIsAchieved(scip->set) )
1673  return SCIP_OKAY;
1674 
1675 #if 1
1676  /* solve at least one LP */
1677  if( SCIPgetNLPIterations(scip) == 0 )
1678  return SCIP_OKAY;
1679 #endif
1680 
1681  vars = SCIPgetOrigVars(scip);
1682  nvars = SCIPgetNOrigVars(scip);
1683  for( i = 0; i < nvars; ++i )
1684  {
1685  SCIP_Real solval;
1686  SCIP_Real lb;
1687  SCIP_Real ub;
1688  SCIP_Bool infeasible;
1689  SCIP_Bool fixed;
1690 
1691  SCIP_CALL( getSolutionValue(scip->set, vars[i], &solval) );
1692  if( solval == SCIP_UNKNOWN ) /*lint !e777*/
1693  {
1694  SCIPerrorMessage("original variable without debugging solution value\n");
1695  SCIPABORT();
1696  }
1697 
1698  lb = SCIPvarGetLbGlobal(vars[i]);
1699  ub = SCIPvarGetUbGlobal(vars[i]);
1700  if( SCIPisLT(scip, solval, lb) || SCIPisGT(scip, solval, ub) )
1701  {
1702  SCIPerrorMessage("solution value %.15g of <%s> outside bounds loc=[%.15g,%.15g], glb=[%.15g,%.15g]\n",
1703  solval, SCIPvarGetName(vars[i]), lb, ub, SCIPvarGetLbGlobal(vars[i]), SCIPvarGetUbGlobal(vars[i]));
1704  SCIPABORT();
1705  }
1706 
1707  SCIP_CALL( SCIPfixVar(scip, vars[i], solval, &infeasible, &fixed) );
1708  if( infeasible )
1709  *result = SCIP_CUTOFF;
1710  else if( fixed )
1711  *result = SCIP_REDUCEDDOM;
1712  }
1713 
1714  return SCIP_OKAY;
1715 }
1716 
1717 /** creates the debugging propagator and includes it in SCIP */
1719  SCIP* scip /**< SCIP data structure */
1720  )
1721 {
1722  assert(scip != NULL);
1723 
1724  /* include propagator */
1725  SCIP_CALL( SCIPincludeProp(scip, "debug", "debugging propagator", 99999999, -1, FALSE,
1726  SCIP_PROPTIMING_ALWAYS, 99999999, 0, SCIP_PRESOLTIMING_FAST, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
1727  NULL, propExecDebug, NULL, NULL) );
1728 
1729  return SCIP_OKAY;
1730 }
1731 
1732 /** adds a solution value for a new variable in the transformed problem that has no original counterpart
1733  * a value can only be set if no value has been set for this variable before
1734  */
1736  SCIP* scip, /**< SCIP data structure */
1737  SCIP_VAR* var, /**< variable for which to add a value */
1738  SCIP_Real val /**< solution value for variable */
1739  )
1740 {
1741  SCIP_DEBUGSOLDATA* debugsoldata;
1742  SCIP_Real testval;
1743  const char* varname;
1744  int i;
1745 
1746  assert(scip != NULL);
1747  assert(var != NULL);
1748  assert(scip->set != NULL);
1749 
1750  debugsoldata = SCIPsetGetDebugSolData(scip->set);
1751  assert(debugsoldata != NULL);
1752 
1753  /* assert that we are in the SCIP instance that we are debugging and not some different (subSCIP,
1754  * auxiliary CIP, ...)
1755  */
1756  if( !SCIPdebugSolIsEnabled(scip) )
1757  return SCIP_OKAY;
1758 
1759  /* check whether a debug solution is available */
1760  if( !debugSolutionAvailable(scip->set) )
1761  return SCIP_OKAY;
1762 
1763  if( debugsoldata->debugsol == NULL )
1764  {
1765  /* make sure a debug solution has been read, so we do not compare against the initial debugsolval == 0 */
1766  SCIP_CALL( readSolution(scip->set) );
1767  }
1768 
1769  /* allocate memory */
1770  if( debugsoldata->nsolvals >= debugsoldata->solsize )
1771  {
1772  debugsoldata->solsize = MAX(2*debugsoldata->solsize, debugsoldata->nsolvals+1);
1773  SCIP_ALLOC( BMSreallocMemoryArray(&debugsoldata->solnames, debugsoldata->solsize) );
1774  SCIP_ALLOC( BMSreallocMemoryArray(&debugsoldata->solvals, debugsoldata->solsize) );
1775  }
1776  assert(debugsoldata->nsolvals < debugsoldata->solsize);
1777 
1778  /* store solution value in sorted list */
1779  varname = SCIPvarGetName(var);
1780  for( i = debugsoldata->nsolvals; i > 0 && strcmp(varname, debugsoldata->solnames[i-1]) < 0; --i )
1781  {
1782  debugsoldata->solnames[i] = debugsoldata->solnames[i-1];
1783  debugsoldata->solvals[i] = debugsoldata->solvals[i-1];
1784  }
1785  if( i > 0 && strcmp(varname, debugsoldata->solnames[i-1]) == 0 )
1786  {
1787  if( REALABS(debugsoldata->solvals[i-1] - val) > 1e-9 )
1788  {
1789  SCIPerrorMessage("already have stored different debugging solution value (%g) for variable <%s>, cannot store %g\n", debugsoldata->solvals[i-1], varname, val);
1790  return SCIP_ERROR;
1791  }
1792  else
1793  {
1794  SCIPdebugMsg(scip, "already have stored debugging solution value %g for variable <%s>, do not store same value again\n", val, varname);
1795  for( ; i < debugsoldata->nsolvals; ++i )
1796  {
1797  debugsoldata->solnames[i] = debugsoldata->solnames[i+1];
1798  debugsoldata->solvals[i] = debugsoldata->solvals[i+1];
1799  }
1800  return SCIP_OKAY;
1801  }
1802  }
1803 
1804  /* insert new solution value */
1805  SCIP_ALLOC( BMSduplicateMemoryArray(&(debugsoldata->solnames[i]), varname, strlen(varname)+1) );
1806  SCIPdebugMsg(scip, "add variable <%s>: value <%g>\n", debugsoldata->solnames[i], val);
1807  debugsoldata->solvals[i] = val;
1808  debugsoldata->nsolvals++;
1809 
1810  /* update objective function value of debug solution */
1811  debugsoldata->debugsolval += debugsoldata->solvals[i] * SCIPvarGetObj(var);
1812  SCIPdebugMsg(scip, "Debug Solution value is now %g.\n", debugsoldata->debugsolval);
1813 
1815  {
1816  /* add values to SCIP debug solution */
1817  SCIP_CALL( SCIPsetSolVal(scip, debugsoldata->debugsol, var, debugsoldata->solvals[i] ) );
1818  }
1819 
1820  /* get solution value once to produce warning if solution was cut off */
1821  SCIPdebugGetSolVal(scip, var, &testval);
1822 
1823  return SCIP_OKAY;
1824 }
1825 
1826 #else
1827 
1828 /** this is a dummy method to make the SunOS gcc linker happy */
1829 extern void SCIPdummyDebugMethodForSun(void);
1831 {
1832  return;
1833 }
1834 
1835 #endif
1836 
1837 
1838 /*
1839  * debug method for LP interface, to check if the LP interface works correct
1840  */
1841 #ifdef SCIP_DEBUG_LP_INTERFACE
1842 
1843 /* check whether coef is the r-th row of the inverse basis matrix B^-1; this is
1844  * the case if( coef * B ) is the r-th unit vector */
1846  SCIP* scip, /**< SCIP data structure */
1847  int r, /**< row number */
1848  SCIP_Real* coef /**< r-th row of the inverse basis matrix */
1849  )
1850 {
1851  SCIP_Real vecval;
1852  SCIP_Real matrixval;
1853  int* basisind;
1854  int nrows;
1855  int idx;
1856  int i;
1857  int k;
1858 
1859  assert(scip != NULL);
1860 
1861  nrows = SCIPgetNLPRows(scip);
1862 
1863  /* get basic indices for the basic matrix B */
1864  SCIP_CALL( SCIPallocBufferArray(scip, &basisind, nrows) );
1865  SCIP_CALL( SCIPgetLPBasisInd(scip, basisind) );
1866 
1867 
1868  /* loop over the columns of B */
1869  for( k = 0; k < nrows; ++k )
1870  {
1871  vecval = 0.0;
1872 
1873  /* indices of basic columns and rows:
1874  * - index i >= 0 corresponds to column i,
1875  * - index i < 0 to row -i-1
1876  */
1877  idx = basisind[k];
1878 
1879  /* check if we have a slack variable; this is the case if idx < 0 */
1880  if( idx >= 0 )
1881  {
1882  /* loop over the rows to compute the corresponding value in the unit vector */
1883  for( i = 0; i < nrows; ++i )
1884  {
1885  SCIP_CALL( SCIPlpiGetCoef(scip->lp->lpi, i, idx, &matrixval) );
1886  vecval += coef[i] * matrixval;
1887  }
1888  }
1889  else
1890  {
1891  assert( idx < 0 );
1892 
1893  /* retransform idx
1894  * - index i >= 0 corresponds to column i,
1895  * - index i < 0 to row -i-1
1896  */
1897  idx = -idx - 1;
1898  assert( idx >= 0 && idx < nrows );
1899 
1900  /* since idx < 0 we are in the case of a slack variable, i.e., the corresponding column
1901  is the idx-unit vector; note that some LP solver return a -idx-unit vector */
1902  /* vecval = REALABS(coef[idx]);*/
1903  vecval = coef[idx];
1904  }
1905 
1906  /* check if vecval fits to the r-th unit vector */
1907  if( k == r && !SCIPisFeasEQ(scip, vecval, 1.0) )
1908  {
1909  /* we expected a 1.0 and found something different */
1910  SCIPmessagePrintWarning(SCIPgetMessagehdlr(scip), "checked SCIPgetLPBInvRow() found value <%g> expected 1.0\n", vecval);
1911  }
1912  else if( k != r && !SCIPisFeasZero(scip, vecval) )
1913  {
1914  /* we expected a 0.0 and found something different */
1915  SCIPmessagePrintWarning(SCIPgetMessagehdlr(scip), "checked SCIPgetLPBInvRow() found value <%g> expected 0.0\n", vecval);
1916  }
1917  }
1918 
1919  SCIPfreeBufferArray(scip, &basisind);
1920 
1921  return SCIP_OKAY;
1922 }
1923 
1924 #endif
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition: type_lp.h:50
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:47363
int SCIPpqueueNElems(SCIP_PQUEUE *pqueue)
Definition: misc.c:1263
SCIP_Bool SCIPsetIsLE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5834
SCIP_Bool SCIPsetIsFeasZero(SCIP_SET *set, SCIP_Real val)
Definition: set.c:6284
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:47298
SCIP_Bool SCIPlpDiving(SCIP_LP *lp)
Definition: lp.c:16992
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
Definition: scip.c:41404
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip.c:821
#define SCIPdebugRemoveNode(blkmem, set, node)
Definition: debug.h:254
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:130
internal methods for branch and bound tree
SCIP_Longint SCIPgetNLPIterations(SCIP *scip)
Definition: scip.c:42333
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:47311
#define SCIPdebugFreeDebugData(set)
Definition: debug.h:248
SCIP_Bool SCIPsetIsFeasEQ(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6174
SCIP_VAR * SCIPbdchginfoGetVar(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:17878
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17276
#define SCIP_MAXSTRLEN
Definition: def.h:259
SCIP_BOUNDCHG * boundchgs
Definition: struct_var.h:125
int SCIProwGetNNonz(SCIP_ROW *row)
Definition: lp.c:16405
#define SCIPdebugCheckImplic(set, var, varfixing, implvar, impltype, implbound)
Definition: debug.h:256
int SCIPgetNOrigVars(SCIP *scip)
Definition: scip.c:12252
#define SCIPdebugSolDataCreate(debugsoldata)
Definition: debug.h:245
const char * SCIProwGetName(SCIP_ROW *row)
Definition: lp.c:16543
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:16842
SCIP_Real SCIPsetInfinity(SCIP_SET *set)
Definition: set.c:5636
SCIP_BOUNDTYPE SCIPboundchgGetBoundtype(SCIP_BOUNDCHG *boundchg)
Definition: var.c:16589
unsigned int nboundchgs
Definition: struct_var.h:123
#define SCIPdebugCheckClique(set, vars, values, nvars)
Definition: debug.h:257
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
Definition: lp.c:16484
#define FALSE
Definition: def.h:64
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2793
#define TRUE
Definition: def.h:63
#define SCIPdebugCheckRow(set, row)
Definition: debug.h:250
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_Real SCIPvarGetNegationConstant(SCIP_VAR *var)
Definition: var.c:17113
SCIP_VAR ** SCIPgetOrigVars(SCIP *scip)
Definition: scip.c:12225
#define BMSallocMemoryArray(ptr, num)
Definition: memory.h:105
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
Definition: scip.c:1235
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2931
int SCIPnodeGetDepth(SCIP_NODE *node)
Definition: tree.c:7352
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:22632
#define SCIP_DECL_PROPEXEC(x)
Definition: type_prop.h:203
#define SCIPdebugCheckVbound(set, var, vbtype, vbvar, vbcoef, vbconstant)
Definition: debug.h:255
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
Definition: var.c:17102
#define SCIPdebugMsg
Definition: scip.h:455
internal methods for LP management
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:8047
SCIP_Longint number
Definition: struct_tree.h:132
SCIP_RETCODE SCIPcreateOrigSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:38115
#define SCIP_PRESOLTIMING_FAST
Definition: type_timing.h:43
SCIP_Bool SCIPsetIsGE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5870
#define SCIPdebugCheckConflict(blkmem, set, node, bdchginfos, relaxedbds, nliterals)
Definition: debug.h:258
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
Definition: scip.c:12506
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
Definition: fileio.c:140
struct SCIP_DebugSolData SCIP_DEBUGSOLDATA
Definition: debug.h:44
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17286
SCIP_Bool SCIPsetIsLT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5816
SCIP_DOMCHG * domchg
Definition: struct_tree.h:148
SCIP_Bool SCIPtreeProbing(SCIP_TREE *tree)
Definition: tree.c:8184
#define SCIPdebugIncludeProp(scip)
Definition: debug.h:260
#define BMSfreeMemoryArray(ptr)
Definition: memory.h:129
internal methods for storing and manipulating the main problem
SCIP_Real SCIPsetLpfeastol(SCIP_SET *set)
Definition: set.c:5698
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:46976
#define SCIPdebugCheckInference(blkmem, set, node, var, newbound, boundtype)
Definition: debug.h:253
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
Definition: lp.c:16593
SCIP_Bool SCIPvarIsTransformedOrigvar(SCIP_VAR *var)
Definition: var.c:12271
int SCIPfeof(SCIP_FILE *stream)
Definition: fileio.c:214
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:46731
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.c:28690
struct SCIP_File SCIP_FILE
Definition: pub_fileio.h:34
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
Definition: fileio.c:187
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7986
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16662
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2826
void SCIPmessagePrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
Definition: message.c:417
#define REALABS(x)
Definition: def.h:173
#define SCIP_PROPTIMING_ALWAYS
Definition: type_timing.h:64
int SCIPgetNLPRows(SCIP *scip)
Definition: scip.c:29696
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:350
SCIP main data structure.
SCIP_Bool SCIPsetIsFeasGE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6262
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:47337
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
Definition: lp.c:16494
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip.c:1360
void SCIPdummyDebugMethodForSun(void)
Definition: debug.c:1830
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8225
#define SCIPdebugCheckBInvRow(scip, r, coef)
Definition: debug.h:286
#define SCIPdebugCheckLbGlobal(scip, var, lb)
Definition: debug.h:251
SCIP_LPI * lpi
Definition: struct_lp.h:282
#define SCIPdebugGetSolVal(scip, var, val)
Definition: debug.h:262
void SCIProwPrint(SCIP_ROW *row, SCIP_MESSAGEHDLR *messagehdlr, FILE *file)
Definition: lp.c:5174
SCIP_Bool SCIPsetIsFeasLE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6218
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
Definition: lp.c:16430
#define SCIPdebugCheckUbGlobal(scip, var, ub)
Definition: debug.h:252
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:125
#define SCIPdebugCheckConss(scip, conss, nconss)
Definition: debug.h:249
internal methods for problem variables
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:22620
#define SCIP_UNKNOWN
Definition: def.h:170
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:38771
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
Definition: lp.c:16440
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:61
SCIP_BOUNDCHGTYPE SCIPboundchgGetBoundchgtype(SCIP_BOUNDCHG *boundchg)
Definition: var.c:16579
void SCIPprintSysError(const char *message)
Definition: misc.c:9920
SCIP_RETCODE SCIPhashmapRemoveAll(SCIP_HASHMAP *hashmap)
Definition: misc.c:3214
int SCIPgetDepth(SCIP *scip)
Definition: scip.c:43045
#define SCIPdebugSolIsValidInSubtree(scip, isvalidinsubtree)
Definition: debug.h:263
#define MAX(x, y)
Definition: tclique_def.h:75
#define SCIPdebugCheckConflictFrontier(blkmem, set, node, bdchginfo, bdchginfos, relaxedbds, nliterals, bdchgqueue, forcedbdchgqueue)
Definition: debug.h:259
methods for debugging
#define SCIPsetDebugMsg
Definition: set.h:1913
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip.c:38535
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17124
SCIP_Real SCIPbdchginfoGetNewbound(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:17868
void ** SCIPpqueueElems(SCIP_PQUEUE *pqueue)
Definition: misc.c:1274
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip.c:25575
SCIP_RETCODE SCIPgetLPBasisInd(SCIP *scip, int *basisind)
Definition: scip.c:29756
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:38994
SCIP_RETCODE SCIPvarGetOrigvarSum(SCIP_VAR **var, SCIP_Real *scalar, SCIP_Real *constant)
Definition: var.c:12184
SCIP_Bool SCIPsetIsFeasLT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6196
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
Definition: lp.c:16450
#define SCIPdebugReset(set)
Definition: debug.h:247
SCIP_DOMCHGBOUND domchgbound
Definition: struct_var.h:153
SCIP_RETCODE SCIPhashmapRemove(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3041
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip.c:39882
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:47002
SCIP_NODE * parent
Definition: struct_tree.h:146
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
Definition: lp.c:16254
#define SCIP_DECL_SORTPTRCOMP(x)
Definition: type_misc.h:163
#define BMSfreeMemoryNull(ptr)
Definition: memory.h:128
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_Bool SCIPsetIsGT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5852
SCIP_RETCODE SCIPhashmapSetImage(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:2971
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16781
#define SCIPdebugSolDisable(scip)
Definition: debug.h:265
SCIP_NODETYPE SCIPnodeGetType(SCIP_NODE *node)
Definition: tree.c:7332
#define SCIP_Real
Definition: def.h:149
enum SCIP_Stage SCIP_STAGE
Definition: type_set.h:50
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.c:7605
SCIP_DEBUGSOLDATA * SCIPsetGetDebugSolData(SCIP_SET *set)
Definition: set.c:5529
#define BMSallocMemory(ptr)
Definition: memory.h:101
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:109
void SCIPsortPtrReal(void **ptrarray, SCIP_Real *realarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
#define SCIPdebugAddSolVal(scip, var, val)
Definition: debug.h:261
SCIP_Bool SCIPsetIsFeasGT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:6240
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16827
SCIP_OBJSENSE SCIPgetObjsense(SCIP *scip)
Definition: scip.c:11049
SCIP_RETCODE SCIPsetSolVals(SCIP *scip, SCIP_SOL *sol, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:38813
#define SCIPdebugSolIsEnabled(scip)
Definition: debug.h:266
SCIP_STAGE SCIPsetGetStage(SCIP_SET *set)
Definition: set.c:2781
int SCIPconsGetActiveDepth(SCIP_CONS *cons)
Definition: cons.c:8036
SCIP_Bool SCIPvarIsTransformed(SCIP_VAR *var)
Definition: var.c:16804
SCIP_RETCODE SCIPlpiGetCoef(SCIP_LPI *lpi, int row, int col, SCIP_Real *val)
SCIP_BOUNDTYPE SCIPbdchginfoGetBoundtype(SCIP_BDCHGINFO *bdchginfo)
Definition: var.c:17898
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:419
int SCIPfclose(SCIP_FILE *fp)
Definition: fileio.c:219
SCIP_LP * lp
Definition: struct_scip.h:80
#define SCIP_ALLOC(x)
Definition: def.h:361
#define SCIPdebugSolEnable(scip)
Definition: debug.h:264
#define SCIPABORT()
Definition: def.h:322
SCIP_Bool SCIPvarIsDeleted(SCIP_VAR *var)
Definition: var.c:16883
SCIP_Bool SCIPisInRestart(SCIP *scip)
Definition: scip.c:17582
#define SCIPdebugFreeSol(set)
Definition: debug.h:246
SCIP callable library.
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:16817
memory allocation routines