Scippy

SCIP

Solving Constraint Integer Programs

primal.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-2016 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 primal.c
17  * @brief methods for collecting primal CIP solutions and primal informations
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 
25 #include "scip/def.h"
26 #include "scip/set.h"
27 #include "scip/stat.h"
28 #include "scip/visual.h"
29 #include "scip/event.h"
30 #include "scip/lp.h"
31 #include "scip/var.h"
32 #include "scip/prob.h"
33 #include "scip/sol.h"
34 #include "scip/primal.h"
35 #include "scip/tree.h"
36 #include "scip/reopt.h"
37 #include "scip/disp.h"
38 #include "scip/pub_message.h"
39 
40 
41 /*
42  * memory growing methods for dynamically allocated arrays
43  */
44 
45 /** ensures, that sols array can store at least num entries */
46 static
48  SCIP_PRIMAL* primal, /**< primal data */
49  SCIP_SET* set, /**< global SCIP settings */
50  int num /**< minimum number of entries to store */
51  )
52 {
53  assert(primal->nsols <= primal->solssize);
54 
55  if( num > primal->solssize )
56  {
57  int newsize;
58 
59  newsize = SCIPsetCalcMemGrowSize(set, num);
60  SCIP_ALLOC( BMSreallocMemoryArray(&primal->sols, newsize) );
61  primal->solssize = newsize;
62  }
63  assert(num <= primal->solssize);
64 
65  return SCIP_OKAY;
66 }
67 
68 /** ensures, that existingsols array can store at least num entries */
69 static
71  SCIP_PRIMAL* primal, /**< primal data */
72  SCIP_SET* set, /**< global SCIP settings */
73  int num /**< minimum number of entries to store */
74  )
75 {
76  assert(primal->nexistingsols <= primal->existingsolssize);
77 
78  if( num > primal->existingsolssize )
79  {
80  int newsize;
81 
82  newsize = SCIPsetCalcMemGrowSize(set, num);
83  SCIP_ALLOC( BMSreallocMemoryArray(&primal->existingsols, newsize) );
84  primal->existingsolssize = newsize;
85  }
86  assert(num <= primal->existingsolssize);
87 
88  return SCIP_OKAY;
89 }
90 
91 /** creates primal data */
93  SCIP_PRIMAL** primal /**< pointer to primal data */
94  )
95 {
96  assert(primal != NULL);
97 
98  SCIP_ALLOC( BMSallocMemory(primal) );
99  (*primal)->sols = NULL;
100  (*primal)->existingsols = NULL;
101  (*primal)->currentsol = NULL;
102  (*primal)->primalray = NULL;
103  (*primal)->solssize = 0;
104  (*primal)->nsols = 0;
105  (*primal)->existingsolssize = 0;
106  (*primal)->nexistingsols = 0;
107  (*primal)->nsolsfound = 0;
108  (*primal)->nlimsolsfound = 0;
109  (*primal)->nbestsolsfound = 0;
110  (*primal)->nlimbestsolsfound = 0;
111  (*primal)->upperbound = SCIP_INVALID;
112  (*primal)->cutoffbound = SCIP_INVALID;
113 
114  return SCIP_OKAY;
115 }
116 
117 /** frees primal data */
119  SCIP_PRIMAL** primal, /**< pointer to primal data */
120  BMS_BLKMEM* blkmem /**< block memory */
121  )
122 {
123  int s;
124 
125  assert(primal != NULL);
126  assert(*primal != NULL);
127 
128  /* free temporary solution for storing current solution */
129  if( (*primal)->currentsol != NULL )
130  {
131  SCIP_CALL( SCIPsolFree(&(*primal)->currentsol, blkmem, *primal) );
132  }
133 
134  /* free solution for storing primal ray */
135  if( (*primal)->primalray != NULL )
136  {
137  SCIP_CALL( SCIPsolFree(&(*primal)->primalray, blkmem, *primal) );
138  }
139 
140  /* free feasible primal CIP solutions */
141  for( s = 0; s < (*primal)->nsols; ++s )
142  {
143  SCIP_CALL( SCIPsolFree(&(*primal)->sols[s], blkmem, *primal) );
144  }
145  assert((*primal)->nexistingsols == 0);
146 
147  BMSfreeMemoryArrayNull(&(*primal)->sols);
148  BMSfreeMemoryArrayNull(&(*primal)->existingsols);
149  BMSfreeMemory(primal);
150 
151  return SCIP_OKAY;
152 }
153 
154 /** sets the cutoff bound in primal data and in LP solver */
155 static
157  SCIP_PRIMAL* primal, /**< primal data */
158  BMS_BLKMEM* blkmem, /**< block memory */
159  SCIP_SET* set, /**< global SCIP settings */
160  SCIP_STAT* stat, /**< problem statistics data */
161  SCIP_PROB* prob, /**< problem data */
162  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
163  SCIP_TREE* tree, /**< branch and bound tree */
164  SCIP_REOPT* reopt, /**< reoptimization data structure */
165  SCIP_LP* lp, /**< current LP data */
166  SCIP_Real cutoffbound /**< new cutoff bound */
167  )
168 {
169  assert(primal != NULL);
170  assert(cutoffbound <= SCIPsetInfinity(set));
171  assert(primal->upperbound == SCIP_INVALID || SCIPsetIsLE(set, cutoffbound, primal->upperbound)); /*lint !e777*/
172  assert(!SCIPtreeInRepropagation(tree));
173 
174  SCIPdebugMessage("changing cutoff bound from %g to %g\n", primal->cutoffbound, cutoffbound);
175 
176  primal->cutoffbound = MIN(cutoffbound, primal->upperbound); /* get rid of numerical issues */
177 
178  /* set cut off value in LP solver */
179  SCIP_CALL( SCIPlpSetCutoffbound(lp, set, prob, primal->cutoffbound) );
180 
181  /* cut off leaves of the tree */
182  SCIP_CALL( SCIPtreeCutoff(tree, reopt, blkmem, set, stat, eventqueue, lp, primal->cutoffbound) );
183 
184  return SCIP_OKAY;
185 }
186 
187 /** sets the cutoff bound in primal data and in LP solver */
189  SCIP_PRIMAL* primal, /**< primal data */
190  BMS_BLKMEM* blkmem, /**< block memory */
191  SCIP_SET* set, /**< global SCIP settings */
192  SCIP_STAT* stat, /**< problem statistics data */
193  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
194  SCIP_PROB* transprob, /**< transformed problem data */
195  SCIP_PROB* origprob, /**< original problem data */
196  SCIP_TREE* tree, /**< branch and bound tree */
197  SCIP_REOPT* reopt, /**< reoptimization data structure */
198  SCIP_LP* lp, /**< current LP data */
199  SCIP_Real cutoffbound, /**< new cutoff bound */
200  SCIP_Bool useforobjlimit /**< should the cutoff bound be used to update the objective limit, if
201  * better? */
202  )
203 {
204  assert(primal != NULL);
205  assert(cutoffbound <= SCIPsetInfinity(set));
206  assert(cutoffbound <= primal->upperbound);
207  assert(transprob != NULL);
208  assert(origprob != NULL);
209 
210  if( cutoffbound < primal->cutoffbound )
211  {
212  if( useforobjlimit )
213  {
214  SCIP_Real objval;
215 
216  objval = SCIPprobExternObjval(transprob, origprob, set, cutoffbound);
217 
218  if( objval < SCIPprobGetObjlim(origprob, set) )
219  {
220  SCIPdebugMessage("changing cutoff bound from %g to %g changes objective limit from %g to %g\n",
221  primal->cutoffbound, cutoffbound, SCIPprobGetObjlim(origprob, set), objval);
222  SCIPprobSetObjlim(origprob, objval);
223  SCIPprobSetObjlim(transprob, objval);
224  }
225  }
226 
227  /* update cutoff bound */
228  SCIP_CALL( primalSetCutoffbound(primal, blkmem, set, stat, transprob, eventqueue, tree, reopt, lp, cutoffbound) );
229  }
230  else if( cutoffbound > primal->cutoffbound )
231  {
232  SCIPerrorMessage("invalid increase in cutoff bound\n");
233  return SCIP_INVALIDDATA;
234  }
235 
236  return SCIP_OKAY;
237 }
238 
239 /** sets upper bound in primal data and in LP solver */
240 static
242  SCIP_PRIMAL* primal, /**< primal data */
243  BMS_BLKMEM* blkmem, /**< block memory */
244  SCIP_SET* set, /**< global SCIP settings */
245  SCIP_STAT* stat, /**< problem statistics data */
246  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
247  SCIP_PROB* prob, /**< transformed problem after presolve */
248  SCIP_TREE* tree, /**< branch and bound tree */
249  SCIP_REOPT* reopt, /**< reoptimization data structure */
250  SCIP_LP* lp, /**< current LP data */
251  SCIP_Real upperbound /**< new upper bound */
252  )
253 {
254  SCIP_Real cutoffbound;
255 
256  assert(primal != NULL);
257  assert(stat != NULL);
258  assert(upperbound <= SCIPsetInfinity(set));
259  assert(upperbound <= primal->upperbound || stat->nnodes == 0);
260 
261  SCIPdebugMessage("changing upper bound from %g to %g\n", primal->upperbound, upperbound);
262 
263  primal->upperbound = upperbound;
264 
265  /* if objective value is always integral, the cutoff bound can be reduced to nearly the previous integer number */
266  if( SCIPprobIsObjIntegral(prob) && !SCIPsetIsInfinity(set, upperbound) )
267  {
268  SCIP_Real delta;
269 
270  delta = SCIPsetCutoffbounddelta(set);
271 
272  cutoffbound = SCIPsetFeasCeil(set, upperbound) - (1.0 - delta);
273  cutoffbound = MIN(cutoffbound, upperbound); /* SCIPsetFeasCeil() can increase bound by almost 1.0 due to numerics
274  * and very large upperbound value */
275  }
276  else
277  cutoffbound = upperbound;
278 
279  /* update cutoff bound */
280  if( cutoffbound < primal->cutoffbound )
281  {
282  SCIP_CALL( primalSetCutoffbound(primal, blkmem, set, stat, prob, eventqueue, tree, reopt, lp, cutoffbound) );
283  }
284 
285  /* update upper bound in visualization output */
286  if( SCIPtreeGetCurrentDepth(tree) >= 0 )
287  {
288  SCIPvisualUpperbound(stat->visual, set, stat, primal->upperbound);
289  }
290 
291  return SCIP_OKAY;
292 }
293 
294 /** sets upper bound in primal data and in LP solver */
296  SCIP_PRIMAL* primal, /**< primal data */
297  BMS_BLKMEM* blkmem, /**< block memory */
298  SCIP_SET* set, /**< global SCIP settings */
299  SCIP_STAT* stat, /**< problem statistics data */
300  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
301  SCIP_PROB* prob, /**< transformed problem after presolve */
302  SCIP_TREE* tree, /**< branch and bound tree */
303  SCIP_REOPT* reopt, /**< reoptimization data structure */
304  SCIP_LP* lp, /**< current LP data */
305  SCIP_Real upperbound /**< new upper bound */
306  )
307 {
308  assert(primal != NULL);
309  assert(upperbound <= SCIPsetInfinity(set));
310 
311  if( upperbound < primal->upperbound )
312  {
313  /* update primal bound */
314  SCIP_CALL( primalSetUpperbound(primal, blkmem, set, stat, eventqueue, prob, tree, reopt, lp, upperbound) );
315  }
316  else if( upperbound > primal->upperbound )
317  {
318  SCIPerrorMessage("invalid increase in upper bound\n");
319  return SCIP_INVALIDDATA;
320  }
321 
322  return SCIP_OKAY;
323 }
324 
325 /** updates upper bound and cutoff bound in primal data after a tightening of the problem's objective limit */
327  SCIP_PRIMAL* primal, /**< primal data */
328  BMS_BLKMEM* blkmem, /**< block memory */
329  SCIP_SET* set, /**< global SCIP settings */
330  SCIP_STAT* stat, /**< problem statistics data */
331  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
332  SCIP_PROB* transprob, /**< transformed problem data */
333  SCIP_PROB* origprob, /**< original problem data */
334  SCIP_TREE* tree, /**< branch and bound tree */
335  SCIP_REOPT* reopt, /**< reoptimization data structure */
336  SCIP_LP* lp /**< current LP data */
337  )
338 {
339  SCIP_Real objlimit;
340  SCIP_Real inf;
341 
342  assert(primal != NULL);
343 
344  /* get internal objective limit */
345  objlimit = SCIPprobInternObjval(transprob, origprob, set, SCIPprobGetObjlim(origprob, set));
346  inf = SCIPsetInfinity(set);
347  objlimit = MIN(objlimit, inf);
348 
349  /* update the cutoff bound */
350  if( objlimit < primal->cutoffbound )
351  {
352  SCIP_CALL( primalSetCutoffbound(primal, blkmem, set, stat, transprob, eventqueue, tree, reopt, lp, objlimit) );
353  }
354 
355  /* set new upper bound (and decrease cutoff bound, if objective value is always integral) */
356  if( objlimit < primal->upperbound )
357  {
358  SCIP_CALL( primalSetUpperbound(primal, blkmem, set, stat, eventqueue, transprob, tree, reopt, lp, objlimit) );
359  }
360 
361  return SCIP_OKAY;
362 }
363 
364 /** recalculates upper bound and cutoff bound in primal data after a change of the problem's objective offset */
366  SCIP_PRIMAL* primal, /**< primal data */
367  BMS_BLKMEM* blkmem, /**< block memory */
368  SCIP_SET* set, /**< global SCIP settings */
369  SCIP_STAT* stat, /**< problem statistics data */
370  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
371  SCIP_PROB* transprob, /**< tranformed problem data */
372  SCIP_PROB* origprob, /**< original problem data */
373  SCIP_TREE* tree, /**< branch and bound tree */
374  SCIP_REOPT* reopt, /**< reoptimization data structure */
375  SCIP_LP* lp /**< current LP data */
376  )
377 {
378  SCIP_SOL* sol;
379  SCIP_Real upperbound;
380  SCIP_Real objval;
381  SCIP_Real inf;
382  int i;
383  int j;
384 
385  assert(primal != NULL);
387 
388  /* recalculate internal objective limit */
389  upperbound = SCIPprobInternObjval(transprob, origprob, set, SCIPprobGetObjlim(origprob, set));
390  inf = SCIPsetInfinity(set);
391  upperbound = MIN(upperbound, inf);
392 
393  /* resort current primal solutions */
394  for( i = 1; i < primal->nsols; ++i )
395  {
396  sol = primal->sols[i];
397  objval = SCIPsolGetObj(sol, set, transprob, origprob);
398  for( j = i; j > 0 && objval < SCIPsolGetObj(primal->sols[j-1], set, transprob, origprob); --j )
399  primal->sols[j] = primal->sols[j-1];
400  primal->sols[j] = sol;
401  }
402 
403  /* compare objective limit to currently best solution */
404  if( primal->nsols > 0 )
405  {
406  SCIP_Real obj;
407 
408  assert(SCIPsolIsOriginal(primal->sols[0]));
409  obj = SCIPsolGetObj(primal->sols[0], set, transprob, origprob);
410 
411  upperbound = MIN(upperbound, obj);
412  }
413 
414  /* invalidate old upper bound */
415  SCIP_CALL( primalSetUpperbound(primal, blkmem, set, stat, eventqueue, transprob, tree, reopt, lp, SCIPsetInfinity(set)) );
416 
417  /* reset the cutoff bound
418  *
419  * @note we might need to relax the bound since in presolving the objective correction of an
420  * aggregation is still in progress
421  */
422  SCIP_CALL( primalSetCutoffbound(primal, blkmem, set, stat, transprob, eventqueue, tree, reopt, lp, upperbound) );
423 
424  /* set new upper bound (and decrease cutoff bound, if objective value is always integral) */
425  SCIP_CALL( primalSetUpperbound(primal, blkmem, set, stat, eventqueue, transprob, tree, reopt, lp, upperbound) );
426 
427  return SCIP_OKAY;
428 }
429 
430 /** adds additional objective offset in original space to all existing solution (in original space) */
432  SCIP_PRIMAL* primal, /**< primal data */
433  SCIP_SET* set, /**< global SCIP settings */
434  SCIP_Real addval /**< additional objective offset in original space */
435  )
436 {
437  int i;
438 
439  assert(primal != NULL);
440  assert(set != NULL);
441  assert(SCIPsetGetStage(set) == SCIP_STAGE_PROBLEM);
442 
443 #ifndef NDEBUG
444  assert(primal->nsols == 0 || SCIPsolGetOrigin(primal->sols[0]) == SCIP_SOLORIGIN_ORIGINAL);
445 
446  /* check current order of primal solutions */
447  for( i = 1; i < primal->nsols; ++i )
448  {
449  assert(SCIPsolGetOrigin(primal->sols[i]) == SCIP_SOLORIGIN_ORIGINAL);
450  assert(SCIPsetIsLE(set, SCIPsolGetOrigObj(primal->sols[i-1]), SCIPsolGetOrigObj(primal->sols[i])));
451  }
452 #endif
453 
454  /* check current order of primal solutions */
455  for( i = 0; i < primal->nexistingsols; ++i )
456  {
457  assert(primal->existingsols[i] != NULL);
458  SCIPsolOrigAddObjval(primal->existingsols[i], addval);
459  }
460 }
461 
462 /** returns whether the current primal bound is justified with a feasible primal solution; if not, the primal bound
463  * was set from the user as objective limit
464  */
466  SCIP_PRIMAL* primal, /**< primal data */
467  SCIP_SET* set, /**< global SCIP settings */
468  SCIP_PROB* transprob, /**< tranformed problem data */
469  SCIP_PROB* origprob /**< original problem data */
470  )
471 {
472  assert(primal != NULL);
473 
474  return (primal->nsols > 0 && SCIPsetIsEQ(set, primal->upperbound, SCIPsolGetObj(primal->sols[0], set, transprob, origprob)));
475 }
476 
477 /** adds primal solution to solution storage at given position */
478 static
480  SCIP_PRIMAL* primal, /**< primal data */
481  BMS_BLKMEM* blkmem, /**< block memory */
482  SCIP_SET* set, /**< global SCIP settings */
483  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
484  SCIP_STAT* stat, /**< problem statistics data */
485  SCIP_PROB* origprob, /**< original problem */
486  SCIP_PROB* transprob, /**< transformed problem after presolve */
487  SCIP_TREE* tree, /**< branch and bound tree */
488  SCIP_REOPT* reopt, /**< reoptimization data structure */
489  SCIP_LP* lp, /**< current LP data */
490  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
491  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
492  SCIP_SOL** solptr, /**< pointer to primal CIP solution */
493  int insertpos, /**< position in solution storage to add solution to */
494  SCIP_Bool replace /**< should the solution at insertpos be replaced by the new solution? */
495  )
496 {
497  SCIP_SOL* sol;
498  SCIP_EVENT event;
499  SCIP_Real obj;
500  int pos;
501 
502  assert(primal != NULL);
503  assert(set != NULL);
504  assert(solptr != NULL);
505  assert(stat != NULL);
506  assert(transprob != NULL);
507  assert(origprob != NULL);
508  assert(0 <= insertpos && insertpos < set->limit_maxsol);
509  assert(tree == NULL || !SCIPtreeInRepropagation(tree));
510 
511  sol = *solptr;
512  assert(sol != NULL);
513  obj = SCIPsolGetObj(sol, set, transprob, origprob);
514 
515  SCIPdebugMessage("insert primal solution %p with obj %g at position %d (replace=%u):\n",
516  (void*)sol, obj, insertpos, replace);
517 
518  SCIPdebug( SCIP_CALL( SCIPsolPrint(sol, set, messagehdlr, stat, transprob, NULL, NULL, FALSE) ) );
519 
520 #if 0 /* this is not a valid debug check, but can be used to track down numerical troubles */
521 #ifndef NDEBUG
522  /* check solution again completely
523  * it fail for different reasons:
524  * - in the LP solver, the feasibility tolerance is a relative measure against the row's norm
525  * - in SCIP, the feasibility tolerance is a relative measure against the row's rhs/lhs
526  * - the rhs/lhs of a row might drastically change during presolving when variables are fixed or (multi-)aggregated
527  */
528  if( !SCIPsolIsOriginal(sol) )
529  {
530  SCIP_Bool feasible;
531 
532  SCIP_CALL( SCIPsolCheck(sol, set, messagehdlr, blkmem, stat, transprob, TRUE, TRUE, TRUE, TRUE, &feasible) );
533 
534  if( !feasible )
535  {
536  SCIPerrorMessage("infeasible solution accepted:\n");
537  SCIP_CALL( SCIPsolPrint(sol, set, messagehdlr, stat, origprob, transprob, NULL, FALSE) );
538  }
539  assert(feasible);
540  }
541 #endif
542 #endif
543 
544  /* completely fill the solution's own value array to unlink it from the LP or pseudo solution */
545  SCIP_CALL( SCIPsolUnlink(sol, set, transprob) );
546 
547  /* allocate memory for solution storage */
548  SCIP_CALL( ensureSolsSize(primal, set, set->limit_maxsol) );
549 
550  /* if set->limit_maxsol was decreased in the meantime, free all solutions exceeding the limit */
551  for( pos = set->limit_maxsol; pos < primal->nsols; ++pos )
552  {
553  SCIP_CALL( SCIPsolFree(&primal->sols[pos], blkmem, primal) );
554  }
555  primal->nsols = MIN(primal->nsols, set->limit_maxsol);
556 
557  /* if the solution should replace an existing one, free this solution, otherwise,
558  * free the last solution if the solution storage is full;
559  */
560  if( replace )
561  {
562  SCIP_CALL( SCIPsolTransform(primal->sols[insertpos], solptr, blkmem, set, primal) );
563  sol = primal->sols[insertpos];
564  }
565  else
566  {
567  if( primal->nsols == set->limit_maxsol )
568  {
569  SCIP_CALL( SCIPsolFree(&primal->sols[set->limit_maxsol - 1], blkmem, primal) );
570  }
571  else
572  {
573  primal->nsols = primal->nsols + 1;
574  assert(primal->nsols <= set->limit_maxsol);
575  }
576 
577  /* move all solutions with worse objective value than the new solution */
578  for( pos = primal->nsols-1; pos > insertpos; --pos )
579  primal->sols[pos] = primal->sols[pos-1];
580 
581  /* insert solution at correct position */
582  assert(0 <= insertpos && insertpos < primal->nsols);
583  primal->sols[insertpos] = sol;
584  primal->nsolsfound++;
585 
586  /* check if solution is better than objective limit */
587  if( SCIPsetIsFeasLE(set, obj, SCIPprobInternObjval(transprob, origprob, set, SCIPprobGetObjlim(origprob, set))) )
588  primal->nlimsolsfound++;
589  }
590 
591  /* if its the first primal solution, store the relevant statistics */
592  if( primal->nsolsfound == 1 )
593  {
594  SCIP_Real primalsolval;
595 
597  stat->nrunsbeforefirst = SCIPsolGetRunnum(sol);
598  stat->firstprimalheur = SCIPsolGetHeur(sol);
599  stat->firstprimaltime = SCIPsolGetTime(sol);
600  stat->firstprimaldepth = SCIPsolGetDepth(sol);
601 
602  primalsolval = obj;
603  stat->firstprimalbound = SCIPprobExternObjval(transprob, origprob, set, primalsolval);
604 
605  SCIPdebugMessage("First Solution stored in problem specific statistics.\n");
606  SCIPdebugMessage("-> %" SCIP_LONGINT_FORMAT " nodes, %d runs, %.2g time, %d depth, %.15g objective\n", stat->nnodesbeforefirst, stat->nrunsbeforefirst,
608  }
609 
610  SCIPdebugMessage(" -> stored at position %d of %d solutions, found %" SCIP_LONGINT_FORMAT " solutions\n",
611  insertpos, primal->nsols, primal->nsolsfound);
612 
613  /* update the solution value sums in variables */
614  if( !SCIPsolIsOriginal(sol) )
615  {
616  SCIPsolUpdateVarsum(sol, set, stat, transprob,
617  (SCIP_Real)(primal->nsols - insertpos)/(SCIP_Real)(2.0*primal->nsols - 1.0));
618  }
619 
620  /* change color of node in visualization output */
621  SCIPvisualFoundSolution(stat->visual, set, stat, SCIPtreeGetCurrentNode(tree), insertpos == 0 ? TRUE : FALSE, sol);
622 
623  /* check, if the global upper bound has to be updated */
624  if( obj < primal->upperbound )
625  {
626  /* update the upper bound */
627  SCIP_CALL( SCIPprimalSetUpperbound(primal, blkmem, set, stat, eventqueue, transprob, tree, reopt, lp, obj) );
628 
629  /* issue BESTSOLFOUND event */
631  primal->nbestsolsfound++;
632  stat->bestsolnode = stat->nnodes;
633  }
634  else
635  {
636  /* issue POORSOLFOUND event */
638  }
639  SCIP_CALL( SCIPeventChgSol(&event, sol) );
640  SCIP_CALL( SCIPeventProcess(&event, set, NULL, NULL, NULL, eventfilter) );
641 
642  /* display node information line */
643  if( insertpos == 0 && !replace && set->stage >= SCIP_STAGE_SOLVING )
644  {
645  SCIP_CALL( SCIPdispPrintLine(set, messagehdlr, stat, NULL, TRUE, TRUE) );
646  }
647 
648  /* if an original solution was added during solving, try to transfer it to the transformed space */
649  if( SCIPsolIsOriginal(sol) && SCIPsetGetStage(set) == SCIP_STAGE_SOLVING && set->misc_transorigsols )
650  {
651  SCIP_Bool added;
652 
653  SCIP_CALL( SCIPprimalTransformSol(primal, sol, blkmem, set, messagehdlr, stat, origprob, transprob, tree, reopt,
654  lp, eventqueue, eventfilter, NULL, NULL, 0, &added) );
655 
656  SCIPdebugMessage("original solution %p was successfully transferred to the transformed problem space\n",
657  (void*)sol);
658 
659  }
660 
661  return SCIP_OKAY;
662 }
663 
664 /** adds primal solution to solution storage at given position */
665 static
667  SCIP_PRIMAL* primal, /**< primal data */
668  BMS_BLKMEM* blkmem, /**< block memory */
669  SCIP_SET* set, /**< global SCIP settings */
670  SCIP_PROB* prob, /**< original problem data */
671  SCIP_SOL* sol, /**< primal CIP solution */
672  int insertpos /**< position in solution storage to add solution to */
673  )
674 {
675  int pos;
676 
677  assert(primal != NULL);
678  assert(set != NULL);
679  assert(prob != NULL);
680  assert(sol != NULL);
681  assert(0 <= insertpos && insertpos < set->limit_maxorigsol);
682  assert(!set->reopt_enable);
683 
684  SCIPdebugMessage("insert primal solution candidate %p with obj %g at position %d:\n", (void*)sol, SCIPsolGetOrigObj(sol), insertpos);
685 
686  /* allocate memory for solution storage */
687  SCIP_CALL( ensureSolsSize(primal, set, set->limit_maxorigsol) );
688 
689  /* if the solution storage is full, free the last solution(s)
690  * more than one solution may be freed, if set->limit_maxorigsol was decreased in the meantime
691  */
692  for( pos = set->limit_maxorigsol-1; pos < primal->nsols; ++pos )
693  {
694  SCIP_CALL( SCIPsolFree(&primal->sols[pos], blkmem, primal) );
695  }
696 
697  /* insert solution at correct position */
698  primal->nsols = MIN(primal->nsols+1, set->limit_maxorigsol);
699  for( pos = primal->nsols-1; pos > insertpos; --pos )
700  primal->sols[pos] = primal->sols[pos-1];
701 
702  assert(0 <= insertpos && insertpos < primal->nsols);
703  primal->sols[insertpos] = sol;
704  primal->nsolsfound++;
705 
706  /* check if solution is better than objective limit */
707  if( SCIPsetIsFeasLE(set, SCIPsolGetOrigObj(sol), SCIPprobGetObjlim(prob, set)) )
708  primal->nlimsolsfound++;
709 
710  SCIPdebugMessage(" -> stored at position %d of %d solutions, found %" SCIP_LONGINT_FORMAT " solutions\n",
711  insertpos, primal->nsols, primal->nsolsfound);
712 
713  return SCIP_OKAY;
714 }
715 
716 /** uses binary search to find position in solution storage */
717 static
719  SCIP_PRIMAL* primal, /**< primal data */
720  SCIP_SET* set, /**< global SCIP settings */
721  SCIP_PROB* transprob, /**< tranformed problem data */
722  SCIP_PROB* origprob, /**< original problem data */
723  SCIP_SOL* sol /**< primal solution to search position for */
724  )
725 {
726  SCIP_SOL** sols;
727  SCIP_Real obj;
728  SCIP_Real middleobj;
729  int left;
730  int right;
731  int middle;
732 
733  assert(primal != NULL);
734 
735  obj = SCIPsolGetObj(sol, set, transprob, origprob);
736  sols = primal->sols;
737 
738  left = -1;
739  right = primal->nsols;
740  while( left < right-1 )
741  {
742  middle = (left+right)/2;
743  assert(left < middle && middle < right);
744  assert(0 <= middle && middle < primal->nsols);
745 
746  middleobj = SCIPsolGetObj(sols[middle], set, transprob, origprob);
747 
748  if( obj < middleobj )
749  right = middle;
750  else
751  left = middle;
752  }
753  assert(left == right-1);
754 
755  /* prefer solutions that live in the transformed space */
756  if( !SCIPsolIsOriginal(sol) )
757  {
758  while( right > 0 && SCIPsolIsOriginal(sols[right-1])
759  && SCIPsetIsEQ(set, SCIPsolGetObj(sols[right-1], set, transprob, origprob), obj) )
760  --right;
761  }
762 
763  return right;
764 }
765 
766 /** uses binary search to find position in solution storage */
767 static
769  SCIP_PRIMAL* primal, /**< primal data */
770  SCIP_SOL* sol /**< primal solution to search position for */
771  )
772 {
773  SCIP_Real obj;
774  SCIP_Real middleobj;
775  int left;
776  int right;
777  int middle;
778 
779  assert(primal != NULL);
780 
781  obj = SCIPsolGetOrigObj(sol);
782 
783  left = -1;
784  right = primal->nsols;
785  while( left < right-1 )
786  {
787  middle = (left+right)/2;
788  assert(left < middle && middle < right);
789  assert(0 <= middle && middle < primal->nsols);
790  middleobj = SCIPsolGetOrigObj(primal->sols[middle]);
791  if( obj < middleobj )
792  right = middle;
793  else
794  left = middle;
795  }
796  assert(left == right-1);
797 
798  return right;
799 }
800 
801 /** returns whether the given primal solution is already existent in the solution storage */
802 static
804  SCIP_PRIMAL* primal, /**< primal data */
805  SCIP_SET* set, /**< global SCIP settings */
806  SCIP_STAT* stat, /**< problem statistics data */
807  SCIP_PROB* origprob, /**< original problem */
808  SCIP_PROB* transprob, /**< transformed problem after presolve */
809  SCIP_SOL* sol, /**< primal solution to search position for */
810  int* insertpos, /**< pointer to insertion position returned by primalSearchSolPos(); the
811  * position might be changed if an existing solution should be replaced */
812  SCIP_Bool* replace /**< pointer to store whether the solution at insertpos should be replaced */
813  )
814 {
815  SCIP_Real obj;
816  int i;
817 
818  assert(primal != NULL);
819  assert(insertpos != NULL);
820  assert(replace != NULL);
821  assert(0 <= (*insertpos) && (*insertpos) <= primal->nsols);
822 
823  obj = SCIPsolGetObj(sol, set, transprob, origprob);
824 
825  assert(primal->sols != NULL || primal->nsols == 0);
826  assert(primal->sols != NULL || (*insertpos) == 0);
827 
828  /* search in the better solutions */
829  for( i = (*insertpos)-1; i >= 0; --i )
830  {
831  SCIP_Real solobj;
832 
833  solobj = SCIPsolGetObj(primal->sols[i], set, transprob, origprob);
834 
835  /* due to transferring the objective value of transformed solutions to the original space, small numerical errors might occur
836  * which can lead to SCIPsetIsLE() failing in case of high absolute numbers
837  */
838  assert(SCIPsetIsLE(set, solobj, obj) || (REALABS(obj) > 1e+13 * SCIPsetEpsilon(set) && SCIPsetIsFeasLE(set, solobj, obj)));
839 
840  if( SCIPsetIsLT(set, solobj, obj) )
841  break;
842 
843  if( SCIPsolsAreEqual(sol, primal->sols[i], set, stat, origprob, transprob) )
844  {
845  if( SCIPsolIsOriginal(primal->sols[i]) && !SCIPsolIsOriginal(sol) )
846  {
847  (*insertpos) = i;
848  (*replace) = TRUE;
849  }
850  return TRUE;
851  }
852  }
853 
854  /* search in the worse solutions */
855  for( i = (*insertpos); i < primal->nsols; ++i )
856  {
857  SCIP_Real solobj;
858 
859  solobj = SCIPsolGetObj(primal->sols[i], set, transprob, origprob);
860 
861  /* due to transferring the objective value of transformed solutions to the original space, small numerical errors might occur
862  * which can lead to SCIPsetIsLE() failing in case of high absolute numbers
863  */
864  assert( SCIPsetIsGE(set, solobj, obj) || (REALABS(obj) > 1e+13 * SCIPsetEpsilon(set) && SCIPsetIsFeasGE(set, solobj, obj)));
865 
866  if( SCIPsetIsGT(set, solobj, obj) )
867  break;
868 
869  if( SCIPsolsAreEqual(sol, primal->sols[i], set, stat, origprob, transprob) )
870  {
871  if( SCIPsolIsOriginal(primal->sols[i]) && !SCIPsolIsOriginal(sol) )
872  {
873  (*insertpos) = i;
874  (*replace) = TRUE;
875  }
876  return TRUE;
877  }
878  }
879 
880  return FALSE;
881 }
882 
883 /** returns whether the given primal solution is already existent in the original solution candidate storage */
884 static
886  SCIP_PRIMAL* primal, /**< primal data */
887  SCIP_SET* set, /**< global SCIP settings */
888  SCIP_STAT* stat, /**< problem statistics data */
889  SCIP_PROB* prob, /**< original problem */
890  SCIP_SOL* sol, /**< primal solution to search position for */
891  int insertpos /**< insertion position returned by primalSearchOrigSolPos() */
892  )
893 {
894  SCIP_Real obj;
895  int i;
896 
897  assert(primal != NULL);
898  assert(0 <= insertpos && insertpos <= primal->nsols);
899 
900  obj = SCIPsolGetOrigObj(sol);
901 
902  /* search in the better solutions */
903  for( i = insertpos-1; i >= 0; --i )
904  {
905  SCIP_Real solobj;
906 
907  solobj = SCIPsolGetOrigObj(primal->sols[i]);
908  assert( SCIPsetIsLE(set, solobj, obj) );
909 
910  if( SCIPsetIsLT(set, solobj, obj) )
911  break;
912 
913  if( SCIPsolsAreEqual(sol, primal->sols[i], set, stat, prob, NULL) )
914  return TRUE;
915  }
916 
917  /* search in the worse solutions */
918  for( i = insertpos; i < primal->nsols; ++i )
919  {
920  SCIP_Real solobj;
921 
922  solobj = SCIPsolGetOrigObj(primal->sols[i]);
923  assert( SCIPsetIsGE(set, solobj, obj) );
924 
925  if( SCIPsetIsGT(set, solobj, obj) )
926  break;
927 
928  if( SCIPsolsAreEqual(sol, primal->sols[i], set, stat, prob, NULL) )
929  return TRUE;
930  }
931 
932  return FALSE;
933 }
934 
935 /** check if we are willing to check the solution for feasibility */
936 static
938  SCIP_PRIMAL* primal, /**< primal data */
939  SCIP_SET* set, /**< global SCIP settings */
940  SCIP_STAT* stat, /**< problem statistics data */
941  SCIP_PROB* origprob, /**< original problem */
942  SCIP_PROB* transprob, /**< transformed problem after presolve */
943  SCIP_SOL* sol, /**< primal CIP solution */
944  int* insertpos, /**< pointer to store the insert position of that solution */
945  SCIP_Bool* replace /**< pointer to store whether the solution at insertpos should be replaced
946  * (e.g., because it lives in the original space) */
947  )
948 {
949  SCIP_Real obj;
950 
951  obj = SCIPsolGetObj(sol, set, transprob, origprob);
952 
953  /* check if we are willing to check worse solutions; a solution is better if the objective is smaller than the
954  * current cutoff bound; solutions with infinite objective value are never accepted
955  */
956  if( (!set->misc_improvingsols || obj < primal->cutoffbound) && !SCIPsetIsInfinity(set, obj) )
957  {
958  /* find insert position for the solution */
959  (*insertpos) = primalSearchSolPos(primal, set, transprob, origprob, sol);
960  (*replace) = FALSE;
961 
962  /* the solution should be added, if the insertpos is smaller than the maximum number of solutions to be stored
963  * and it does not already exist or it does exist, but the existing solution should be replaced by the new one
964  */
965  if( (*insertpos) < set->limit_maxsol &&
966  (!primalExistsSol(primal, set, stat, origprob, transprob, sol, insertpos, replace) || (*replace)) )
967  return TRUE;
968  }
969 
970  return FALSE;
971 }
972 
973 /** check if we are willing to store the solution candidate for later checking */
974 static
976  SCIP_PRIMAL* primal, /**< primal data */
977  SCIP_SET* set, /**< global SCIP settings */
978  SCIP_STAT* stat, /**< problem statistics data */
979  SCIP_PROB* origprob, /**< original problem */
980  SCIP_SOL* sol, /**< primal CIP solution */
981  int* insertpos /**< pointer to store the insert position of that solution */
982  )
983 {
984  assert(SCIPsolIsOriginal(sol));
985 
986  /* find insert position for the solution */
987  (*insertpos) = primalSearchOrigSolPos(primal, sol);
988 
989  if( !set->reopt_enable && (*insertpos) < set->limit_maxorigsol && !primalExistsOrigSol(primal, set, stat, origprob, sol, *insertpos) )
990  return TRUE;
991 
992  return FALSE;
993 }
994 
995 /** adds primal solution to solution storage by copying it */
997  SCIP_PRIMAL* primal, /**< primal data */
998  BMS_BLKMEM* blkmem, /**< block memory */
999  SCIP_SET* set, /**< global SCIP settings */
1000  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
1001  SCIP_STAT* stat, /**< problem statistics data */
1002  SCIP_PROB* origprob, /**< original problem */
1003  SCIP_PROB* transprob, /**< transformed problem after presolve */
1004  SCIP_TREE* tree, /**< branch and bound tree */
1005  SCIP_REOPT* reopt, /**< reoptimization data structure */
1006  SCIP_LP* lp, /**< current LP data */
1007  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1008  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1009  SCIP_SOL* sol, /**< primal CIP solution */
1010  SCIP_Bool* stored /**< stores whether given solution was good enough to keep */
1011  )
1012 {
1013  SCIP_Bool replace;
1014  int insertpos;
1015 
1016  assert(primal != NULL);
1017  assert(transprob != NULL);
1018  assert(origprob != NULL);
1019  assert(sol != NULL);
1020  assert(stored != NULL);
1021 
1022  insertpos = -1;
1023 
1024  if( solOfInterest(primal, set, stat, origprob, transprob, sol, &insertpos, &replace) )
1025  {
1026  SCIP_SOL* solcopy;
1027 #ifdef SCIP_MORE_DEBUG
1028  int i;
1029 #endif
1030 
1031  assert(insertpos >= 0 && insertpos < set->limit_maxsol);
1032 
1033  /* create a copy of the solution */
1034  SCIP_CALL( SCIPsolCopy(&solcopy, blkmem, set, stat, primal, sol) );
1035 
1036  /* insert copied solution into solution storage */
1037  SCIP_CALL( primalAddSol(primal, blkmem, set, messagehdlr, stat, origprob, transprob,
1038  tree, reopt, lp, eventqueue, eventfilter, &solcopy, insertpos, replace) );
1039 #ifdef SCIP_MORE_DEBUG
1040  for( i = 0; i < primal->nsols - 1; ++i )
1041  {
1042  assert(SCIPsetIsLE(set, SCIPsolGetObj(primal->sols[i], set, transprob, origprob), SCIPsolGetObj(primal->sols[i+1], set, transprob, origprob)));
1043  }
1044 #endif
1045  *stored = TRUE;
1046  }
1047  else
1048  *stored = FALSE;
1049 
1050  return SCIP_OKAY;
1051 }
1052 
1053 /** adds primal solution to solution storage, frees the solution afterwards */
1055  SCIP_PRIMAL* primal, /**< primal data */
1056  BMS_BLKMEM* blkmem, /**< block memory */
1057  SCIP_SET* set, /**< global SCIP settings */
1058  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
1059  SCIP_STAT* stat, /**< problem statistics data */
1060  SCIP_PROB* origprob, /**< original problem */
1061  SCIP_PROB* transprob, /**< transformed problem after presolve */
1062  SCIP_TREE* tree, /**< branch and bound tree */
1063  SCIP_REOPT* reopt, /**< reoptimization data structure */
1064  SCIP_LP* lp, /**< current LP data */
1065  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1066  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1067  SCIP_SOL** sol, /**< pointer to primal CIP solution; is cleared in function call */
1068  SCIP_Bool* stored /**< stores whether given solution was good enough to keep */
1069  )
1070 {
1071  SCIP_Bool replace;
1072  int insertpos;
1073 
1074  assert(primal != NULL);
1075  assert(transprob != NULL);
1076  assert(origprob != NULL);
1077  assert(sol != NULL);
1078  assert(*sol != NULL);
1079  assert(stored != NULL);
1080 
1081  insertpos = -1;
1082 
1083  if( solOfInterest(primal, set, stat, origprob, transprob, *sol, &insertpos, &replace) )
1084  {
1085  assert(insertpos >= 0 && insertpos < set->limit_maxsol);
1086 
1087  /* insert solution into solution storage */
1088  SCIP_CALL( primalAddSol(primal, blkmem, set, messagehdlr, stat, origprob, transprob,
1089  tree, reopt, lp, eventqueue, eventfilter, sol, insertpos, replace) );
1090 
1091  /* clear the pointer, such that the user cannot access the solution anymore */
1092  *sol = NULL;
1093 
1094  *stored = TRUE;
1095  }
1096  else
1097  {
1098  /* the solution is too bad -> free it immediately */
1099  SCIP_CALL( SCIPsolFree(sol, blkmem, primal) );
1100 
1101  *stored = FALSE;
1102  }
1103  assert(*sol == NULL);
1104 
1105  return SCIP_OKAY;
1106 }
1107 
1108 /** adds primal solution to solution candidate storage of original problem space */
1110  SCIP_PRIMAL* primal, /**< primal data */
1111  BMS_BLKMEM* blkmem, /**< block memory */
1112  SCIP_SET* set, /**< global SCIP settings */
1113  SCIP_STAT* stat, /**< problem statistics data */
1114  SCIP_PROB* prob, /**< original problem data */
1115  SCIP_SOL* sol, /**< primal CIP solution; is cleared in function call */
1116  SCIP_Bool* stored /**< stores whether given solution was good enough to keep */
1117  )
1118 {
1119  int insertpos;
1120 
1121  assert(primal != NULL);
1122  assert(sol != NULL);
1123  assert(SCIPsolIsOriginal(sol));
1124  assert(stored != NULL);
1125 
1126  insertpos = -1;
1127 
1128  if( origsolOfInterest(primal, set, stat, prob, sol, &insertpos) )
1129  {
1130  SCIP_SOL* solcopy;
1131 
1132  assert(insertpos >= 0 && insertpos < set->limit_maxorigsol);
1133  assert(!set->reopt_enable);
1134 
1135  /* create a copy of the solution */
1136  SCIP_CALL( SCIPsolCopy(&solcopy, blkmem, set, stat, primal, sol) );
1137 
1138  /* insert solution into solution storage */
1139  SCIP_CALL( primalAddOrigSol(primal, blkmem, set, prob, solcopy, insertpos) );
1140 
1141  *stored = TRUE;
1142  }
1143  else
1144  *stored = FALSE;
1145 
1146  return SCIP_OKAY;
1147 }
1148 
1149 /** adds primal solution to solution candidate storage of original problem space, frees the solution afterwards */
1151  SCIP_PRIMAL* primal, /**< primal data */
1152  BMS_BLKMEM* blkmem, /**< block memory */
1153  SCIP_SET* set, /**< global SCIP settings */
1154  SCIP_STAT* stat, /**< problem statistics data */
1155  SCIP_PROB* prob, /**< original problem data */
1156  SCIP_SOL** sol, /**< pointer to primal CIP solution; is cleared in function call */
1157  SCIP_Bool* stored /**< stores whether given solution was good enough to keep */
1158  )
1159 {
1160  int insertpos;
1161 
1162  assert(primal != NULL);
1163  assert(sol != NULL);
1164  assert(*sol != NULL);
1165  assert(SCIPsolIsOriginal(*sol));
1166  assert(stored != NULL);
1167 
1168  insertpos = -1;
1169 
1170  if( origsolOfInterest(primal, set, stat, prob, *sol, &insertpos) )
1171  {
1172  assert(insertpos >= 0 && insertpos < set->limit_maxorigsol);
1173  assert(!set->reopt_enable);
1174 
1175  /* insert solution into solution storage */
1176  SCIP_CALL( primalAddOrigSol(primal, blkmem, set, prob, *sol, insertpos) );
1177 
1178  /* clear the pointer, such that the user cannot access the solution anymore */
1179  *sol = NULL;
1180 
1181  *stored = TRUE;
1182  }
1183  else
1184  {
1185  /* the solution is too bad -> free it immediately */
1186  SCIP_CALL( SCIPsolFree(sol, blkmem, primal) );
1187 
1188  *stored = FALSE;
1189  }
1190  assert(*sol == NULL);
1191 
1192  return SCIP_OKAY;
1193 }
1194 
1195 /** links temporary solution of primal data to current solution */
1196 static
1198  SCIP_PRIMAL* primal, /**< primal data */
1199  BMS_BLKMEM* blkmem, /**< block memory */
1200  SCIP_SET* set, /**< global SCIP settings */
1201  SCIP_STAT* stat, /**< problem statistics data */
1202  SCIP_PROB* prob, /**< transformed problem data */
1203  SCIP_TREE* tree, /**< branch and bound tree */
1204  SCIP_LP* lp, /**< current LP data */
1205  SCIP_HEUR* heur /**< heuristic that found the solution (or NULL if it's from the tree) */
1206  )
1207 {
1208  assert(primal != NULL);
1209 
1210  if( primal->currentsol == NULL )
1211  {
1212  SCIP_CALL( SCIPsolCreateCurrentSol(&primal->currentsol, blkmem, set, stat, prob, primal, tree, lp, heur) );
1213  }
1214  else
1215  {
1216  SCIP_CALL( SCIPsolLinkCurrentSol(primal->currentsol, set, stat, prob, tree, lp) );
1217  SCIPsolSetHeur(primal->currentsol, heur);
1218  }
1219 
1220  return SCIP_OKAY;
1221 }
1222 
1223 /** adds current LP/pseudo solution to solution storage */
1225  SCIP_PRIMAL* primal, /**< primal data */
1226  BMS_BLKMEM* blkmem, /**< block memory */
1227  SCIP_SET* set, /**< global SCIP settings */
1228  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
1229  SCIP_STAT* stat, /**< problem statistics data */
1230  SCIP_PROB* origprob, /**< original problem */
1231  SCIP_PROB* transprob, /**< transformed problem after presolve */
1232  SCIP_TREE* tree, /**< branch and bound tree */
1233  SCIP_REOPT* reopt, /**< reoptimization data structure */
1234  SCIP_LP* lp, /**< current LP data */
1235  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1236  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1237  SCIP_HEUR* heur, /**< heuristic that found the solution (or NULL if it's from the tree) */
1238  SCIP_Bool* stored /**< stores whether given solution was good enough to keep */
1239  )
1240 {
1241  assert(primal != NULL);
1242 
1243  /* link temporary solution to current solution */
1244  SCIP_CALL( primalLinkCurrentSol(primal, blkmem, set, stat, transprob, tree, lp, heur) );
1245 
1246  /* add solution to solution storage */
1247  SCIP_CALL( SCIPprimalAddSol(primal, blkmem, set, messagehdlr, stat, origprob, transprob,
1248  tree, reopt, lp, eventqueue, eventfilter, primal->currentsol, stored) );
1249 
1250  return SCIP_OKAY;
1251 }
1252 
1253 /** checks primal solution; if feasible, adds it to storage by copying it */
1255  SCIP_PRIMAL* primal, /**< primal data */
1256  BMS_BLKMEM* blkmem, /**< block memory */
1257  SCIP_SET* set, /**< global SCIP settings */
1258  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
1259  SCIP_STAT* stat, /**< problem statistics data */
1260  SCIP_PROB* origprob, /**< original problem */
1261  SCIP_PROB* transprob, /**< transformed problem after presolve */
1262  SCIP_TREE* tree, /**< branch and bound tree */
1263  SCIP_REOPT* reopt, /**< reoptimization data structure */
1264  SCIP_LP* lp, /**< current LP data */
1265  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1266  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1267  SCIP_SOL* sol, /**< primal CIP solution */
1268  SCIP_Bool printreason, /**< Should all reasons of violations be printed? */
1269  SCIP_Bool checkbounds, /**< Should the bounds of the variables be checked? */
1270  SCIP_Bool checkintegrality, /**< Has integrality to be checked? */
1271  SCIP_Bool checklprows, /**< Do constraints represented by rows in the current LP have to be checked? */
1272  SCIP_Bool* stored /**< stores whether given solution was feasible and good enough to keep */
1273  )
1274 {
1275  SCIP_Bool feasible;
1276  SCIP_Bool replace;
1277  int insertpos;
1278 
1279  assert(primal != NULL);
1280  assert(set != NULL);
1281  assert(transprob != NULL);
1282  assert(origprob != NULL);
1283  assert(tree != NULL);
1284  assert(sol != NULL);
1285  assert(stored != NULL);
1286 
1287  /* if we want to solve exactly, the constraint handlers cannot rely on the LP's feasibility */
1288  checklprows = checklprows || set->misc_exactsolve;
1289 
1290  insertpos = -1;
1291 
1292  if( solOfInterest(primal, set, stat, origprob, transprob, sol, &insertpos, &replace) )
1293  {
1294  /* check solution for feasibility */
1295  SCIP_CALL( SCIPsolCheck(sol, set, messagehdlr, blkmem, stat, transprob, printreason, checkbounds, checkintegrality, checklprows, &feasible) );
1296  }
1297  else
1298  feasible = FALSE;
1299 
1300  if( feasible )
1301  {
1302  SCIP_SOL* solcopy;
1303 
1304  assert(insertpos >= 0 && insertpos < set->limit_maxsol);
1305 
1306  /* create a copy of the solution */
1307  SCIP_CALL( SCIPsolCopy(&solcopy, blkmem, set, stat, primal, sol) );
1308 
1309  /* insert copied solution into solution storage */
1310  SCIP_CALL( primalAddSol(primal, blkmem, set, messagehdlr, stat, origprob, transprob,
1311  tree, reopt, lp, eventqueue, eventfilter, &solcopy, insertpos, replace) );
1312 
1313  *stored = TRUE;
1314  }
1315  else
1316  *stored = FALSE;
1317 
1318  return SCIP_OKAY;
1319 }
1320 
1321 /** checks primal solution; if feasible, adds it to storage; solution is freed afterwards */
1323  SCIP_PRIMAL* primal, /**< primal data */
1324  BMS_BLKMEM* blkmem, /**< block memory */
1325  SCIP_SET* set, /**< global SCIP settings */
1326  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
1327  SCIP_STAT* stat, /**< problem statistics data */
1328  SCIP_PROB* origprob, /**< original problem */
1329  SCIP_PROB* transprob, /**< transformed problem after presolve */
1330  SCIP_TREE* tree, /**< branch and bound tree */
1331  SCIP_REOPT* reopt, /**< reoptimization data structure */
1332  SCIP_LP* lp, /**< current LP data */
1333  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1334  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1335  SCIP_SOL** sol, /**< pointer to primal CIP solution; is cleared in function call */
1336  SCIP_Bool printreason, /**< Should all the reasons of violations be printed? */
1337  SCIP_Bool checkbounds, /**< Should the bounds of the variables be checked? */
1338  SCIP_Bool checkintegrality, /**< Has integrality to be checked? */
1339  SCIP_Bool checklprows, /**< Do constraints represented by rows in the current LP have to be checked? */
1340  SCIP_Bool* stored /**< stores whether solution was feasible and good enough to keep */
1341  )
1342 {
1343  SCIP_Bool feasible;
1344  SCIP_Bool replace;
1345  int insertpos;
1346 
1347  assert(primal != NULL);
1348  assert(transprob != NULL);
1349  assert(origprob != NULL);
1350  assert(tree != NULL);
1351  assert(sol != NULL);
1352  assert(*sol != NULL);
1353  assert(stored != NULL);
1354 
1355  *stored = FALSE;
1356 
1357  /* if we want to solve exactly, the constraint handlers cannot rely on the LP's feasibility */
1358  checklprows = checklprows || set->misc_exactsolve;
1359 
1360  insertpos = -1;
1361 
1362  if( solOfInterest(primal, set, stat, origprob, transprob, *sol, &insertpos, &replace) )
1363  {
1364  /* check solution for feasibility */
1365  SCIP_CALL( SCIPsolCheck(*sol, set, messagehdlr, blkmem, stat, transprob, printreason, checkbounds, checkintegrality, checklprows, &feasible) );
1366  }
1367  else
1368  feasible = FALSE;
1369 
1370  if( feasible )
1371  {
1372  assert(insertpos >= 0 && insertpos < set->limit_maxsol);
1373 
1374  /* insert solution into solution storage */
1375  SCIP_CALL( primalAddSol(primal, blkmem, set, messagehdlr, stat, origprob, transprob,
1376  tree, reopt, lp, eventqueue, eventfilter, sol, insertpos, replace) );
1377 
1378  /* clear the pointer, such that the user cannot access the solution anymore */
1379  *sol = NULL;
1380  *stored = TRUE;
1381  }
1382  else
1383  {
1384  /* the solution is too bad or infeasible -> free it immediately */
1385  SCIP_CALL( SCIPsolFree(sol, blkmem, primal) );
1386  *stored = FALSE;
1387  }
1388  assert(*sol == NULL);
1389 
1390  return SCIP_OKAY;
1391 }
1392 
1393 /** checks current LP/pseudo solution; if feasible, adds it to storage */
1395  SCIP_PRIMAL* primal, /**< primal data */
1396  BMS_BLKMEM* blkmem, /**< block memory */
1397  SCIP_SET* set, /**< global SCIP settings */
1398  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
1399  SCIP_STAT* stat, /**< problem statistics data */
1400  SCIP_PROB* origprob, /**< original problem */
1401  SCIP_PROB* transprob, /**< transformed problem after presolve */
1402  SCIP_TREE* tree, /**< branch and bound tree */
1403  SCIP_REOPT* reopt, /**< reoptimization data structure */
1404  SCIP_LP* lp, /**< current LP data */
1405  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1406  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1407  SCIP_HEUR* heur, /**< heuristic that found the solution (or NULL if it's from the tree) */
1408  SCIP_Bool printreason, /**< Should all reasons of violations be printed? */
1409  SCIP_Bool checkintegrality, /**< Has integrality to be checked? */
1410  SCIP_Bool checklprows, /**< Do constraints represented by rows in the current LP have to be checked? */
1411  SCIP_Bool* stored /**< stores whether given solution was good enough to keep */
1412  )
1413 {
1414  assert(primal != NULL);
1415 
1416  /* link temporary solution to current solution */
1417  SCIP_CALL( primalLinkCurrentSol(primal, blkmem, set, stat, transprob, tree, lp, heur) );
1418 
1419  /* add solution to solution storage */
1420  SCIP_CALL( SCIPprimalTrySol(primal, blkmem, set, messagehdlr, stat, origprob, transprob,
1421  tree, reopt, lp, eventqueue, eventfilter, primal->currentsol,
1422  printreason, FALSE, checkintegrality, checklprows, stored) );
1423 
1424  return SCIP_OKAY;
1425 }
1426 
1427 /** inserts solution into the global array of all existing primal solutions */
1429  SCIP_PRIMAL* primal, /**< primal data */
1430  SCIP_SET* set, /**< global SCIP settings */
1431  SCIP_SOL* sol /**< primal CIP solution */
1432  )
1433 {
1434  assert(primal != NULL);
1435  assert(sol != NULL);
1436  assert(SCIPsolGetPrimalIndex(sol) == -1);
1437 
1438  /* allocate memory for solution storage */
1439  SCIP_CALL( ensureExistingsolsSize(primal, set, primal->nexistingsols+1) );
1440 
1441  /* append solution */
1442  SCIPsolSetPrimalIndex(sol, primal->nexistingsols);
1443  primal->existingsols[primal->nexistingsols] = sol;
1444  primal->nexistingsols++;
1445 
1446  return SCIP_OKAY;
1447 }
1448 
1449 /** removes solution from the global array of all existing primal solutions */
1451  SCIP_PRIMAL* primal, /**< primal data */
1452  SCIP_SOL* sol /**< primal CIP solution */
1453  )
1454 {
1455  int idx;
1456 
1457  assert(primal != NULL);
1458  assert(sol != NULL);
1459 
1460 #ifndef NDEBUG
1461  for( idx = 0; idx < primal->nexistingsols; ++idx )
1462  {
1463  assert(idx == SCIPsolGetPrimalIndex(primal->existingsols[idx]));
1464  }
1465 #endif
1466 
1467  /* remove solution */
1468  idx = SCIPsolGetPrimalIndex(sol);
1469  assert(0 <= idx && idx < primal->nexistingsols);
1470  assert(sol == primal->existingsols[idx]);
1471  if( idx < primal->nexistingsols-1 )
1472  {
1473  primal->existingsols[idx] = primal->existingsols[primal->nexistingsols-1];
1474  SCIPsolSetPrimalIndex(primal->existingsols[idx], idx);
1475  }
1476  primal->nexistingsols--;
1477 }
1478 
1479 /** updates all existing primal solutions after a change in a variable's objective value */
1481  SCIP_PRIMAL* primal, /**< primal data */
1482  SCIP_VAR* var, /**< problem variable */
1483  SCIP_Real oldobj, /**< old objective value */
1484  SCIP_Real newobj /**< new objective value */
1485  )
1486 {
1487  int i;
1488 
1489  assert(primal != NULL);
1490 
1491  for( i = 0; i < primal->nexistingsols; ++i )
1492  {
1493  if( !SCIPsolIsOriginal(primal->existingsols[i]) )
1494  SCIPsolUpdateVarObj(primal->existingsols[i], var, oldobj, newobj);
1495  }
1496 }
1497 
1498 /** retransforms all existing solutions to original problem space */
1500  SCIP_PRIMAL* primal, /**< primal data */
1501  SCIP_SET* set, /**< global SCIP settings */
1502  SCIP_STAT* stat, /**< problem statistics data */
1503  SCIP_PROB* origprob, /**< original problem */
1504  SCIP_PROB* transprob /**< transformed problem */
1505  )
1506 {
1507  SCIP_Bool hasinfval;
1508  int i;
1509 
1510  assert(primal != NULL);
1511 
1512  for( i = 0; i < primal->nsols; ++i )
1513  {
1514  if( SCIPsolGetOrigin(primal->sols[i]) == SCIP_SOLORIGIN_ZERO )
1515  {
1516  SCIP_CALL( SCIPsolRetransform(primal->sols[i], set, stat, origprob, transprob, &hasinfval) );
1517  }
1518  }
1519 
1520  return SCIP_OKAY;
1521 }
1522 
1523 /** tries to transform original solution to the transformed problem space */
1525  SCIP_PRIMAL* primal, /**< primal data */
1526  SCIP_SOL* sol, /**< primal solution */
1527  BMS_BLKMEM* blkmem, /**< block memory */
1528  SCIP_SET* set, /**< global SCIP settings */
1529  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
1530  SCIP_STAT* stat, /**< problem statistics data */
1531  SCIP_PROB* origprob, /**< original problem */
1532  SCIP_PROB* transprob, /**< transformed problem after presolve */
1533  SCIP_TREE* tree, /**< branch and bound tree */
1534  SCIP_REOPT* reopt, /**< reoptimization data structure */
1535  SCIP_LP* lp, /**< current LP data */
1536  SCIP_EVENTQUEUE* eventqueue, /**< event queue */
1537  SCIP_EVENTFILTER* eventfilter, /**< event filter for global (not variable dependent) events */
1538  SCIP_Real* solvals, /**< array for internal use to store solution values, or NULL;
1539  * if the method is called multiple times in a row, an array with size >=
1540  * number of active variables should be given for performance reasons */
1541  SCIP_Bool* solvalset, /**< array for internal use to store which solution values were set, or NULL;
1542  * if the method is called multiple times in a row, an array with size >=
1543  * number of active variables should be given for performance reasons */
1544  int solvalssize, /**< size of solvals and solvalset arrays, should be >= number of active
1545  * variables */
1546  SCIP_Bool* added /**< pointer to store whether the solution was added */
1547  )
1548 {
1549  SCIP_VAR** origvars;
1550  SCIP_VAR** transvars;
1551  SCIP_VAR* var;
1552  SCIP_Real* localsolvals;
1553  SCIP_Bool* localsolvalset;
1554  SCIP_Real solval;
1555  SCIP_Real scalar;
1556  SCIP_Real constant;
1557  SCIP_Bool localarrays;
1558  SCIP_Bool feasible;
1559  int norigvars;
1560  int ntransvars;
1561  int nvarsset;
1562  int v;
1563 
1564  assert(origprob != NULL);
1565  assert(transprob != NULL);
1566  assert(SCIPsolIsOriginal(sol));
1567  assert(solvalssize == 0 || solvals != NULL);
1568  assert(solvalssize == 0 || solvalset != NULL);
1569 
1570  origvars = origprob->vars;
1571  norigvars = origprob->nvars;
1572  transvars = transprob->vars;
1573  ntransvars = transprob->nvars;
1574  assert(solvalssize == 0 || solvalssize >= ntransvars);
1575 
1576  SCIPdebugMessage("try to transfer original solution %p with objective %g into the transformed problem space\n",
1577  (void*)sol, SCIPsolGetOrigObj(sol));
1578 
1579  /* if no solvals and solvalset arrays are given, allocate local ones, otherwise use the given ones */
1580  localarrays = (solvalssize == 0);
1581  if( localarrays )
1582  {
1583  SCIP_CALL( SCIPsetAllocBufferArray(set, &localsolvals, ntransvars) );
1584  SCIP_CALL( SCIPsetAllocBufferArray(set, &localsolvalset, ntransvars) );
1585  }
1586  else
1587  {
1588  localsolvals = solvals;
1589  localsolvalset = solvalset;
1590  }
1591 
1592  BMSclearMemoryArray(localsolvalset, ntransvars);
1593  feasible = TRUE;
1594  (*added) = FALSE;
1595  nvarsset = 0;
1596 
1597  /* for each original variable, get the corresponding active, fixed or multi-aggregated variable;
1598  * if it resolves to an active variable, we set its solution value or check whether an already stored solution value
1599  * is consistent; if it resolves to a fixed variable, we check that the fixing matches the original solution value;
1600  * multi-aggregated variables are skipped, because their value is defined by setting solution values for the active
1601  * variables, anyway
1602  */
1603  for( v = 0; v < norigvars && feasible; ++v )
1604  {
1605  var = origvars[v];
1606 
1607  solval = SCIPsolGetVal(sol, set, stat, var);
1608 
1609  /* get corresponding active, fixed, or multi-aggregated variable */
1610  scalar = 1.0;
1611  constant = 0.0;
1612  SCIP_CALL( SCIPvarGetProbvarSum(&var, set, &scalar, &constant) );
1615 
1616  /* check whether the fixing corresponds to the solution value of the original variable */
1617  if( scalar == 0.0 )
1618  {
1619  assert(SCIPvarGetStatus(var) == SCIP_VARSTATUS_FIXED ||
1620  (SCIPsetIsInfinity(set, constant) || SCIPsetIsInfinity(set, -constant)));
1621 
1622  if( !SCIPsetIsEQ(set, solval, constant) )
1623  {
1624  SCIPdebugMessage("original variable <%s> (solval=%g) resolves to fixed variable <%s> (original solval=%g)\n",
1625  SCIPvarGetName(origvars[v]), solval, SCIPvarGetName(var), constant);
1626  feasible = FALSE;
1627  }
1628  }
1629  else if( SCIPvarIsActive(var) )
1630  {
1631  /* if we already assigned a solution value to the transformed variable, check that it corresponds to the
1632  * value obtained from the currently regarded original variable
1633  */
1634  if( localsolvalset[SCIPvarGetProbindex(var)] )
1635  {
1636  if( !SCIPsetIsEQ(set, solval, scalar * localsolvals[SCIPvarGetProbindex(var)] + constant) )
1637  {
1638  SCIPdebugMessage("original variable <%s> (solval=%g) resolves to active variable <%s> with assigned solval %g (original solval=%g)\n",
1639  SCIPvarGetName(origvars[v]), solval, SCIPvarGetName(var), localsolvals[SCIPvarGetProbindex(var)],
1640  scalar * localsolvals[SCIPvarGetProbindex(var)] + constant);
1641  feasible = FALSE;
1642  }
1643  }
1644  /* assign solution value to the transformed variable */
1645  else
1646  {
1647  assert(scalar != 0.0);
1648 
1649  localsolvals[SCIPvarGetProbindex(var)] = (solval - constant) / scalar;
1650  localsolvalset[SCIPvarGetProbindex(var)] = TRUE;
1651  ++nvarsset;
1652  }
1653  }
1654 #ifndef NDEBUG
1655  /* we do not have to handle multi-aggregated variables here, since by assigning values to all active variabes,
1656  * we implicitly assign values to the multi-aggregated variables, too
1657  */
1658  else
1659  assert(SCIPvarGetStatus(var) == SCIP_VARSTATUS_MULTAGGR);
1660 #endif
1661  }
1662 
1663  /* if the solution values of fixed and active variables lead to no contradiction, construct solution and try it */
1664  if( feasible )
1665  {
1666  SCIP_SOL* transsol;
1667 
1668  SCIP_CALL( SCIPsolCreate(&transsol, blkmem, set, stat, primal, tree, SCIPsolGetHeur(sol)) );
1669 
1670  /* set solution values for variables to which we assigned a value */
1671  for( v = 0; v < ntransvars; ++v )
1672  {
1673  if( localsolvalset[v] )
1674  {
1675  SCIP_CALL( SCIPsolSetVal(transsol, set, stat, tree, transvars[v], localsolvals[v]) );
1676  }
1677  }
1678 
1679  SCIP_CALL( SCIPprimalTrySolFree(primal, blkmem, set, messagehdlr, stat, origprob, transprob,
1680  tree, reopt, lp, eventqueue, eventfilter, &transsol, FALSE, TRUE, TRUE, TRUE, added) );
1681 
1682  SCIPdebugMessage("solution transferred, %d/%d active variables set (stored=%u)\n", nvarsset, ntransvars, *added);
1683  }
1684  else
1685  (*added) = FALSE;
1686 
1687  /* free local arrays, if needed */
1688  if( localarrays )
1689  {
1690  SCIPsetFreeBufferArray(set, &localsolvalset);
1691  SCIPsetFreeBufferArray(set, &localsolvals);
1692  }
1693 
1694  return SCIP_OKAY;
1695 }
SCIP_Real cutoffbound
Definition: struct_primal.h:45
static SCIP_RETCODE primalLinkCurrentSol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_TREE *tree, SCIP_LP *lp, SCIP_HEUR *heur)
Definition: primal.c:1197
SCIP_RETCODE SCIPprimalTrySol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: primal.c:1254
SCIP_RETCODE SCIPsolUnlink(SCIP_SOL *sol, SCIP_SET *set, SCIP_PROB *prob)
Definition: sol.c:951
SCIP_Bool SCIPsetIsInfinity(SCIP_SET *set, SCIP_Real val)
Definition: set.c:5180
internal methods for managing events
SCIP_HEUR * SCIPsolGetHeur(SCIP_SOL *sol)
Definition: sol.c:2252
SCIP_Bool SCIPsetIsLE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5238
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16443
internal methods for storing primal CIP solutions
void SCIPprimalSolFreed(SCIP_PRIMAL *primal, SCIP_SOL *sol)
Definition: primal.c:1450
internal methods for branch and bound tree
SCIP_RETCODE SCIPprimalTrySolFree(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_SOL **sol, SCIP_Bool printreason, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: primal.c:1322
static SCIP_RETCODE primalAddOrigSol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_PROB *prob, SCIP_SOL *sol, int insertpos)
Definition: primal.c:666
SCIP_SOLORIGIN SCIPsolGetOrigin(SCIP_SOL *sol)
Definition: sol.c:2169
static SCIP_RETCODE primalSetUpperbound(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_PROB *prob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_Real upperbound)
Definition: primal.c:241
SCIP_RETCODE SCIPdispPrintLine(SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, FILE *file, SCIP_Bool forcedisplay, SCIP_Bool endline)
Definition: disp.c:362
int nrunsbeforefirst
Definition: struct_stat.h:218
SCIP_RETCODE SCIPeventChgType(SCIP_EVENT *event, SCIP_EVENTTYPE eventtype)
Definition: event.c:927
#define SCIPsetAllocBufferArray(set, ptr, num)
Definition: set.h:1788
int SCIPsolGetDepth(SCIP_SOL *sol)
Definition: sol.c:2242
#define NULL
Definition: lpi_spx.cpp:130
SCIP_Real SCIPsetInfinity(SCIP_SET *set)
Definition: set.c:5042
SCIP_RETCODE SCIPprimalAddOrigSol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_SOL *sol, SCIP_Bool *stored)
Definition: primal.c:1109
SCIP_RETCODE SCIPsolLinkCurrentSol(SCIP_SOL *sol, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_TREE *tree, SCIP_LP *lp)
Definition: sol.c:891
SCIP_SOL ** sols
Definition: struct_primal.h:47
SCIP_SOL * currentsol
Definition: struct_primal.h:49
#define FALSE
Definition: def.h:56
SCIP_RETCODE SCIPeventProcess(SCIP_EVENT *event, SCIP_SET *set, SCIP_PRIMAL *primal, SCIP_LP *lp, SCIP_BRANCHCAND *branchcand, SCIP_EVENTFILTER *eventfilter)
Definition: event.c:1418
SCIP_RETCODE SCIPsolCopy(SCIP_SOL **sol, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PRIMAL *primal, SCIP_SOL *sourcesol)
Definition: sol.c:339
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
static SCIP_RETCODE ensureSolsSize(SCIP_PRIMAL *primal, SCIP_SET *set, int num)
Definition: primal.c:47
#define SCIP_CALL(x)
Definition: def.h:266
void SCIPsolSetPrimalIndex(SCIP_SOL *sol, int primalindex)
Definition: sol.c:2272
SCIP_Real SCIPprobInternObjval(SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_SET *set, SCIP_Real objval)
Definition: prob.c:1975
int SCIPtreeGetCurrentDepth(SCIP_TREE *tree)
Definition: tree.c:7957
SCIP_Bool SCIPsolsAreEqual(SCIP_SOL *sol1, SCIP_SOL *sol2, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob)
Definition: sol.c:1865
SCIP_Real SCIPsetCutoffbounddelta(SCIP_SET *set)
Definition: set.c:5155
int SCIPsetCalcMemGrowSize(SCIP_SET *set, int num)
Definition: set.c:4766
SCIP_Longint nsolsfound
Definition: struct_primal.h:38
#define SCIPdebugMessage
Definition: pub_message.h:77
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:85
methods for creating output for visualization tools (VBC, BAK)
SCIP_VISUAL * visual
Definition: struct_stat.h:137
internal methods for LP management
internal methods for collecting primal CIP solutions and primal informations
SCIP_Real SCIPsolGetVal(SCIP_SOL *sol, SCIP_SET *set, SCIP_STAT *stat, SCIP_VAR *var)
Definition: sol.c:1245
SCIP_Bool SCIPsetIsGE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5274
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16562
SCIP_RETCODE SCIPprimalAddCurrentSol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_HEUR *heur, SCIP_Bool *stored)
Definition: primal.c:1224
SCIP_RETCODE SCIPprimalUpdateObjlimit(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:326
SCIP_Real SCIPsolGetTime(SCIP_SOL *sol)
Definition: sol.c:2212
SCIP_Real SCIPprobGetObjlim(SCIP_PROB *prob, SCIP_SET *set)
Definition: prob.c:2152
SCIP_Bool SCIPsetIsLT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5220
SCIP_RETCODE SCIPeventChgSol(SCIP_EVENT *event, SCIP_SOL *sol)
Definition: event.c:1198
SCIP_Real SCIPsolGetObj(SCIP_SOL *sol, SCIP_SET *set, SCIP_PROB *transprob, SCIP_PROB *origprob)
Definition: sol.c:1438
void SCIPsolUpdateVarsum(SCIP_SOL *sol, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_Real weight)
Definition: sol.c:1677
internal methods for storing and manipulating the main problem
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_Longint nbestsolsfound
Definition: struct_primal.h:41
static int primalSearchOrigSolPos(SCIP_PRIMAL *primal, SCIP_SOL *sol)
Definition: primal.c:768
SCIP_Longint bestsolnode
Definition: struct_stat.h:84
SCIP_Bool SCIPtreeInRepropagation(SCIP_TREE *tree)
Definition: tree.c:7930
SCIP_RETCODE SCIPsolCreateCurrentSol(SCIP_SOL **sol, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_PRIMAL *primal, SCIP_TREE *tree, SCIP_LP *lp, SCIP_HEUR *heur)
Definition: sol.c:645
int SCIPsolGetRunnum(SCIP_SOL *sol)
Definition: sol.c:2222
void SCIPsolSetHeur(SCIP_SOL *sol, SCIP_HEUR *heur)
Definition: sol.c:2293
SCIP_HEUR * firstprimalheur
Definition: struct_stat.h:138
SCIP_RETCODE SCIPsolSetVal(SCIP_SOL *sol, SCIP_SET *set, SCIP_STAT *stat, SCIP_TREE *tree, SCIP_VAR *var, SCIP_Real val)
Definition: sol.c:980
#define BMSallocMemory(ptr)
Definition: memory.h:74
SCIP_Real SCIPsetFeasCeil(SCIP_SET *set, SCIP_Real val)
Definition: set.c:5758
static SCIP_Bool primalExistsSol(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_SOL *sol, int *insertpos, SCIP_Bool *replace)
Definition: primal.c:803
SCIP_RETCODE SCIPsolPrint(SCIP_SOL *sol, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_PROB *transprob, FILE *file, SCIP_Bool printzeros)
Definition: sol.c:1925
static SCIP_RETCODE primalAddSol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_SOL **solptr, int insertpos, SCIP_Bool replace)
Definition: primal.c:479
SCIP_Bool SCIPprobIsObjIntegral(SCIP_PROB *prob)
Definition: prob.c:2128
internal methods for global SCIP settings
SCIP_Bool SCIPsetIsFeasGE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5666
#define BMSreallocMemoryArray(ptr, num)
Definition: memory.h:82
#define BMSfreeMemory(ptr)
Definition: memory.h:100
SCIP_Bool SCIPsetIsEQ(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5202
SCIP_RETCODE SCIPprimalRetransformSolutions(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob)
Definition: primal.c:1499
SCIP_RETCODE SCIPprimalTryCurrentSol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_HEUR *heur, SCIP_Bool printreason, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
Definition: primal.c:1394
SCIP_Bool SCIPsetIsFeasLE(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5622
SCIP_RETCODE SCIPsolTransform(SCIP_SOL *sol, SCIP_SOL **transsol, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_PRIMAL *primal)
Definition: sol.c:377
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:103
SCIP_RETCODE SCIPprimalSetCutoffbound(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, SCIP_Real cutoffbound, SCIP_Bool useforobjlimit)
Definition: primal.c:188
data structures and methods for collecting reoptimization information
internal methods for problem variables
SCIP_RETCODE SCIPprimalSolCreated(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_SOL *sol)
Definition: primal.c:1428
#define SCIP_Bool
Definition: def.h:53
static SCIP_Bool origsolOfInterest(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_SOL *sol, int *insertpos)
Definition: primal.c:975
void SCIPprimalUpdateVarObj(SCIP_PRIMAL *primal, SCIP_VAR *var, SCIP_Real oldobj, SCIP_Real newobj)
Definition: primal.c:1480
SCIP_Real SCIPsolGetOrigObj(SCIP_SOL *sol)
Definition: sol.c:2189
SCIP_RETCODE SCIPsolCreate(SCIP_SOL **sol, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PRIMAL *primal, SCIP_TREE *tree, SCIP_HEUR *heur)
Definition: sol.c:274
SCIP_Longint SCIPsolGetNodenum(SCIP_SOL *sol)
Definition: sol.c:2232
SCIP_RETCODE SCIPsolRetransform(SCIP_SOL *sol, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_Bool *hasinfval)
Definition: sol.c:1705
void SCIPsolOrigAddObjval(SCIP_SOL *sol, SCIP_Real addval)
Definition: sol.c:2200
static SCIP_RETCODE primalSetCutoffbound(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_EVENTQUEUE *eventqueue, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_Real cutoffbound)
Definition: primal.c:156
void SCIPprobSetObjlim(SCIP_PROB *prob, SCIP_Real objlim)
Definition: prob.c:1407
SCIP_Bool SCIPsolIsOriginal(SCIP_SOL *sol)
Definition: sol.c:2179
SCIP_Longint nnodesbeforefirst
Definition: struct_stat.h:92
static SCIP_Bool solOfInterest(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_SOL *sol, int *insertpos, SCIP_Bool *replace)
Definition: primal.c:937
SCIP_RETCODE SCIPprimalAddOrigSolFree(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_SOL **sol, SCIP_Bool *stored)
Definition: primal.c:1150
SCIP_RETCODE SCIPprimalSetUpperbound(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_PROB *prob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_Real upperbound)
Definition: primal.c:295
#define SCIP_EVENTTYPE_BESTSOLFOUND
Definition: type_event.h:82
SCIP_RETCODE SCIPprimalAddSolFree(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_SOL **sol, SCIP_Bool *stored)
Definition: primal.c:1054
#define SCIP_EVENTTYPE_POORSOLFOUND
Definition: type_event.h:81
SCIP_RETCODE SCIPlpSetCutoffbound(SCIP_LP *lp, SCIP_SET *set, SCIP_PROB *prob, SCIP_Real cutoffbound)
Definition: lp.c:12476
#define REALABS(x)
Definition: def.h:151
SCIP_Bool SCIPprimalUpperboundIsSol(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_PROB *transprob, SCIP_PROB *origprob)
Definition: primal.c:465
SCIP_NODE * SCIPtreeGetCurrentNode(SCIP_TREE *tree)
Definition: tree.c:7940
public methods for message output
SCIP_Real upperbound
Definition: struct_primal.h:44
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:16750
SCIP_Bool SCIPsetIsGT(SCIP_SET *set, SCIP_Real val1, SCIP_Real val2)
Definition: set.c:5256
SCIP_RETCODE SCIPprimalAddSol(SCIP_PRIMAL *primal, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_SOL *sol, SCIP_Bool *stored)
Definition: primal.c:996
int SCIPsolGetPrimalIndex(SCIP_SOL *sol)
Definition: sol.c:2262
void SCIPsolUpdateVarObj(SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real oldobj, SCIP_Real newobj)
Definition: sol.c:1455
#define SCIP_Real
Definition: def.h:127
internal methods for problem statistics
SCIP_RETCODE SCIPsolCheck(SCIP_SOL *sol, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_Bool printreason, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *feasible)
Definition: sol.c:1474
SCIP_VAR ** vars
Definition: struct_prob.h:54
SCIP_Real firstprimaltime
Definition: struct_stat.h:98
#define MIN(x, y)
Definition: memory.c:67
SCIP_Real firstprimalbound
Definition: struct_stat.h:97
#define SCIPsetFreeBufferArray(set, ptr)
Definition: set.h:1795
#define SCIP_INVALID
Definition: def.h:147
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:365
SCIP_RETCODE SCIPprimalTransformSol(SCIP_PRIMAL *primal, SCIP_SOL *sol, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, SCIP_STAT *stat, SCIP_PROB *origprob, SCIP_PROB *transprob, SCIP_TREE *tree, SCIP_REOPT *reopt, SCIP_LP *lp, SCIP_EVENTQUEUE *eventqueue, SCIP_EVENTFILTER *eventfilter, SCIP_Real *solvals, SCIP_Bool *solvalset, int solvalssize, SCIP_Bool *added)
Definition: primal.c:1524
SCIP_Real SCIPsetEpsilon(SCIP_SET *set)
Definition: set.c:5064
SCIP_STAGE SCIPsetGetStage(SCIP_SET *set)
Definition: set.c:2423
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:16730
SCIP_Real SCIPprobExternObjval(SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_SET *set, SCIP_Real objval)
Definition: prob.c:1953
#define SCIPdebug(x)
Definition: pub_message.h:74
static int primalSearchSolPos(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_PROB *transprob, SCIP_PROB *origprob, SCIP_SOL *sol)
Definition: primal.c:718
void SCIPprimalAddOrigObjoffset(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_Real addval)
Definition: primal.c:431
SCIP_RETCODE SCIPprimalCreate(SCIP_PRIMAL **primal)
Definition: primal.c:92
SCIP_RETCODE SCIPtreeCutoff(SCIP_TREE *tree, SCIP_REOPT *reopt, BMS_BLKMEM *blkmem, SCIP_SET *set, SCIP_STAT *stat, SCIP_EVENTQUEUE *eventqueue, SCIP_LP *lp, SCIP_Real cutoffbound)
Definition: tree.c:4891
common defines and data types used in all packages of SCIP
SCIP_Longint nnodes
Definition: struct_stat.h:64
static SCIP_RETCODE ensureExistingsolsSize(SCIP_PRIMAL *primal, SCIP_SET *set, int num)
Definition: primal.c:70
static SCIP_Bool primalExistsOrigSol(SCIP_PRIMAL *primal, SCIP_SET *set, SCIP_STAT *stat, SCIP_PROB *prob, SCIP_SOL *sol, int insertpos)
Definition: primal.c:885
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:392
SCIP_RETCODE SCIPvarGetProbvarSum(SCIP_VAR **var, SCIP_SET *set, SCIP_Real *scalar, SCIP_Real *constant)
Definition: var.c:11906
SCIP_RETCODE SCIPprimalFree(SCIP_PRIMAL **primal, BMS_BLKMEM *blkmem)
Definition: primal.c:118
int firstprimaldepth
Definition: struct_stat.h:219
#define SCIP_ALLOC(x)
Definition: def.h:277
int existingsolssize
Definition: struct_primal.h:54
void SCIPvisualUpperbound(SCIP_VISUAL *visual, SCIP_SET *set, SCIP_STAT *stat, SCIP_Real upperbound)
Definition: visual.c:752
SCIP_Longint nlimsolsfound
Definition: struct_primal.h:39
SCIP_SOL ** existingsols
Definition: struct_primal.h:48
void SCIPvisualFoundSolution(SCIP_VISUAL *visual, SCIP_SET *set, SCIP_STAT *stat, SCIP_NODE *node, SCIP_Bool bettersol, SCIP_SOL *sol)
Definition: visual.c:656
SCIP_RETCODE SCIPsolFree(SCIP_SOL **sol, BMS_BLKMEM *blkmem, SCIP_PRIMAL *primal)
Definition: sol.c:704
internal methods for displaying runtime statistics