Scippy

SCIP

Solving Constraint Integer Programs

prob.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file prob.c
17  * @brief Methods and datastructures for storing and manipulating the main problem
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <assert.h>
24 #include <string.h>
25 
26 #include "scip/def.h"
27 #include "scip/set.h"
28 #include "scip/stat.h"
29 #include "scip/event.h"
30 #include "scip/lp.h"
31 #include "scip/var.h"
32 #include "scip/prob.h"
33 #include "scip/primal.h"
34 #include "scip/tree.h"
35 #include "scip/reopt.h"
36 #include "scip/branch.h"
37 #include "scip/cons.h"
38 #include "scip/conflictstore.h"
39 #include "scip/pub_message.h"
40 #include "scip/pub_misc.h"
41 
42 
43 #define OBJSCALE_MAXDNOM 1000000LL /**< maximal denominator in objective integral scaling */
44 #define OBJSCALE_MAXSCALE 1000000.0 /**< maximal scalar to reach objective integrality */
45 #define OBJSCALE_MAXFINALSCALE 1000.0 /**< maximal final value to apply as scaling */
46 
47 
48 
49 /*
50  * dymanic memory arrays
51  */
52 
53 /** resizes vars array to be able to store at least num entries */
54 static
56  SCIP_PROB* prob, /**< problem data */
57  SCIP_SET* set, /**< global SCIP settings */
58  int num /**< minimal number of slots in array */
59  )
60 {
61  assert(prob != NULL);
62  assert(set != NULL);
63 
64  if( num > prob->varssize )
65  {
66  int newsize;
67 
68  newsize = SCIPsetCalcMemGrowSize(set, num);
69  SCIP_ALLOC( BMSreallocMemoryArray(&prob->vars, newsize) );
70  prob->varssize = newsize;
71  }
72  assert(num <= prob->varssize);
73 
74  return SCIP_OKAY;
75 }
76 
77 /** resizes fixedvars array to be able to store at least num entries */
78 static
80  SCIP_PROB* prob, /**< problem data */
81  SCIP_SET* set, /**< global SCIP settings */
82  int num /**< minimal number of slots in array */
83  )
84 {
85  assert(prob != NULL);
86  assert(set != NULL);
87 
88  if( num > prob->fixedvarssize )
89  {
90  int newsize;
91 
92  newsize = SCIPsetCalcMemGrowSize(set, num);
93  SCIP_ALLOC( BMSreallocMemoryArray(&prob->fixedvars, newsize) );
94  prob->fixedvarssize = newsize;
95  }
96  assert(num <= prob->fixedvarssize);
97 
98  return SCIP_OKAY;
99 }
100 
101 /** resizes deletedvars array to be able to store at least num entries */
102 static
104  SCIP_PROB* prob, /**< problem data */
105  SCIP_SET* set, /**< global SCIP settings */
106  int num /**< minimal number of slots in array */
107  )
108 {
109  assert(prob != NULL);
110  assert(set != NULL);
111 
112  if( num > prob->deletedvarssize )
113  {
114  int newsize;
115 
116  newsize = SCIPsetCalcMemGrowSize(set, num);
117  SCIP_ALLOC( BMSreallocMemoryArray(&prob->deletedvars, newsize) );
118  prob->deletedvarssize = newsize;
119  }
120  assert(num <= prob->deletedvarssize);
121 
122  return SCIP_OKAY;
123 }
124 
125 /** resizes conss array to be able to store at least num entries */
126 static
128  SCIP_PROB* prob, /**< problem data */
129  SCIP_SET* set, /**< global SCIP settings */
130  int num /**< minimal number of slots in array */
131  )
132 {
133  assert(prob != NULL);
134  assert(set != NULL);
135 
136  if( num > prob->consssize )
137  {
138  int newsize;
139 
140  newsize = SCIPsetCalcMemGrowSize(set, num);
141  SCIP_ALLOC( BMSreallocMemoryArray(&prob->conss, newsize) );
142  prob->consssize = newsize;
143  }
144  assert(num <= prob->consssize);
145 
146  return SCIP_OKAY;
147 }
148 
149 /** returns whether the constraint has a name */
150 static
152  SCIP_CONS* cons /**< constraint */
153  )
154 {
155  const char* name;
156 
157  name = SCIPconsGetName(cons);
158 
159  return (name != NULL && name[0] != '\0');
160 }
161 
162 /** returns whether the variable has a name */
163 static
165  SCIP_VAR* var /**< variable */
166  )
167 {
168  const char* name;
169 
170  name = SCIPvarGetName(var);
171 
172  return (name != NULL && name[0] != '\0');
173 }
174 
175 
176 
177 /*
178  * problem creation
179  */
180 
181 /** creates problem data structure by copying the source problem
182  *
183  * If the problem type requires the use of variable pricers, these pricers should be activated with calls
184  * to SCIPactivatePricer(). These pricers are automatically deactivated, when the problem is freed.
185  */
187  SCIP_PROB** prob, /**< pointer to problem data structure */
188  BMS_BLKMEM* blkmem, /**< block memory */
189  SCIP_SET* set, /**< global SCIP settings */
190  const char* name, /**< problem name */
191  SCIP* sourcescip, /**< source SCIP data structure */
192  SCIP_PROB* sourceprob, /**< source problem structure */
193  SCIP_HASHMAP* varmap, /**< a hashmap to store the mapping of source variables corresponding
194  * target variables */
195  SCIP_HASHMAP* consmap, /**< a hashmap to store the mapping of source constraints to the corresponding
196  * target constraints */
197  SCIP_Bool global /**< create a global or a local copy? */
198  )
199 {
200  SCIP_PROBDATA* targetdata = NULL;
201  SCIP_RESULT result = SCIP_DIDNOTRUN;
202 
203  assert(prob != NULL);
204  assert(set != NULL);
205  assert(blkmem != NULL);
206  assert(sourcescip != NULL);
207  assert(sourceprob != NULL);
208  assert(varmap != NULL);
209  assert(consmap != NULL);
210 
211  /* create problem and initialize callbacks with NULL */
212  SCIP_CALL( SCIPprobCreate(prob, blkmem, set, name, NULL, NULL, NULL, NULL, NULL, NULL, NULL, FALSE) );
213 
214  /* call user copy callback method */
215  if( sourceprob->probdata != NULL && sourceprob->probcopy != NULL )
216  {
217  SCIP_CALL( sourceprob->probcopy(set->scip, sourcescip, sourceprob->probdata, varmap, consmap, &targetdata, global, &result) );
218 
219  /* evaluate result */
220  if( result != SCIP_DIDNOTRUN && result != SCIP_SUCCESS )
221  {
222  SCIPerrorMessage("probdata copying method returned invalid result <%d>\n", result);
223  return SCIP_INVALIDRESULT;
224  }
225 
226  assert(targetdata == NULL || result == SCIP_SUCCESS);
227 
228  /* if copying was successful, add data and callbacks */
229  if( result == SCIP_SUCCESS )
230  {
231  assert( targetdata != NULL );
232  (*prob)->probdelorig = sourceprob->probdelorig;
233  (*prob)->probtrans = sourceprob->probtrans;
234  (*prob)->probdeltrans = sourceprob->probdeltrans;
235  (*prob)->probinitsol = sourceprob->probinitsol;
236  (*prob)->probexitsol = sourceprob->probexitsol;
237  (*prob)->probcopy = sourceprob->probcopy;
238  (*prob)->probdata = targetdata;
239  }
240  }
241 
242  return SCIP_OKAY;
243 }
244 
245 /** creates problem data structure
246  * If the problem type requires the use of variable pricers, these pricers should be activated with calls
247  * to SCIPactivatePricer(). These pricers are automatically deactivated, when the problem is freed.
248  */
250  SCIP_PROB** prob, /**< pointer to problem data structure */
251  BMS_BLKMEM* blkmem, /**< block memory */
252  SCIP_SET* set, /**< global SCIP settings */
253  const char* name, /**< problem name */
254  SCIP_DECL_PROBDELORIG ((*probdelorig)), /**< frees user data of original problem */
255  SCIP_DECL_PROBTRANS ((*probtrans)), /**< creates user data of transformed problem by transforming original user data */
256  SCIP_DECL_PROBDELTRANS((*probdeltrans)), /**< frees user data of transformed problem */
257  SCIP_DECL_PROBINITSOL ((*probinitsol)), /**< solving process initialization method of transformed data */
258  SCIP_DECL_PROBEXITSOL ((*probexitsol)), /**< solving process deinitialization method of transformed data */
259  SCIP_DECL_PROBCOPY ((*probcopy)), /**< copies user data if you want to copy it to a subscip, or NULL */
260  SCIP_PROBDATA* probdata, /**< user problem data set by the reader */
261  SCIP_Bool transformed /**< is this the transformed problem? */
262  )
263 {
264  assert(prob != NULL);
265 
266  SCIP_ALLOC( BMSallocMemory(prob) );
267  SCIP_ALLOC( BMSduplicateMemoryArray(&(*prob)->name, name, strlen(name)+1) );
268 
269  (*prob)->probdata = probdata;
270  (*prob)->probcopy = probcopy;
271  (*prob)->probdelorig = probdelorig;
272  (*prob)->probtrans = probtrans;
273  (*prob)->probdeltrans = probdeltrans;
274  (*prob)->probinitsol = probinitsol;
275  (*prob)->probexitsol = probexitsol;
276  if( set->misc_usevartable )
277  {
278  SCIP_CALL( SCIPhashtableCreate(&(*prob)->varnames, blkmem,
279  (set->misc_usesmalltables ? SCIP_HASHSIZE_NAMES_SMALL : SCIP_HASHSIZE_NAMES),
280  SCIPhashGetKeyVar, SCIPhashKeyEqString, SCIPhashKeyValString, NULL) );
281  }
282  else
283  (*prob)->varnames = NULL;
284  (*prob)->vars = NULL;
285  (*prob)->varssize = 0;
286  (*prob)->nvars = 0;
287  (*prob)->nbinvars = 0;
288  (*prob)->nintvars = 0;
289  (*prob)->nimplvars = 0;
290  (*prob)->ncontvars = 0;
291  (*prob)->ncolvars = 0;
292  (*prob)->fixedvars = NULL;
293  (*prob)->fixedvarssize = 0;
294  (*prob)->nfixedvars = 0;
295  (*prob)->deletedvars = NULL;
296  (*prob)->deletedvarssize = 0;
297  (*prob)->ndeletedvars = 0;
298  (*prob)->nobjvars = 0;
299  if( set->misc_useconstable )
300  {
301  SCIP_CALL( SCIPhashtableCreate(&(*prob)->consnames, blkmem,
302  (set->misc_usesmalltables ? SCIP_HASHSIZE_NAMES_SMALL : SCIP_HASHSIZE_NAMES),
303  SCIPhashGetKeyCons, SCIPhashKeyEqString, SCIPhashKeyValString, NULL) );
304  }
305  else
306  (*prob)->consnames = NULL;
307  (*prob)->conss = NULL;
308  (*prob)->consssize = 0;
309  (*prob)->nconss = 0;
310  (*prob)->maxnconss = 0;
311  (*prob)->startnvars = 0;
312  (*prob)->startnconss = 0;
313  (*prob)->objsense = SCIP_OBJSENSE_MINIMIZE;
314  (*prob)->objoffset = 0.0;
315  (*prob)->objscale = 1.0;
316  (*prob)->objlim = SCIP_INVALID;
317  (*prob)->dualbound = SCIP_INVALID;
318  (*prob)->objisintegral = FALSE;
319  (*prob)->transformed = transformed;
320  (*prob)->nlpenabled = FALSE;
321  (*prob)->permuted = FALSE;
322  (*prob)->conscompression = FALSE;
323 
324  return SCIP_OKAY;
325 }
326 
327 /** sets callback to free user data of original problem */
329  SCIP_PROB* prob, /**< problem */
330  SCIP_DECL_PROBDELORIG ((*probdelorig)) /**< frees user data of original problem */
331  )
332 {
333  assert(prob != NULL);
334 
335  prob->probdelorig = probdelorig;
336 }
337 
338 /** sets callback to create user data of transformed problem by transforming original user data */
340  SCIP_PROB* prob, /**< problem */
341  SCIP_DECL_PROBTRANS ((*probtrans)) /**< creates user data of transformed problem by transforming original user data */
342  )
343 {
344  assert(prob != NULL);
345 
346  prob->probtrans = probtrans;
347 }
348 
349 /** sets callback to free user data of transformed problem */
351  SCIP_PROB* prob, /**< problem */
352  SCIP_DECL_PROBDELTRANS((*probdeltrans)) /**< frees user data of transformed problem */
353  )
354 {
355  assert(prob != NULL);
356 
357  prob->probdeltrans = probdeltrans;
358 }
359 
360 /** sets solving process initialization callback of transformed data */
362  SCIP_PROB* prob, /**< problem */
363  SCIP_DECL_PROBINITSOL ((*probinitsol)) /**< solving process initialization callback of transformed data */
364  )
365 {
366  assert(prob != NULL);
367 
368  prob->probinitsol= probinitsol;
369 }
370 
371 /** sets solving process deinitialization callback of transformed data */
373  SCIP_PROB* prob, /**< problem */
374  SCIP_DECL_PROBEXITSOL ((*probexitsol)) /**< solving process deinitialization callback of transformed data */
375  )
376 {
377  assert(prob != NULL);
378 
379  prob->probexitsol= probexitsol;
380 }
381 
382 /** sets callback to copy user data to copy it to a subscip, or NULL */
384  SCIP_PROB* prob, /**< problem */
385  SCIP_DECL_PROBCOPY ((*probcopy)) /**< copies user data if you want to copy it to a subscip, or NULL */
386  )
387 {
388  assert(prob != NULL);
389 
390  prob->probcopy= probcopy;
391 }
392 
393 /** frees problem data structure */
395  SCIP_PROB** prob, /**< pointer to problem data structure */
396  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
397  BMS_BLKMEM* blkmem, /**< block memory buffer */
398  SCIP_SET* set, /**< global SCIP settings */
399  SCIP_STAT* stat, /**< dynamic problem statistics */
400  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
401  SCIP_LP* lp /**< current LP data (or NULL, if it's the original problem) */
402  )
403 {
404  SCIP_Bool warnreleasevar = TRUE;
405  int v;
406 
407  assert(prob != NULL);
408  assert(*prob != NULL);
409  assert(set != NULL);
410 
411  /* remove all constraints from the problem */
412  while( (*prob)->nconss > 0 )
413  {
414  /*@todo for debug mode it even might sense, to sort them downwards after their arraypos */
415  assert((*prob)->conss != NULL);
416  SCIP_CALL( SCIPprobDelCons(*prob, blkmem, set, stat, (*prob)->conss[(*prob)->nconss - 1]) );
417  }
418 
419  if( (*prob)->transformed )
420  {
421  int h;
422 
423  /* unlock variables for all constraint handlers that don't need constraints */
424  for( h = 0; h < set->nconshdlrs; ++h )
425  {
426  if( !SCIPconshdlrNeedsCons(set->conshdlrs[h]) )
427  {
428  SCIP_CALL( SCIPconshdlrUnlockVars(set->conshdlrs[h], set) );
429  }
430  }
431  }
432 
433  /* free constraint array */
434  BMSfreeMemoryArrayNull(&(*prob)->conss);
435 
436  /* free user problem data */
437  if( (*prob)->transformed )
438  {
439  if( (*prob)->probdeltrans != NULL )
440  {
441  SCIP_CALL( (*prob)->probdeltrans(set->scip, &(*prob)->probdata) );
442  }
443  }
444  else
445  {
446  if( (*prob)->probdelorig != NULL )
447  {
448  SCIP_CALL( (*prob)->probdelorig(set->scip, &(*prob)->probdata) );
449  }
450  }
451 
452  /* release problem variables */
453  for( v = (*prob)->nvars - 1; v >= 0; --v )
454  {
455  assert(SCIPvarGetProbindex((*prob)->vars[v]) >= 0);
456 
457  if ( warnreleasevar && SCIPvarGetNUses((*prob)->vars[v]) > 1 )
458  {
459  SCIPmessageFPrintWarning(messagehdlr, "%s variable <%s> not released when freeing SCIP. Consider releasing variable first.\n",
460  (*prob)->transformed ? "Transformed" : "Original", SCIPvarGetName((*prob)->vars[v]));
461  warnreleasevar = FALSE;
462  }
463 
464  SCIP_CALL( SCIPvarRemove((*prob)->vars[v], blkmem, NULL, set, TRUE) );
465  SCIP_CALL( SCIPvarRelease(&(*prob)->vars[v], blkmem, set, eventqueue, lp) );
466  }
467  BMSfreeMemoryArrayNull(&(*prob)->vars);
468 
469  /* release fixed problem variables */
470  for( v = (*prob)->nfixedvars - 1; v >= 0; --v )
471  {
472  assert(SCIPvarGetProbindex((*prob)->fixedvars[v]) == -1);
473 
474  if ( warnreleasevar && SCIPvarGetNUses((*prob)->fixedvars[v]) > 1 )
475  {
476  SCIPmessageFPrintWarning(messagehdlr, "%s variable <%s> not released when freeing SCIP. Consider releasing variable first.\n",
477  (*prob)->transformed ? "Transformed" : "Original", SCIPvarGetName((*prob)->fixedvars[v]));
478  warnreleasevar = FALSE;
479  }
480 
481  SCIP_CALL( SCIPvarRelease(&(*prob)->fixedvars[v], blkmem, set, eventqueue, lp) );
482  }
483  BMSfreeMemoryArrayNull(&(*prob)->fixedvars);
484 
485  /* free deleted problem variables array */
486  BMSfreeMemoryArrayNull(&(*prob)->deletedvars);
487 
488  /* free hash tables for names */
489  if( (*prob)->varnames != NULL )
490  {
491  SCIPhashtableFree(&(*prob)->varnames);
492  }
493  if( (*prob)->consnames != NULL )
494  {
495  SCIPhashtableFree(&(*prob)->consnames);
496  }
497  BMSfreeMemoryArray(&(*prob)->name);
498  BMSfreeMemory(prob);
499 
500  return SCIP_OKAY;
501 }
502 
503 /** transform problem data into normalized form */
505  SCIP_PROB* source, /**< problem to transform */
506  BMS_BLKMEM* blkmem, /**< block memory buffer */
507  SCIP_SET* set, /**< global SCIP settings */
508  SCIP_STAT* stat, /**< problem statistics */
509  SCIP_PRIMAL* primal, /**< primal data */
510  SCIP_TREE* tree, /**< branch and bound tree */
511  SCIP_REOPT* reopt, /**< reoptimization data structure */
512  SCIP_LP* lp, /**< current LP data */
513  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
514  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
515  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
516  SCIP_CONFLICTSTORE* conflictstore, /**< conflict store */
517  SCIP_PROB** target /**< pointer to target problem data structure */
518  )
519 {
520  SCIP_VAR* targetvar;
521  SCIP_CONS* targetcons;
522  char transname[SCIP_MAXSTRLEN];
523  int v;
524  int c;
525  int h;
526 
527  assert(set != NULL);
528  assert(source != NULL);
529  assert(blkmem != NULL);
530  assert(target != NULL);
531 
532  SCIPsetDebugMsg(set, "transform problem: original has %d variables\n", source->nvars);
533 
534  /* create target problem data (probdelorig and probtrans are not needed, probdata is set later) */
535  (void) SCIPsnprintf(transname, SCIP_MAXSTRLEN, "t_%s", source->name);
536  SCIP_CALL( SCIPprobCreate(target, blkmem, set, transname, source->probdelorig, source->probtrans, source->probdeltrans,
537  source->probinitsol, source->probexitsol, source->probcopy, NULL, TRUE) );
538  SCIPprobSetObjsense(*target, source->objsense);
539 
540  /* transform objective limit */
541  if( source->objlim < SCIP_INVALID )
542  SCIPprobSetObjlim(*target, source->objlim);
543 
544  /* transform dual bound */
545  if( source->dualbound < SCIP_INVALID )
546  SCIPprobSetDualbound(*target, source->dualbound);
547 
548  /* transform and copy all variables to target problem */
549  SCIP_CALL( probEnsureVarsMem(*target, set, source->nvars) );
550  for( v = 0; v < source->nvars; ++v )
551  {
552  SCIP_CALL( SCIPvarTransform(source->vars[v], blkmem, set, stat, source->objsense, &targetvar) );
553  SCIP_CALL( SCIPprobAddVar(*target, blkmem, set, lp, branchcand, eventfilter, eventqueue, targetvar) );
554  SCIP_CALL( SCIPvarRelease(&targetvar, blkmem, set, eventqueue, NULL) );
555  }
556  assert((*target)->nvars == source->nvars);
557  assert((*target)->nobjvars == SCIPprobGetNObjVars(*target, set));
558 
559  /* call user data transformation */
560  if( source->probtrans != NULL )
561  {
562  SCIP_CALL( source->probtrans(set->scip, source->probdata, &(*target)->probdata) );
563  }
564  else
565  (*target)->probdata = source->probdata;
566 
567  /* transform and copy all constraints to target problem */
568  for( c = 0; c < source->nconss; ++c )
569  {
570  SCIP_CALL( SCIPconsTransform(source->conss[c], blkmem, set, &targetcons) );
571  SCIP_CALL( SCIPprobAddCons(*target, set, stat, targetcons) );
572  SCIP_CALL( SCIPconsRelease(&targetcons, blkmem, set) );
573  }
574 
575  /* lock variables for all constraint handlers that don't need constraints */
576  for( h = 0; h < set->nconshdlrs; ++h )
577  {
578  if( !SCIPconshdlrNeedsCons(set->conshdlrs[h]) )
579  {
580  SCIP_CALL( SCIPconshdlrLockVars(set->conshdlrs[h], set) );
581  }
582  }
583 
584  /* objective value is always integral, iff original objective value is always integral and shift is integral */
585  (*target)->objisintegral = source->objisintegral && SCIPsetIsIntegral(set, (*target)->objoffset);
586 
587  /* check, whether objective value is always integral by inspecting the problem, if it is the case adjust the
588  * cutoff bound if primal solution is already known
589  */
590  SCIP_CALL( SCIPprobCheckObjIntegral(*target, source, blkmem, set, stat, primal, tree, reopt, lp, eventqueue) );
591 
592  /* copy the nlpenabled flag */
593  (*target)->nlpenabled = source->nlpenabled;
594 
595  /* mark the transformed problem to be permuted iff the source problem is permuted */
596  (*target)->permuted = source->permuted;
597 
598  /* transform the conflict pool */
599  SCIP_CALL( SCIPconflictstoreTransform(conflictstore, blkmem, set, stat, tree, *target, reopt) );
600 
601  return SCIP_OKAY;
602 }
603 
604 /** resets the global and local bounds of original variables in original problem to their original values */
606  SCIP_PROB* prob, /**< original problem data */
607  BMS_BLKMEM* blkmem, /**< block memory */
608  SCIP_SET* set, /**< global SCIP settings */
609  SCIP_STAT* stat /**< problem statistics */
610  )
611 {
612  int v;
613 
614  assert(prob != NULL);
615  assert(prob->nfixedvars == 0);
616 
617  for( v = 0; v < prob->nvars; ++v )
618  {
619  SCIP_CALL( SCIPvarResetBounds(prob->vars[v], blkmem, set, stat) );
620  }
621 
622  return SCIP_OKAY;
623 }
624 
625 /** (Re)Sort the variables, which appear in the four categories (binary, integer, implicit, continuous) after presolve
626  * with respect to their original index (within their categories). Adjust the problem index afterwards which is
627  * supposed to reflect the position in the variable array. This additional (re)sorting is supposed to get more robust
628  * against the order presolving fixed variables. (We also reobtain a possible block structure induced by the user
629  * model)
630  */
632  SCIP_PROB* prob /**< problem data */
633  )
634 {
635  SCIP_VAR** vars;
636  int nbinvars;
637  int nintvars;
638  int nimplvars;
639  int ncontvars;
640  int nvars;
641  int v;
642 
643  vars = prob->vars;
644  nvars = prob->nvars;
645  nbinvars = prob->nbinvars;
646  nintvars = prob->nintvars;
647  nimplvars = prob->nimplvars;
648  ncontvars = prob->ncontvars;
649 
650  if( nvars == 0 )
651  return;
652 
653  assert(vars != NULL);
654  assert(nbinvars + nintvars + nimplvars + ncontvars == nvars);
655 
656  SCIPdebugMessage("entering sorting with respect to original block structure! \n");
657 
658  /* sort binaries */
659  if( nbinvars > 0 )
660  SCIPsortPtr((void**)vars, SCIPvarComp, nbinvars);
661 
662  /* sort integers */
663  if( nintvars > 0 )
664  SCIPsortPtr((void**)&vars[nbinvars], SCIPvarComp, nintvars);
665 
666  /* sort implicit variables */
667  if( nimplvars > 0 )
668  SCIPsortPtr((void**)&vars[nbinvars + nintvars], SCIPvarComp, nimplvars);
669 
670  /* sort continuous variables*/
671  if( ncontvars > 0 )
672  SCIPsortPtr((void**)&vars[nbinvars + nintvars + nimplvars], SCIPvarComp, ncontvars);
673 
674  /* after sorting, the problem index of each variable has to be adjusted */
675  for( v = 0; v < nvars; ++v )
676  {
677  vars[v]->probindex = v;
678  SCIPdebugMessage("Variable: Problem index <%d>, original index <%d> \n", vars[v]->probindex, vars[v]->index);
679  }
680 }
681 
682 
683 
684 /*
685  * problem modification
686  */
687 
688 /** sets user problem data */
690  SCIP_PROB* prob, /**< problem */
691  SCIP_PROBDATA* probdata /**< user problem data to use */
692  )
693 {
694  assert(prob != NULL);
695 
696  prob->probdata = probdata;
697 }
698 
699 /** inserts variable at the correct position in vars array, depending on its type */
700 static
702  SCIP_PROB* prob, /**< problem data */
703  SCIP_VAR* var /**< variable to insert */
704  )
705 {
706  int insertpos;
707  int intstart;
708  int implstart;
709  int contstart;
710 
711  assert(prob != NULL);
712  assert(prob->vars != NULL);
713  assert(prob->nvars < prob->varssize);
714  assert(var != NULL);
715  assert(SCIPvarGetProbindex(var) == -1);
719  /* original variables cannot go into transformed problem and transformed variables cannot go into original problem */
720  assert((SCIPvarGetStatus(var) != SCIP_VARSTATUS_ORIGINAL) == prob->transformed);
721 
722  /* insert variable in array */
723  insertpos = prob->nvars;
724  intstart = prob->nbinvars;
725  implstart = intstart + prob->nintvars;
726  contstart = implstart + prob->nimplvars;
727 
729  prob->ncontvars++;
730  else
731  {
732  if( insertpos > contstart )
733  {
734  prob->vars[insertpos] = prob->vars[contstart];
735  SCIPvarSetProbindex(prob->vars[insertpos], insertpos);
736  insertpos = contstart;
737  }
738  assert(insertpos == contstart);
739 
741  prob->nimplvars++;
742  else
743  {
744  if( insertpos > implstart )
745  {
746  prob->vars[insertpos] = prob->vars[implstart];
747  SCIPvarSetProbindex(prob->vars[insertpos], insertpos);
748  insertpos = implstart;
749  }
750  assert(insertpos == implstart);
751 
753  prob->nintvars++;
754  else
755  {
756  assert(SCIPvarGetType(var) == SCIP_VARTYPE_BINARY);
757  if( insertpos > intstart )
758  {
759  prob->vars[insertpos] = prob->vars[intstart];
760  SCIPvarSetProbindex(prob->vars[insertpos], insertpos);
761  insertpos = intstart;
762  }
763  assert(insertpos == intstart);
764 
765  prob->nbinvars++;
766  }
767  }
768  }
769  prob->nvars++;
770 
771  assert(prob->nvars == prob->nbinvars + prob->nintvars + prob->nimplvars + prob->ncontvars);
772  assert((SCIPvarGetType(var) == SCIP_VARTYPE_BINARY && insertpos == prob->nbinvars - 1)
773  || (SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER && insertpos == prob->nbinvars + prob->nintvars - 1)
774  || (SCIPvarGetType(var) == SCIP_VARTYPE_IMPLINT && insertpos == prob->nbinvars + prob->nintvars + prob->nimplvars - 1)
776  && insertpos == prob->nbinvars + prob->nintvars + prob->nimplvars + prob->ncontvars - 1));
777 
778  prob->vars[insertpos] = var;
779  SCIPvarSetProbindex(var, insertpos);
780 
781  /* update number of column variables in problem */
783  prob->ncolvars++;
784  assert(0 <= prob->ncolvars && prob->ncolvars <= prob->nvars);
785 }
786 
787 /** removes variable from vars array */
788 static
790  SCIP_PROB* prob, /**< problem data */
791  BMS_BLKMEM* blkmem, /**< block memory */
792  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
793  SCIP_SET* set, /**< global SCIP settings */
794  SCIP_VAR* var /**< variable to remove */
795  )
796 {
797  int freepos;
798  int intstart;
799  int implstart;
800  int contstart;
801 
802  assert(prob != NULL);
803  assert(var != NULL);
804  assert(SCIPvarGetProbindex(var) >= 0);
805  assert(prob->vars != NULL);
806  assert(prob->vars[SCIPvarGetProbindex(var)] == var);
807 
808  intstart = prob->nbinvars;
809  implstart = intstart + prob->nintvars;
810  contstart = implstart + prob->nimplvars;
811 
812  switch( SCIPvarGetType(var) )
813  {
814  case SCIP_VARTYPE_BINARY:
815  assert(0 <= SCIPvarGetProbindex(var) && SCIPvarGetProbindex(var) < intstart);
816  prob->nbinvars--;
817  break;
819  assert(intstart <= SCIPvarGetProbindex(var) && SCIPvarGetProbindex(var) < implstart);
820  prob->nintvars--;
821  break;
823  assert(implstart <= SCIPvarGetProbindex(var) && SCIPvarGetProbindex(var) < contstart);
824  prob->nimplvars--;
825  break;
827  assert(contstart <= SCIPvarGetProbindex(var) && SCIPvarGetProbindex(var) < prob->nvars);
828  prob->ncontvars--;
829  break;
830  default:
831  SCIPerrorMessage("unknown variable type\n");
832  SCIPABORT();
833  return SCIP_INVALIDDATA; /*lint !e527*/
834  }
835 
836  /* move last binary, last integer, last implicit, and last continuous variable forward to fill the free slot */
837  freepos = SCIPvarGetProbindex(var);
838  if( freepos < intstart-1 )
839  {
840  /* move last binary variable to free slot */
841  prob->vars[freepos] = prob->vars[intstart-1];
842  SCIPvarSetProbindex(prob->vars[freepos], freepos);
843  freepos = intstart-1;
844  }
845  if( freepos < implstart-1 )
846  {
847  /* move last integer variable to free slot */
848  prob->vars[freepos] = prob->vars[implstart-1];
849  SCIPvarSetProbindex(prob->vars[freepos], freepos);
850  freepos = implstart-1;
851  }
852  if( freepos < contstart-1 )
853  {
854  /* move last implicit integer variable to free slot */
855  prob->vars[freepos] = prob->vars[contstart-1];
856  SCIPvarSetProbindex(prob->vars[freepos], freepos);
857  freepos = contstart-1;
858  }
859  if( freepos < prob->nvars-1 )
860  {
861  /* move last implicit integer variable to free slot */
862  prob->vars[freepos] = prob->vars[prob->nvars-1];
863  SCIPvarSetProbindex(prob->vars[freepos], freepos);
864  freepos = prob->nvars-1;
865  }
866  assert(freepos == prob->nvars-1);
867 
868  prob->nvars--;
869  assert(prob->nvars == prob->nbinvars + prob->nintvars + prob->nimplvars + prob->ncontvars);
870 
871  /* update number of column variables in problem */
873  prob->ncolvars--;
874  assert(0 <= prob->ncolvars && prob->ncolvars <= prob->nvars);
875 
876  /* inform the variable that it is no longer in the problem; if necessary, delete it from the implication graph */
877  SCIP_CALL( SCIPvarRemove(var, blkmem, cliquetable, set, FALSE) );
878 
879  return SCIP_OKAY;
880 }
881 
882 /** adds variable's name to the namespace */
884  SCIP_PROB* prob, /**< problem data */
885  SCIP_VAR* var /**< variable */
886  )
887 {
888  assert(SCIPvarGetProbindex(var) != -1);
889 
890  if( varHasName(var) && prob->varnames != NULL )
891  {
892  SCIP_CALL( SCIPhashtableInsert(prob->varnames, (void*)var) );
893  }
894 
895  return SCIP_OKAY;
896 }
897 
898 /** removes variable's name from the namespace */
900  SCIP_PROB* prob, /**< problem data */
901  SCIP_VAR* var /**< variable */
902  )
903 {
904  if( varHasName(var) && prob->varnames != NULL )
905  {
906  assert(SCIPhashtableExists(prob->varnames, (void*)var));
907  SCIP_CALL( SCIPhashtableRemove(prob->varnames, (void*)var) );
908  }
909 
910  return SCIP_OKAY;
911 }
912 
913 /** adds variable to the problem and captures it */
915  SCIP_PROB* prob, /**< problem data */
916  BMS_BLKMEM* blkmem, /**< block memory buffers */
917  SCIP_SET* set, /**< global SCIP settings */
918  SCIP_LP* lp, /**< current LP data */
919  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
920  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
921  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
922  SCIP_VAR* var /**< variable to add */
923  )
924 {
925  assert(prob != NULL);
926  assert(set != NULL);
927  assert(var != NULL);
928  assert(SCIPvarGetProbindex(var) == -1);
932  /* original variables cannot go into transformed problem and transformed variables cannot go into original problem */
933  assert((SCIPvarGetStatus(var) != SCIP_VARSTATUS_ORIGINAL) == prob->transformed);
934 
935 #ifndef NDEBUG
936  /* check if we add this variables to the same scip, where we created it */
937  if( var->scip != set->scip )
938  {
939  SCIPerrorMessage("variable belongs to a different scip instance\n");
940  return SCIP_INVALIDDATA;
941  }
942 #endif
943 
944  /* capture variable */
945  SCIPvarCapture(var);
946 
947  /* allocate additional memory */
948  SCIP_CALL( probEnsureVarsMem(prob, set, prob->nvars+1) );
949 
950  /* insert variable in vars array and mark it to be in problem */
951  probInsertVar(prob, var);
952 
953  /* add variable's name to the namespace */
954  SCIP_CALL( SCIPprobAddVarName(prob, var) );
955 
956  /* update branching candidates and pseudo and loose objective value in the LP */
958  {
959  SCIP_CALL( SCIPbranchcandUpdateVar(branchcand, set, var) );
960  SCIP_CALL( SCIPlpUpdateAddVar(lp, set, var) );
961  }
962 
963  SCIPsetDebugMsg(set, "added variable <%s> to problem (%d variables: %d binary, %d integer, %d implicit, %d continuous)\n",
964  SCIPvarGetName(var), prob->nvars, prob->nbinvars, prob->nintvars, prob->nimplvars, prob->ncontvars);
965 
966  if( prob->transformed )
967  {
968  SCIP_EVENT* event;
969 
970  /* issue VARADDED event */
971  SCIP_CALL( SCIPeventCreateVarAdded(&event, blkmem, var) );
972  SCIP_CALL( SCIPeventqueueAdd(eventqueue, blkmem, set, NULL, NULL, NULL, eventfilter, &event) );
973 
974  /* update the number of variables with non-zero objective coefficient */
975  SCIPprobUpdateNObjVars(prob, set, 0.0, SCIPvarGetObj(var));
976 
977  /* set varlocks to ensure that no dual reduction can be performed */
978  if( set->reopt_enable || !set->misc_allowdualreds )
979  {
980  SCIP_CALL( SCIPvarAddLocks(var, blkmem, set, eventqueue, 1, 1) );
981  }
982 
983  /* SCIP assumes that the status of objisintegral does not change after transformation. Thus, the objective of all
984  * new variables beyond that stage has to be compatible. */
985  assert( SCIPsetGetStage(set) == SCIP_STAGE_TRANSFORMING || ! prob->objisintegral || SCIPsetIsZero(set, SCIPvarGetObj(var)) ||
986  ( SCIPvarIsIntegral(var) && SCIPsetIsIntegral(set, SCIPvarGetObj(var)) ) );
987  }
988 
989  return SCIP_OKAY;
990 }
991 
992 /** marks variable to be removed from the problem; however, the variable is NOT removed from the constraints */
994  SCIP_PROB* prob, /**< problem data */
995  BMS_BLKMEM* blkmem, /**< block memory */
996  SCIP_SET* set, /**< global SCIP settings */
997  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
998  SCIP_VAR* var, /**< problem variable */
999  SCIP_Bool* deleted /**< pointer to store whether marking variable to be deleted was successful */
1000  )
1001 {
1002  assert(prob != NULL);
1003  assert(set != NULL);
1004  assert(var != NULL);
1005  assert(deleted != NULL);
1006  assert(SCIPvarGetProbindex(var) != -1);
1010 
1011  *deleted = FALSE;
1012 
1013  /* don't remove variables that are not in the problem */
1014  /**@todo what about negated variables? should the negation variable be removed instead? */
1015  if( SCIPvarGetProbindex(var) == -1 )
1016  return SCIP_OKAY;
1017 
1018  /* don't remove the direct counterpart of an original variable from the transformed problem, because otherwise
1019  * operations on the original variables would be applied to a NULL pointer
1020  */
1021  if( SCIPvarIsTransformedOrigvar(var) )
1022  return SCIP_OKAY;
1023 
1024  assert(SCIPvarGetNegatedVar(var) == NULL);
1025 
1026  SCIPsetDebugMsg(set, "deleting variable <%s> from problem (%d variables: %d binary, %d integer, %d implicit, %d continuous)\n",
1027  SCIPvarGetName(var), prob->nvars, prob->nbinvars, prob->nintvars, prob->nimplvars, prob->ncontvars);
1028 
1029  /* mark variable to be deleted from the problem */
1030  SCIPvarMarkDeleted(var);
1031 
1032  if( prob->transformed )
1033  {
1034  SCIP_EVENT* event;
1035 
1036  assert(eventqueue != NULL);
1037 
1038  /* issue VARDELETED event */
1039  SCIP_CALL( SCIPeventCreateVarDeleted(&event, blkmem, var) );
1040  SCIP_CALL( SCIPeventqueueAdd(eventqueue, blkmem, set, NULL, NULL, NULL, NULL, &event) );
1041  }
1042 
1043  /* remember that the variable should be deleted from the problem in SCIPprobPerformVarDeletions() */
1044  SCIP_CALL( probEnsureDeletedvarsMem(prob, set, prob->ndeletedvars+1) );
1045  prob->deletedvars[prob->ndeletedvars] = var;
1046  prob->ndeletedvars++;
1047 
1048  *deleted = TRUE;
1049 
1050  return SCIP_OKAY;
1051 }
1052 
1053 /** actually removes the deleted variables from the problem and releases them */
1055  SCIP_PROB* prob, /**< problem data */
1056  BMS_BLKMEM* blkmem, /**< block memory */
1057  SCIP_SET* set, /**< global SCIP settings */
1058  SCIP_STAT* stat, /**< dynamic problem statistics */
1059  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1060  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
1061  SCIP_LP* lp, /**< current LP data (may be NULL) */
1062  SCIP_BRANCHCAND* branchcand /**< branching candidate storage */
1063  )
1064 {
1065  int i;
1066 
1067  assert(prob != NULL);
1068  assert(set != NULL);
1069 
1070  /* delete variables from the constraints;
1071  * do this only in solving stage, in presolving, it is already handled by the constraint handlers
1072  */
1073  if( SCIPsetGetStage(set) == SCIP_STAGE_SOLVING )
1074  {
1075  for( i = 0; i < set->nconshdlrs; ++i )
1076  {
1077  SCIP_CALL( SCIPconshdlrDelVars(set->conshdlrs[i], blkmem, set, stat) );
1078  }
1079  }
1080 
1081  for( i = 0; i < prob->ndeletedvars; ++i )
1082  {
1083  SCIP_VAR* var;
1084 
1085  var = prob->deletedvars[i];
1086 
1087  /* don't delete the variable, if it was fixed or aggregated in the meantime */
1088  if( SCIPvarGetProbindex(var) >= 0 )
1089  {
1090  SCIPsetDebugMsg(set, "perform deletion of <%s> [%p]\n", SCIPvarGetName(var), (void*)var);
1091 
1092  /* convert column variable back into loose variable, free LP column */
1094  {
1095  SCIP_CALL( SCIPvarLoose(var, blkmem, set, eventqueue, prob, lp) );
1096  }
1097 
1098  /* update branching candidates and pseudo and loose objective value in the LP */
1100  {
1101  SCIP_CALL( SCIPlpUpdateDelVar(lp, set, var) );
1102  SCIP_CALL( SCIPbranchcandRemoveVar(branchcand, var) );
1103  }
1104 
1105  /* remove variable's name from the namespace */
1106  SCIP_CALL( SCIPprobRemoveVarName(prob, var) );
1107 
1108  /* remove variable from vars array and mark it to be not in problem */
1109  SCIP_CALL( probRemoveVar(prob, blkmem, cliquetable, set, var) );
1110 
1111  /* update the number of variables with non-zero objective coefficient */
1112  if( prob->transformed )
1113  SCIPprobUpdateNObjVars(prob, set, SCIPvarGetObj(var), 0.0);
1114 
1115  /* release variable */
1116  SCIP_CALL( SCIPvarRelease(&prob->deletedvars[i], blkmem, set, eventqueue, lp) );
1117  }
1118  }
1119  prob->ndeletedvars = 0;
1120 
1121  return SCIP_OKAY;
1122 }
1123 
1124 /** changes the type of a variable in the problem */
1126  SCIP_PROB* prob, /**< problem data */
1127  BMS_BLKMEM* blkmem, /**< block memory */
1128  SCIP_SET* set, /**< global SCIP settings */
1129  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
1130  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
1131  SCIP_VAR* var, /**< variable to add */
1132  SCIP_VARTYPE vartype /**< new type of variable */
1133  )
1134 {
1135  assert(prob != NULL);
1136  assert(var != NULL);
1137  assert(SCIPvarGetProbindex(var) >= 0);
1141  assert(branchcand != NULL || SCIPvarGetStatus(var) == SCIP_VARSTATUS_ORIGINAL);
1142 
1143  if( SCIPvarGetType(var) == vartype )
1144  return SCIP_OKAY;
1145 
1146  /* temporarily remove variable from branching candidates */
1147  if( branchcand != NULL )
1148  {
1149  SCIP_CALL( SCIPbranchcandRemoveVar(branchcand, var) );
1150  }
1151 
1152  /* temporarily remove variable from problem */
1153  SCIP_CALL( probRemoveVar(prob, blkmem, cliquetable, set, var) );
1154 
1155  /* change the type of the variable */
1156  SCIP_CALL( SCIPvarChgType(var, vartype) );
1157 
1158  /* reinsert variable into problem */
1159  probInsertVar(prob, var);
1160 
1161  /* update branching candidates */
1162  if( branchcand != NULL )
1163  {
1164  SCIP_CALL( SCIPbranchcandUpdateVar(branchcand, set, var) );
1165  }
1166 
1167  return SCIP_OKAY;
1168 }
1169 
1170 /** informs problem, that the given loose problem variable changed its status */
1172  SCIP_PROB* prob, /**< problem data */
1173  BMS_BLKMEM* blkmem, /**< block memory */
1174  SCIP_SET* set, /**< global SCIP settings */
1175  SCIP_BRANCHCAND* branchcand, /**< branching candidate storage */
1176  SCIP_CLIQUETABLE* cliquetable, /**< clique table data structure */
1177  SCIP_VAR* var /**< problem variable */
1178  )
1179 {
1180  assert(prob != NULL);
1181  assert(var != NULL);
1182  assert(SCIPvarGetProbindex(var) != -1);
1183 
1184  /* get current status of variable */
1185  switch( SCIPvarGetStatus(var) )
1186  {
1188  SCIPerrorMessage("variables cannot switch to ORIGINAL status\n");
1189  return SCIP_INVALIDDATA;
1190 
1191  case SCIP_VARSTATUS_LOOSE:
1192  /* variable switched from column to loose */
1193  prob->ncolvars--;
1194  break;
1195 
1196  case SCIP_VARSTATUS_COLUMN:
1197  /* variable switched from non-column to column */
1198  prob->ncolvars++;
1199  break;
1200 
1201  case SCIP_VARSTATUS_FIXED:
1205  /* variable switched from unfixed to fixed (if it was fixed before, probindex would have been -1) */
1206 
1207  /* remove variable from problem */
1208  SCIP_CALL( probRemoveVar(prob, blkmem, cliquetable, set, var) );
1209 
1210  /* insert variable in fixedvars array */
1211  SCIP_CALL( probEnsureFixedvarsMem(prob, set, prob->nfixedvars+1) );
1212  prob->fixedvars[prob->nfixedvars] = var;
1213  prob->nfixedvars++;
1214 
1215  /* update branching candidates */
1216  SCIP_CALL( SCIPbranchcandUpdateVar(branchcand, set, var) );
1217  break;
1218 
1219  default:
1220  SCIPerrorMessage("invalid variable status <%d>\n", SCIPvarGetStatus(var));
1221  return SCIP_INVALIDDATA;
1222  }
1223  assert(0 <= prob->ncolvars && prob->ncolvars <= prob->nvars);
1224 
1225  return SCIP_OKAY;
1226 }
1227 
1228 /** adds constraint's name to the namespace */
1230  SCIP_PROB* prob, /**< problem data */
1231  SCIP_CONS* cons /**< constraint */
1232  )
1233 {
1234  /* add constraint's name to the namespace */
1235  if( consHasName(cons) && prob->consnames != NULL )
1236  {
1237  SCIP_CALL( SCIPhashtableInsert(prob->consnames, (void*)cons) );
1238  }
1239 
1240  return SCIP_OKAY;
1241 }
1242 
1243 /** remove constraint's name from the namespace */
1245  SCIP_PROB* prob, /**< problem data */
1246  SCIP_CONS* cons /**< constraint */
1247  )
1248 {
1249  /* remove constraint's name from the namespace */
1250  if( consHasName(cons) && prob->consnames != NULL )
1251  {
1252  SCIP_CONS* currentcons;
1253  currentcons = (SCIP_CONS*)SCIPhashtableRetrieve(prob->consnames, (void*)(cons->name));
1254  if( currentcons == cons )
1255  {
1256  SCIP_CALL( SCIPhashtableRemove(prob->consnames, (void*)cons) );
1257  }
1258  }
1259 
1260  return SCIP_OKAY;
1261 }
1262 
1263 /** adds constraint to the problem and captures it;
1264  * a local constraint is automatically upgraded into a global constraint
1265  */
1267  SCIP_PROB* prob, /**< problem data */
1268  SCIP_SET* set, /**< global SCIP settings */
1269  SCIP_STAT* stat, /**< dynamic problem statistics */
1270  SCIP_CONS* cons /**< constraint to add */
1271  )
1272 {
1273  assert(prob != NULL);
1274  assert(cons != NULL);
1275  assert(cons->addconssetchg == NULL);
1276  assert(cons->addarraypos == -1);
1277 
1278 #ifndef NDEBUG
1279  /* check if we add this constraint to the same scip, where we create the constraint */
1280  if( cons->scip != set->scip )
1281  {
1282  SCIPerrorMessage("constraint belongs to different scip instance\n");
1283  return SCIP_INVALIDDATA;
1284  }
1285 #endif
1286  SCIPsetDebugMsg(set, "adding constraint <%s> to global problem -> %d constraints\n",
1287  SCIPconsGetName(cons), prob->nconss+1);
1288 
1289  /* mark the constraint as problem constraint, and remember the constraint's position */
1290  cons->addconssetchg = NULL;
1291  cons->addarraypos = prob->nconss;
1292 
1293  /* add the constraint to the problem's constraint array */
1294  SCIP_CALL( probEnsureConssMem(prob, set, prob->nconss+1) );
1295  prob->conss[prob->nconss] = cons;
1296  prob->nconss++;
1297  prob->maxnconss = MAX(prob->maxnconss, prob->nconss);
1298 
1299  /* undelete constraint, if it was globally deleted in the past */
1300  cons->deleted = FALSE;
1301 
1302  /* mark constraint to be globally valid */
1303  SCIPconsSetLocal(cons, FALSE);
1304 
1305  /* capture constraint */
1306  SCIPconsCapture(cons);
1307 
1308  /* add constraint's name to the namespace */
1309  SCIP_CALL( SCIPprobAddConsName(prob, cons) );
1310 
1311  /* if the problem is the transformed problem, activate and lock constraint */
1312  if( prob->transformed )
1313  {
1314  /* activate constraint */
1315  if( !SCIPconsIsActive(cons) )
1316  {
1317  SCIP_CALL( SCIPconsActivate(cons, set, stat, -1, (stat->nnodes <= 1)) );
1318  }
1319 
1320  /* if constraint is a check-constraint, lock roundings of constraint's variables */
1321  if( SCIPconsIsChecked(cons) )
1322  {
1323  SCIP_CALL( SCIPconsAddLocks(cons, set, +1, 0) );
1324  }
1325  }
1326 
1327  return SCIP_OKAY;
1328 }
1329 
1330 /** releases and removes constraint from the problem; if the user has not captured the constraint for his own use, the
1331  * constraint may be invalid after the call
1332  */
1334  SCIP_PROB* prob, /**< problem data */
1335  BMS_BLKMEM* blkmem, /**< block memory */
1336  SCIP_SET* set, /**< global SCIP settings */
1337  SCIP_STAT* stat, /**< dynamic problem statistics */
1338  SCIP_CONS* cons /**< constraint to remove */
1339  )
1340 {
1341  int arraypos;
1342 
1343  assert(prob != NULL);
1344  assert(blkmem != NULL);
1345  assert(cons != NULL);
1346  assert(cons->addconssetchg == NULL);
1347  assert(0 <= cons->addarraypos && cons->addarraypos < prob->nconss);
1348  assert(prob->conss != NULL);
1349  assert(prob->conss[cons->addarraypos] == cons);
1350 
1351  /* if the problem is the transformed problem, deactivate and unlock constraint */
1352  if( prob->transformed )
1353  {
1354  /* if constraint is a check-constraint, unlock roundings of constraint's variables */
1355  if( SCIPconsIsChecked(cons) )
1356  {
1357  SCIP_CALL( SCIPconsAddLocks(cons, set, -1, 0) );
1358  }
1359 
1360  /* deactivate constraint, if it is currently active */
1361  if( cons->active && !cons->updatedeactivate )
1362  {
1363  SCIP_CALL( SCIPconsDeactivate(cons, set, stat) );
1364  }
1365  }
1366  assert(!cons->active || cons->updatedeactivate);
1367  assert(!cons->enabled || cons->updatedeactivate);
1368 
1369  /* remove constraint's name from the namespace */
1370  SCIP_CALL( SCIPprobRemoveConsName(prob, cons) );
1371 
1372  /* remove the constraint from the problem's constraint array */
1373  arraypos = cons->addarraypos;
1374  prob->conss[arraypos] = prob->conss[prob->nconss-1];
1375  assert(prob->conss[arraypos] != NULL);
1376  assert(prob->conss[arraypos]->addconssetchg == NULL);
1377  prob->conss[arraypos]->addarraypos = arraypos;
1378  prob->nconss--;
1379 
1380  /* mark the constraint to be no longer in the problem */
1381  cons->addarraypos = -1;
1382 
1383  /* release constraint */
1384  SCIP_CALL( SCIPconsRelease(&cons, blkmem, set) );
1385 
1386  return SCIP_OKAY;
1387 }
1388 
1389 /** remembers the current number of constraints in the problem's internal data structure
1390  * - resets maximum number of constraints to current number of constraints
1391  * - remembers current number of constraints as starting number of constraints
1392  */
1394  SCIP_PROB* prob /**< problem data */
1395  )
1396 {
1397  assert(prob != NULL);
1398 
1399  /* remember number of constraints for statistic */
1400  prob->maxnconss = prob->nconss;
1401  prob->startnvars = prob->nvars;
1402  prob->startnconss = prob->nconss;
1403 }
1404 
1405 /** sets objective sense: minimization or maximization */
1407  SCIP_PROB* prob, /**< problem data */
1408  SCIP_OBJSENSE objsense /**< new objective sense */
1409  )
1410 {
1411  assert(prob != NULL);
1412  assert(prob->objsense == SCIP_OBJSENSE_MAXIMIZE || prob->objsense == SCIP_OBJSENSE_MINIMIZE);
1413  assert(objsense == SCIP_OBJSENSE_MAXIMIZE || objsense == SCIP_OBJSENSE_MINIMIZE);
1414 
1415  prob->objsense = objsense;
1416 }
1417 
1418 /** adds value to objective offset */
1420  SCIP_PROB* prob, /**< problem data */
1421  SCIP_Real addval /**< value to add to objective offset */
1422  )
1423 {
1424  assert(prob != NULL);
1425  assert(prob->transformed);
1426 
1427  SCIPdebugMessage("adding %g to objective offset %g: new offset = %g\n", addval, prob->objoffset, prob->objoffset + addval);
1428  prob->objoffset += addval;
1429 }
1430 
1431 /** sets the dual bound on objective function */
1433  SCIP_PROB* prob, /**< problem data */
1434  SCIP_Real dualbound /**< external dual bound */
1435  )
1436 {
1437  assert(prob != NULL);
1438 
1439  prob->dualbound = dualbound;
1440 }
1441 
1442 /** sets limit on objective function, such that only solutions better than this limit are accepted */
1444  SCIP_PROB* prob, /**< problem data */
1445  SCIP_Real objlim /**< external objective limit */
1446  )
1447 {
1448  assert(prob != NULL);
1449 
1450  prob->objlim = objlim;
1451 }
1452 
1453 /** informs the problem, that its objective value is always integral in every feasible solution */
1455  SCIP_PROB* prob /**< problem data */
1456  )
1457 {
1458  assert(prob != NULL);
1459 
1460  prob->objisintegral = TRUE;
1461 }
1462 
1463 /** sets integral objective value flag, if all variables with non-zero objective values are integral and have
1464  * integral objective value and also updates the cutoff bound if primal solution is already known
1465  */
1467  SCIP_PROB* transprob, /**< tranformed problem data */
1468  SCIP_PROB* origprob, /**< original problem data */
1469  BMS_BLKMEM* blkmem, /**< block memory */
1470  SCIP_SET* set, /**< global SCIP settings */
1471  SCIP_STAT* stat, /**< problem statistics data */
1472  SCIP_PRIMAL* primal, /**< primal data */
1473  SCIP_TREE* tree, /**< branch and bound tree */
1474  SCIP_REOPT* reopt, /**< reoptimization data structure */
1475  SCIP_LP* lp, /**< current LP data */
1476  SCIP_EVENTQUEUE* eventqueue /**< event queue */
1477  )
1478 {
1479  SCIP_Real obj;
1480  int v;
1481 
1482  assert(transprob != NULL);
1483  assert(origprob != NULL);
1484 
1485  /* if we know already, that the objective value is integral, nothing has to be done */
1486  if( transprob->objisintegral )
1487  return SCIP_OKAY;
1488 
1489  /* if there exist unknown variables, we cannot conclude that the objective value is always integral */
1490  if( set->nactivepricers != 0 )
1491  return SCIP_OKAY;
1492 
1493  /* if the objective value offset is fractional, the value itself is possibly fractional */
1494  if( !SCIPsetIsIntegral(set, transprob->objoffset) )
1495  return SCIP_OKAY;
1496 
1497  /* scan through the variables */
1498  for( v = 0; v < transprob->nvars; ++v )
1499  {
1500  /* get objective value of variable */
1501  obj = SCIPvarGetObj(transprob->vars[v]);
1502 
1503  /* check, if objective value is non-zero */
1504  if( !SCIPsetIsZero(set, obj) )
1505  {
1506  /* if variable's objective value is fractional, the problem's objective value may also be fractional */
1507  if( !SCIPsetIsIntegral(set, obj) )
1508  break;
1509 
1510  /* if variable with non-zero objective value is continuous, the problem's objective value may be fractional */
1511  if( SCIPvarGetType(transprob->vars[v]) == SCIP_VARTYPE_CONTINUOUS )
1512  break;
1513  }
1514  }
1515 
1516  /* objective value is integral, if the variable loop scanned all variables */
1517  if( v == transprob->nvars )
1518  {
1519  transprob->objisintegral = TRUE;
1520 
1521  /* update upper bound and cutoff bound in primal data structure due to new internality information */
1522  SCIP_CALL( SCIPprimalUpdateObjoffset(primal, blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp) );
1523  }
1524 
1525  return SCIP_OKAY;
1526 }
1527 
1528 /** update the number of variables with non-zero objective coefficient */
1530  SCIP_PROB* prob, /**< problem data */
1531  SCIP_SET* set, /**< global SCIP settings */
1532  SCIP_Real oldobj, /**< old objective value for variable */
1533  SCIP_Real newobj /**< new objective value for variable */
1534  )
1535 {
1536  assert(prob->transformed);
1537 
1538  if( !SCIPsetIsZero(set, oldobj) )
1539  prob->nobjvars--;
1540 
1541  if( !SCIPsetIsZero(set, newobj) )
1542  prob->nobjvars++;
1543 }
1544 
1545 /** update the dual bound if its better as the current one */
1547  SCIP_PROB* prob, /**< problem data */
1548  SCIP_Real newbound /**< new dual bound for the node (if it's tighter than the old one) */
1549  )
1550 {
1551  if( prob->dualbound == SCIP_INVALID ) /*lint !e777*/
1552  SCIPprobSetDualbound(prob, newbound);
1553  else
1554  {
1555  switch( prob->objsense )
1556  {
1558  prob->dualbound = MAX(newbound, prob->dualbound);
1559  break;
1560 
1562  prob->dualbound = MIN(newbound, prob->dualbound);
1563  break;
1564 
1565  default:
1566  SCIPerrorMessage("invalid objective sense <%d>\n", prob->objsense);
1567  SCIPABORT();
1568  }
1569  }
1570 }
1571 
1572 /** invalidates the dual bound */
1574  SCIP_PROB* prob /**< problem data */
1575  )
1576 {
1577  assert(prob != NULL);
1578 
1579  prob->dualbound = SCIP_INVALID;
1580 }
1581 
1582 /** if possible, scales objective function such that it is integral with gcd = 1 */
1584  SCIP_PROB* transprob, /**< tranformed problem data */
1585  SCIP_PROB* origprob, /**< original problem data */
1586  BMS_BLKMEM* blkmem, /**< block memory */
1587  SCIP_SET* set, /**< global SCIP settings */
1588  SCIP_STAT* stat, /**< problem statistics data */
1589  SCIP_PRIMAL* primal, /**< primal data */
1590  SCIP_TREE* tree, /**< branch and bound tree */
1591  SCIP_REOPT* reopt, /**< reoptimization data structure */
1592  SCIP_LP* lp, /**< current LP data */
1593  SCIP_EVENTQUEUE* eventqueue /**< event queue */
1594  )
1595 {
1596  int v;
1597  int nints;
1598 
1599  assert(transprob != NULL);
1600  assert(set != NULL);
1601 
1602  /* do not change objective if there are pricers involved */
1603  if( set->nactivepricers != 0 )
1604  return SCIP_OKAY;
1605 
1606  nints = transprob->nvars - transprob->ncontvars;
1607 
1608  /* scan through the continuous variables */
1609  for( v = nints; v < transprob->nvars; ++v )
1610  {
1611  SCIP_Real obj;
1612 
1613  /* get objective value of variable; it it is non-zero, no scaling can be applied */
1614  obj = SCIPvarGetObj(transprob->vars[v]);
1615  if( !SCIPsetIsZero(set, obj) )
1616  break;
1617  }
1618 
1619  /* only continue if all continuous variables have obj = 0 */
1620  if( v == transprob->nvars )
1621  {
1622  SCIP_Real* objvals;
1623  SCIP_Real intscalar;
1624  SCIP_Bool success;
1625 
1626  /* get temporary memory */
1627  SCIP_CALL( SCIPsetAllocBufferArray(set, &objvals, nints) );
1628 
1629  /* get objective values of integer variables */
1630  for( v = 0; v < nints; ++v )
1631  objvals[v] = SCIPvarGetObj(transprob->vars[v]);
1632 
1633  /* calculate integral scalar */
1635  &intscalar, &success) );
1636 
1637  SCIPsetDebugMsg(set, "integral objective scalar: success=%u, intscalar=%g\n", success, intscalar);
1638 
1639  if( success )
1640  {
1641  SCIP_Longint gcd;
1642 
1643  assert(intscalar > 0.0);
1644 
1645  /* calculate gcd of resulting integral coefficients */
1646  gcd = 0;
1647  for( v = 0; v < nints && gcd != 1; ++v )
1648  {
1649  SCIP_Longint absobj;
1650 
1651  /* if absobj exceeds maximum SCIP_Longint value, return */
1652  if( REALABS(objvals[v]) * intscalar + 0.5 > SCIP_LONGINT_MAX )
1653  {
1654  SCIPsetFreeBufferArray(set, &objvals);
1655  return SCIP_OKAY;
1656  }
1657 
1658  absobj = (SCIP_Longint)(REALABS(objvals[v]) * intscalar + 0.5);
1659  if( gcd == 0 )
1660  gcd = absobj;
1661  else if( absobj > 0 )
1662  gcd = SCIPcalcGreComDiv(gcd, absobj);
1663  }
1664  if( gcd != 0 )
1665  intscalar /= gcd;
1666  SCIPsetDebugMsg(set, "integral objective scalar: gcd=%" SCIP_LONGINT_FORMAT ", intscalar=%g\n", gcd, intscalar);
1667 
1668  /* only apply scaling if the final scalar is small enough */
1669  if( intscalar <= OBJSCALE_MAXFINALSCALE )
1670  {
1671  /* apply scaling */
1672  if( !SCIPsetIsEQ(set, intscalar, 1.0) )
1673  {
1674  /* calculate scaled objective values */
1675  for( v = 0; v < nints; ++v )
1676  {
1677  SCIP_Real newobj;
1678 
1679  /* check if new obj is really integral */
1680  newobj = intscalar * SCIPvarGetObj(transprob->vars[v]);
1681  if( !SCIPsetIsFeasIntegral(set, newobj) )
1682  break;
1683  objvals[v] = SCIPsetFeasFloor(set, newobj);
1684  }
1685 
1686  /* change the variables' objective values and adjust objscale and objoffset */
1687  if( v == nints )
1688  {
1689  for( v = 0; v < nints; ++v )
1690  {
1691  SCIPsetDebugMsg(set, " -> var <%s>: newobj = %.6f\n", SCIPvarGetName(transprob->vars[v]), objvals[v]);
1692  SCIP_CALL( SCIPvarChgObj(transprob->vars[v], blkmem, set, transprob, primal, lp, eventqueue, objvals[v]) );
1693  }
1694  transprob->objoffset *= intscalar;
1695  transprob->objscale /= intscalar;
1696  transprob->objisintegral = TRUE;
1697  SCIPsetDebugMsg(set, "integral objective scalar: objscale=%g\n", transprob->objscale);
1698 
1699  /* update upperbound and cutoffbound in primal data structure */
1700  SCIP_CALL( SCIPprimalUpdateObjoffset(primal, blkmem, set, stat, eventqueue, transprob, origprob, tree, reopt, lp) );
1701  }
1702  }
1703  }
1704  }
1705 
1706  /* free temporary memory */
1707  SCIPsetFreeBufferArray(set, &objvals);
1708  }
1709 
1710  return SCIP_OKAY;
1711 }
1712 
1713 /** remembers the current solution as root solution in the problem variables */
1715  SCIP_PROB* prob, /**< problem data */
1716  SCIP_SET* set, /**< global SCIP settings */
1717  SCIP_STAT* stat, /**< SCIP statistics */
1718  SCIP_LP* lp, /**< current LP data */
1719  SCIP_Bool roothaslp /**< is the root solution from LP? */
1720  )
1721 {
1722  int v;
1723 
1724  assert(prob != NULL);
1725  assert(prob->transformed);
1726 
1727  if( roothaslp )
1728  {
1729  for( v = 0; v < prob->nvars; ++v )
1730  SCIPvarStoreRootSol(prob->vars[v], roothaslp);
1731 
1733  SCIPlpStoreRootObjval(lp, set, prob);
1734 
1735  /* compute root LP best-estimate */
1736  SCIPstatComputeRootLPBestEstimate(stat, set, SCIPlpGetColumnObjval(lp), prob->vars, prob->nbinvars + prob->nintvars + prob->nimplvars);
1737  }
1738 }
1739 
1740 /** remembers the best solution w.r.t. root reduced cost propagation as root solution in the problem variables */
1742  SCIP_PROB* prob, /**< problem data */
1743  SCIP_SET* set, /**< global SCIP settings */
1744  SCIP_STAT* stat, /**< problem statistics */
1745  SCIP_LP* lp /**< current LP data */
1746  )
1747 {
1748  SCIP_Real rootlpobjval;
1749  int v;
1750 
1751  assert(prob != NULL);
1752  assert(lp != NULL);
1753  assert(prob->transformed);
1754  assert(lp->lpsolstat == SCIP_LPSOLSTAT_OPTIMAL);
1755 
1756  /* in case we have a zero objective fucntion, we skip the root reduced cost update */
1757  if( SCIPprobGetNObjVars(prob, set) == 0 )
1758  return;
1759 
1760  SCIPsetDebugMsg(set, "update root reduced costs\n");
1761 
1762  /* compute current root LP objective value */
1763  rootlpobjval = SCIPlpGetObjval(lp, set, prob);
1764  assert(rootlpobjval != SCIP_INVALID); /*lint !e777*/
1765 
1766  for( v = 0; v < prob->nvars; ++v )
1767  {
1768  SCIP_VAR* var;
1769  SCIP_COL* col;
1770  SCIP_Real rootsol = 0.0;
1771  SCIP_Real rootredcost = 0.0;
1772 
1773  var = prob->vars[v];
1774  assert(var != NULL);
1775 
1776  /* check if the variable is part of the LP */
1778  continue;
1779 
1780  col = SCIPvarGetCol(var);
1781  assert(col != NULL);
1782 
1784 
1785  if( !SCIPvarIsBinary(var) )
1786  {
1787  rootsol = SCIPvarGetSol(var, TRUE);
1788  rootredcost = SCIPcolGetRedcost(col, stat, lp);
1789  }
1790  else
1791  {
1792  SCIP_Real primsol;
1793  SCIP_BASESTAT basestat;
1794  SCIP_Bool lpissolbasic;
1795 
1796  basestat = SCIPcolGetBasisStatus(col);
1797  lpissolbasic = SCIPlpIsSolBasic(lp);
1798  primsol = SCIPcolGetPrimsol(col);
1799 
1800  if( (lpissolbasic && (basestat == SCIP_BASESTAT_LOWER || basestat == SCIP_BASESTAT_UPPER)) ||
1801  (!lpissolbasic && (SCIPsetIsFeasEQ(set, SCIPvarGetLbLocal(var), primsol) ||
1802  SCIPsetIsFeasEQ(set, SCIPvarGetUbLocal(var), primsol))) )
1803  {
1804  SCIP_Real lbrootredcost;
1805  SCIP_Real ubrootredcost;
1806 
1807  /* get reduced cost if the variable gets fixed to zero */
1808  lbrootredcost = SCIPvarGetImplRedcost(var, set, FALSE, stat, prob, lp);
1809  assert( !SCIPsetIsDualfeasPositive(set, lbrootredcost)
1811 
1812  /* get reduced cost if the variable gets fixed to one */
1813  ubrootredcost = SCIPvarGetImplRedcost(var, set, TRUE, stat, prob, lp);
1814  assert( !SCIPsetIsDualfeasNegative(set, ubrootredcost)
1816 
1817  if( -lbrootredcost > ubrootredcost )
1818  {
1819  rootredcost = lbrootredcost;
1820  rootsol = 1.0;
1821  }
1822  else
1823  {
1824  rootredcost = ubrootredcost;
1825  rootsol = 0.0;
1826  }
1827  }
1828  }
1829 
1830  /* update the current solution as best root solution in the problem variables if it is better */
1831  SCIPvarUpdateBestRootSol(var, set, rootsol, rootredcost, rootlpobjval);
1832  }
1833 }
1834 
1835 /** informs problem, that the presolving process was finished, and updates all internal data structures */
1837  SCIP_PROB* prob, /**< problem data */
1838  SCIP_SET* set /**< global SCIP settings */
1839  )
1840 { /*lint --e{715}*/
1841  return SCIP_OKAY;
1842 }
1843 
1844 /** initializes problem for branch and bound process and resets all constraint's ages and histories of current run */
1846  SCIP_PROB* prob, /**< problem data */
1847  SCIP_SET* set /**< global SCIP settings */
1848  )
1849 {
1850  int c;
1851  int v;
1852 
1853  assert(prob != NULL);
1854  assert(prob->transformed);
1855  assert(set != NULL);
1856 
1857  /* reset constraint's ages */
1858  for( c = 0; c < prob->nconss; ++c )
1859  {
1860  SCIP_CALL( SCIPconsResetAge(prob->conss[c], set) );
1861  }
1862 
1863  /* initialize variables for solving */
1864  for( v = 0; v < prob->nvars; ++v )
1865  SCIPvarInitSolve(prob->vars[v]);
1866 
1867  /* call user data function */
1868  if( prob->probinitsol != NULL )
1869  {
1870  SCIP_CALL( prob->probinitsol(set->scip, prob->probdata) );
1871  }
1872 
1873  /* assert that the counter for variables with nonzero objective is correct */
1874  assert(prob->nobjvars == SCIPprobGetNObjVars(prob, set));
1875 
1876  return SCIP_OKAY;
1877 }
1878 
1879 /** deinitializes problem after branch and bound process, and converts all COLUMN variables back into LOOSE variables */
1881  SCIP_PROB* prob, /**< problem data */
1882  BMS_BLKMEM* blkmem, /**< block memory */
1883  SCIP_SET* set, /**< global SCIP settings */
1884  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1885  SCIP_LP* lp, /**< current LP data */
1886  SCIP_Bool restart /**< was this exit solve call triggered by a restart? */
1887  )
1888 {
1889  SCIP_VAR* var;
1890  int v;
1891 
1892  assert(prob != NULL);
1893  assert(prob->transformed);
1894  assert(set != NULL);
1895 
1896  /* call user data function */
1897  if( prob->probexitsol != NULL )
1898  {
1899  SCIP_CALL( prob->probexitsol(set->scip, prob->probdata, restart) );
1900  }
1901 
1902  /* convert all COLUMN variables back into LOOSE variables */
1903  if( prob->ncolvars > 0 )
1904  {
1905  for( v = 0; v < prob->nvars; ++v )
1906  {
1907  var = prob->vars[v];
1909  {
1910  SCIP_CALL( SCIPvarLoose(var, blkmem, set, eventqueue, prob, lp) );
1911  }
1912 
1913  /* invalided root reduced cost, root reduced solution, and root LP objective value for each variable */
1914  SCIPvarSetBestRootSol(var, 0.0, 0.0, SCIP_INVALID);
1915  }
1916  }
1917  assert(prob->ncolvars == 0);
1918 
1919  return SCIP_OKAY;
1920 }
1921 
1922 
1923 
1924 
1925 /*
1926  * problem information
1927  */
1928 
1929 /** sets problem name */
1931  SCIP_PROB* prob, /**< problem data */
1932  const char* name /**< name to be set */
1933  )
1934 {
1935  assert(prob != NULL);
1936 
1937  BMSfreeMemoryArray(&(prob->name));
1938  SCIP_ALLOC( BMSduplicateMemoryArray(&(prob->name), name, strlen(name)+1) );
1939 
1940  return SCIP_OKAY;
1941 }
1942 
1943 /** returns the number of implicit binary variables, meaning variable of vartype != SCIP_VARTYPE_BINARY and !=
1944  * SCIP_VARTYPE_CONTINUOUS but with global bounds [0,1]
1945  *
1946  * @note this number needs to be computed, because it cannot be updated like the other counters for binary and integer
1947  * variables, each time the variable type changes(, we would need to update this counter each time a global bound
1948  * changes), even at the end of presolving this cannot be computed, because some variable can change to an
1949  * implicit binary status
1950  */
1952  SCIP_PROB* prob /**< problem data */
1953  )
1954 {
1955  int v;
1956  int nimplbinvars = 0;
1957 
1958  for( v = prob->nbinvars + prob->nintvars + prob->nimplvars - 1; v >= prob->nbinvars; --v )
1959  {
1960  if( SCIPvarIsBinary(prob->vars[v]) )
1961  ++nimplbinvars;
1962  }
1963 
1964  return nimplbinvars;
1965 }
1966 
1967 /** returns the number of variables with non-zero objective coefficient */
1969  SCIP_PROB* prob, /**< problem data */
1970  SCIP_SET* set /**< global SCIP settings */
1971  )
1972 {
1973  if( prob->transformed )
1974  {
1975  /* this is much too expensive, to check it in each debug run */
1976 #ifdef SCIP_MORE_DEBUG
1977  int nobjvars;
1978  int v;
1979 
1980  nobjvars = 0;
1981 
1982  for( v = prob->nvars - 1; v >= 0; --v )
1983  {
1984  if( !SCIPsetIsZero(set, SCIPvarGetObj(prob->vars[v])) )
1985  nobjvars++;
1986  }
1987 
1988  /* check that the internal count is correct */
1989  assert(prob->nobjvars == nobjvars);
1990 #endif
1991  return prob->nobjvars;
1992  }
1993  else
1994  {
1995  int nobjvars;
1996  int v;
1997 
1998  nobjvars = 0;
1999 
2000  for( v = prob->nvars - 1; v >= 0; --v )
2001  {
2002  if( !SCIPsetIsZero(set, SCIPvarGetObj(prob->vars[v])) )
2003  nobjvars++;
2004  }
2005  return nobjvars;
2006  }
2007 }
2008 
2009 /** returns the external value of the given internal objective value */
2011  SCIP_PROB* transprob, /**< tranformed problem data */
2012  SCIP_PROB* origprob, /**< original problem data */
2013  SCIP_SET* set, /**< global SCIP settings */
2014  SCIP_Real objval /**< internal objective value */
2015  )
2016 {
2017  assert(set != NULL);
2018  assert(origprob != NULL);
2019  assert(transprob != NULL);
2020  assert(transprob->transformed);
2021  assert(transprob->objscale > 0.0);
2022 
2023  if( SCIPsetIsInfinity(set, objval) )
2024  return (SCIP_Real)transprob->objsense * SCIPsetInfinity(set);
2025  else if( SCIPsetIsInfinity(set, -objval) )
2026  return -(SCIP_Real)transprob->objsense * SCIPsetInfinity(set);
2027  else
2028  return (SCIP_Real)transprob->objsense * transprob->objscale * (objval + transprob->objoffset) + origprob->objoffset;
2029 }
2030 
2031 /** returns the internal value of the given external objective value */
2033  SCIP_PROB* transprob, /**< tranformed problem data */
2034  SCIP_PROB* origprob, /**< original problem data */
2035  SCIP_SET* set, /**< global SCIP settings */
2036  SCIP_Real objval /**< external objective value */
2037  )
2038 {
2039  assert(set != NULL);
2040  assert(origprob != NULL);
2041  assert(transprob != NULL);
2042  assert(transprob->transformed);
2043  assert(transprob->objscale > 0.0);
2044 
2045  if( SCIPsetIsInfinity(set, objval) )
2046  return (SCIP_Real)transprob->objsense * SCIPsetInfinity(set);
2047  else if( SCIPsetIsInfinity(set, -objval) )
2048  return -(SCIP_Real)transprob->objsense * SCIPsetInfinity(set);
2049  else
2050  return (SCIP_Real)transprob->objsense * (objval - origprob->objoffset)/transprob->objscale - transprob->objoffset;
2051 }
2052 
2053 /** returns variable of the problem with given name */
2055  SCIP_PROB* prob, /**< problem data */
2056  const char* name /**< name of variable to find */
2057  )
2058 {
2059  assert(prob != NULL);
2060  assert(name != NULL);
2061 
2062  if( prob->varnames == NULL )
2063  {
2064  SCIPerrorMessage("Cannot find variable if variable-names hashtable was disabled (due to parameter <misc/usevartable>)\n");
2065  SCIPABORT();/*lint --e{527}*/ /* only in debug mode */
2066  return NULL;
2067  }
2068 
2069  return (SCIP_VAR*)(SCIPhashtableRetrieve(prob->varnames, (char*)name));
2070 }
2071 
2072 /** returns constraint of the problem with given name */
2074  SCIP_PROB* prob, /**< problem data */
2075  const char* name /**< name of variable to find */
2076  )
2077 {
2078  assert(prob != NULL);
2079  assert(name != NULL);
2080 
2081  if( prob->consnames == NULL )
2082  {
2083  SCIPerrorMessage("Cannot find constraint if constraint-names hashtable was disabled (due to parameter <misc/useconstable>)\n");
2084  SCIPABORT();/*lint --e{527}*/ /* only in debug mode */
2085  return NULL;
2086  }
2087 
2088  return (SCIP_CONS*)(SCIPhashtableRetrieve(prob->consnames, (char*)name));
2089 }
2090 
2091 /** displays current pseudo solution */
2093  SCIP_PROB* prob, /**< problem data */
2094  SCIP_SET* set, /**< global SCIP settings */
2095  SCIP_MESSAGEHDLR* messagehdlr /**< message handler */
2096  )
2097 {
2098  SCIP_VAR* var;
2099  SCIP_Real solval;
2100  int v;
2101 
2102  for( v = 0; v < prob->nvars; ++v )
2103  {
2104  var = prob->vars[v];
2105  assert(var != NULL);
2106  solval = SCIPvarGetPseudoSol(var);
2107  if( !SCIPsetIsZero(set, solval) )
2108  SCIPmessagePrintInfo(messagehdlr, " <%s>=%.15g", SCIPvarGetName(var), solval);
2109  }
2110  SCIPmessagePrintInfo(messagehdlr, "\n");
2111 }
2112 
2113 /** outputs problem statistics */
2115  SCIP_PROB* prob, /**< problem data */
2116  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
2117  FILE* file /**< output file (or NULL for standard output) */
2118  )
2119 {
2120  assert(prob != NULL);
2121 
2122  SCIPmessageFPrintInfo(messagehdlr, file, " Problem name : %s\n", prob->name);
2123  SCIPmessageFPrintInfo(messagehdlr, file, " Variables : %d (%d binary, %d integer, %d implicit integer, %d continuous)\n",
2124  prob->nvars, prob->nbinvars, prob->nintvars, prob->nimplvars, prob->ncontvars);
2125  SCIPmessageFPrintInfo(messagehdlr, file, " Constraints : %d initial, %d maximal\n", prob->startnconss, prob->maxnconss);
2126  if( ! prob->transformed )
2127  SCIPmessageFPrintInfo(messagehdlr, file, " Objective sense : %s\n", prob->objsense == SCIP_OBJSENSE_MINIMIZE ? "minimize" : "maximize");
2128 }
2129 
2130 #ifndef NDEBUG
2131 
2132 /* In debug mode, the following methods are implemented as function calls to ensure
2133  * type validity.
2134  * In optimized mode, the methods are implemented as defines to improve performance.
2135  * However, we want to have them in the library anyways, so we have to undef the defines.
2136  */
2137 
2138 #undef SCIPprobIsPermuted
2139 #undef SCIPprobMarkPermuted
2140 #undef SCIPprobIsTransformed
2141 #undef SCIPprobIsObjIntegral
2142 #undef SCIPprobAllColsInLP
2143 #undef SCIPprobGetObjlim
2144 #undef SCIPprobGetData
2145 #undef SCIPprobGetName
2146 #undef SCIPprobGetNVars
2147 #undef SCIPprobGetNBinVars
2148 #undef SCIPprobGetNIntVars
2149 #undef SCIPprobGetNImplVars
2150 #undef SCIPprobGetNContVars
2151 #undef SCIPprobGetNConss
2152 #undef SCIPprobGetVars
2153 #undef SCIPprobGetObjoffset
2154 #undef SCIPisConsCompressedEnabled
2155 #undef SCIPprobEnableConsCompression
2156 
2157 /** is the problem permuted */
2159  SCIP_PROB* prob
2160  )
2161 {
2162  assert(prob != NULL);
2163 
2164  return prob->permuted;
2165 }
2166 
2167 /** mark the problem as permuted */
2169  SCIP_PROB* prob
2170  )
2171 {
2172  assert(prob != NULL);
2173 
2174  prob->permuted = TRUE;
2175 }
2176 
2177 /** is the problem data transformed */
2179  SCIP_PROB* prob /**< problem data */
2180  )
2181 {
2182  assert(prob != NULL);
2183 
2184  return prob->transformed;
2185 }
2186 
2187 /** returns whether the objective value is known to be integral in every feasible solution */
2189  SCIP_PROB* prob /**< problem data */
2190  )
2191 {
2192  assert(prob != NULL);
2193 
2194  return prob->objisintegral;
2195 }
2196 
2197 /** returns TRUE iff all columns, i.e. every variable with non-empty column w.r.t. all ever created rows, are present
2198  * in the LP, and FALSE, if there are additional already existing columns, that may be added to the LP in pricing
2199  */
2201  SCIP_PROB* prob, /**< problem data */
2202  SCIP_SET* set, /**< global SCIP settings */
2203  SCIP_LP* lp /**< current LP data */
2204  )
2205 {
2206  assert(SCIPlpGetNCols(lp) <= prob->ncolvars && prob->ncolvars <= prob->nvars);
2207 
2208  return (SCIPlpGetNCols(lp) == prob->ncolvars && set->nactivepricers == 0);
2209 }
2210 
2211 /** gets limit on objective function in external space */
2213  SCIP_PROB* prob, /**< problem data */
2214  SCIP_SET* set /**< global SCIP settings */
2215  )
2216 {
2217  assert(prob != NULL);
2218  assert(set != NULL);
2219 
2220  return prob->objlim >= SCIP_INVALID ? (SCIP_Real)(prob->objsense) * SCIPsetInfinity(set) : prob->objlim;
2221 }
2222 
2223 /** gets user problem data */
2225  SCIP_PROB* prob /**< problem */
2226  )
2227 {
2228  assert(prob != NULL);
2229 
2230  return prob->probdata;
2231 }
2232 
2233 /** gets problem name */
2234 const char* SCIPprobGetName(
2235  SCIP_PROB* prob /**< problem data */
2236  )
2237 {
2238  assert(prob != NULL);
2239  return prob->name;
2240 }
2241 
2242 /** gets number of problem variables */
2244  SCIP_PROB* prob /**< problem data */
2245  )
2246 {
2247  assert(prob != NULL);
2248  return prob->nvars;
2249 }
2250 
2251 /** gets number of binary problem variables */
2253  SCIP_PROB* prob /**< problem data */
2254  )
2255 {
2256  assert(prob != NULL);
2257  return prob->nbinvars;
2258 }
2259 
2260 /** gets number of integer problem variables */
2262  SCIP_PROB* prob /**< problem data */
2263  )
2264 {
2265  assert(prob != NULL);
2266  return prob->nintvars;
2267 }
2268 
2269 /** gets number of implicit integer problem variables */
2271  SCIP_PROB* prob /**< problem data */
2272  )
2273 {
2274  assert(prob != NULL);
2275  return prob->nimplvars;
2276 }
2277 
2278 /** gets number of continuous problem variables */
2280  SCIP_PROB* prob /**< problem data */
2281  )
2282 {
2283  assert(prob != NULL);
2284  return prob->ncontvars;
2285 }
2286 
2287 /** gets problem variables */
2289  SCIP_PROB* prob /**< problem data */
2290  )
2291 {
2292  assert(prob != NULL);
2293  return prob->vars;
2294 }
2295 
2296 /** gets number of problem constraints */
2298  SCIP_PROB* prob /**< problem data */
2299  )
2300 {
2301  assert(prob != NULL);
2302  return prob->nconss;
2303 }
2304 
2305 /** gets the objective offset */
2307  SCIP_PROB* prob /**< problem data */
2308  )
2309 {
2310  assert(prob != NULL);
2311  return prob->objoffset;
2312 }
2313 
2314 /** gets the objective scalar */
2316  SCIP_PROB* prob /**< problem data */
2317  )
2318 {
2319  assert(prob != NULL);
2320  return prob->objscale;
2321 }
2322 
2323 /** is constraint compression enabled for this problem? */
2325  SCIP_PROB* prob /**< problem data */
2326  )
2327 {
2328  assert(prob != NULL);
2329 
2330  return prob->conscompression;
2331 }
2332 
2333 /** enable problem compression, i.e., constraints can reduce memory size by removing fixed variables during creation */
2335  SCIP_PROB* prob /**< problem data */
2336  )
2337 {
2338  assert(prob != NULL);
2339 
2340  prob->conscompression = TRUE;
2341 }
2342 
2343 #endif
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_Bool SCIPsetIsInfinity(SCIP_SET *set, SCIP_Real val)
Definition: set.c:5522
internal methods for managing events
SCIP_VAR * SCIPprobFindVar(SCIP_PROB *prob, const char *name)
Definition: prob.c:2054
int SCIPprobGetNBinVars(SCIP_PROB *prob)
Definition: prob.c:2252
void SCIPvarUpdateBestRootSol(SCIP_VAR *var, SCIP_SET *set, SCIP_Real rootsol, SCIP_Real rootredcost, SCIP_Real rootlpobjval)
Definition: var.c:12584
SCIP_RETCODE SCIPlpUpdateAddVar(SCIP_LP *lp, SCIP_SET *set, SCIP_VAR *var)
Definition: lp.c:13373
static void probInsertVar(SCIP_PROB *prob, SCIP_VAR *var)
Definition: prob.c:701
void SCIPstatComputeRootLPBestEstimate(SCIP_STAT *stat, SCIP_SET *set, SCIP_Real rootlpobjval, SCIP_VAR **vars, int nvars)
Definition: stat.c:643
SCIP_HASHTABLE * varnames
Definition: struct_prob.h:54
SCIP_RETCODE SCIPconsActivate(SCIP_CONS *cons, SCIP_SET *set, SCIP_STAT *stat, int depth, SCIP_Bool focusnode)
Definition: cons.c:6638
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:103
int SCIPprobGetNConss(SCIP_PROB *prob)
Definition: prob.c:2297
unsigned int active
Definition: struct_cons.h:76
internal methods for branch and bound tree
SCIP_Bool SCIPprobIsConsCompressionEnabled(SCIP_PROB *prob)
Definition: prob.c:2324
void SCIPprobSetData(SCIP_PROB *prob, SCIP_PROBDATA *probdata)
Definition: prob.c:689
SCIP_PROBDATA * SCIPprobGetData(SCIP_PROB *prob)
Definition: prob.c:2224
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2254
void SCIPprobUpdateBestRootSol(SCIP_PROB *prob, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp)
Definition: prob.c:1741
SCIP_Bool SCIPsetIsFeasEQ(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5920
enum SCIP_BaseStat SCIP_BASESTAT
Definition: type_lpi.h:86
#define SCIP_DECL_PROBINITSOL(x)
Definition: type_prob.h:97
void SCIPlpSetRootLPIsRelax(SCIP_LP *lp, SCIP_Bool isrelax)
Definition: lp.c:16691
SCIP_RETCODE SCIPeventqueueAdd(SCIP_EVENTQUEUE *eventqueue, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_PRIMAL *primal, SCIP_LP *lp, SCIP_BRANCHCAND *branchcand, SCIP_EVENTFILTER *eventfilter, SCIP_EVENT **event)
Definition: event.c:2112
#define SCIP_MAXSTRLEN
Definition: def.h:215
SCIP_RETCODE SCIPconflictstoreTransform(SCIP_CONFLICTSTORE *conflictstore, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_TREE *tree, SCIP_PROB *transprob, SCIP_REOPT *reopt)
#define SCIP_DECL_PROBDELORIG(x)
Definition: type_prob.h:55
SCIP_BASESTAT SCIPcolGetBasisStatus(SCIP_COL *col)
Definition: lp.c:16070
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17222
SCIP_RETCODE SCIPprobChgVarType(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_BRANCHCAND *branchcand, SCIP_CLIQUETABLE *cliquetable, SCIP_VAR *var, SCIP_VARTYPE vartype)
Definition: prob.c:1125
SCIP_RETCODE SCIPvarAddLocks(SCIP_VAR *var, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_EVENTQUEUE *eventqueue, int addnlocksdown, int addnlocksup)
Definition: var.c:3047
SCIP_RETCODE SCIPprobVarChangedStatus(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_BRANCHCAND *branchcand, SCIP_CLIQUETABLE *cliquetable, SCIP_VAR *var)
Definition: prob.c:1171
int nintvars
Definition: struct_prob.h:63
void SCIPprobAddObjoffset(SCIP_PROB *prob, SCIP_Real addval)
Definition: prob.c:1419
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:16732
SCIP_Real SCIPsetInfinity(SCIP_SET *set)
Definition: set.c:5384
SCIP_Real SCIPvarGetSol(SCIP_VAR *var, SCIP_Bool getlpval)
Definition: var.c:12561
int SCIPprobGetNVars(SCIP_PROB *prob)
Definition: prob.c:2243
int startnconss
Definition: struct_prob.h:76
#define SCIP_DECL_PROBDELTRANS(x)
Definition: type_prob.h:86
void SCIPvarSetProbindex(SCIP_VAR *var, int probindex)
Definition: var.c:5635
static SCIP_Bool consHasName(SCIP_CONS *cons)
Definition: prob.c:151
#define FALSE
Definition: def.h:64
SCIP_Bool SCIPlpIsSolBasic(SCIP_LP *lp)
Definition: lp.c:16789
SCIP_Bool SCIPsetIsFeasIntegral(SCIP_SET *set, SCIP_Real val)
Definition: set.c:6063
SCIP_Real objoffset
Definition: struct_prob.h:41
SCIP_RETCODE SCIPvarTransform(SCIP_VAR *origvar, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_OBJSENSE objsense, SCIP_VAR **transvar)
Definition: var.c:3290
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:9340
SCIP_Bool SCIPsetIsZero(SCIP_SET *set, SCIP_Real val)
Definition: set.c:5634
#define TRUE
Definition: def.h:63
void SCIPprobSetExitsol(SCIP_PROB *prob, SCIP_DECL_PROBEXITSOL((*probexitsol)))
Definition: prob.c:372
void SCIPprobMarkNConss(SCIP_PROB *prob)
Definition: prob.c:1393
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
unsigned int enabled
Definition: struct_cons.h:82
SCIP_Real SCIPprobInternObjval(SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_SET *set, SCIP_Real objval)
Definition: prob.c:2032
#define SCIPsetAllocBufferArray(set, ptr, num)
Definition: set.h:1834
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:16859
internal methods for branching rules and branching candidate storage
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:5096
void SCIPvarInitSolve(SCIP_VAR *var)
Definition: var.c:2810
SCIP_RETCODE SCIPprobInitSolve(SCIP_PROB *prob, SCIP_SET *set)
Definition: prob.c:1845
SCIP_VAR ** fixedvars
Definition: struct_prob.h:56
SCIP_RETCODE SCIPprobScaleObj(SCIP_PROB *transprob, SCIP_PROB *origprob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PRIMAL *primal, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue)
Definition: prob.c:1583
#define SCIPdebugMessage
Definition: pub_message.h:77
void SCIPprobUpdateNObjVars(SCIP_PROB *prob, SCIP_SET *set, SCIP_Real oldobj, SCIP_Real newobj)
Definition: prob.c:1529
int nimplvars
Definition: struct_prob.h:64
#define SCIP_DECL_PROBCOPY(x)
Definition: type_prob.h:140
#define SCIP_LONGINT_MAX
Definition: def.h:121
#define SCIPsetFreeBufferArray(set, ptr)
Definition: set.h:1841
#define BMSfreeMemory(ptr)
Definition: memory.h:100
SCIP_LPSOLSTAT SCIPlpGetSolstat(SCIP_LP *lp)
Definition: lp.c:12452
internal methods for LP management
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
Definition: cons.c:7942
SCIP_RETCODE SCIPconsResetAge(SCIP_CONS *cons, SCIP_SET *set)
Definition: cons.c:7058
SCIP_HASHTABLE * consnames
Definition: struct_prob.h:58
internal methods for collecting primal CIP solutions and primal informations
SCIP_CONSSETCHG * addconssetchg
Definition: struct_cons.h:48
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
Definition: misc.c:2015
void SCIPprobSetObjIntegral(SCIP_PROB *prob)
Definition: prob.c:1454
int SCIPlpGetNCols(SCIP_LP *lp)
Definition: lp.c:16574
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
Definition: var.c:16982
int nobjvars
Definition: struct_prob.h:71
SCIP_Real dualbound
Definition: struct_prob.h:45
void SCIPprobPrintPseudoSol(SCIP_PROB *prob, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr)
Definition: prob.c:2092
SCIP_RETCODE SCIPprobFree(SCIP_PROB **prob, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_LP *lp)
Definition: prob.c:394
SCIP_Real SCIPprobGetObjlim(SCIP_PROB *prob, SCIP_SET *set)
Definition: prob.c:2212
int ndeletedvars
Definition: struct_prob.h:70
unsigned int deleted
Definition: struct_cons.h:85
SCIP_RETCODE SCIPprobAddConsName(SCIP_PROB *prob, SCIP_CONS *cons)
Definition: prob.c:1229
void SCIPprobSetInitsol(SCIP_PROB *prob, SCIP_DECL_PROBINITSOL((*probinitsol)))
Definition: prob.c:361
SCIP_Real SCIPprobGetObjscale(SCIP_PROB *prob)
Definition: prob.c:2315
static SCIP_RETCODE probEnsureVarsMem(SCIP_PROB *prob, SCIP_SET *set, int num)
Definition: prob.c:55
SCIP_RETCODE SCIPvarChgType(SCIP_VAR *var, SCIP_VARTYPE vartype)
Definition: var.c:5750
void SCIPprobSetCopy(SCIP_PROB *prob, SCIP_DECL_PROBCOPY((*probcopy)))
Definition: prob.c:383
SCIP_Real SCIPvarGetImplRedcost(SCIP_VAR *var, SCIP_SET *set, SCIP_Bool varfixing, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_LP *lp)
Definition: var.c:12771
SCIP_RETCODE SCIPprobPerformVarDeletions(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_CLIQUETABLE *cliquetable, SCIP_LP *lp, SCIP_BRANCHCAND *branchcand)
Definition: prob.c:1054
static SCIP_RETCODE probEnsureDeletedvarsMem(SCIP_PROB *prob, SCIP_SET *set, int num)
Definition: prob.c:103
SCIP_RETCODE SCIPprobRemoveVarName(SCIP_PROB *prob, SCIP_VAR *var)
Definition: prob.c:899
void SCIPprobSetObjsense(SCIP_PROB *prob, SCIP_OBJSENSE objsense)
Definition: prob.c:1406
SCIP_Real SCIPcolGetPrimsol(SCIP_COL *col)
Definition: lp.c:16035
int SCIPprobGetNImplVars(SCIP_PROB *prob)
Definition: prob.c:2270
#define BMSfreeMemoryArray(ptr)
Definition: memory.h:102
#define OBJSCALE_MAXFINALSCALE
Definition: prob.c:45
SCIP_Bool permuted
Definition: struct_prob.h:81
internal methods for storing and manipulating the main problem
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPconsTransform(SCIP_CONS *origcons, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_CONS **transcons)
Definition: cons.c:6319
SCIP_RETCODE SCIPprobExitSolve(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_EVENTQUEUE *eventqueue, SCIP_LP *lp, SCIP_Bool restart)
Definition: prob.c:1880
#define OBJSCALE_MAXDNOM
Definition: prob.c:43
SCIP_CONS * SCIPprobFindCons(SCIP_PROB *prob, const char *name)
Definition: prob.c:2073
SCIP_RETCODE SCIPvarChgObj(SCIP_VAR *var, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_PROB *prob, SCIP_PRIMAL *primal, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_Real newobj)
Definition: var.c:5801
int varssize
Definition: struct_prob.h:60
void SCIPprobEnableConsCompression(SCIP_PROB *prob)
Definition: prob.c:2334
SCIP_RETCODE SCIPvarRelease(SCIP_VAR **var, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_EVENTQUEUE *eventqueue, SCIP_LP *lp)
Definition: var.c:2765
SCIP_Bool SCIPvarIsTransformedOrigvar(SCIP_VAR *var)
Definition: var.c:12167
SCIP_RETCODE SCIPeventCreateVarAdded(SCIP_EVENT **event, BMS_BLKMEM *blkmem, SCIP_VAR *var)
Definition: event.c:478
SCIP_RETCODE SCIPconshdlrDelVars(SCIP_CONSHDLR *conshdlr, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat)
Definition: cons.c:4052
SCIP_Bool objisintegral
Definition: struct_prob.h:78
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7881
SCIP_OBJSENSE objsense
Definition: struct_prob.h:77
static SCIP_RETCODE probEnsureConssMem(SCIP_PROB *prob, SCIP_SET *set, int num)
Definition: prob.c:127
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16552
int SCIPprobGetNObjVars(SCIP_PROB *prob, SCIP_SET *set)
Definition: prob.c:1968
#define NULL
Definition: lpi_spx1.cpp:137
char * name
Definition: struct_prob.h:46
#define REALABS(x)
Definition: def.h:159
SCIP_RETCODE SCIPprobSetName(SCIP_PROB *prob, const char *name)
Definition: prob.c:1930
SCIP_Bool SCIPprobIsObjIntegral(SCIP_PROB *prob)
Definition: prob.c:2188
void SCIPsortPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
internal methods for global SCIP settings
internal methods for storing conflicts
SCIP * scip
Definition: struct_cons.h:40
#define SCIP_CALL(x)
Definition: def.h:306
void SCIPmessageFPrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
Definition: message.c:441
SCIP_RETCODE SCIPprobAddVarName(SCIP_PROB *prob, SCIP_VAR *var)
Definition: prob.c:883
SCIP_RETCODE SCIPprobResetBounds(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat)
Definition: prob.c:605
void SCIPmessagePrintInfo(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr,...)
Definition: message.c:584
SCIP_RETCODE SCIPhashtableRemove(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2384
int SCIPprobGetNContVars(SCIP_PROB *prob)
Definition: prob.c:2279
SCIP_RETCODE SCIPconsAddLocks(SCIP_CONS *cons, SCIP_SET *set, int nlockspos, int nlocksneg)
Definition: cons.c:7159
SCIP_RETCODE SCIPprobCreate(SCIP_PROB **prob, BMS_BLKMEM *blkmem, SCIP_SET *set, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata, SCIP_Bool transformed)
Definition: prob.c:249
SCIP_Bool SCIPsetIsEQ(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5544
SCIP_Bool conscompression
Definition: struct_prob.h:82
SCIP_Real SCIPlpGetObjval(SCIP_LP *lp, SCIP_SET *set, SCIP_PROB *prob)
Definition: lp.c:12468
void SCIPprobResortVars(SCIP_PROB *prob)
Definition: prob.c:631
int SCIPprobGetNIntVars(SCIP_PROB *prob)
Definition: prob.c:2261
SCIP_Bool SCIPconshdlrNeedsCons(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:5029
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:98
SCIP_RETCODE SCIPconshdlrUnlockVars(SCIP_CONSHDLR *conshdlr, SCIP_SET *set)
Definition: cons.c:4098
void SCIPvarSetBestRootSol(SCIP_VAR *var, SCIP_Real rootsol, SCIP_Real rootredcost, SCIP_Real rootlpobjval)
Definition: var.c:13149
#define SCIP_DECL_PROBTRANS(x)
Definition: type_prob.h:74
data structures and methods for collecting reoptimization information
internal methods for problem variables
SCIP_Bool SCIPsetIsIntegral(SCIP_SET *set, SCIP_Real val)
Definition: set.c:5667
public data structures and miscellaneous methods
SCIP_PROBDATA * probdata
Definition: struct_prob.h:53
#define SCIP_Bool
Definition: def.h:61
#define SCIP_DECL_PROBEXITSOL(x)
Definition: type_prob.h:110
void SCIPvarCapture(SCIP_VAR *var)
Definition: var.c:2753
SCIP_Bool SCIPprobIsPermuted(SCIP_PROB *prob)
Definition: prob.c:2158
char * name
Definition: struct_cons.h:43
int ncontvars
Definition: struct_prob.h:65
int nbinvars
Definition: struct_prob.h:62
SCIP_Real SCIPprobGetObjoffset(SCIP_PROB *prob)
Definition: prob.c:2306
enum SCIP_Objsense SCIP_OBJSENSE
Definition: type_prob.h:41
SCIP_RETCODE SCIPvarRemove(SCIP_VAR *var, BMS_BLKMEM *blkmem, SCIP_CLIQUETABLE *cliquetable, SCIP_SET *set, SCIP_Bool final)
Definition: var.c:5668
SCIP_RETCODE SCIPconsRelease(SCIP_CONS **cons, BMS_BLKMEM *blkmem, SCIP_SET *set)
Definition: cons.c:6112
void SCIPvarStoreRootSol(SCIP_VAR *var, SCIP_Bool roothaslp)
Definition: var.c:12573
#define MAX(x, y)
Definition: tclique_def.h:75
void SCIPprobSetTrans(SCIP_PROB *prob, SCIP_DECL_PROBTRANS((*probtrans)))
Definition: prob.c:339
SCIP_RETCODE SCIPprobCheckObjIntegral(SCIP_PROB *transprob, SCIP_PROB *origprob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PRIMAL *primal, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue)
Definition: prob.c:1466
#define SCIPsetDebugMsg
Definition: set.h:1870
SCIP_RETCODE SCIPeventCreateVarDeleted(SCIP_EVENT **event, BMS_BLKMEM *blkmem, SCIP_VAR *var)
Definition: event.c:496
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8080
SCIP_Bool SCIPprobAllColsInLP(SCIP_PROB *prob, SCIP_SET *set, SCIP_LP *lp)
Definition: prob.c:2200
SCIP_RETCODE SCIPprobRemoveConsName(SCIP_PROB *prob, SCIP_CONS *cons)
Definition: prob.c:1244
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17014
SCIP_VAR ** deletedvars
Definition: struct_prob.h:57
SCIP_RETCODE SCIPprobTransform(SCIP_PROB *source, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PRIMAL *primal, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_BRANCHCAND *branchcand, SCIP_EVENTFILTER *eventfilter, SCIP_EVENTQUEUE *eventqueue, SCIP_CONFLICTSTORE *conflictstore, SCIP_PROB **target)
Definition: prob.c:504
SCIP_COL * SCIPvarGetCol(SCIP_VAR *var)
Definition: var.c:16880
SCIP_RETCODE SCIPbranchcandUpdateVar(SCIP_BRANCHCAND *branchcand, SCIP_SET *set, SCIP_VAR *var)
Definition: branch.c:1099
void * SCIPhashtableRetrieve(SCIP_HASHTABLE *hashtable, void *key)
Definition: misc.c:2315
SCIP_Bool transformed
Definition: struct_prob.h:79
void SCIPprobPrintStatistics(SCIP_PROB *prob, SCIP_MESSAGEHDLR *messagehdlr, FILE *file)
Definition: prob.c:2114
void SCIPprobSetObjlim(SCIP_PROB *prob, SCIP_Real objlim)
Definition: prob.c:1443
int maxnconss
Definition: struct_prob.h:74
SCIP_RETCODE SCIPprobDelCons(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_CONS *cons)
Definition: prob.c:1333
int nfixedvars
Definition: struct_prob.h:68
int ncolvars
Definition: struct_prob.h:66
SCIP * scip
Definition: struct_var.h:200
void SCIPprobStoreRootSol(SCIP_PROB *prob, SCIP_SET *set, SCIP_STAT *stat, SCIP_LP *lp, SCIP_Bool roothaslp)
Definition: prob.c:1714
SCIP_Bool SCIPprobIsTransformed(SCIP_PROB *prob)
Definition: prob.c:2178
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:2065
#define SCIP_HASHSIZE_NAMES
Definition: def.h:225
SCIP_Bool SCIPsetIsDualfeasPositive(SCIP_SET *set, SCIP_Real val)
Definition: set.c:6252
SCIP_RETCODE SCIPvarLoose(SCIP_VAR *var, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_EVENTQUEUE *eventqueue, SCIP_PROB *prob, SCIP_LP *lp)
Definition: var.c:3436
SCIP_Real SCIPsetFeasFloor(SCIP_SET *set, SCIP_Real val)
Definition: set.c:6087
void SCIPlpStoreRootObjval(SCIP_LP *lp, SCIP_SET *set, SCIP_PROB *prob)
Definition: lp.c:12527
SCIP_Real objlim
Definition: struct_prob.h:44
void SCIPconsCapture(SCIP_CONS *cons)
Definition: cons.c:6100
struct SCIP_ProbData SCIP_PROBDATA
Definition: type_prob.h:44
SCIP_Bool nlpenabled
Definition: struct_prob.h:80
int fixedvarssize
Definition: struct_prob.h:67
static SCIP_RETCODE probEnsureFixedvarsMem(SCIP_PROB *prob, SCIP_SET *set, int num)
Definition: prob.c:79
static SCIP_RETCODE probRemoveVar(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_CLIQUETABLE *cliquetable, SCIP_SET *set, SCIP_VAR *var)
Definition: prob.c:789
SCIP_RETCODE SCIPprobCopy(SCIP_PROB **prob, BMS_BLKMEM *blkmem, SCIP_SET *set, const char *name, SCIP *sourcescip, SCIP_PROB *sourceprob, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global)
Definition: prob.c:186
int nconss
Definition: struct_prob.h:73
#define SCIP_HASHSIZE_NAMES_SMALL
Definition: def.h:228
public methods for message output
void SCIPprobUpdateDualbound(SCIP_PROB *prob, SCIP_Real newbound)
Definition: prob.c:1546
void SCIPprobSetDelorig(SCIP_PROB *prob, SCIP_DECL_PROBDELORIG((*probdelorig)))
Definition: prob.c:328
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
Definition: message.c:608
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16671
SCIP_RETCODE SCIPvarResetBounds(SCIP_VAR *var, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat)
Definition: var.c:8760
#define SCIP_Real
Definition: def.h:135
internal methods for problem statistics
SCIP_VAR ** vars
Definition: struct_prob.h:55
void SCIPprobSetDualbound(SCIP_PROB *prob, SCIP_Real dualbound)
Definition: prob.c:1432
#define MIN(x, y)
Definition: memory.c:75
int consssize
Definition: struct_prob.h:72
SCIP_VAR ** SCIPprobGetVars(SCIP_PROB *prob)
Definition: prob.c:2288
#define BMSallocMemory(ptr)
Definition: memory.h:74
SCIP_CONS ** conss
Definition: struct_prob.h:59
#define SCIP_INVALID
Definition: def.h:155
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:82
internal methods for constraints and constraint handlers
int SCIPvarGetNUses(SCIP_VAR *var)
Definition: var.c:16562
SCIP_Bool SCIPlpIsRelax(SCIP_LP *lp)
Definition: lp.c:16769
SCIP_RETCODE SCIPprimalUpdateObjoffset(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp)
Definition: primal.c:441
#define SCIP_Longint
Definition: def.h:120
SCIP_RETCODE SCIPcalcIntegralScalar(SCIP_Real *vals, int nvals, SCIP_Real mindelta, SCIP_Real maxdelta, SCIP_Longint maxdnom, SCIP_Real maxscale, SCIP_Real *intscalar, SCIP_Bool *success)
Definition: misc.c:8237
int SCIPprobGetNImplBinVars(SCIP_PROB *prob)
Definition: prob.c:1951
SCIP_RETCODE SCIPbranchcandRemoveVar(SCIP_BRANCHCAND *branchcand, SCIP_VAR *var)
Definition: branch.c:1082
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16717
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2366
void SCIPprobInvalidateDualbound(SCIP_PROB *prob)
Definition: prob.c:1573
void SCIPprobSetDeltrans(SCIP_PROB *prob, SCIP_DECL_PROBDELTRANS((*probdeltrans)))
Definition: prob.c:350
SCIP_Real SCIPsetEpsilon(SCIP_SET *set)
Definition: set.c:5406
SCIP_STAGE SCIPsetGetStage(SCIP_SET *set)
Definition: set.c:2669
unsigned int updatedeactivate
Definition: struct_cons.h:89
enum SCIP_Vartype SCIP_VARTYPE
Definition: type_var.h:60
SCIP_Real SCIPprobExternObjval(SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_SET *set, SCIP_Real objval)
Definition: prob.c:2010
static SCIP_Bool varHasName(SCIP_VAR *var)
Definition: prob.c:164
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17232
SCIP_RETCODE SCIPprobAddCons(SCIP_PROB *prob, SCIP_SET *set, SCIP_STAT *stat, SCIP_CONS *cons)
Definition: prob.c:1266
int addarraypos
Definition: struct_cons.h:50
SCIP_RETCODE SCIPconsDeactivate(SCIP_CONS *cons, SCIP_SET *set, SCIP_STAT *stat)
Definition: cons.c:6680
SCIP_Bool SCIPsetIsDualfeasNegative(SCIP_SET *set, SCIP_Real val)
Definition: set.c:6263
void SCIPconsSetLocal(SCIP_CONS *cons, SCIP_Bool local)
Definition: cons.c:6556
SCIP_RETCODE SCIPprobDelVar(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_EVENTQUEUE *eventqueue, SCIP_VAR *var, SCIP_Bool *deleted)
Definition: prob.c:993
common defines and data types used in all packages of SCIP
SCIP_Longint nnodes
Definition: struct_stat.h:71
SCIP_RETCODE SCIPprobExitPresolve(SCIP_PROB *prob, SCIP_SET *set)
Definition: prob.c:1836
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:392
SCIP_RETCODE SCIPlpUpdateDelVar(SCIP_LP *lp, SCIP_SET *set, SCIP_VAR *var)
Definition: lp.c:13394
int startnvars
Definition: struct_prob.h:75
SCIP_Real SCIPvarGetPseudoSol(SCIP_VAR *var)
Definition: var.c:17618
SCIP_Real SCIPcolGetRedcost(SCIP_COL *col, SCIP_STAT *stat, SCIP_LP *lp)
Definition: lp.c:3811
#define SCIP_ALLOC(x)
Definition: def.h:317
SCIP_Real SCIPlpGetColumnObjval(SCIP_LP *lp)
Definition: lp.c:12496
#define SCIPABORT()
Definition: def.h:278
SCIP_LPSOLSTAT lpsolstat
Definition: struct_lp.h:329
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:16743
SCIP_RETCODE SCIPconshdlrLockVars(SCIP_CONSHDLR *conshdlr, SCIP_SET *set)
Definition: cons.c:4083
const char * SCIPprobGetName(SCIP_PROB *prob)
Definition: prob.c:2234
SCIP_Longint SCIPcalcGreComDiv(SCIP_Longint val1, SCIP_Longint val2)
Definition: misc.c:7945
void SCIPprobMarkPermuted(SCIP_PROB *prob)
Definition: prob.c:2168
void SCIPvarMarkDeleted(SCIP_VAR *var)
Definition: var.c:5704
#define OBJSCALE_MAXSCALE
Definition: prob.c:44
SCIP_RETCODE SCIPprobAddVar(SCIP_PROB *prob, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_LP *lp, SCIP_BRANCHCAND *branchcand, SCIP_EVENTFILTER *eventfilter, SCIP_EVENTQUEUE *eventqueue, SCIP_VAR *var)
Definition: prob.c:914
SCIP_Real objscale
Definition: struct_prob.h:42
int deletedvarssize
Definition: struct_prob.h:69