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