Scippy

SCIP

Solving Constraint Integer Programs

heur_multistart.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 heur_multistart.c
26  * @ingroup DEFPLUGINS_HEUR
27  * @brief multistart heuristic for convex and nonconvex MINLPs
28  * @author Benjamin Mueller
29  */
30 
31 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32 
33 #include "blockmemshell/memory.h"
34 #include "scip/scip_expr.h"
35 #include "scip/pub_expr.h"
36 #include "scip/heur_multistart.h"
37 #include "scip/heur_subnlp.h"
38 #include "scip/pub_heur.h"
39 #include "scip/pub_message.h"
40 #include "scip/pub_misc.h"
41 #include "scip/pub_misc_sort.h"
42 #include "scip/pub_nlp.h"
43 #include "scip/pub_var.h"
44 #include "scip/scip_general.h"
45 #include "scip/scip_heur.h"
46 #include "scip/scip_mem.h"
47 #include "scip/scip_message.h"
48 #include "scip/scip_nlp.h"
49 #include "scip/scip_nlpi.h"
50 #include "scip/scip_numerics.h"
51 #include "scip/scip_param.h"
52 #include "scip/scip_prob.h"
53 #include "scip/scip_randnumgen.h"
54 #include "scip/scip_sol.h"
55 #include "scip/scip_timing.h"
56 #include <string.h>
57 
58 
59 #define HEUR_NAME "multistart"
60 #define HEUR_DESC "multistart heuristic for convex and nonconvex MINLPs"
61 #define HEUR_DISPCHAR SCIP_HEURDISPCHAR_LNS
62 #define HEUR_PRIORITY -2100000
63 #define HEUR_FREQ 0
64 #define HEUR_FREQOFS 0
65 #define HEUR_MAXDEPTH -1
66 #define HEUR_TIMING SCIP_HEURTIMING_AFTERNODE
67 #define HEUR_USESSUBSCIP TRUE /**< does the heuristic use a secondary SCIP instance? */
68 
69 #define DEFAULT_RANDSEED 131 /**< initial random seed */
70 #define DEFAULT_NRNDPOINTS 100 /**< default number of generated random points per call */
71 #define DEFAULT_MAXBOUNDSIZE 2e+4 /**< default maximum variable domain size for unbounded variables */
72 #define DEFAULT_MAXITER 300 /**< default number of iterations to reduce the violation of a point */
73 #define DEFAULT_MINIMPRFAC 0.05 /**< default minimum required improving factor to proceed in improvement of a point */
74 #define DEFAULT_MINIMPRITER 10 /**< default number of iteration when checking the minimum improvement */
75 #define DEFAULT_MAXRELDIST 0.15 /**< default maximum distance between two points in the same cluster */
76 #define DEFAULT_GRADLIMIT 5e+6 /**< default limit for gradient computations for all improvePoint() calls */
77 #define DEFAULT_MAXNCLUSTER 3 /**< default maximum number of considered clusters per heuristic call */
78 #define DEFAULT_ONLYNLPS TRUE /**< should the heuristic run only on continuous problems? */
79 
80 #define MINFEAS -1e+4 /**< minimum feasibility for a point; used for filtering and improving
81  * feasibility */
82 #define MINIMPRFAC 0.95 /**< improvement factor used to discard randomly generated points with a
83  * too large objective value */
84 #define GRADCOSTFAC_LINEAR 1.0 /**< gradient cost factor for the number of linear variables */
85 #define GRADCOSTFAC_NONLINEAR 3.0 /**< gradient cost factor for the number of nodes in nonlinear expression */
86 
87 /*
88  * Data structures
89  */
90 
91 /** primal heuristic data */
92 struct SCIP_HeurData
93 {
94  int nrndpoints; /**< number of random points generated per execution call */
95  SCIP_Real maxboundsize; /**< maximum variable domain size for unbounded variables */
96  SCIP_RANDNUMGEN* randnumgen; /**< random number generator */
97  SCIP_HEUR* heursubnlp; /**< sub-NLP heuristic */
98 
99  int maxiter; /**< number of iterations to reduce the maximum violation of a point */
100  SCIP_Real minimprfac; /**< minimum required improving factor to proceed in the improvement of a single point */
101  int minimpriter; /**< number of iteration when checking the minimum improvement */
102 
103  SCIP_Real maxreldist; /**< maximum distance between two points in the same cluster */
104  SCIP_Real gradlimit; /**< limit for gradient computations for all improvePoint() calls (0 for no limit) */
105  int maxncluster; /**< maximum number of considered clusters per heuristic call */
106  SCIP_Bool onlynlps; /**< should the heuristic run only on continuous problems? */
107 };
108 
109 
110 /*
111  * Local methods
112  */
113 
114 
115 /** returns an unique index of a variable in the range of 0,..,SCIPgetNVars(scip)-1 */
116 #ifndef NDEBUG
117 static
118 int getVarIndex(
119  SCIP_HASHMAP* varindex, /**< maps variables to indicies between 0,..,SCIPgetNVars(scip)-1 */
120  SCIP_VAR* var /**< variable */
121  )
122 {
123  assert(varindex != NULL);
124  assert(var != NULL);
125  assert(SCIPhashmapExists(varindex, (void*)var));
126 
127  return SCIPhashmapGetImageInt(varindex, (void*)var);
128 }
129 #else
130 #define getVarIndex(varindex,var) (SCIPhashmapGetImageInt((varindex), (void*)(var)))
131 #endif
132 
133 /** samples and stores random points; stores points which have a better objective value than the current incumbent
134  * solution
135  */
136 static
138  SCIP* scip, /**< SCIP data structure */
139  SCIP_SOL** rndpoints, /**< array to store all random points */
140  int nmaxrndpoints, /**< maximum number of random points to compute */
141  SCIP_Real maxboundsize, /**< maximum variable domain size for unbounded variables */
142  SCIP_RANDNUMGEN* randnumgen, /**< random number generator */
143  SCIP_Real bestobj, /**< objective value in the transformed space of the current incumbent */
144  int* nstored /**< pointer to store the number of randomly generated points */
145  )
146 {
147  SCIP_VAR** vars;
148  SCIP_SOL* sol;
149  SCIP_Real val;
150  SCIP_Real lb;
151  SCIP_Real ub;
152  int nvars;
153  int niter;
154  int i;
155 
156  assert(scip != NULL);
157  assert(rndpoints != NULL);
158  assert(nmaxrndpoints > 0);
159  assert(maxboundsize > 0.0);
160  assert(randnumgen != NULL);
161  assert(nstored != NULL);
162 
163  vars = SCIPgetVars(scip);
164  nvars = SCIPgetNVars(scip);
165  *nstored = 0;
166 
167  SCIP_CALL( SCIPcreateSol(scip, &sol, NULL) );
168 
169  for( niter = 0; niter < 3 * nmaxrndpoints && *nstored < nmaxrndpoints; ++niter )
170  {
171  for( i = 0; i < nvars; ++i )
172  {
173  lb = MIN(SCIPvarGetLbLocal(vars[i]), SCIPvarGetUbLocal(vars[i])); /*lint !e666*/
174  ub = MAX(SCIPvarGetLbLocal(vars[i]), SCIPvarGetUbLocal(vars[i])); /*lint !e666*/
175 
176  if( SCIPisFeasEQ(scip, lb, ub) )
177  val = (lb + ub) / 2.0;
178  /* use a smaller domain for unbounded variables */
179  else if( !SCIPisInfinity(scip, -lb) && !SCIPisInfinity(scip, ub) )
180  val = SCIPrandomGetReal(randnumgen, lb, ub);
181  else if( !SCIPisInfinity(scip, -lb) )
182  val = lb + SCIPrandomGetReal(randnumgen, 0.0, maxboundsize);
183  else if( !SCIPisInfinity(scip, ub) )
184  val = ub - SCIPrandomGetReal(randnumgen, 0.0, maxboundsize);
185  else
186  {
187  assert(SCIPisInfinity(scip, -lb) && SCIPisInfinity(scip, ub));
188  val = SCIPrandomGetReal(randnumgen, -0.5*maxboundsize, 0.5*maxboundsize);
189  }
190  assert(SCIPisFeasGE(scip, val, lb) && SCIPisFeasLE(scip, val, ub));
191 
192  /* set solution value; round the sampled point for integer variables */
193  if( SCIPvarGetType(vars[i]) < SCIP_VARTYPE_CONTINUOUS )
194  val = SCIPfeasRound(scip, val);
195  SCIP_CALL( SCIPsetSolVal(scip, sol, vars[i], val) );
196  }
197 
198  /* add solution if it is good enough */
199  if( SCIPisLE(scip, SCIPgetSolTransObj(scip, sol), bestobj) )
200  {
201  SCIP_CALL( SCIPcreateSolCopy(scip, &rndpoints[*nstored], sol) );
202  ++(*nstored);
203  }
204  }
205  assert(*nstored <= nmaxrndpoints);
206  SCIPdebugMsg(scip, "found %d randomly generated points\n", *nstored);
207 
208  SCIP_CALL( SCIPfreeSol(scip, &sol) );
209 
210  return SCIP_OKAY;
211 }
212 
213 /** computes the minimum feasibility of a given point; a negative value means that there is an infeasibility */
214 static
216  SCIP* scip, /**< SCIP data structure */
217  SCIP_NLROW** nlrows, /**< array containing all nlrows */
218  int nnlrows, /**< total number of nlrows */
219  SCIP_SOL* sol, /**< solution */
220  SCIP_Real* minfeas /**< buffer to store the minimum feasibility */
221  )
222 {
223  SCIP_Real tmp;
224  int i;
225 
226  assert(scip != NULL);
227  assert(sol != NULL);
228  assert(minfeas != NULL);
229  assert(nlrows != NULL);
230  assert(nnlrows > 0);
231 
232  *minfeas = SCIPinfinity(scip);
233 
234  for( i = 0; i < nnlrows; ++i )
235  {
236  assert(nlrows[i] != NULL);
237 
238  SCIP_CALL( SCIPgetNlRowSolFeasibility(scip, nlrows[i], sol, &tmp) );
239  *minfeas = MIN(*minfeas, tmp);
240  }
241 
242  return SCIP_OKAY;
243 }
244 
245 /** computes the gradient for a given point and nonlinear row */
246 static
248  SCIP* scip, /**< SCIP data structure */
249  SCIP_NLROW* nlrow, /**< nonlinear row */
250  SCIP_SOL* sol, /**< solution to compute the gradient for */
251  SCIP_HASHMAP* varindex, /**< maps variables to indicies between 0,..,SCIPgetNVars(scip)-1 uniquely */
252  SCIP_EXPRITER* exprit, /**< expression iterator that can be used */
253  SCIP_Real* grad, /**< buffer to store the gradient; grad[varindex(i)] corresponds to SCIPgetVars(scip)[i] */
254  SCIP_Real* norm /**< buffer to store ||grad||^2 */
255  )
256 {
257  SCIP_EXPR* expr;
258  SCIP_VAR* var;
259  int i;
260 
261  assert(scip != NULL);
262  assert(nlrow != NULL);
263  assert(varindex != NULL);
264  assert(sol != NULL);
265  assert(norm != NULL);
266 
267  BMSclearMemoryArray(grad, SCIPgetNVars(scip));
268  *norm = 0.0;
269 
270  /* linear part */
271  for( i = 0; i < SCIPnlrowGetNLinearVars(nlrow); i++ )
272  {
273  var = SCIPnlrowGetLinearVars(nlrow)[i];
274  assert(var != NULL);
275  assert(getVarIndex(varindex, var) >= 0 && getVarIndex(varindex, var) < SCIPgetNVars(scip));
276 
277  grad[getVarIndex(varindex, var)] += SCIPnlrowGetLinearCoefs(nlrow)[i];
278  }
279 
280  /* expression part */
281  expr = SCIPnlrowGetExpr(nlrow);
282 
283  if( expr != NULL )
284  {
285  assert(exprit != NULL);
286 
287  SCIP_CALL( SCIPevalExprGradient(scip, expr, sol, 0L) );
288 
289  /* TODO: change this when nlrows store the vars */
291  for( ; !SCIPexpriterIsEnd(exprit); expr = SCIPexpriterGetNext(exprit) ) /*lint !e441*/ /*lint !e440*/
292  {
293  if( !SCIPisExprVar(scip, expr) )
294  continue;
295 
296  var = SCIPgetVarExprVar(expr);
297  assert(var != NULL);
298  assert(getVarIndex(varindex, var) >= 0 && getVarIndex(varindex, var) < SCIPgetNVars(scip));
299 
300  grad[getVarIndex(varindex, var)] += SCIPexprGetDerivative(expr);
301  }
302  }
303 
304  /* compute ||grad||^2 */
305  for( i = 0; i < SCIPgetNVars(scip); ++i )
306  *norm += SQR(grad[i]);
307 
308  return SCIP_OKAY;
309 }
310 
311 /** use consensus vectors to improve feasibility for a given starting point */
312 static
314  SCIP* scip, /**< SCIP data structure */
315  SCIP_NLROW** nlrows, /**< array containing all nlrows */
316  int nnlrows, /**< total number of nlrows */
317  SCIP_HASHMAP* varindex, /**< maps variables to indicies between 0,..,SCIPgetNVars(scip)-1 */
318  SCIP_SOL* point, /**< random generated point */
319  int maxiter, /**< maximum number of iterations */
320  SCIP_Real minimprfac, /**< minimum required improving factor to proceed in the improvement of a single point */
321  int minimpriter, /**< number of iteration when checking the minimum improvement */
322  SCIP_Real* minfeas, /**< pointer to store the minimum feasibility */
323  SCIP_Real* nlrowgradcosts, /**< estimated costs for each gradient computation */
324  SCIP_Real* gradcosts /**< pointer to store the estimated gradient costs */
325  )
326 {
327  SCIP_VAR** vars;
328  SCIP_EXPRITER* exprit;
329  SCIP_Real* grad;
330  SCIP_Real* updatevec;
331  SCIP_Real lastminfeas;
332  int nvars;
333  int r;
334  int i;
335 
336  assert(varindex != NULL);
337  assert(point != NULL);
338  assert(maxiter > 0);
339  assert(minfeas != NULL);
340  assert(nlrows != NULL);
341  assert(nnlrows > 0);
342  assert(nlrowgradcosts != NULL);
343  assert(gradcosts != NULL);
344 
345  *gradcosts = 0.0;
346 
347  SCIP_CALL( getMinFeas(scip, nlrows, nnlrows, point, minfeas) );
348 #ifdef SCIP_DEBUG_IMPROVEPOINT
349  printf("start minfeas = %e\n", *minfeas);
350 #endif
351 
352  /* stop since start point is feasible */
353  if( !SCIPisFeasLT(scip, *minfeas, 0.0) )
354  {
355 #ifdef SCIP_DEBUG_IMPROVEPOINT
356  printf("start point is feasible");
357 #endif
358  return SCIP_OKAY;
359  }
360 
361  lastminfeas = *minfeas;
362  vars = SCIPgetVars(scip);
363  nvars = SCIPgetNVars(scip);
364 
365  SCIP_CALL( SCIPallocBufferArray(scip, &grad, nvars) );
366  SCIP_CALL( SCIPallocBufferArray(scip, &updatevec, nvars) );
367  SCIP_CALL( SCIPcreateExpriter(scip, &exprit) );
368 
369  /* main loop */
370  for( r = 0; r < maxiter && SCIPisFeasLT(scip, *minfeas, 0.0); ++r )
371  {
372  SCIP_Real feasibility;
373  SCIP_Real activity;
374  SCIP_Real nlrownorm;
375  SCIP_Real scale;
376  int nviolnlrows;
377 
378  BMSclearMemoryArray(updatevec, nvars);
379  nviolnlrows = 0;
380 
381  for( i = 0; i < nnlrows; ++i )
382  {
383  int j;
384 
385  SCIP_CALL( SCIPgetNlRowSolFeasibility(scip, nlrows[i], point, &feasibility) );
386 
387  /* do not consider non-violated constraints */
388  if( SCIPisFeasGE(scip, feasibility, 0.0) )
389  continue;
390 
391  /* increase number of violated nlrows */
392  ++nviolnlrows;
393 
394  SCIP_CALL( SCIPgetNlRowSolActivity(scip, nlrows[i], point, &activity) );
395  SCIP_CALL( computeGradient(scip, nlrows[i], point, varindex, exprit, grad, &nlrownorm) );
396 
397  /* update estimated costs for computing gradients */
398  *gradcosts += nlrowgradcosts[i];
399 
400  /* stop if the gradient disappears at the current point */
401  if( SCIPisZero(scip, nlrownorm) )
402  {
403 #ifdef SCIP_DEBUG_IMPROVEPOINT
404  printf("gradient vanished at current point -> stop\n");
405 #endif
406  goto TERMINATE;
407  }
408 
409  /* compute -g(x_k) / ||grad(g)(x_k)||^2 for a constraint g(x_k) <= 0 */
410  scale = -feasibility / nlrownorm;
411  if( !SCIPisInfinity(scip, SCIPnlrowGetRhs(nlrows[i])) && SCIPisGT(scip, activity, SCIPnlrowGetRhs(nlrows[i])) )
412  scale *= -1.0;
413 
414  /* skip nonliner row if the scaler is too small or too large */
415  if( SCIPisEQ(scip, scale, 0.0) || SCIPisHugeValue(scip, REALABS(scale)) )
416  continue;
417 
418  for( j = 0; j < nvars; ++j )
419  updatevec[j] += scale * grad[j];
420  }
421 
422  /* if there are no violated rows, stop since start point is feasible */
423  if( nviolnlrows == 0 )
424  {
425  assert(updatevec[i] == 0.0);
426  return SCIP_OKAY;
427  }
428 
429  for( i = 0; i < nvars; ++i )
430  {
431  /* adjust point */
432  updatevec[i] = SCIPgetSolVal(scip, point, vars[i]) + updatevec[i] / nviolnlrows;
433  updatevec[i] = MIN(updatevec[i], SCIPvarGetUbLocal(vars[i])); /*lint !e666*/
434  updatevec[i] = MAX(updatevec[i], SCIPvarGetLbLocal(vars[i])); /*lint !e666*/
435 
436  SCIP_CALL( SCIPsetSolVal(scip, point, vars[i], updatevec[i]) );
437  }
438 
439  /* update feasibility */
440  SCIP_CALL( getMinFeas(scip, nlrows, nnlrows, point, minfeas) );
441 
442  /* check stopping criterion */
443  if( r % minimpriter == 0 && r > 0 )
444  {
445  if( *minfeas <= MINFEAS
446  || (*minfeas-lastminfeas) / MAX(REALABS(*minfeas), REALABS(lastminfeas)) < minimprfac ) /*lint !e666*/
447  break;
448  lastminfeas = *minfeas;
449  }
450  }
451 
452 TERMINATE:
453 #ifdef SCIP_DEBUG_IMPROVEPOINT
454  printf("niter=%d minfeas=%e\n", r, *minfeas);
455 #endif
456 
457  SCIPfreeExpriter(&exprit);
458 
459  SCIPfreeBufferArray(scip, &updatevec);
460  SCIPfreeBufferArray(scip, &grad);
461 
462  return SCIP_OKAY;
463 }
464 
465 /** sorts points w.r.t their feasibilities; points with a feasibility which is too small (w.r.t. the geometric mean of
466  * all feasibilities) will be filtered out
467  */
468 static
470  SCIP* scip, /**< SCIP data structure */
471  SCIP_SOL** points, /**< array containing improved points */
472  SCIP_Real* feasibilities, /**< array containing feasibility for each point (sorted) */
473  int npoints, /**< total number of points */
474  int* nusefulpoints /**< pointer to store the total number of useful points */
475  )
476 {
477  SCIP_Real minfeas;
478  SCIP_Real meanfeas;
479  int i;
480 
481  assert(points != NULL);
482  assert(feasibilities != NULL);
483  assert(npoints > 0);
484  assert(nusefulpoints != NULL);
485 
486  /* sort points w.r.t their feasibilities; non-negative feasibility correspond to feasible points for the NLP */
487  SCIPsortDownRealPtr(feasibilities, (void**)points, npoints);
488  minfeas = feasibilities[npoints - 1];
489 
490  /* check if all points are feasible */
491  if( SCIPisFeasGE(scip, minfeas, 0.0) )
492  {
493  *nusefulpoints = npoints;
494  return SCIP_OKAY;
495  }
496 
497  *nusefulpoints = 0;
498 
499  /* compute shifted geometric mean of feasibilities (shift value = 1 - minfeas) */
500  meanfeas = 1.0;
501  for( i = 0; i < npoints; ++i )
502  {
503  assert(feasibilities[i] - minfeas + 1.0 > 0.0);
504  meanfeas *= pow(feasibilities[i] - minfeas + 1.0, 1.0 / npoints);
505  }
506  meanfeas += minfeas - 1.0;
507  SCIPdebugMsg(scip, "meanfeas = %e\n", meanfeas);
508 
509  /* keep all points with which have a feasibility not much below the geometric mean of infeasibilities */
510  for( i = 0; i < npoints; ++i )
511  {
512  if( SCIPisFeasLT(scip, feasibilities[i], 0.0)
513  && (feasibilities[i] <= 1.05 * meanfeas || SCIPisLE(scip, feasibilities[i], MINFEAS)) )
514  break;
515 
516  ++(*nusefulpoints);
517  }
518 
519  return SCIP_OKAY;
520 }
521 
522 /** returns the relative distance between two points; considers a smaller bounded domain for unbounded variables */
523 static
525  SCIP* scip, /**< SCIP data structure */
526  SCIP_SOL* x, /**< first point */
527  SCIP_SOL* y, /**< second point */
528  SCIP_Real maxboundsize /**< maximum variable domain size for unbounded variables */
529  )
530 {
531  SCIP_VAR** vars;
532  int nvars;
533  SCIP_Real distance;
534  SCIP_Real solx;
535  SCIP_Real soly;
536  SCIP_Real lb;
537  SCIP_Real ub;
538  int i;
539 
540  assert(x != NULL);
541  assert(y != NULL);
542 
543  vars = SCIPgetVars(scip);
544  nvars = SCIPgetNVars(scip);
545  distance = 0.0;
546 
547  if( nvars == 0 )
548  return 0.0;
549 
550  for( i = 0; i < nvars; ++i )
551  {
552  lb = SCIPvarGetLbLocal(vars[i]);
553  ub = SCIPvarGetUbLocal(vars[i]);
554  solx = SCIPgetSolVal(scip, x, vars[i]);
555  soly = SCIPgetSolVal(scip, y, vars[i]);
556 
557  /* adjust lower and upper bounds for unbounded variables*/
558  if( SCIPisInfinity(scip, -lb) && SCIPisInfinity(scip, ub) )
559  {
560  lb = -maxboundsize / 2.0;
561  ub = +maxboundsize / 2.0;
562  }
563  else if( SCIPisInfinity(scip, -lb) )
564  {
565  lb = ub - maxboundsize;
566  }
567  else if( SCIPisInfinity(scip, ub) )
568  {
569  ub = lb + maxboundsize;
570  }
571 
572  /* project solution values to the variable domain */
573  solx = MIN(MAX(solx, lb), ub);
574  soly = MIN(MAX(soly, lb), ub);
575 
576  distance += REALABS(solx - soly) / MAX(1.0, ub - lb);
577  }
578 
579  return distance / nvars;
580 }
581 
582 /** cluster useful points with a greedy algorithm */
583 static
585  SCIP* scip, /**< SCIP data structure */
586  SCIP_SOL** points, /**< array containing improved points */
587  int npoints, /**< total number of points */
588  int* clusteridx, /**< array to store for each point the index of the cluster */
589  int* ncluster, /**< pointer to store the total number of cluster */
590  SCIP_Real maxboundsize, /**< maximum variable domain size for unbounded variables */
591  SCIP_Real maxreldist, /**< maximum relative distance between any two points of the same cluster */
592  int maxncluster /**< maximum number of clusters to compute */
593  )
594 {
595  int i;
596 
597  assert(points != NULL);
598  assert(npoints > 0);
599  assert(clusteridx != NULL);
600  assert(ncluster != NULL);
601  assert(maxreldist >= 0.0);
602  assert(maxncluster >= 0);
603 
604  /* initialize cluster indices */
605  for( i = 0; i < npoints; ++i )
606  clusteridx[i] = INT_MAX;
607 
608  *ncluster = 0;
609 
610  for( i = 0; i < npoints && (*ncluster < maxncluster); ++i )
611  {
612  int j;
613 
614  /* point is already assigned to a cluster */
615  if( clusteridx[i] != INT_MAX )
616  continue;
617 
618  /* create a new cluster for i */
619  clusteridx[i] = *ncluster;
620 
621  for( j = i + 1; j < npoints; ++j )
622  {
623  if( clusteridx[j] == INT_MAX && getRelDistance(scip, points[i], points[j], maxboundsize) <= maxreldist )
624  clusteridx[j] = *ncluster;
625  }
626 
627  ++(*ncluster);
628  }
629 
630 #ifndef NDEBUG
631  for( i = 0; i < npoints; ++i )
632  {
633  assert(clusteridx[i] >= 0);
634  assert(clusteridx[i] < *ncluster || clusteridx[i] == INT_MAX);
635  }
636 #endif
637 
638  return SCIP_OKAY;
639 }
640 
641 /** calls the sub-NLP heuristic for a given cluster */
642 static
644  SCIP* scip, /**< SCIP data structure */
645  SCIP_HEUR* heur, /**< multi-start heuristic */
646  SCIP_HEUR* nlpheur, /**< pointer to NLP local search heuristics */
647  SCIP_SOL** points, /**< array containing improved points */
648  int npoints, /**< total number of points */
649  SCIP_Bool* success /**< pointer to store if we could find a solution */
650  )
651 {
652  SCIP_VAR** vars;
653  SCIP_SOL* refpoint;
654  SCIP_RESULT nlpresult;
655  SCIP_Real val;
656  int nbinvars;
657  int nintvars;
658  int nvars;
659  int i;
660 
661  assert(points != NULL);
662  assert(npoints > 0);
663 
664  SCIP_CALL( SCIPgetVarsData(scip, &vars, &nvars, &nbinvars, &nintvars, NULL, NULL) );
665  *success = FALSE;
666 
667  SCIP_CALL( SCIPcreateSol(scip, &refpoint, heur) );
668 
669  /* compute reference point */
670  for( i = 0; i < nvars; ++i )
671  {
672  int p;
673 
674  val = 0.0;
675 
676  for( p = 0; p < npoints; ++p )
677  {
678  assert(points[p] != NULL);
679  val += SCIPgetSolVal(scip, points[p], vars[i]);
680  }
681 
682  SCIP_CALL( SCIPsetSolVal(scip, refpoint, vars[i], val / npoints) );
683  }
684 
685  /* round point for sub-NLP heuristic */
686  SCIP_CALL( SCIProundSol(scip, refpoint, success) );
687  SCIPdebugMsg(scip, "rounding of refpoint successfully? %u\n", *success);
688 
689  /* round variables manually if the locks did not allow us to round them */
690  if( !(*success) )
691  {
692  for( i = 0; i < nbinvars + nintvars; ++i )
693  {
694  val = SCIPgetSolVal(scip, refpoint, vars[i]);
695 
696  if( !SCIPisFeasIntegral(scip, val) )
697  {
698  assert(SCIPisFeasIntegral(scip, SCIPvarGetLbLocal(vars[i])));
699  assert(SCIPisFeasIntegral(scip, SCIPvarGetUbLocal(vars[i])));
700 
701  /* round and adjust value */
702  val = SCIPround(scip, val);
703  val = MIN(val, SCIPvarGetUbLocal(vars[i])); /*lint !e666*/
704  val = MAX(val, SCIPvarGetLbLocal(vars[i])); /*lint !e666*/
705  assert(SCIPisFeasIntegral(scip, val));
706 
707  SCIP_CALL( SCIPsetSolVal(scip, refpoint, vars[i], val) );
708  }
709  }
710  }
711 
712  /* call sub-NLP heuristic */
713  SCIP_CALL( SCIPapplyHeurSubNlp(scip, nlpheur, &nlpresult, refpoint, NULL) );
714  SCIP_CALL( SCIPfreeSol(scip, &refpoint) );
715 
716  /* let sub-NLP heuristic decide whether the solution is feasible or not */
717  *success = nlpresult == SCIP_FOUNDSOL;
718 
719  return SCIP_OKAY;
720 }
721 
722 /** recursive helper function to count the number of nodes in a sub-expr */
723 static
724 int getExprSize(
725  SCIP_EXPR* expr /**< expression */
726  )
727 {
728  int sum;
729  int i;
730 
731  assert(expr != NULL);
732 
733  sum = 0;
734  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
735  {
736  SCIP_EXPR* child = SCIPexprGetChildren(expr)[i];
737  sum += getExprSize(child);
738  }
739  return 1 + sum;
740 }
741 
742 /** main function of the multi-start heuristic (see @ref heur_multistart.h for more details); it consists of the
743  * following four steps:
744  *
745  * 1. sampling points in the current domain; for unbounded variables we use a bounded box
746  *
747  * 2. reduce infeasibility by using a gradient descent method
748  *
749  * 3. cluster points; filter points with a too large infeasibility
750  *
751  * 4. compute start point for each cluster and use it in the sub-NLP heuristic (@ref heur_subnlp.h)
752  */
753 static
755  SCIP* scip, /**< SCIP data structure */
756  SCIP_HEUR* heur, /**< heuristic */
757  SCIP_HEURDATA* heurdata, /**< heuristic data */
758  SCIP_RESULT* result /**< pointer to store the result */
759  )
760 {
761  SCIP_NLROW** nlrows;
762  SCIP_SOL** points;
763  SCIP_HASHMAP* varindex;
764  SCIP_Real* feasibilities;
765  SCIP_Real* nlrowgradcosts;
766  int* clusteridx;
767  SCIP_Real gradlimit;
768  SCIP_Real bestobj;
769  int nusefulpoints;
770  int nrndpoints;
771  int ncluster;
772  int nnlrows;
773  int npoints;
774  int start;
775  int i;
776 
777  assert(scip != NULL);
778  assert(heur != NULL);
779  assert(result != NULL);
780  assert(heurdata != NULL);
781 
782  SCIPdebugMsg(scip, "call applyHeur()\n");
783 
784  nlrows = SCIPgetNLPNlRows(scip);
785  nnlrows = SCIPgetNNLPNlRows(scip);
786  bestobj = SCIPgetNSols(scip) > 0 ? MINIMPRFAC * SCIPgetSolTransObj(scip, SCIPgetBestSol(scip)) : SCIPinfinity(scip);
787 
788  SCIP_CALL( SCIPallocBufferArray(scip, &points, heurdata->nrndpoints) );
789  SCIP_CALL( SCIPallocBufferArray(scip, &nlrowgradcosts, nnlrows) );
790  SCIP_CALL( SCIPallocBufferArray(scip, &feasibilities, heurdata->nrndpoints) );
791  SCIP_CALL( SCIPallocBufferArray(scip, &clusteridx, heurdata->nrndpoints) );
792  SCIP_CALL( SCIPhashmapCreate(&varindex, SCIPblkmem(scip), SCIPgetNVars(scip)) );
793 
794  /* create an unique mapping of all variables to 0,..,SCIPgetNVars(scip)-1 */
795  for( i = 0; i < SCIPgetNVars(scip); ++i )
796  {
797  SCIP_CALL( SCIPhashmapInsertInt(varindex, (void*)SCIPgetVars(scip)[i], i) );
798  }
799 
800  /* compute estimated costs of computing a gradient for each nlrow */
801  for( i = 0; i < nnlrows; ++i )
802  {
803  nlrowgradcosts[i] = GRADCOSTFAC_LINEAR * SCIPnlrowGetNLinearVars(nlrows[i]);
804  if( SCIPnlrowGetExpr(nlrows[i]) != NULL )
805  nlrowgradcosts[i] += GRADCOSTFAC_NONLINEAR * getExprSize(SCIPnlrowGetExpr(nlrows[i]));
806  }
807 
808  /*
809  * 1. sampling points in the current domain; for unbounded variables we use a bounded box
810  */
811  SCIP_CALL( sampleRandomPoints(scip, points, heurdata->nrndpoints, heurdata->maxboundsize, heurdata->randnumgen,
812  bestobj, &nrndpoints) );
813  assert(nrndpoints >= 0);
814 
815  if( nrndpoints == 0 )
816  goto TERMINATE;
817 
818  /*
819  * 2. improve points via consensus vectors
820  */
821  gradlimit = heurdata->gradlimit == 0.0 ? SCIPinfinity(scip) : heurdata->gradlimit;
822  for( npoints = 0; npoints < nrndpoints && gradlimit >= 0 && !SCIPisStopped(scip); ++npoints )
823  {
824  SCIP_Real gradcosts;
825 
826  SCIP_CALL( improvePoint(scip, nlrows, nnlrows, varindex, points[npoints],
827  heurdata->maxiter, heurdata->minimprfac, heurdata->minimpriter, &feasibilities[npoints], nlrowgradcosts,
828  &gradcosts) );
829 
830  gradlimit -= gradcosts;
831  SCIPdebugMsg(scip, "improve point %d / %d gradlimit = %g\n", npoints, nrndpoints, gradlimit);
832  }
833  assert(npoints >= 0 && npoints <= nrndpoints);
834 
835  if( npoints == 0 )
836  goto TERMINATE;
837 
838  /*
839  * 3. filter and cluster points
840  */
841  SCIP_CALL( filterPoints(scip, points, feasibilities, npoints, &nusefulpoints) );
842  assert(nusefulpoints >= 0);
843  SCIPdebugMsg(scip, "nusefulpoints = %d\n", nusefulpoints);
844 
845  if( nusefulpoints == 0 )
846  goto TERMINATE;
847 
848  SCIP_CALL( clusterPointsGreedy(scip, points, nusefulpoints, clusteridx, &ncluster, heurdata->maxboundsize,
849  heurdata->maxreldist, heurdata->maxncluster) );
850  assert(ncluster >= 0 && ncluster <= heurdata->maxncluster);
851  SCIPdebugMsg(scip, "ncluster = %d\n", ncluster);
852 
853  SCIPsortIntPtr(clusteridx, (void**)points, nusefulpoints);
854 
855  /*
856  * 4. compute start point for each cluster and use it in the sub-NLP heuristic (@ref heur_subnlp.h)
857  */
858  start = 0;
859  while( start < nusefulpoints && clusteridx[start] != INT_MAX && !SCIPisStopped(scip) )
860  {
861  SCIP_Bool success;
862  int end;
863 
864  end = start;
865  while( end < nusefulpoints && clusteridx[start] == clusteridx[end] )
866  ++end;
867 
868  assert(end - start > 0);
869 
870  /* call sub-NLP heuristic */
871  SCIP_CALL( solveNLP(scip, heur, heurdata->heursubnlp, &points[start], end - start, &success) );
872  SCIPdebugMsg(scip, "solveNLP result = %u\n", success);
873 
874  if( success )
875  *result = SCIP_FOUNDSOL;
876 
877  /* go to the next cluster */
878  start = end;
879  }
880 
881 TERMINATE:
882  /* free memory */
883  for( i = nrndpoints - 1; i >= 0 ; --i )
884  {
885  assert(points[i] != NULL);
886  SCIP_CALL( SCIPfreeSol(scip, &points[i]) );
887  }
888 
889  SCIPhashmapFree(&varindex);
890  SCIPfreeBufferArray(scip, &clusteridx);
891  SCIPfreeBufferArray(scip, &feasibilities);
892  SCIPfreeBufferArray(scip, &nlrowgradcosts);
893  SCIPfreeBufferArray(scip, &points);
894 
895  return SCIP_OKAY;
896 }
897 
898 /*
899  * Callback methods of primal heuristic
900  */
901 
902 /** copy method for primal heuristic plugins (called when SCIP copies plugins) */
903 static
904 SCIP_DECL_HEURCOPY(heurCopyMultistart)
905 { /*lint --e{715}*/
906  assert(strcmp(SCIPheurGetName(heur), HEUR_NAME) == 0);
907 
908  /* call inclusion method of primal heuristic */
910 
911  return SCIP_OKAY;
912 }
913 
914 /** destructor of primal heuristic to free user data (called when SCIP is exiting) */
915 static
916 SCIP_DECL_HEURFREE(heurFreeMultistart)
917 { /*lint --e{715}*/
918  SCIP_HEURDATA* heurdata;
919 
920  /* free heuristic data */
921  heurdata = SCIPheurGetData(heur);
922 
923  SCIPfreeBlockMemory(scip, &heurdata);
924  SCIPheurSetData(heur, NULL);
925 
926  return SCIP_OKAY;
927 }
928 
929 /** initialization method of primal heuristic (called after problem was transformed) */
930 static
931 SCIP_DECL_HEURINIT(heurInitMultistart)
932 { /*lint --e{715}*/
933  SCIP_HEURDATA* heurdata;
934 
935  assert( heur != NULL );
936 
937  heurdata = SCIPheurGetData(heur);
938  assert(heurdata != NULL);
939 
940  SCIP_CALL( SCIPcreateRandom(scip, &heurdata->randnumgen,
942 
943  /* try to find sub-NLP heuristic */
944  heurdata->heursubnlp = SCIPfindHeur(scip, "subnlp");
945 
946  return SCIP_OKAY;
947 }
948 
949 /** deinitialization method of primal heuristic (called before transformed problem is freed) */
950 static
951 SCIP_DECL_HEUREXIT(heurExitMultistart)
952 { /*lint --e{715}*/
953  SCIP_HEURDATA* heurdata;
954 
955  assert( heur != NULL );
956 
957  heurdata = SCIPheurGetData(heur);
958  assert(heurdata != NULL);
959  assert(heurdata->randnumgen != NULL);
960 
961  SCIPfreeRandom(scip, &heurdata->randnumgen);
962 
963  return SCIP_OKAY;
964 }
965 
966 /** execution method of primal heuristic */
967 static
968 SCIP_DECL_HEUREXEC(heurExecMultistart)
969 { /*lint --e{715}*/
970  SCIP_HEURDATA* heurdata;
971 
972  assert( heur != NULL );
973 
974  heurdata = SCIPheurGetData(heur);
975  assert(heurdata != NULL);
976 
977  *result = SCIP_DIDNOTRUN;
978 
979  /* check cases for which the heuristic is not applicable */
980  if( !SCIPisNLPConstructed(scip) || heurdata->heursubnlp == NULL || SCIPgetNNlpis(scip) <= 0 )
981  return SCIP_OKAY;
982 
983  /* check whether the heuristic should be applied for a problem containing integer variables */
984  if( heurdata->onlynlps && (SCIPgetNBinVars(scip) > 0 || SCIPgetNIntVars(scip) > 0) )
985  return SCIP_OKAY;
986 
987  *result = SCIP_DIDNOTFIND;
988 
989  SCIP_CALL( applyHeur(scip, heur, heurdata, result) );
990 
991  return SCIP_OKAY;
992 }
993 
994 /*
995  * primal heuristic specific interface methods
996  */
997 
998 /** creates the multistart primal heuristic and includes it in SCIP */
1000  SCIP* scip /**< SCIP data structure */
1001  )
1002 {
1003  SCIP_HEURDATA* heurdata;
1004  SCIP_HEUR* heur;
1005 
1006  /* create multistart primal heuristic data */
1007  SCIP_CALL( SCIPallocBlockMemory(scip, &heurdata) );
1008  BMSclearMemory(heurdata);
1009 
1010  /* include primal heuristic */
1011  SCIP_CALL( SCIPincludeHeurBasic(scip, &heur,
1013  HEUR_MAXDEPTH, HEUR_TIMING, HEUR_USESSUBSCIP, heurExecMultistart, heurdata) );
1014 
1015  assert(heur != NULL);
1016 
1017  /* set non fundamental callbacks via setter functions */
1018  SCIP_CALL( SCIPsetHeurCopy(scip, heur, heurCopyMultistart) );
1019  SCIP_CALL( SCIPsetHeurFree(scip, heur, heurFreeMultistart) );
1020  SCIP_CALL( SCIPsetHeurInit(scip, heur, heurInitMultistart) );
1021  SCIP_CALL( SCIPsetHeurExit(scip, heur, heurExitMultistart) );
1022 
1023  /* add multistart primal heuristic parameters */
1024  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/nrndpoints",
1025  "number of random points generated per execution call",
1026  &heurdata->nrndpoints, FALSE, DEFAULT_NRNDPOINTS, 0, INT_MAX, NULL, NULL) );
1027 
1028  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/maxboundsize",
1029  "maximum variable domain size for unbounded variables",
1030  &heurdata->maxboundsize, FALSE, DEFAULT_MAXBOUNDSIZE, 0.0, SCIPinfinity(scip), NULL, NULL) );
1031 
1032  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/maxiter",
1033  "number of iterations to reduce the maximum violation of a point",
1034  &heurdata->maxiter, FALSE, DEFAULT_MAXITER, 0, INT_MAX, NULL, NULL) );
1035 
1036  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/minimprfac",
1037  "minimum required improving factor to proceed in improvement of a single point",
1038  &heurdata->minimprfac, FALSE, DEFAULT_MINIMPRFAC, -SCIPinfinity(scip), SCIPinfinity(scip), NULL, NULL) );
1039 
1040  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/minimpriter",
1041  "number of iteration when checking the minimum improvement",
1042  &heurdata->minimpriter, FALSE, DEFAULT_MINIMPRITER, 1, INT_MAX, NULL, NULL) );
1043 
1044  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/maxreldist",
1045  "maximum distance between two points in the same cluster",
1046  &heurdata->maxreldist, FALSE, DEFAULT_MAXRELDIST, 0.0, SCIPinfinity(scip), NULL, NULL) );
1047 
1048  SCIP_CALL( SCIPaddRealParam(scip, "heuristics/" HEUR_NAME "/gradlimit",
1049  "limit for gradient computations for all improvePoint() calls (0 for no limit)",
1050  &heurdata->gradlimit, FALSE, DEFAULT_GRADLIMIT, 0.0, SCIPinfinity(scip), NULL, NULL) );
1051 
1052  SCIP_CALL( SCIPaddIntParam(scip, "heuristics/" HEUR_NAME "/maxncluster",
1053  "maximum number of considered clusters per heuristic call",
1054  &heurdata->maxncluster, FALSE, DEFAULT_MAXNCLUSTER, 0, INT_MAX, NULL, NULL) );
1055 
1056  SCIP_CALL( SCIPaddBoolParam(scip, "heuristics/" HEUR_NAME "/onlynlps",
1057  "should the heuristic run only on continuous problems?",
1058  &heurdata->onlynlps, FALSE, DEFAULT_ONLYNLPS, NULL, NULL) );
1059 
1060  return SCIP_OKAY;
1061 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:61
void SCIPfreeRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen)
int SCIPgetNIntVars(SCIP *scip)
Definition: scip_prob.c:2090
int SCIPgetNNLPNlRows(SCIP *scip)
Definition: scip_nlp.c:341
SCIP_RETCODE SCIPexpriterInit(SCIP_EXPRITER *iterator, SCIP_EXPR *expr, SCIP_EXPRITER_TYPE type, SCIP_Bool allowrevisit)
Definition: expriter.c:500
#define MINFEAS
SCIP_Bool SCIPisNLPConstructed(SCIP *scip)
Definition: scip_nlp.c:110
#define HEUR_NAME
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for SCIP parameter handling
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
public methods for memory management
int SCIPexprGetNChildren(SCIP_EXPR *expr)
Definition: expr.c:3808
#define HEUR_TIMING
static int getVarIndex(SCIP_HASHMAP *varindex, SCIP_VAR *var)
SCIP_RETCODE SCIPsetHeurExit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEUREXIT((*heurexit)))
Definition: scip_heur.c:210
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17975
public methods for timing
void SCIPsortDownRealPtr(SCIP_Real *realarray, void **ptrarray, int len)
#define DEFAULT_MAXNCLUSTER
SCIP_Real SCIPfeasRound(SCIP *scip, SCIP_Real val)
SCIP_VAR ** SCIPnlrowGetLinearVars(SCIP_NLROW *nlrow)
Definition: nlp.c:1783
static SCIP_DECL_HEURINIT(heurInitMultistart)
SCIP_Bool SCIPisFeasGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
Definition: scip_prob.c:1874
#define DEFAULT_MAXBOUNDSIZE
#define FALSE
Definition: def.h:96
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:3023
SCIP_RETCODE SCIPapplyHeurSubNlp(SCIP *scip, SCIP_HEUR *heur, SCIP_RESULT *result, SCIP_SOL *refpoint, SCIP_SOL *resultsol)
Definition: heur_subnlp.c:1766
SCIP_Real SCIPinfinity(SCIP *scip)
#define TRUE
Definition: def.h:95
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
SCIP_RETCODE SCIPhashmapInsertInt(SCIP_HASHMAP *hashmap, void *origin, int image)
Definition: misc.c:3141
SCIP_Real SCIPnlrowGetRhs(SCIP_NLROW *nlrow)
Definition: nlp.c:1823
static SCIP_DECL_HEUREXEC(heurExecMultistart)
int SCIPnlrowGetNLinearVars(SCIP_NLROW *nlrow)
Definition: nlp.c:1773
#define HEUR_USESSUBSCIP
struct SCIP_HeurData SCIP_HEURDATA
Definition: type_heur.h:76
public methods for problem variables
static SCIP_RETCODE improvePoint(SCIP *scip, SCIP_NLROW **nlrows, int nnlrows, SCIP_HASHMAP *varindex, SCIP_SOL *point, int maxiter, SCIP_Real minimprfac, int minimpriter, SCIP_Real *minfeas, SCIP_Real *nlrowgradcosts, SCIP_Real *gradcosts)
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:108
SCIP_RETCODE SCIPincludeHeurBasic(SCIP *scip, SCIP_HEUR **heur, const char *name, const char *desc, char dispchar, int priority, int freq, int freqofs, int maxdepth, SCIP_HEURTIMING timingmask, SCIP_Bool usessubscip, SCIP_DECL_HEUREXEC((*heurexec)), SCIP_HEURDATA *heurdata)
Definition: scip_heur.c:117
SCIP_RETCODE SCIPgetNlRowSolActivity(SCIP *scip, SCIP_NLROW *nlrow, SCIP_SOL *sol, SCIP_Real *activity)
Definition: scip_nlp.c:1463
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
static SCIP_RETCODE getMinFeas(SCIP *scip, SCIP_NLROW **nlrows, int nnlrows, SCIP_SOL *sol, SCIP_Real *minfeas)
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip_mem.h:136
void SCIPheurSetData(SCIP_HEUR *heur, SCIP_HEURDATA *heurdata)
Definition: heur.c:1371
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip_mem.h:89
static SCIP_DECL_HEURCOPY(heurCopyMultistart)
#define SCIPdebugMsg
Definition: scip_message.h:78
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:83
SCIP_VAR ** x
Definition: circlepacking.c:63
SCIP_RETCODE SCIPevalExprGradient(SCIP *scip, SCIP_EXPR *expr, SCIP_SOL *sol, SCIP_Longint soltag)
Definition: scip_expr.c:1667
public methods for numerical tolerances
public functions to work with algebraic expressions
static SCIP_DECL_HEURFREE(heurFreeMultistart)
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3372
static SCIP_RETCODE solveNLP(SCIP *scip, SCIP_HEUR *heur, SCIP_HEUR *nlpheur, SCIP_SOL **points, int npoints, SCIP_Bool *success)
void SCIPsortIntPtr(int *intarray, void **ptrarray, int len)
int SCIPgetNNlpis(SCIP *scip)
Definition: scip_nlpi.c:199
SCIP_EXPR ** SCIPexprGetChildren(SCIP_EXPR *expr)
Definition: expr.c:3818
public methods for NLPI solver interfaces
#define DEFAULT_RANDSEED
SCIP_RETCODE SCIPcreateSolCopy(SCIP *scip, SCIP_SOL **sol, SCIP_SOL *sourcesol)
Definition: scip_sol.c:618
const char * SCIPheurGetName(SCIP_HEUR *heur)
Definition: heur.c:1450
SCIP_HEUR * SCIPfindHeur(SCIP *scip, const char *name)
Definition: scip_heur.c:258
#define MINIMPRFAC
#define DEFAULT_NRNDPOINTS
SCIP_Real SCIPexprGetDerivative(SCIP_EXPR *expr)
Definition: expr.c:3908
#define DEFAULT_MINIMPRFAC
static SCIP_RETCODE applyHeur(SCIP *scip, SCIP_HEUR *heur, SCIP_HEURDATA *heurdata, SCIP_RESULT *result)
SCIP_RETCODE SCIPsetHeurFree(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURFREE((*heurfree)))
Definition: scip_heur.c:178
#define DEFAULT_MAXITER
SCIP_VAR * SCIPgetVarExprVar(SCIP_EXPR *expr)
Definition: expr_var.c:416
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip_mem.c:57
public functions to work with algebraic expressions
#define HEUR_FREQOFS
#define DEFAULT_ONLYNLPS
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:3057
#define NULL
Definition: lpi_spx1.cpp:164
SCIP_Real SCIPgetSolTransObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip_sol.c:1491
static int getExprSize(SCIP_EXPR *expr)
#define REALABS(x)
Definition: def.h:210
#define SCIP_CALL(x)
Definition: def.h:393
SCIP_NLROW ** SCIPgetNLPNlRows(SCIP *scip)
Definition: scip_nlp.c:319
SCIP_Bool SCIPisFeasLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define GRADCOSTFAC_LINEAR
static SCIP_DECL_HEUREXIT(heurExitMultistart)
#define GRADCOSTFAC_NONLINEAR
public methods for primal heuristic plugins and divesets
SCIP_RETCODE SCIPcreateExpriter(SCIP *scip, SCIP_EXPRITER **iterator)
Definition: scip_expr.c:2311
public methods for NLP management
SCIP_Bool SCIPisHugeValue(SCIP *scip, SCIP_Real val)
static SCIP_RETCODE filterPoints(SCIP *scip, SCIP_SOL **points, SCIP_Real *feasibilities, int npoints, int *nusefulpoints)
SCIP_RETCODE SCIPcreateRandom(SCIP *scip, SCIP_RANDNUMGEN **randnumgen, unsigned int initialseed, SCIP_Bool useglobalseed)
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip_mem.h:124
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip_sol.c:1221
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:93
#define HEUR_MAXDEPTH
SCIP_RETCODE SCIProundSol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool *success)
Definition: scip_sol.c:2455
#define MAX(x, y)
Definition: tclique_def.h:92
#define DEFAULT_MINIMPRITER
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip_sol.c:985
static SCIP_RETCODE sampleRandomPoints(SCIP *scip, SCIP_SOL **rndpoints, int nmaxrndpoints, SCIP_Real maxboundsize, SCIP_RANDNUMGEN *randnumgen, SCIP_Real bestobj, int *nstored)
SCIP_EXPR * SCIPexpriterGetNext(SCIP_EXPRITER *iterator)
Definition: expriter.c:857
int SCIPgetNSols(SCIP *scip)
Definition: scip_sol.c:2214
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
#define BMSclearMemory(ptr)
Definition: memory.h:131
#define HEUR_DISPCHAR
int SCIPgetNBinVars(SCIP *scip)
Definition: scip_prob.c:2045
SCIP_Real SCIPrandomGetReal(SCIP_RANDNUMGEN *randnumgen, SCIP_Real minrandval, SCIP_Real maxrandval)
Definition: misc.c:10034
int SCIPgetNVars(SCIP *scip)
Definition: scip_prob.c:2000
void SCIPfreeExpriter(SCIP_EXPRITER **iterator)
Definition: scip_expr.c:2325
public methods for nonlinear relaxation
#define HEUR_FREQ
SCIP_Real * SCIPnlrowGetLinearCoefs(SCIP_NLROW *nlrow)
Definition: nlp.c:1793
SCIP_Real * r
Definition: circlepacking.c:59
methods for sorting joint arrays of various types
general public methods
static SCIP_Real getRelDistance(SCIP *scip, SCIP_SOL *x, SCIP_SOL *y, SCIP_Real maxboundsize)
SCIP_SOL * SCIPgetBestSol(SCIP *scip)
Definition: scip_sol.c:2313
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPgetNlRowSolFeasibility(SCIP *scip, SCIP_NLROW *nlrow, SCIP_SOL *sol, SCIP_Real *feasibility)
Definition: scip_nlp.c:1497
public methods for solutions
public methods for random numbers
public methods for message output
NLP local search primal heuristic using sub-SCIPs.
SCIP_RETCODE SCIPsetHeurInit(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURINIT((*heurinit)))
Definition: scip_heur.c:194
SCIP_Bool SCIPisExprVar(SCIP *scip, SCIP_EXPR *expr)
Definition: scip_expr.c:1430
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip_prob.c:1955
#define SCIP_Real
Definition: def.h:186
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip_general.c:703
SCIP_VAR ** y
Definition: circlepacking.c:64
#define HEUR_DESC
public methods for message handling
#define DEFAULT_GRADLIMIT
static SCIP_RETCODE computeGradient(SCIP *scip, SCIP_NLROW *nlrow, SCIP_SOL *sol, SCIP_HASHMAP *varindex, SCIP_EXPRITER *exprit, SCIP_Real *grad, SCIP_Real *norm)
static SCIP_RETCODE clusterPointsGreedy(SCIP *scip, SCIP_SOL **points, int npoints, int *clusteridx, int *ncluster, SCIP_Real maxboundsize, SCIP_Real maxreldist, int maxncluster)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:17425
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_RETCODE SCIPincludeHeurMultistart(SCIP *scip)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPsetHeurCopy(SCIP *scip, SCIP_HEUR *heur, SCIP_DECL_HEURCOPY((*heurcopy)))
Definition: scip_heur.c:162
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17985
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:132
public methods for primal heuristics
SCIP_Bool SCIPexpriterIsEnd(SCIP_EXPRITER *iterator)
Definition: expriter.c:968
int SCIPhashmapGetImageInt(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:3230
SCIP_HEURDATA * SCIPheurGetData(SCIP_HEUR *heur)
Definition: heur.c:1361
#define DEFAULT_MAXRELDIST
public methods for global and local (sub)problems
SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip_sol.c:1361
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:139
#define HEUR_PRIORITY
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip_param.c:57
SCIP_EXPR * SCIPnlrowGetExpr(SCIP_NLROW *nlrow)
Definition: nlp.c:1803
multistart heuristic for convex and nonconvex MINLPs
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip_sol.c:328
memory allocation routines