Scippy

SCIP

Solving Constraint Integer Programs

scip_message.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_message.c
17  * @brief public methods for message handling
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Gerald Gamrath
21  * @author Robert Lion Gottwald
22  * @author Stefan Heinz
23  * @author Gregor Hendel
24  * @author Thorsten Koch
25  * @author Alexander Martin
26  * @author Marc Pfetsch
27  * @author Michael Winkler
28  * @author Kati Wolter
29  *
30  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include "nlpi/nlpi.h"
36 #include "scip/debug.h"
37 #include "scip/pub_message.h"
38 #include "scip/scip_message.h"
39 #include "scip/struct_scip.h"
40 #include "scip/struct_set.h"
41 #include "scip/struct_stat.h"
42 
43 /** installs the given message handler, such that all messages are passed to this handler. A messages handler can be
44  * created via SCIPmessagehdlrCreate().
45  *
46  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
47  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
48  *
49  * @pre this method can be called in one of the following stages of the SCIP solving process:
50  * - \ref SCIP_STAGE_INIT
51  * - \ref SCIP_STAGE_PROBLEM
52  *
53  * @note The currently installed messages handler gets freed if this SCIP instance is its last user (w.r.t. capture/release).
54  */
56  SCIP* scip, /**< SCIP data structure */
57  SCIP_MESSAGEHDLR* messagehdlr /**< message handler to install, or NULL to suppress all output */
58  )
59 {
60  int i;
61 
62  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetMessagehdlr", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
63 
64  assert(scip != NULL);
65  assert(scip->set != NULL);
66  assert(scip->set->nlpis != NULL || scip->set->nnlpis == 0);
67 
68  /* update message handler in NLP solver interfaces */
69  for( i = 0; i < scip->set->nnlpis; ++i )
70  {
71  assert(scip->set->nlpis[i] != NULL);
72 
73  SCIP_CALL( SCIPnlpiSetMessageHdlr(scip->set->nlpis[i], messagehdlr) );
74  }
75 
76  SCIPmessagehdlrCapture(messagehdlr);
77 
79  assert(scip->messagehdlr == NULL);
80 
81  scip->messagehdlr = messagehdlr;
82 
83  return SCIP_OKAY;
84 }
85 
86 /** returns the currently installed message handler
87  *
88  * @return the currently installed message handler, or NULL if messages are currently suppressed
89  */
91  SCIP* scip /**< SCIP data structure */
92  )
93 {
94  return scip->messagehdlr;
95 }
96 
97 /** sets the log file name for the currently installed message handler */
99  SCIP* scip, /**< SCIP data structure */
100  const char* filename /**< name of log file, or NULL (no log) */
101  )
102 {
103  if( scip->messagehdlr != NULL )
104  {
105  SCIPmessagehdlrSetLogfile(scip->messagehdlr, filename);
106  }
107 }
108 
109 /** sets the currently installed message handler to be quiet (or not) */
111  SCIP* scip, /**< SCIP data structure */
112  SCIP_Bool quiet /**< should screen messages be suppressed? */
113  )
114 {
115  if( scip->messagehdlr != NULL )
116  {
117  SCIPmessagehdlrSetQuiet(scip->messagehdlr, quiet);
118  }
119 }
120 
121 /** prints a warning message via the message handler */
123  SCIP* scip, /**< SCIP data structure */
124  const char* formatstr, /**< format string like in printf() function */
125  ... /**< format arguments line in printf() function */
126  )
127 {
128  va_list ap;
129 
130  assert(scip != NULL);
131 
132  va_start(ap, formatstr); /*lint !e838*/
133  SCIPmessageVFPrintWarning(scip->messagehdlr, formatstr, ap);
134  va_end(ap);
135 }
136 
137 /** prints a debug message */
139  SCIP* scip, /**< SCIP data structure */
140  const char* sourcefile, /**< name of the source file that called the function */
141  int sourceline, /**< line in the source file where the function was called */
142  const char* formatstr, /**< format string like in printf() function */
143  ... /**< format arguments line in printf() function */
144  )
145 {
146  int subscipdepth = 0;
147  va_list ap;
148 
149  assert( sourcefile != NULL );
150  assert( scip != NULL );
151 
152  if ( scip->stat != NULL )
153  subscipdepth = scip->stat->subscipdepth;
154  if ( subscipdepth > 0 )
155  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "%d: [%s:%d] debug: ", subscipdepth, sourcefile, sourceline);
156  else
157  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "[%s:%d] debug: ", sourcefile, sourceline);
158 
159  va_start(ap, formatstr); /*lint !e838*/
160  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
161  va_end(ap);
162 }
163 
164 /** prints a debug message without precode */
166  SCIP* scip, /**< SCIP data structure */
167  const char* formatstr, /**< format string like in printf() function */
168  ... /**< format arguments line in printf() function */
169  )
170 {
171  va_list ap;
172 
173  assert( scip != NULL );
174 
175  va_start(ap, formatstr); /*lint !e838*/
176  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
177  va_end(ap);
178 }
179 
180 /** prints a dialog message that requests user interaction or is a direct response to a user interactive command */
182  SCIP* scip, /**< SCIP data structure */
183  FILE* file, /**< file stream to print into, or NULL for stdout */
184  const char* formatstr, /**< format string like in printf() function */
185  ... /**< format arguments line in printf() function */
186  )
187 {
188  va_list ap;
189 
190  assert(scip != NULL);
191 
192  va_start(ap, formatstr); /*lint !e838*/
193  SCIPmessageVFPrintDialog(scip->messagehdlr, file, formatstr, ap);
194  va_end(ap);
195 }
196 
197 /** prints a message */
199  SCIP* scip, /**< SCIP data structure */
200  FILE* file, /**< file stream to print into, or NULL for stdout */
201  const char* formatstr, /**< format string like in printf() function */
202  ... /**< format arguments line in printf() function */
203  )
204 {
205  va_list ap;
206 
207  assert(scip != NULL);
208 
209  va_start(ap, formatstr); /*lint !e838*/
210  SCIPmessageVFPrintInfo(scip->messagehdlr, file, formatstr, ap);
211  va_end(ap);
212 }
213 
214 /** prints a message depending on the verbosity level */
216  SCIP* scip, /**< SCIP data structure */
217  SCIP_VERBLEVEL msgverblevel, /**< verbosity level of this message */
218  FILE* file, /**< file stream to print into, or NULL for stdout */
219  const char* formatstr, /**< format string like in printf() function */
220  ... /**< format arguments line in printf() function */
221  )
222 {
223  va_list ap;
224 
225  assert(scip != NULL);
226  assert(scip->set != NULL);
227 
228  va_start(ap, formatstr); /*lint !e838*/
229  SCIPmessageVFPrintVerbInfo(scip->messagehdlr, scip->set->disp_verblevel, msgverblevel, file, formatstr, ap);
230  va_end(ap);
231 }
232 
233 /** returns the current message verbosity level
234  *
235  * @return message verbosity level of SCIP
236  *
237  * @see \ref SCIP_VerbLevel "SCIP_VERBLEVEL" for a list of all verbosity levels
238  */
240  SCIP* scip /**< SCIP data structure */
241  )
242 {
243  assert(scip != NULL);
244  assert(scip->set != NULL);
245 
246  return scip->set->disp_verblevel;
247 }
SCIP_STAT * stat
Definition: struct_scip.h:69
void SCIPmessageVFPrintVerbInfo(SCIP_MESSAGEHDLR *messagehdlr, SCIP_VERBLEVEL verblevel, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:713
#define NULL
Definition: def.h:253
SCIP_RETCODE SCIPsetMessagehdlr(SCIP *scip, SCIP_MESSAGEHDLR *messagehdlr)
Definition: scip_message.c:55
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
Definition: scip_message.c:110
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:181
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:122
internal methods for NLPI solver interfaces
void SCIPmessagehdlrCapture(SCIP_MESSAGEHDLR *messagehdlr)
Definition: message.c:329
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:215
#define FALSE
Definition: def.h:73
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
enum SCIP_VerbLevel SCIP_VERBLEVEL
Definition: type_message.h:48
void SCIPsetMessagehdlrLogfile(SCIP *scip, const char *filename)
Definition: scip_message.c:98
SCIP_NLPI ** nlpis
Definition: struct_set.h:89
SCIP_RETCODE SCIPnlpiSetMessageHdlr(SCIP_NLPI *nlpi, SCIP_MESSAGEHDLR *messagehdlr)
Definition: nlpi.c:720
void SCIPmessagehdlrSetLogfile(SCIP_MESSAGEHDLR *messagehdlr, const char *filename)
Definition: message.c:383
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2010
SCIP_RETCODE SCIPmessagehdlrRelease(SCIP_MESSAGEHDLR **messagehdlr)
Definition: message.c:338
#define SCIP_CALL(x)
Definition: def.h:365
SCIP main data structure.
void SCIPprintDebugMessage(SCIP *scip, const char *sourcefile, int sourceline, const char *formatstr,...)
Definition: scip_message.c:138
#define SCIP_Bool
Definition: def.h:70
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
Definition: scip_message.c:239
void SCIPmessagehdlrSetQuiet(SCIP_MESSAGEHDLR *messagehdlr, SCIP_Bool quiet)
Definition: message.c:401
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
Definition: scip_message.c:90
methods for debugging
void SCIPdebugMessagePrint(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:165
datastructures for problem statistics
void SCIPmessageVFPrintDialog(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:539
void SCIPmessageVFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:623
SCIP_VERBLEVEL disp_verblevel
Definition: struct_set.h:261
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
Definition: message.c:608
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:65
void SCIPmessageVFPrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr, va_list ap)
Definition: message.c:455
public methods for message handling
int nnlpis
Definition: struct_set.h:130
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:198
datastructures for global SCIP settings
int subscipdepth
Definition: struct_stat.h:200