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-2022 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 scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_message.c
17  * @ingroup OTHER_CFILES
18  * @brief public methods for message handling
19  * @author Tobias Achterberg
20  * @author Timo Berthold
21  * @author Gerald Gamrath
22  * @author Leona Gottwald
23  * @author Stefan Heinz
24  * @author Gregor Hendel
25  * @author Thorsten Koch
26  * @author Alexander Martin
27  * @author Marc Pfetsch
28  * @author Michael Winkler
29  * @author Kati Wolter
30  *
31  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
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  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetMessagehdlr", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
61 
62  assert(scip != NULL);
63  assert(scip->set != NULL);
64 
65  SCIPmessagehdlrCapture(messagehdlr);
66 
68  assert(scip->messagehdlr == NULL);
69 
70  scip->messagehdlr = messagehdlr;
71 
72  return SCIP_OKAY;
73 }
74 
75 /** returns the currently installed message handler
76  *
77  * @return the currently installed message handler, or NULL if messages are currently suppressed
78  */
80  SCIP* scip /**< SCIP data structure */
81  )
82 {
83  return scip->messagehdlr;
84 }
85 
86 /** sets the log file name for the currently installed message handler */
88  SCIP* scip, /**< SCIP data structure */
89  const char* filename /**< name of log file, or NULL (no log) */
90  )
91 {
92  if( scip->messagehdlr != NULL )
93  {
94  SCIPmessagehdlrSetLogfile(scip->messagehdlr, filename);
95  }
96 }
97 
98 /** sets the currently installed message handler to be quiet (or not) */
100  SCIP* scip, /**< SCIP data structure */
101  SCIP_Bool quiet /**< should screen messages be suppressed? */
102  )
103 {
104  if( scip->messagehdlr != NULL )
105  {
106  SCIPmessagehdlrSetQuiet(scip->messagehdlr, quiet);
107  }
108 }
109 
110 /** prints a warning message via the message handler */
112  SCIP* scip, /**< SCIP data structure */
113  const char* formatstr, /**< format string like in printf() function */
114  ... /**< format arguments line in printf() function */
115  )
116 {
117  va_list ap;
118 
119  assert(scip != NULL);
120 
121  va_start(ap, formatstr); /*lint !e838*/
122  SCIPmessageVFPrintWarning(scip->messagehdlr, formatstr, ap);
123  va_end(ap);
124 }
125 
126 /** prints a debug message */
128  SCIP* scip, /**< SCIP data structure */
129  const char* sourcefile, /**< name of the source file that called the function */
130  int sourceline, /**< line in the source file where the function was called */
131  const char* formatstr, /**< format string like in printf() function */
132  ... /**< format arguments line in printf() function */
133  )
134 {
135  const char* filename;
136  int subscipdepth = 0;
137  va_list ap;
138 
139  assert( sourcefile != NULL );
140  assert( scip != NULL );
141 
142  /* strip directory from filename */
143 #if defined(_WIN32) || defined(_WIN64)
144  filename = strrchr(sourcefile, '\\');
145 #else
146  filename = strrchr(sourcefile, '/');
147 #endif
148  if ( filename == NULL )
149  filename = sourcefile;
150  else
151  ++filename;
152 
153  if ( scip->stat != NULL )
154  subscipdepth = scip->stat->subscipdepth;
155  if ( subscipdepth > 0 )
156  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "%d: [%s:%d] debug: ", subscipdepth, filename, sourceline);
157  else
158  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "[%s:%d] debug: ", filename, sourceline);
159 
160  va_start(ap, formatstr); /*lint !e838*/
161  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
162  va_end(ap);
163 }
164 
165 /** prints a debug message without precode */
167  SCIP* scip, /**< SCIP data structure */
168  const char* formatstr, /**< format string like in printf() function */
169  ... /**< format arguments line in printf() function */
170  )
171 {
172  va_list ap;
173 
174  assert( scip != NULL );
175 
176  va_start(ap, formatstr); /*lint !e838*/
177  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
178  va_end(ap);
179 }
180 
181 /** prints a dialog message that requests user interaction or is a direct response to a user interactive command */
183  SCIP* scip, /**< SCIP data structure */
184  FILE* file, /**< file stream to print into, or NULL for stdout */
185  const char* formatstr, /**< format string like in printf() function */
186  ... /**< format arguments line in printf() function */
187  )
188 {
189  va_list ap;
190 
191  assert(scip != NULL);
192 
193  va_start(ap, formatstr); /*lint !e838*/
194  SCIPmessageVFPrintDialog(scip->messagehdlr, file, formatstr, ap);
195  va_end(ap);
196 }
197 
198 /** prints a message */
200  SCIP* scip, /**< SCIP data structure */
201  FILE* file, /**< file stream to print into, or NULL for stdout */
202  const char* formatstr, /**< format string like in printf() function */
203  ... /**< format arguments line in printf() function */
204  )
205 {
206  va_list ap;
207 
208  assert(scip != NULL);
209 
210  va_start(ap, formatstr); /*lint !e838*/
211  SCIPmessageVFPrintInfo(scip->messagehdlr, file, formatstr, ap);
212  va_end(ap);
213 }
214 
215 /** prints a message depending on the verbosity level */
217  SCIP* scip, /**< SCIP data structure */
218  SCIP_VERBLEVEL msgverblevel, /**< verbosity level of this message */
219  FILE* file, /**< file stream to print into, or NULL for stdout */
220  const char* formatstr, /**< format string like in printf() function */
221  ... /**< format arguments line in printf() function */
222  )
223 {
224  va_list ap;
225 
226  assert(scip != NULL);
227  assert(scip->set != NULL);
228 
229  va_start(ap, formatstr); /*lint !e838*/
230  SCIPmessageVFPrintVerbInfo(scip->messagehdlr, scip->set->disp_verblevel, msgverblevel, file, formatstr, ap);
231  va_end(ap);
232 }
233 
234 /** returns the current message verbosity level
235  *
236  * @return message verbosity level of SCIP
237  *
238  * @see \ref SCIP_VerbLevel "SCIP_VERBLEVEL" for a list of all verbosity levels
239  */
241  SCIP* scip /**< SCIP data structure */
242  )
243 {
244  assert(scip != NULL);
245  assert(scip->set != NULL);
246 
247  return scip->set->disp_verblevel;
248 }
SCIP_STAT * stat
Definition: struct_scip.h:70
void SCIPmessageVFPrintVerbInfo(SCIP_MESSAGEHDLR *messagehdlr, SCIP_VERBLEVEL verblevel, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:714
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:182
SCIP_RETCODE SCIPsetMessagehdlr(SCIP *scip, SCIP_MESSAGEHDLR *messagehdlr)
Definition: scip_message.c:55
void SCIPmessagehdlrCapture(SCIP_MESSAGEHDLR *messagehdlr)
Definition: message.c:330
#define FALSE
Definition: def.h:87
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
Definition: scip_message.c:240
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
enum SCIP_VerbLevel SCIP_VERBLEVEL
Definition: type_message.h:48
void SCIPdebugMessagePrint(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:166
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
Definition: scip_message.c:79
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:111
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:199
void SCIPmessagehdlrSetLogfile(SCIP_MESSAGEHDLR *messagehdlr, const char *filename)
Definition: message.c:384
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:2177
void SCIPprintDebugMessage(SCIP *scip, const char *sourcefile, int sourceline, const char *formatstr,...)
Definition: scip_message.c:127
#define NULL
Definition: lpi_spx1.cpp:155
SCIP_RETCODE SCIPmessagehdlrRelease(SCIP_MESSAGEHDLR **messagehdlr)
Definition: message.c:339
#define SCIP_CALL(x)
Definition: def.h:384
SCIP main data structure.
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:216
#define SCIP_Bool
Definition: def.h:84
void SCIPmessagehdlrSetQuiet(SCIP_MESSAGEHDLR *messagehdlr, SCIP_Bool quiet)
Definition: message.c:402
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
Definition: scip_message.c:99
methods for debugging
datastructures for problem statistics
void SCIPmessageVFPrintDialog(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:540
void SCIPmessageVFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:624
SCIP_VERBLEVEL disp_verblevel
Definition: struct_set.h:280
void SCIPsetMessagehdlrLogfile(SCIP *scip, const char *filename)
Definition: scip_message.c:87
SCIP_SET * set
Definition: struct_scip.h:63
public methods for message output
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
Definition: message.c:609
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:66
void SCIPmessageVFPrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr, va_list ap)
Definition: message.c:456
public methods for message handling
datastructures for global SCIP settings
int subscipdepth
Definition: struct_stat.h:208