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-2023 Zuse Institute Berlin (ZIB) */
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 scip_message.c
26  * @ingroup OTHER_CFILES
27  * @brief public methods for message handling
28  * @author Tobias Achterberg
29  * @author Timo Berthold
30  * @author Gerald Gamrath
31  * @author Leona Gottwald
32  * @author Stefan Heinz
33  * @author Gregor Hendel
34  * @author Thorsten Koch
35  * @author Alexander Martin
36  * @author Marc Pfetsch
37  * @author Michael Winkler
38  * @author Kati Wolter
39  *
40  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
41  */
42 
43 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
44 
45 #include "scip/debug.h"
46 #include "scip/pub_message.h"
47 #include "scip/scip_message.h"
48 #include "scip/struct_scip.h"
49 #include "scip/struct_set.h"
50 #include "scip/struct_stat.h"
51 
52 /** installs the given message handler, such that all messages are passed to this handler. A messages handler can be
53  * created via SCIPmessagehdlrCreate().
54  *
55  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
56  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
57  *
58  * @pre this method can be called in one of the following stages of the SCIP solving process:
59  * - \ref SCIP_STAGE_INIT
60  * - \ref SCIP_STAGE_PROBLEM
61  *
62  * @note The currently installed messages handler gets freed if this SCIP instance is its last user (w.r.t. capture/release).
63  */
65  SCIP* scip, /**< SCIP data structure */
66  SCIP_MESSAGEHDLR* messagehdlr /**< message handler to install, or NULL to suppress all output */
67  )
68 {
69  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetMessagehdlr", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
70 
71  assert(scip != NULL);
72  assert(scip->set != NULL);
73 
74  SCIPmessagehdlrCapture(messagehdlr);
75 
77  assert(scip->messagehdlr == NULL);
78 
79  scip->messagehdlr = messagehdlr;
80 
81  return SCIP_OKAY;
82 }
83 
84 /** returns the currently installed message handler
85  *
86  * @return the currently installed message handler, or NULL if messages are currently suppressed
87  */
89  SCIP* scip /**< SCIP data structure */
90  )
91 {
92  return scip->messagehdlr;
93 }
94 
95 /** sets the log file name for the currently installed message handler */
97  SCIP* scip, /**< SCIP data structure */
98  const char* filename /**< name of log file, or NULL (no log) */
99  )
100 {
101  if( scip->messagehdlr != NULL )
102  {
103  SCIPmessagehdlrSetLogfile(scip->messagehdlr, filename);
104  }
105 }
106 
107 /** sets the currently installed message handler to be quiet (or not) */
109  SCIP* scip, /**< SCIP data structure */
110  SCIP_Bool quiet /**< should screen messages be suppressed? */
111  )
112 {
113  if( scip->messagehdlr != NULL )
114  {
115  SCIPmessagehdlrSetQuiet(scip->messagehdlr, quiet);
116  }
117 }
118 
119 /** prints a warning message via the message handler */
121  SCIP* scip, /**< SCIP data structure */
122  const char* formatstr, /**< format string like in printf() function */
123  ... /**< format arguments line in printf() function */
124  )
125 {
126  va_list ap;
127 
128  assert(scip != NULL);
129 
130  va_start(ap, formatstr); /*lint !e838*/
131  SCIPmessageVFPrintWarning(scip->messagehdlr, formatstr, ap);
132  va_end(ap);
133 }
134 
135 /** prints a debug message */
137  SCIP* scip, /**< SCIP data structure */
138  const char* sourcefile, /**< name of the source file that called the function */
139  int sourceline, /**< line in the source file where the function was called */
140  const char* formatstr, /**< format string like in printf() function */
141  ... /**< format arguments line in printf() function */
142  )
143 {
144  const char* filename;
145  int subscipdepth = 0;
146  va_list ap;
147 
148  assert( sourcefile != NULL );
149  assert( scip != NULL );
150 
151  /* strip directory from filename */
152 #if defined(_WIN32) || defined(_WIN64)
153  filename = strrchr(sourcefile, '\\');
154 #else
155  filename = strrchr(sourcefile, '/');
156 #endif
157  if ( filename == NULL )
158  filename = sourcefile;
159  else
160  ++filename;
161 
162  if ( scip->stat != NULL )
163  subscipdepth = scip->stat->subscipdepth;
164  if ( subscipdepth > 0 )
165  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "%d: [%s:%d] debug: ", subscipdepth, filename, sourceline);
166  else
167  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "[%s:%d] debug: ", filename, sourceline);
168 
169  va_start(ap, formatstr); /*lint !e838*/
170  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
171  va_end(ap);
172 }
173 
174 /** prints a debug message without precode */
176  SCIP* scip, /**< SCIP data structure */
177  const char* formatstr, /**< format string like in printf() function */
178  ... /**< format arguments line in printf() function */
179  )
180 {
181  va_list ap;
182 
183  assert( scip != NULL );
184 
185  va_start(ap, formatstr); /*lint !e838*/
186  SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
187  va_end(ap);
188 }
189 
190 /** prints a dialog message that requests user interaction or is a direct response to a user interactive command */
192  SCIP* scip, /**< SCIP data structure */
193  FILE* file, /**< file stream to print into, or NULL for stdout */
194  const char* formatstr, /**< format string like in printf() function */
195  ... /**< format arguments line in printf() function */
196  )
197 {
198  va_list ap;
199 
200  assert(scip != NULL);
201 
202  va_start(ap, formatstr); /*lint !e838*/
203  SCIPmessageVFPrintDialog(scip->messagehdlr, file, formatstr, ap);
204  va_end(ap);
205 }
206 
207 /** prints a message */
209  SCIP* scip, /**< SCIP data structure */
210  FILE* file, /**< file stream to print into, or NULL for stdout */
211  const char* formatstr, /**< format string like in printf() function */
212  ... /**< format arguments line in printf() function */
213  )
214 {
215  va_list ap;
216 
217  assert(scip != NULL);
218 
219  va_start(ap, formatstr); /*lint !e838*/
220  SCIPmessageVFPrintInfo(scip->messagehdlr, file, formatstr, ap);
221  va_end(ap);
222 }
223 
224 /** prints a message depending on the verbosity level */
226  SCIP* scip, /**< SCIP data structure */
227  SCIP_VERBLEVEL msgverblevel, /**< verbosity level of this message */
228  FILE* file, /**< file stream to print into, or NULL for stdout */
229  const char* formatstr, /**< format string like in printf() function */
230  ... /**< format arguments line in printf() function */
231  )
232 {
233  va_list ap;
234 
235  assert(scip != NULL);
236  assert(scip->set != NULL);
237 
238  va_start(ap, formatstr); /*lint !e838*/
239  SCIPmessageVFPrintVerbInfo(scip->messagehdlr, scip->set->disp_verblevel, msgverblevel, file, formatstr, ap);
240  va_end(ap);
241 }
242 
243 /** returns the current message verbosity level
244  *
245  * @return message verbosity level of SCIP
246  *
247  * @see \ref SCIP_VerbLevel "SCIP_VERBLEVEL" for a list of all verbosity levels
248  */
250  SCIP* scip /**< SCIP data structure */
251  )
252 {
253  assert(scip != NULL);
254  assert(scip->set != NULL);
255 
256  return scip->set->disp_verblevel;
257 }
SCIP_STAT * stat
Definition: struct_scip.h:79
void SCIPmessageVFPrintVerbInfo(SCIP_MESSAGEHDLR *messagehdlr, SCIP_VERBLEVEL verblevel, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:723
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:191
SCIP_RETCODE SCIPsetMessagehdlr(SCIP *scip, SCIP_MESSAGEHDLR *messagehdlr)
Definition: scip_message.c:64
void SCIPmessagehdlrCapture(SCIP_MESSAGEHDLR *messagehdlr)
Definition: message.c:339
#define FALSE
Definition: def.h:96
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
Definition: scip_message.c:249
#define TRUE
Definition: def.h:95
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
enum SCIP_VerbLevel SCIP_VERBLEVEL
Definition: type_message.h:57
void SCIPdebugMessagePrint(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:175
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
Definition: scip_message.c:88
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:120
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:208
void SCIPmessagehdlrSetLogfile(SCIP_MESSAGEHDLR *messagehdlr, const char *filename)
Definition: message.c:393
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:2208
void SCIPprintDebugMessage(SCIP *scip, const char *sourcefile, int sourceline, const char *formatstr,...)
Definition: scip_message.c:136
#define NULL
Definition: lpi_spx1.cpp:164
SCIP_RETCODE SCIPmessagehdlrRelease(SCIP_MESSAGEHDLR **messagehdlr)
Definition: message.c:348
#define SCIP_CALL(x)
Definition: def.h:394
SCIP main data structure.
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:225
#define SCIP_Bool
Definition: def.h:93
void SCIPmessagehdlrSetQuiet(SCIP_MESSAGEHDLR *messagehdlr, SCIP_Bool quiet)
Definition: message.c:411
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
Definition: scip_message.c:108
methods for debugging
datastructures for problem statistics
void SCIPmessageVFPrintDialog(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:549
void SCIPmessageVFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr, va_list ap)
Definition: message.c:633
SCIP_VERBLEVEL disp_verblevel
Definition: struct_set.h:289
void SCIPsetMessagehdlrLogfile(SCIP *scip, const char *filename)
Definition: scip_message.c:96
SCIP_SET * set
Definition: struct_scip.h:72
public methods for message output
void SCIPmessageFPrintInfo(SCIP_MESSAGEHDLR *messagehdlr, FILE *file, const char *formatstr,...)
Definition: message.c:618
SCIP_MESSAGEHDLR * messagehdlr
Definition: struct_scip.h:75
void SCIPmessageVFPrintWarning(SCIP_MESSAGEHDLR *messagehdlr, const char *formatstr, va_list ap)
Definition: message.c:465
public methods for message handling
datastructures for global SCIP settings
int subscipdepth
Definition: struct_stat.h:217