Scippy

SCIP

Solving Constraint Integer Programs

nlhdlr.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 nlhdlr.c
26  * @ingroup OTHER_CFILES
27  * @brief functions for nonlinearity handlers of nonlinear constraint handler
28  * @author Ksenia Bestuzheva
29  * @author Benjamin Mueller
30  * @author Felipe Serrano
31  * @author Stefan Vigerske
32  */
33 
34 #include <assert.h>
35 
36 #include "scip/pub_nlhdlr.h"
37 #include "scip/nlhdlr.h"
38 #include "scip/struct_nlhdlr.h"
39 #include "scip/scip_timing.h"
40 #include "scip/scip_mem.h"
41 #include "scip/scip_param.h"
42 #include "scip/scip_message.h"
43 #include "scip/pub_misc.h"
44 
45 /**@addtogroup PublicNlhdlrInterfaceMethods
46  * @{
47  */
48 
49 #ifdef NDEBUG
50 /* Undo the defines from pub_nlhdlr.h, which exist if NDEBUG is defined. */
51 #undef SCIPnlhdlrSetCopyHdlr
52 #undef SCIPnlhdlrSetFreeHdlrData
53 #undef SCIPnlhdlrSetFreeExprData
54 #undef SCIPnlhdlrSetInitExit
55 #undef SCIPnlhdlrSetProp
56 #undef SCIPnlhdlrSetSepa
57 #undef SCIPnlhdlrGetName
58 #undef SCIPnlhdlrGetDesc
59 #undef SCIPnlhdlrGetDetectPriority
60 #undef SCIPnlhdlrGetEnfoPriority
61 #undef SCIPnlhdlrIsEnabled
62 #undef SCIPnlhdlrGetData
63 #undef SCIPnlhdlrHasIntEval
64 #undef SCIPnlhdlrHasReverseProp
65 #undef SCIPnlhdlrHasInitSepa
66 #undef SCIPnlhdlrHasExitSepa
67 #undef SCIPnlhdlrHasEnfo
68 #undef SCIPnlhdlrHasEstimate
69 #endif
70 
71 /** sets the copy handler callback of a nonlinear handler */
73  SCIP_NLHDLR* nlhdlr, /**< nonlinear handler */
74  SCIP_DECL_NLHDLRCOPYHDLR((*copy)) /**< copy callback (can be NULL) */
75  )
76 {
77  assert(nlhdlr != NULL);
78 
79  nlhdlr->copyhdlr = copy;
80 }
81 
82 /** sets the nonlinear handler callback to free the nonlinear handler data */
84  SCIP_NLHDLR* nlhdlr, /**< nonlinear handler */
85  SCIP_DECL_NLHDLRFREEHDLRDATA((*freehdlrdata)) /**< handler free callback (can be NULL) */
86  )
87 {
88  assert(nlhdlr != NULL);
89 
90  nlhdlr->freehdlrdata = freehdlrdata;
91 }
92 
93 /** sets the nonlinear handler callback to free expression specific data of nonlinear handler */
95  SCIP_NLHDLR* nlhdlr, /**< nonlinear handler */
96  SCIP_DECL_NLHDLRFREEEXPRDATA((*freeexprdata)) /**< nonlinear handler expression data free callback
97  (can be NULL if data does not need to be freed) */
98  )
99 {
100  assert(nlhdlr != NULL);
101 
102  nlhdlr->freeexprdata = freeexprdata;
103 }
104 
105 /** sets the initialization and deinitialization callback of a nonlinear handler */
107  SCIP_NLHDLR* nlhdlr, /**< nonlinear handler */
108  SCIP_DECL_NLHDLRINIT((*init)), /**< initialization callback (can be NULL) */
109  SCIP_DECL_NLHDLREXIT((*exit_)) /**< deinitialization callback (can be NULL) */
110  )
111 {
112  assert(nlhdlr != NULL);
113 
114  nlhdlr->init = init;
115  nlhdlr->exit = exit_;
116 }
117 
118 /** sets the propagation callbacks of a nonlinear handler */
120  SCIP_NLHDLR* nlhdlr, /**< nonlinear handler */
121  SCIP_DECL_NLHDLRINTEVAL((*inteval)), /**< interval evaluation callback (can be NULL) */
122  SCIP_DECL_NLHDLRREVERSEPROP((*reverseprop)) /**< reverse propagation callback (can be NULL) */
123  )
124 {
125  assert(nlhdlr != NULL);
126 
127  nlhdlr->inteval = inteval;
128  nlhdlr->reverseprop = reverseprop;
129 }
130 
131 /** sets the enforcement callbacks of a nonlinear handler */
133  SCIP_NLHDLR* nlhdlr, /**< nonlinear handler */
134  SCIP_DECL_NLHDLRINITSEPA((*initsepa)), /**< separation initialization callback (can be NULL) */
135  SCIP_DECL_NLHDLRENFO((*enfo)), /**< enforcement callback (can be NULL if estimate is not NULL) */
136  SCIP_DECL_NLHDLRESTIMATE((*estimate)), /**< estimation callback (can be NULL if sepa is not NULL) */
137  SCIP_DECL_NLHDLREXITSEPA((*exitsepa)) /**< separation deinitialization callback (can be NULL) */
138  )
139 {
140  assert(nlhdlr != NULL);
141  assert(enfo != NULL || estimate != NULL);
142 
143  nlhdlr->initsepa = initsepa;
144  nlhdlr->enfo = enfo;
145  nlhdlr->estimate = estimate;
146  nlhdlr->exitsepa = exitsepa;
147 }
148 
149 /** gives name of nonlinear handler */
150 const char* SCIPnlhdlrGetName(
151  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
152  )
153 {
154  assert(nlhdlr != NULL);
155 
156  return nlhdlr->name;
157 }
158 
159 /** gives description of nonlinear handler, can be NULL */
160 const char* SCIPnlhdlrGetDesc(
161  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
162  )
163 {
164  assert(nlhdlr != NULL);
165 
166  return nlhdlr->desc;
167 }
168 
169 /** gives detection priority of nonlinear handler */
171  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
172  )
173 {
174  assert(nlhdlr != NULL);
175 
176  return nlhdlr->detectpriority;
177 }
178 
179 /** gives enforcement priority of nonlinear handler */
181  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
182  )
183 {
184  assert(nlhdlr != NULL);
185 
186  return nlhdlr->enfopriority;
187 }
188 
189 /** returns whether nonlinear handler is enabled */
191  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
192  )
193 {
194  assert(nlhdlr != NULL);
195 
196  return nlhdlr->enabled;
197 }
198 
199 /** gives handler data of nonlinear handler */
201  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
202  )
203 {
204  assert(nlhdlr != NULL);
205 
206  return nlhdlr->data;
207 }
208 
209 /** returns whether nonlinear handler implements the interval evaluation callback */
211  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
212  )
213 {
214  return nlhdlr->inteval != NULL;
215 }
216 
217 /** returns whether nonlinear handler implements the reverse propagation callback */
219  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
220  )
221 {
222  return nlhdlr->reverseprop != NULL;
223 }
224 
225 /** returns whether nonlinear handler implements the separation initialization callback */
227  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
228  )
229 {
230  return nlhdlr->initsepa != NULL;
231 }
232 
233 /** returns whether nonlinear handler implements the separation deinitialization callback */
235  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
236  )
237 {
238  return nlhdlr->exitsepa != NULL;
239 }
240 
241 /** returns whether nonlinear handler implements the enforcement callback */
243  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
244  )
245 {
246  return nlhdlr->enfo != NULL;
247 }
248 
249 /** returns whether nonlinear handler implements the estimator callback */
251  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
252  )
253 {
254  return nlhdlr->estimate != NULL;
255 }
256 
257 /** compares two nonlinear handlers by detection priority
258  *
259  * if handlers have same detection priority, then compare by name
260  */
261 SCIP_DECL_SORTPTRCOMP(SCIPnlhdlrComp)
262 {
263  SCIP_NLHDLR* h1;
264  SCIP_NLHDLR* h2;
265 
266  assert(elem1 != NULL);
267  assert(elem2 != NULL);
268 
269  h1 = (SCIP_NLHDLR*)elem1;
270  h2 = (SCIP_NLHDLR*)elem2;
271 
272  if( h1->detectpriority != h2->detectpriority )
273  return h1->detectpriority - h2->detectpriority;
274 
275  return strcmp(h1->name, h2->name);
276 }
277 
278 #ifdef SCIP_DISABLED_CODE
279 /** compares nonlinear handler by enforcement priority
280  *
281  * if handlers have same enforcement priority, then compare by detection priority, then by name
282  */
283 SCIP_DECL_SORTPTRCOMP(SCIPnlhdlrCompEnfo)
284 {
285  SCIP_NLHDLR* h1;
286  SCIP_NLHDLR* h2;
287 
288  assert(elem1 != NULL);
289  assert(elem2 != NULL);
290 
291  h1 = (SCIP_NLHDLR*)elem1;
292  h2 = (SCIP_NLHDLR*)elem2;
293 
294  if( h1->enfopriority != h2->enfopriority )
295  return h1->enfopriority - h2->enfopriority;
296 
297  if( h1->detectpriority != h2->detectpriority )
298  return h1->detectpriority - h2->detectpriority;
299 
300  return strcmp(h1->name, h2->name);
301 }
302 #endif
303 
304 /** @} */
305 
306 /* nlhdlr private API functions from nlhdlr.h */
307 
308 #ifndef NDEBUG
309 #undef SCIPnlhdlrResetNDetectionslast
310 #undef SCIPnlhdlrIncrementNCutoffs
311 #undef SCIPnlhdlrIncrementNSeparated
312 #endif
313 
314 /** creates a nonlinear handler */
316  SCIP* scip, /**< SCIP data structure */
317  SCIP_NLHDLR** nlhdlr, /**< buffer to store pointer to created nonlinear handler */
318  const char* name, /**< name of nonlinear handler (must not be NULL) */
319  const char* desc, /**< description of nonlinear handler (can be NULL) */
320  int detectpriority, /**< detection priority of nonlinear handler */
321  int enfopriority, /**< enforcement priority of nonlinear handler */
322  SCIP_DECL_NLHDLRDETECT((*detect)), /**< structure detection callback of nonlinear handler */
323  SCIP_DECL_NLHDLREVALAUX((*evalaux)), /**< auxiliary evaluation callback of nonlinear handler */
324  SCIP_NLHDLRDATA* nlhdlrdata /**< data of nonlinear handler (can be NULL) */
325  )
326 {
328 
329  assert(scip != NULL);
330  assert(nlhdlr != NULL);
331  assert(name != NULL);
332  assert(detect != NULL);
333  assert(evalaux != NULL);
334 
335  SCIP_CALL( SCIPallocClearBlockMemory(scip, nlhdlr) );
336 
337  SCIP_CALL( SCIPduplicateMemoryArray(scip, &(*nlhdlr)->name, name, strlen(name)+1) );
338  if( desc != NULL )
339  {
340  SCIP_CALL_FINALLY( SCIPduplicateMemoryArray(scip, &(*nlhdlr)->desc, desc, strlen(desc)+1),
341  SCIPfreeMemoryArray(scip, &(*nlhdlr)->name) );
342  }
343 
344  (*nlhdlr)->detectpriority = detectpriority;
345  (*nlhdlr)->enfopriority = enfopriority;
346  (*nlhdlr)->data = nlhdlrdata;
347  (*nlhdlr)->detect = detect;
348  (*nlhdlr)->evalaux = evalaux;
349 
350  SCIP_CALL( SCIPcreateClock(scip, &(*nlhdlr)->detecttime) );
351  SCIP_CALL( SCIPcreateClock(scip, &(*nlhdlr)->enfotime) );
352  SCIP_CALL( SCIPcreateClock(scip, &(*nlhdlr)->proptime) );
353  SCIP_CALL( SCIPcreateClock(scip, &(*nlhdlr)->intevaltime) );
354 
355  (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "nlhdlr/%s/enabled", name);
356  SCIP_CALL( SCIPaddBoolParam(scip, paramname, "should this nonlinear handler be used",
357  &(*nlhdlr)->enabled, FALSE, TRUE, NULL, NULL) );
358 
359  return SCIP_OKAY;
360 }
361 
362 /** frees a nonlinear handler */
364  SCIP* scip, /**< SCIP data structure */
365  SCIP_NLHDLR** nlhdlr /**< pointer to nonlinear handler to be freed */
366  )
367 {
368  assert(nlhdlr != NULL);
369  assert(*nlhdlr != NULL);
370 
371  if( (*nlhdlr)->freehdlrdata != NULL )
372  {
373  SCIP_CALL( (*nlhdlr)->freehdlrdata(scip, *nlhdlr, &(*nlhdlr)->data) );
374  }
375 
376  /* free clocks */
377  SCIP_CALL( SCIPfreeClock(scip, &(*nlhdlr)->detecttime) );
378  SCIP_CALL( SCIPfreeClock(scip, &(*nlhdlr)->enfotime) );
379  SCIP_CALL( SCIPfreeClock(scip, &(*nlhdlr)->proptime) );
380  SCIP_CALL( SCIPfreeClock(scip, &(*nlhdlr)->intevaltime) );
381 
382  SCIPfreeMemory(scip, &(*nlhdlr)->name);
383  SCIPfreeMemoryNull(scip, &(*nlhdlr)->desc);
384 
385  SCIPfreeBlockMemory(scip, nlhdlr);
386 
387  return SCIP_OKAY;
388 }
389 
390 /** call the handler copy callback of a nonlinear handler */
391 SCIP_DECL_NLHDLRCOPYHDLR(SCIPnlhdlrCopyhdlr)
392 {
393  /* TODO for now just don't copy disabled nlhdlr, a clean way would probably be to first copy and disable then */
394  if( sourcenlhdlr->copyhdlr != NULL && sourcenlhdlr->enabled )
395  {
396  SCIP_CALL( sourcenlhdlr->copyhdlr(targetscip, targetconshdlr, sourceconshdlr, sourcenlhdlr) );
397  }
398 
399  return SCIP_OKAY;
400 }
401 
402 /** call the free expression specific data callback of a nonlinear handler */
403 SCIP_DECL_NLHDLRFREEEXPRDATA(SCIPnlhdlrFreeexprdata)
404 {
405  assert(nlhdlr != NULL);
406  assert(nlhdlrexprdata != NULL);
407  assert(*nlhdlrexprdata != NULL);
408 
409  if( nlhdlr->freeexprdata != NULL )
410  {
411  SCIP_CALL( nlhdlr->freeexprdata(scip, nlhdlr, expr, nlhdlrexprdata) );
412  assert(*nlhdlrexprdata == NULL);
413  }
414 
415  return SCIP_OKAY;
416 }
417 
418 /** call the initialization callback of a nonlinear handler */
419 SCIP_DECL_NLHDLRINIT(SCIPnlhdlrInit)
420 {
421  assert(nlhdlr != NULL);
422 
423  nlhdlr->nenfocalls = 0;
424  nlhdlr->nintevalcalls = 0;
425  nlhdlr->npropcalls = 0;
426  nlhdlr->nseparated = 0;
427  nlhdlr->ncutoffs = 0;
428  nlhdlr->ndomreds = 0;
429  nlhdlr->nbranchscores = 0;
430  nlhdlr->ndetections = 0;
431  nlhdlr->ndetectionslast = 0;
432 
433  SCIP_CALL( SCIPresetClock(scip, nlhdlr->detecttime) );
434  SCIP_CALL( SCIPresetClock(scip, nlhdlr->enfotime) );
435  SCIP_CALL( SCIPresetClock(scip, nlhdlr->proptime) );
436  SCIP_CALL( SCIPresetClock(scip, nlhdlr->intevaltime) );
437 
438  if( nlhdlr->init != NULL )
439  {
440  SCIP_CALL( nlhdlr->init(scip, nlhdlr) );
441  }
442 
443  return SCIP_OKAY;
444 }
445 
446 /** call the deinitialization callback of a nonlinear handler */
447 SCIP_DECL_NLHDLREXIT(SCIPnlhdlrExit)
448 {
449  assert(nlhdlr != NULL);
450 
451  if( nlhdlr->exit != NULL )
452  {
453  SCIP_CALL( nlhdlr->exit(scip, nlhdlr) );
454  }
455 
456  return SCIP_OKAY;
457 }
458 
459 /** call the detect callback of a nonlinear handler */
460 SCIP_DECL_NLHDLRDETECT(SCIPnlhdlrDetect)
461 {
462  assert(scip != NULL);
463  assert(nlhdlr != NULL);
464  assert(nlhdlr->detect != NULL);
465  assert(nlhdlr->detecttime != NULL);
466  assert(participating != NULL);
467 
468  SCIP_CALL( SCIPstartClock(scip, nlhdlr->detecttime) );
469  SCIP_CALL( nlhdlr->detect(scip, conshdlr, nlhdlr, expr, cons, enforcing, participating, nlhdlrexprdata) );
470  SCIP_CALL( SCIPstopClock(scip, nlhdlr->detecttime) );
471 
472  if( *participating != SCIP_NLHDLR_METHOD_NONE )
473  {
474  ++nlhdlr->ndetections;
475  ++nlhdlr->ndetectionslast;
476  }
477 
478  return SCIP_OKAY;
479 }
480 
481 /** call the auxiliary evaluation callback of a nonlinear handler */
482 SCIP_DECL_NLHDLREVALAUX(SCIPnlhdlrEvalaux)
483 {
484  assert(nlhdlr != NULL);
485  assert(nlhdlr->evalaux != NULL);
486 
487  SCIP_CALL( nlhdlr->evalaux(scip, nlhdlr, expr, nlhdlrexprdata, auxvalue, sol) );
488 
489  return SCIP_OKAY;
490 }
491 
492 /** call the interval evaluation callback of a nonlinear handler */
493 SCIP_DECL_NLHDLRINTEVAL(SCIPnlhdlrInteval)
494 {
495  assert(scip != NULL);
496  assert(nlhdlr != NULL);
497  assert(nlhdlr->intevaltime != NULL);
498 
499  if( nlhdlr->inteval != NULL )
500  {
501  SCIP_CALL( SCIPstartClock(scip, nlhdlr->intevaltime) );
502  SCIP_CALL( nlhdlr->inteval(scip, nlhdlr, expr, nlhdlrexprdata, interval, intevalvar, intevalvardata) );
503  SCIP_CALL( SCIPstopClock(scip, nlhdlr->intevaltime) );
504 
505  ++nlhdlr->nintevalcalls;
506  }
507 
508  return SCIP_OKAY;
509 }
510 
511 /** call the reverse propagation callback of a nonlinear handler */
512 SCIP_DECL_NLHDLRREVERSEPROP(SCIPnlhdlrReverseprop)
513 {
514  assert(scip != NULL);
515  assert(nlhdlr != NULL);
516  assert(nlhdlr->proptime != NULL);
517  assert(infeasible != NULL);
518  assert(nreductions != NULL);
519 
520  if( nlhdlr->reverseprop == NULL )
521  {
522  *infeasible = FALSE;
523  *nreductions = 0;
524 
525  return SCIP_OKAY;
526  }
527 
528  SCIP_CALL( SCIPstartClock(scip, nlhdlr->proptime) );
529  SCIP_CALL( nlhdlr->reverseprop(scip, conshdlr, nlhdlr, expr, nlhdlrexprdata, bounds, infeasible, nreductions) );
530  SCIP_CALL( SCIPstopClock(scip, nlhdlr->proptime) );
531 
532  /* update statistics */
533  nlhdlr->ndomreds += *nreductions;
534  if( *infeasible )
535  ++nlhdlr->ncutoffs;
536  ++nlhdlr->npropcalls;
537 
538  return SCIP_OKAY;
539 }
540 
541 /** call the separation initialization callback of a nonlinear handler */
542 SCIP_DECL_NLHDLRINITSEPA(SCIPnlhdlrInitsepa)
543 {
544  assert(scip != NULL);
545  assert(nlhdlr != NULL);
546  assert(nlhdlr->enfotime != NULL);
547  assert(infeasible != NULL);
548 
549  if( nlhdlr->initsepa == NULL )
550  {
551  *infeasible = FALSE;
552  return SCIP_OKAY;
553  }
554 
555  SCIP_CALL( SCIPstartClock(scip, nlhdlr->enfotime) );
556  SCIP_CALL( nlhdlr->initsepa(scip, conshdlr, cons, nlhdlr, expr, nlhdlrexprdata, overestimate, underestimate, infeasible) );
557  SCIP_CALL( SCIPstopClock(scip, nlhdlr->enfotime) );
558 
559  ++nlhdlr->nenfocalls;
560  if( *infeasible )
561  ++nlhdlr->ncutoffs;
562 
563  return SCIP_OKAY;
564 }
565 
566 /** call the separation deinitialization callback of a nonlinear handler */
567 SCIP_DECL_NLHDLREXITSEPA(SCIPnlhdlrExitsepa)
568 {
569  assert(scip != NULL);
570  assert(nlhdlr != NULL);
571  assert(nlhdlr->enfotime != NULL);
572 
573  if( nlhdlr->exitsepa != NULL )
574  {
575  SCIP_CALL( SCIPstartClock(scip, nlhdlr->enfotime) );
576  SCIP_CALL( nlhdlr->exitsepa(scip, nlhdlr, expr, nlhdlrexprdata) );
577  SCIP_CALL( SCIPstopClock(scip, nlhdlr->enfotime) );
578  }
579 
580  return SCIP_OKAY;
581 }
582 
583 /** call the enforcement callback of a nonlinear handler */
584 SCIP_DECL_NLHDLRENFO(SCIPnlhdlrEnfo)
585 {
586  assert(scip != NULL);
587  assert(nlhdlr != NULL);
588  assert(nlhdlr->enfotime != NULL);
589  assert(result != NULL);
590 
591  if( nlhdlr->enfo == NULL )
592  {
593  *result = SCIP_DIDNOTRUN;
594  return SCIP_OKAY;
595  }
596 
597 #ifndef NDEBUG
598  /* check that auxvalue is correct by reevaluating */
599  {
600  SCIP_Real auxvaluetest;
601  SCIP_CALL( SCIPnlhdlrEvalaux(scip, nlhdlr, expr, nlhdlrexprdata, &auxvaluetest, sol) );
602  /* we should get EXACTLY the same value from calling evalaux with the same solution as before */
603  assert(auxvalue == auxvaluetest); /*lint !e777*/
604  }
605 #endif
606 
607  SCIP_CALL( SCIPstartClock(scip, nlhdlr->enfotime) );
608  SCIP_CALL( nlhdlr->enfo(scip, conshdlr, cons, nlhdlr, expr, nlhdlrexprdata, sol, auxvalue,
609  overestimate, allowweakcuts, separated, addbranchscores, result) );
610  SCIP_CALL( SCIPstopClock(scip, nlhdlr->enfotime) );
611 
612  /* update statistics */
613  ++nlhdlr->nenfocalls;
614  switch( *result )
615  {
616  case SCIP_SEPARATED :
617  ++nlhdlr->nseparated;
618  break;
619  case SCIP_BRANCHED:
620  ++nlhdlr->nbranchscores;
621  break;
622  case SCIP_CUTOFF:
623  ++nlhdlr->ncutoffs;
624  break;
625  case SCIP_REDUCEDDOM:
626  ++nlhdlr->ndomreds;
627  break;
628  default: ;
629  } /*lint !e788*/
630 
631  return SCIP_OKAY;
632 }
633 
634 /** call the estimator callback of a nonlinear handler */
635 SCIP_DECL_NLHDLRESTIMATE(SCIPnlhdlrEstimate)
636 {
637  assert(scip != NULL);
638  assert(nlhdlr != NULL);
639  assert(nlhdlr->enfotime != NULL);
640  assert(success != NULL);
641  assert(addedbranchscores != NULL);
642 
643  if( nlhdlr->estimate == NULL )
644  {
645  *success = FALSE;
646  *addedbranchscores = FALSE;
647  return SCIP_OKAY;
648  }
649 
650 #ifndef NDEBUG
651  /* check that auxvalue is correct by reevaluating */
652  {
653  SCIP_Real auxvaluetest;
654  SCIP_CALL( SCIPnlhdlrEvalaux(scip, nlhdlr, expr, nlhdlrexprdata, &auxvaluetest, sol) );
655  /* we should get EXACTLY the same value from calling evalaux with the same solution as before */
656  assert(auxvalue == auxvaluetest); /*lint !e777*/
657  }
658 #endif
659 
660  SCIP_CALL( SCIPstartClock(scip, nlhdlr->enfotime) );
661  SCIP_CALL( nlhdlr->estimate(scip, conshdlr, nlhdlr, expr, nlhdlrexprdata, sol, auxvalue, overestimate, targetvalue, addbranchscores, rowpreps, success, addedbranchscores) );
662  SCIP_CALL( SCIPstopClock(scip, nlhdlr->enfotime) );
663 
664  /* update statistics */
665  ++nlhdlr->nenfocalls;
666 
667  return SCIP_OKAY;
668 }
669 
670 /** reset number of detections counter for last round */
672  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
673  )
674 {
675  assert(nlhdlr != NULL);
676  nlhdlr->ndetectionslast = 0;
677 }
678 
679 /** increments number of cutoffs in statistics */
681  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
682  )
683 {
684  assert(nlhdlr != NULL);
685  ++nlhdlr->ncutoffs;
686 }
687 
688 /** increments number of separations in statistics */
690  SCIP_NLHDLR* nlhdlr /**< nonlinear handler */
691  )
692 {
693  assert(nlhdlr != NULL);
694  ++nlhdlr->nseparated;
695 }
696 
697 /** print statistics for nonlinear handlers */
699  SCIP* scip, /**< SCIP data structure */
700  SCIP_NLHDLR** nlhdlrs, /**< nonlinear handlers */
701  int nnlhdlrs, /**< number of nonlinear handlers */
702  FILE* file /**< file handle, or NULL for standard out */
703  )
704 {
705  int i;
706 
707  SCIPinfoMessage(scip, file, "Nlhdlrs : %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s\n",
708  "Detects", "DetectAll", "DetectTime",
709  "#IntEval", "IntEvalTi",
710  "#RevProp", "RevPropTi", "DomReds", "Cutoffs",
711  "#Enforce", "EnfoTime", "Cuts", "Branching");
712 
713  for( i = 0; i < nnlhdlrs; ++i )
714  {
715  /* skip disabled nlhdlr */
716  if( !nlhdlrs[i]->enabled )
717  continue;
718 
719  SCIPinfoMessage(scip, file, " %-17s:", nlhdlrs[i]->name);
720  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->ndetectionslast);
721  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->ndetections);
722  SCIPinfoMessage(scip, file, " %10.2f", SCIPgetClockTime(scip, nlhdlrs[i]->detecttime));
723 
724  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->nintevalcalls);
725  SCIPinfoMessage(scip, file, " %10.2f", SCIPgetClockTime(scip, nlhdlrs[i]->intevaltime));
726 
727  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->npropcalls);
728  SCIPinfoMessage(scip, file, " %10.2f", SCIPgetClockTime(scip, nlhdlrs[i]->proptime));
729  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->ndomreds);
730  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->ncutoffs);
731 
732  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->nenfocalls);
733  SCIPinfoMessage(scip, file, " %10.2f", SCIPgetClockTime(scip, nlhdlrs[i]->enfotime));
734  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->nseparated);
735  SCIPinfoMessage(scip, file, " %10lld", nlhdlrs[i]->nbranchscores);
736 
737  SCIPinfoMessage(scip, file, "\n");
738  }
739 }
SCIP_Bool SCIPnlhdlrIsEnabled(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:190
SCIP_Longint nbranchscores
Definition: struct_nlhdlr.h:77
public methods for SCIP parameter handling
SCIP_Longint ndetectionslast
Definition: struct_nlhdlr.h:76
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
public methods for memory management
#define SCIP_NLHDLR_METHOD_NONE
Definition: type_nlhdlr.h:50
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
SCIP_DECL_NLHDLRCOPYHDLR(SCIPnlhdlrCopyhdlr)
Definition: nlhdlr.c:391
void SCIPnlhdlrResetNDetectionslast(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:671
#define SCIP_MAXSTRLEN
Definition: def.h:302
void SCIPnlhdlrSetFreeExprData(SCIP_NLHDLR *nlhdlr, SCIP_DECL_NLHDLRFREEEXPRDATA((*freeexprdata)))
Definition: nlhdlr.c:94
#define SCIP_DECL_NLHDLRFREEHDLRDATA(x)
Definition: type_nlhdlr.h:82
int SCIPnlhdlrGetDetectPriority(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:170
SCIP_DECL_NLHDLRINITSEPA(SCIPnlhdlrInitsepa)
Definition: nlhdlr.c:542
SCIP_DECL_NLHDLRINTEVAL(SCIPnlhdlrInteval)
Definition: nlhdlr.c:493
SCIP_Bool SCIPnlhdlrHasReverseProp(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:218
#define SCIP_CALL_FINALLY(x, y)
Definition: def.h:435
public methods for timing
SCIP_RETCODE SCIPstopClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:178
#define FALSE
Definition: def.h:96
void SCIPnlhdlrSetFreeHdlrData(SCIP_NLHDLR *nlhdlr, SCIP_DECL_NLHDLRFREEHDLRDATA((*freehdlrdata)))
Definition: nlhdlr.c:83
SCIP_Longint ndomreds
Definition: struct_nlhdlr.h:74
SCIP_Longint nseparated
Definition: struct_nlhdlr.h:72
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10764
#define TRUE
Definition: def.h:95
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
SCIP_Longint nintevalcalls
Definition: struct_nlhdlr.h:70
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip_mem.h:108
void SCIPnlhdlrPrintStatistics(SCIP *scip, SCIP_NLHDLR **nlhdlrs, int nnlhdlrs, FILE *file)
Definition: nlhdlr.c:698
SCIP_RETCODE SCIPfreeClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip_timing.c:127
SCIP_Bool SCIPnlhdlrHasExitSepa(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:234
SCIP_Longint npropcalls
Definition: struct_nlhdlr.h:71
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:208
SCIP_Longint ndetections
Definition: struct_nlhdlr.h:75
void SCIPnlhdlrIncrementNSeparated(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:689
SCIP_DECL_NLHDLREXITSEPA(SCIPnlhdlrExitsepa)
Definition: nlhdlr.c:567
SCIP_DECL_NLHDLRENFO(SCIPnlhdlrEnfo)
Definition: nlhdlr.c:584
SCIP_CLOCK * detecttime
Definition: struct_nlhdlr.h:79
SCIP_RETCODE SCIPcreateClock(SCIP *scip, SCIP_CLOCK **clck)
Definition: scip_timing.c:76
SCIP_RETCODE SCIPnlhdlrCreate(SCIP *scip, SCIP_NLHDLR **nlhdlr, const char *name, const char *desc, int detectpriority, int enfopriority, SCIP_DECL_NLHDLRDETECT((*detect)), SCIP_DECL_NLHDLREVALAUX((*evalaux)), SCIP_NLHDLRDATA *nlhdlrdata)
Definition: nlhdlr.c:315
const char * SCIPnlhdlrGetName(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:150
SCIP_Bool SCIPnlhdlrHasIntEval(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:210
#define NULL
Definition: lpi_spx1.cpp:164
void SCIPnlhdlrIncrementNCutoffs(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:680
SCIP_CLOCK * enfotime
Definition: struct_nlhdlr.h:80
#define SCIP_CALL(x)
Definition: def.h:393
SCIP_DECL_NLHDLREVALAUX(SCIPnlhdlrEvalaux)
Definition: nlhdlr.c:482
#define SCIPfreeMemoryNull(scip, ptr)
Definition: scip_mem.h:79
SCIP_Longint nenfocalls
Definition: struct_nlhdlr.h:69
SCIP_Bool enabled
Definition: struct_nlhdlr.h:51
const char * SCIPnlhdlrGetDesc(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:160
SCIP_NLHDLRDATA * data
Definition: struct_nlhdlr.h:47
void SCIPnlhdlrSetSepa(SCIP_NLHDLR *nlhdlr, SCIP_DECL_NLHDLRINITSEPA((*initsepa)), SCIP_DECL_NLHDLRENFO((*enfo)), SCIP_DECL_NLHDLRESTIMATE((*estimate)), SCIP_DECL_NLHDLREXITSEPA((*exitsepa)))
Definition: nlhdlr.c:132
SCIP_DECL_NLHDLRDETECT(SCIPnlhdlrDetect)
Definition: nlhdlr.c:460
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:93
SCIP_DECL_NLHDLRFREEEXPRDATA(SCIPnlhdlrFreeexprdata)
Definition: nlhdlr.c:403
static const char * paramname[]
Definition: lpi_msk.c:5040
SCIP_RETCODE SCIPnlhdlrFree(SCIP *scip, SCIP_NLHDLR **nlhdlr)
Definition: nlhdlr.c:363
SCIP_Real SCIPgetClockTime(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:319
void SCIPnlhdlrSetProp(SCIP_NLHDLR *nlhdlr, SCIP_DECL_NLHDLRINTEVAL((*inteval)), SCIP_DECL_NLHDLRREVERSEPROP((*reverseprop)))
Definition: nlhdlr.c:119
SCIP_DECL_SORTPTRCOMP(SCIPnlhdlrComp)
Definition: nlhdlr.c:261
SCIP_DECL_NLHDLRINIT(SCIPnlhdlrInit)
Definition: nlhdlr.c:419
int SCIPnlhdlrGetEnfoPriority(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:180
#define SCIPfreeMemory(scip, ptr)
Definition: scip_mem.h:78
SCIP_Bool SCIPnlhdlrHasEnfo(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:242
SCIP_RETCODE SCIPresetClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:144
SCIP_DECL_NLHDLRREVERSEPROP(SCIPnlhdlrReverseprop)
Definition: nlhdlr.c:512
SCIP_DECL_NLHDLRESTIMATE(SCIPnlhdlrEstimate)
Definition: nlhdlr.c:635
void SCIPnlhdlrSetInitExit(SCIP_NLHDLR *nlhdlr, SCIP_DECL_NLHDLRINIT((*init)), SCIP_DECL_NLHDLREXIT((*exit_)))
Definition: nlhdlr.c:106
structure definitions related to nonlinear handlers of nonlinear constraints
#define SCIP_Real
Definition: def.h:186
public methods for message handling
SCIP_Bool SCIPnlhdlrHasEstimate(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:250
SCIP_Bool SCIPnlhdlrHasInitSepa(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:226
SCIP_NLHDLRDATA * SCIPnlhdlrGetData(SCIP_NLHDLR *nlhdlr)
Definition: nlhdlr.c:200
SCIP_CLOCK * intevaltime
Definition: struct_nlhdlr.h:82
struct SCIP_NlhdlrData SCIP_NLHDLRDATA
Definition: type_nlhdlr.h:412
int detectpriority
Definition: struct_nlhdlr.h:49
SCIP_CLOCK * proptime
Definition: struct_nlhdlr.h:81
private functions of nonlinear handlers of nonlinear constraints
#define SCIPallocClearBlockMemory(scip, ptr)
Definition: scip_mem.h:91
public functions of nonlinear handlers of nonlinear constraints
SCIP_DECL_NLHDLREXIT(SCIPnlhdlrExit)
Definition: nlhdlr.c:447
SCIP_Longint ncutoffs
Definition: struct_nlhdlr.h:73
SCIP_RETCODE SCIPstartClock(SCIP *scip, SCIP_CLOCK *clck)
Definition: scip_timing.c:161
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
void SCIPnlhdlrSetCopyHdlr(SCIP_NLHDLR *nlhdlr, SCIP_DECL_NLHDLRCOPYHDLR((*copy)))
Definition: nlhdlr.c:72