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-2020 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 "nlpi/nlpi.h"
37 #include "scip/debug.h"
38 #include "scip/pub_message.h"
39 #include "scip/scip_message.h"
40 #include "scip/struct_scip.h"
41 #include "scip/struct_set.h"
42 #include "scip/struct_stat.h"
43 
44 /** installs the given message handler, such that all messages are passed to this handler. A messages handler can be
45  * created via SCIPmessagehdlrCreate().
46  *
47  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
48  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
49  *
50  * @pre this method can be called in one of the following stages of the SCIP solving process:
51  * - \ref SCIP_STAGE_INIT
52  * - \ref SCIP_STAGE_PROBLEM
53  *
54  * @note The currently installed messages handler gets freed if this SCIP instance is its last user (w.r.t. capture/release).
55  */
57  SCIP* scip, /**< SCIP data structure */
58  SCIP_MESSAGEHDLR* messagehdlr /**< message handler to install, or NULL to suppress all output */
59  )
60 {
61  int i;
62 
63  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetMessagehdlr", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
64 
65  assert(scip != NULL);
66  assert(scip->set != NULL);
67  assert(scip->set->nlpis != NULL || scip->set->nnlpis == 0);
68 
69  /* update message handler in NLP solver interfaces */
70  for( i = 0; i < scip->set->nnlpis; ++i )
71  {
72  assert(scip->set->nlpis[i] != NULL);
73 
74  SCIP_CALL( SCIPnlpiSetMessageHdlr(scip->set->nlpis[i], messagehdlr) );
75  }
76 
77  SCIPmessagehdlrCapture(messagehdlr);
78 
80  assert(scip->messagehdlr == NULL);
81 
82  scip->messagehdlr = messagehdlr;
83 
84  return SCIP_OKAY;
85 }
86 
87 /** returns the currently installed message handler
88  *
89  * @return the currently installed message handler, or NULL if messages are currently suppressed
90  */
92  SCIP* scip /**< SCIP data structure */
93  )
94 {
95  return scip->messagehdlr;
96 }
97 
98 /** sets the log file name for the currently installed message handler */
100  SCIP* scip, /**< SCIP data structure */
101  const char* filename /**< name of log file, or NULL (no log) */
102  )
103 {
104  if( scip->messagehdlr != NULL )
105  {
106  SCIPmessagehdlrSetLogfile(scip->messagehdlr, filename);
107  }
108 }
109 
110 /** sets the currently installed message handler to be quiet (or not) */
112  SCIP* scip, /**< SCIP data structure */
113  SCIP_Bool quiet /**< should screen messages be suppressed? */
114  )
115 {
116  if( scip->messagehdlr != NULL )
117  {
118  SCIPmessagehdlrSetQuiet(scip->messagehdlr, quiet);
119  }
120 }
121 
122 /** prints a warning message via the message handler */
124  SCIP* scip, /**< SCIP data structure */
125  const char* formatstr, /**< format string like in printf() function */
126  ... /**< format arguments line in printf() function */
127  )
128 {
129  va_list ap;
130 
131  assert(scip != NULL);
132 
133  va_start(ap, formatstr); /*lint !e838*/
134  SCIPmessageVFPrintWarning(scip->messagehdlr, formatstr, ap);
135  va_end(ap);
136 }
137 
138 /** prints a debug message */
140  SCIP* scip, /**< SCIP data structure */
141  const char* sourcefile, /**< name of the source file that called the function */
142  int sourceline, /**< line in the source file where the function was called */
143  const char* formatstr, /**< format string like in printf() function */
144  ... /**< format arguments line in printf() function */
145  )
146 {
147  int subscipdepth = 0;
148  va_list ap;
149 
150  assert( sourcefile != NULL );
151  assert( scip != NULL );
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, sourcefile, sourceline);
157  else
158  SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "[%s:%d] debug: ", sourcefile, 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
SCIP_RETCODE SCIPsetMessagehdlr(SCIP *scip, SCIP_MESSAGEHDLR *messagehdlr)
Definition: scip_message.c:56
void SCIPsetMessagehdlrQuiet(SCIP *scip, SCIP_Bool quiet)
Definition: scip_message.c:111
void SCIPdialogMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:182
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:123
internal methods for NLPI solver interfaces
void SCIPmessagehdlrCapture(SCIP_MESSAGEHDLR *messagehdlr)
Definition: message.c:330
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip_message.c:216
#define FALSE
Definition: def.h:73
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
enum SCIP_VerbLevel SCIP_VERBLEVEL
Definition: type_message.h:48
void SCIPsetMessagehdlrLogfile(SCIP *scip, const char *filename)
Definition: scip_message.c:99
SCIP_NLPI ** nlpis
Definition: struct_set.h:89
SCIP_RETCODE SCIPnlpiSetMessageHdlr(SCIP_NLPI *nlpi, SCIP_MESSAGEHDLR *messagehdlr)
Definition: nlpi.c:722
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:2025
#define NULL
Definition: lpi_spx1.cpp:155
SCIP_RETCODE SCIPmessagehdlrRelease(SCIP_MESSAGEHDLR **messagehdlr)
Definition: message.c:339
#define SCIP_CALL(x)
Definition: def.h:364
SCIP main data structure.
void SCIPprintDebugMessage(SCIP *scip, const char *sourcefile, int sourceline, const char *formatstr,...)
Definition: scip_message.c:139
#define SCIP_Bool
Definition: def.h:70
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
Definition: scip_message.c:240
void SCIPmessagehdlrSetQuiet(SCIP_MESSAGEHDLR *messagehdlr, SCIP_Bool quiet)
Definition: message.c:402
SCIP_MESSAGEHDLR * SCIPgetMessagehdlr(SCIP *scip)
Definition: scip_message.c:91
methods for debugging
void SCIPdebugMessagePrint(SCIP *scip, const char *formatstr,...)
Definition: scip_message.c:166
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:265
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
int nnlpis
Definition: struct_set.h:130
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip_message.c:199
datastructures for global SCIP settings
int subscipdepth
Definition: struct_stat.h:205