Scippy

SCIP

Solving Constraint Integer Programs

table.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 table.c
17  * @ingroup OTHER_CFILES
18  * @brief methods and datastructures for displaying statistics tables
19  * @author Tristan Gally
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include <stdio.h>
25 #include <assert.h>
26 #include <string.h>
27 
28 #include "scip/def.h"
29 #include "blockmemshell/memory.h"
30 #include "scip/set.h"
31 #include "scip/stat.h"
32 #include "scip/scip.h"
33 #include "scip/table.h"
34 #include "scip/pub_message.h"
35 #include "scip/pub_misc.h"
36 #include "scip/syncstore.h"
37 #include "scip/struct_table.h"
38 
39 
40 
41 /*
42  * statistics table methods
43  */
44 
45 /** copies the given statistics table to a new scip */
47  SCIP_TABLE* table, /**< statistics table */
48  SCIP_SET* set /**< SCIP_SET of SCIP to copy to */
49  )
50 {
51  assert(table != NULL);
52  assert(set != NULL);
53  assert(set->scip != NULL);
54 
55  if( table->tablecopy != NULL )
56  {
57  SCIPsetDebugMsg(set, "including statistics table %s in subscip %p\n", SCIPtableGetName(table), (void*)set->scip);
58  SCIP_CALL( table->tablecopy(set->scip, table) );
59  }
60  return SCIP_OKAY;
61 }
62 
63 /** internal method for creating a statistics table */
64 static
66  SCIP_TABLE** table, /**< pointer to store statistics table */
67  SCIP_SET* set, /**< global SCIP settings */
68  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
69  BMS_BLKMEM* blkmem, /**< block memory for parameter settings */
70  const char* name, /**< name of statistics table */
71  const char* desc, /**< description of statistics table */
72  SCIP_Bool active, /**< should the table be activated by default? */
73  SCIP_DECL_TABLECOPY ((*tablecopy)), /**< copy method of statistics table or NULL if you don't want to copy your plugin into sub-SCIPs */
74  SCIP_DECL_TABLEFREE ((*tablefree)), /**< destructor of statistics table */
75  SCIP_DECL_TABLEINIT ((*tableinit)), /**< initialize statistics table */
76  SCIP_DECL_TABLEEXIT ((*tableexit)), /**< deinitialize statistics table */
77  SCIP_DECL_TABLEINITSOL ((*tableinitsol)), /**< solving process initialization method of statistics table */
78  SCIP_DECL_TABLEEXITSOL ((*tableexitsol)), /**< solving process deinitialization method of statistics table */
79  SCIP_DECL_TABLEOUTPUT ((*tableoutput)), /**< output method */
80  SCIP_TABLEDATA* tabledata, /**< display statistics table */
81  int position, /**< position of statistics table */
82  SCIP_STAGE earlieststage /**< output of the statistics table is only printed from this stage onwards */
83  )
84 {
86  char paramdesc[SCIP_MAXSTRLEN];
87 
88  assert(table != NULL);
89  assert(name != NULL);
90  assert(desc != NULL);
91  assert(tableoutput != NULL);
92 
93  SCIP_ALLOC( BMSallocMemory(table) );
94  BMSclearMemory(*table);
95 
96  SCIP_ALLOC( BMSduplicateMemoryArray(&(*table)->name, name, strlen(name)+1) );
97  SCIP_ALLOC( BMSduplicateMemoryArray(&(*table)->desc, desc, strlen(desc)+1) );
98  (*table)->tablecopy = tablecopy;
99  (*table)->tablefree = tablefree;
100  (*table)->tableinit = tableinit;
101  (*table)->tableexit = tableexit;
102  (*table)->tableinitsol = tableinitsol;
103  (*table)->tableexitsol = tableexitsol;
104  (*table)->tableoutput = tableoutput;
105  (*table)->tabledata = tabledata;
106  (*table)->position = position;
107  (*table)->earlieststage = earlieststage;
108  (*table)->initialized = FALSE;
109  (*table)->active = active;
110 
111  /* add parameters */
112  (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "table/%s/active", name);
113  (void) SCIPsnprintf(paramdesc, SCIP_MAXSTRLEN, "is statistics table <%s> active", name);
114  SCIP_CALL( SCIPsetAddBoolParam(set, messagehdlr, blkmem, paramname, paramdesc,
115  &(*table)->active, FALSE, active, NULL, NULL) );
116 
117  return SCIP_OKAY;
118 }
119 
120 /** creates a statistics table */
122  SCIP_TABLE** table, /**< pointer to store statistics table */
123  SCIP_SET* set, /**< global SCIP settings */
124  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
125  BMS_BLKMEM* blkmem, /**< block memory for parameter settings */
126  const char* name, /**< name of statistics table */
127  const char* desc, /**< description of statistics table */
128  SCIP_Bool active, /**< should the table be activated by default? */
129  SCIP_DECL_TABLECOPY ((*tablecopy)), /**< copy method of statistics table or NULL if you don't want to copy your plugin into sub-SCIPs */
130  SCIP_DECL_TABLEFREE ((*tablefree)), /**< destructor of statistics table */
131  SCIP_DECL_TABLEINIT ((*tableinit)), /**< initialize statistics table */
132  SCIP_DECL_TABLEEXIT ((*tableexit)), /**< deinitialize statistics table */
133  SCIP_DECL_TABLEINITSOL ((*tableinitsol)), /**< solving process initialization method of statistics table */
134  SCIP_DECL_TABLEEXITSOL ((*tableexitsol)), /**< solving process deinitialization method of statistics table */
135  SCIP_DECL_TABLEOUTPUT ((*tableoutput)), /**< output method */
136  SCIP_TABLEDATA* tabledata, /**< display statistics table */
137  int position, /**< position of statistics table */
138  SCIP_STAGE earlieststage /**< output of the statistics table is only printed from this stage onwards */
139  )
140 {
141  assert(table != NULL);
142  assert(name != NULL);
143  assert(desc != NULL);
144  assert(tableoutput != NULL);
145 
146  SCIP_CALL_FINALLY( doTableCreate(table, set, messagehdlr, blkmem, name, desc, active, tablecopy, tablefree,
147  tableinit, tableexit, tableinitsol, tableexitsol, tableoutput, tabledata, position, earlieststage),
148  (void) SCIPtableFree(table, set) );
149 
150  return SCIP_OKAY;
151 }
152 
153 /** frees memory of statistics table */
155  SCIP_TABLE** table, /**< pointer to statistics table data structure */
156  SCIP_SET* set /**< global SCIP settings */
157  )
158 {
159  assert(table != NULL);
160  if( *table == NULL )
161  return SCIP_OKAY;
162  assert(!(*table)->initialized);
163  assert(set != NULL);
164 
165  /* call destructor of statistics table */
166  if( (*table)->tablefree != NULL )
167  {
168  SCIP_CALL( (*table)->tablefree(set->scip, *table) );
169  }
170 
171  BMSfreeMemoryArrayNull(&(*table)->name);
172  BMSfreeMemoryArrayNull(&(*table)->desc);
173  BMSfreeMemory(table);
174 
175  return SCIP_OKAY;
176 }
177 
178 /** initializes statistics table */
180  SCIP_TABLE* table, /**< statistics table */
181  SCIP_SET* set /**< global SCIP settings */
182  )
183 {
184  assert(table != NULL);
185  assert(set != NULL);
186 
187  if( table->initialized )
188  {
189  SCIPerrorMessage("statistics table <%s> already initialized\n", table->name);
190  return SCIP_INVALIDCALL;
191  }
192 
193  if( table->tableinit != NULL )
194  {
195  SCIP_CALL( table->tableinit(set->scip, table) );
196  }
197  table->initialized = TRUE;
198 
199  return SCIP_OKAY;
200 }
201 
202 /** deinitializes statistics table */
204  SCIP_TABLE* table, /**< statistics table */
205  SCIP_SET* set /**< global SCIP settings */
206  )
207 {
208  assert(table != NULL);
209  assert(set != NULL);
210 
211  if( !table->initialized )
212  {
213  SCIPerrorMessage("statistics table <%s> not initialized\n", table->name);
214  return SCIP_INVALIDCALL;
215  }
216 
217  if( table->tableexit != NULL )
218  {
219  SCIP_CALL( table->tableexit(set->scip, table) );
220  }
221  table->initialized = FALSE;
222 
223  return SCIP_OKAY;
224 }
225 
226 /** informs statistics table that the branch and bound process is being started */
228  SCIP_TABLE* table, /**< statistics table */
229  SCIP_SET* set /**< global SCIP settings */
230  )
231 {
232  assert(table != NULL);
233  assert(set != NULL);
234 
235  /* call solving process initialization method of statistics table */
236  if( table->tableinitsol != NULL )
237  {
238  SCIP_CALL( table->tableinitsol(set->scip, table) );
239  }
240 
241  return SCIP_OKAY;
242 }
243 
244 /** informs statistics table that the branch and bound process data is being freed */
246  SCIP_TABLE* table, /**< statistics table */
247  SCIP_SET* set /**< global SCIP settings */
248  )
249 {
250  assert(table != NULL);
251  assert(set != NULL);
252 
253  /* call solving process deinitialization method of statistics table */
254  if( table->tableexitsol != NULL )
255  {
256  SCIP_CALL( table->tableexitsol(set->scip, table) );
257  }
258 
259  return SCIP_OKAY;
260 }
261 
262 /** output statistics table to screen */
264  SCIP_TABLE* table, /**< statistics table */
265  SCIP_SET* set, /**< global SCIP settings */
266  FILE* file /**< output file (or NULL for standard output) */
267  )
268 {
269  assert(table != NULL);
270  assert(table->tableoutput != NULL);
271  assert(set != NULL);
272 
273  SCIP_CALL( table->tableoutput(set->scip, table, file) );
274 
275  return SCIP_OKAY;
276 }
277 
278 /** gets user data of statistics table */
280  SCIP_TABLE* table /**< statistics table */
281  )
282 {
283  assert(table != NULL);
284 
285  return table->tabledata;
286 }
287 
288 /** sets user data of statistics table; user has to free old data in advance! */
290  SCIP_TABLE* table, /**< statistics table */
291  SCIP_TABLEDATA* tabledata /**< new statistics table user data */
292  )
293 {
294  assert(table != NULL);
295 
296  table->tabledata = tabledata;
297 }
298 
299 /** gets name of statistics table */
300 const char* SCIPtableGetName(
301  SCIP_TABLE* table /**< statistics table */
302  )
303 {
304  assert(table != NULL);
305 
306  return table->name;
307 }
308 
309 /** gets description of statistics table */
310 const char* SCIPtableGetDesc(
311  SCIP_TABLE* table /**< statistics table */
312  )
313 {
314  assert(table != NULL);
315 
316  return table->desc;
317 }
318 
319 /** gets position of statistics table */
321  SCIP_TABLE* table /**< statistics table */
322  )
323 {
324  assert(table != NULL);
325 
326  return table->position;
327 }
328 
329 /** gets earliest stage of statistics table */
331  SCIP_TABLE* table /**< statistics table */
332  )
333 {
334  assert(table != NULL);
335 
336  return table->earlieststage;
337 }
338 
339 /** is statistics table currently active? */
341  SCIP_TABLE* table /**< statistics table */
342  )
343 {
344  assert(table != NULL);
345 
346  return table->active;
347 }
348 
349 /** is statistics table initialized? */
351  SCIP_TABLE* table /**< statistics table */
352  )
353 {
354  assert(table != NULL);
355 
356  return table->initialized;
357 }
char * name
Definition: struct_table.h:38
#define SCIP_DECL_TABLEINITSOL(x)
Definition: type_table.h:93
#define BMSfreeMemoryArrayNull(ptr)
Definition: memory.h:141
SCIP_RETCODE SCIPtableInitsol(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:227
SCIP_Bool SCIPtableIsActive(SCIP_TABLE *table)
Definition: table.c:340
SCIP_Bool active
Definition: struct_table.h:51
#define SCIP_MAXSTRLEN
Definition: def.h:293
SCIP_TABLEDATA * tabledata
Definition: struct_table.h:47
#define SCIP_CALL_FINALLY(x, y)
Definition: def.h:426
internal methods for displaying statistics tables
SCIP_RETCODE SCIPtableFree(SCIP_TABLE **table, SCIP_SET *set)
Definition: table.c:154
#define FALSE
Definition: def.h:87
const char * SCIPtableGetName(SCIP_TABLE *table)
Definition: table.c:300
#define SCIP_DECL_TABLEFREE(x)
Definition: type_table.h:66
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10755
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
static GRAPHNODE ** active
#define BMSfreeMemory(ptr)
Definition: memory.h:138
SCIP_STAGE SCIPtableGetEarliestStage(SCIP_TABLE *table)
Definition: table.c:330
Definition: heur_padm.c:123
SCIP_STAGE earlieststage
Definition: struct_table.h:49
int SCIPtableGetPosition(SCIP_TABLE *table)
Definition: table.c:320
SCIP_Bool SCIPtableIsInitialized(SCIP_TABLE *table)
Definition: table.c:350
const char * SCIPtableGetDesc(SCIP_TABLE *table)
Definition: table.c:310
#define SCIPerrorMessage
Definition: pub_message.h:55
SCIP_RETCODE SCIPtableInit(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:179
char * desc
Definition: struct_table.h:39
SCIP_RETCODE SCIPtableOutput(SCIP_TABLE *table, SCIP_SET *set, FILE *file)
Definition: table.c:263
#define NULL
Definition: lpi_spx1.cpp:155
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:384
#define BMSduplicateMemoryArray(ptr, source, num)
Definition: memory.h:136
the function declarations for the synchronization store
public data structures and miscellaneous methods
#define SCIP_Bool
Definition: def.h:84
SCIP_RETCODE SCIPtableExitsol(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:245
static const char * paramname[]
Definition: lpi_msk.c:5031
#define SCIP_DECL_TABLECOPY(x)
Definition: type_table.h:58
#define SCIPsetDebugMsg
Definition: set.h:1761
#define SCIP_DECL_TABLEEXIT(x)
Definition: type_table.h:82
SCIP_RETCODE SCIPtableCopyInclude(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:46
#define BMSclearMemory(ptr)
Definition: memory.h:122
#define SCIP_DECL_TABLEINIT(x)
Definition: type_table.h:74
SCIP_RETCODE SCIPtableExit(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:203
void SCIPtableSetData(SCIP_TABLE *table, SCIP_TABLEDATA *tabledata)
Definition: table.c:289
static SCIP_RETCODE doTableCreate(SCIP_TABLE **table, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, SCIP_Bool active, SCIP_DECL_TABLECOPY((*tablecopy)), SCIP_DECL_TABLEFREE((*tablefree)), SCIP_DECL_TABLEINIT((*tableinit)), SCIP_DECL_TABLEEXIT((*tableexit)), SCIP_DECL_TABLEINITSOL((*tableinitsol)), SCIP_DECL_TABLEEXITSOL((*tableexitsol)), SCIP_DECL_TABLEOUTPUT((*tableoutput)), SCIP_TABLEDATA *tabledata, int position, SCIP_STAGE earlieststage)
Definition: table.c:65
public methods for message output
internal methods for problem statistics
enum SCIP_Stage SCIP_STAGE
Definition: type_set.h:50
SCIP_TABLEDATA * SCIPtableGetData(SCIP_TABLE *table)
Definition: table.c:279
#define BMSallocMemory(ptr)
Definition: memory.h:111
data structures for displaying statistics tables
SCIP_RETCODE SCIPtableCreate(SCIP_TABLE **table, SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, SCIP_Bool active, SCIP_DECL_TABLECOPY((*tablecopy)), SCIP_DECL_TABLEFREE((*tablefree)), SCIP_DECL_TABLEINIT((*tableinit)), SCIP_DECL_TABLEEXIT((*tableexit)), SCIP_DECL_TABLEINITSOL((*tableinitsol)), SCIP_DECL_TABLEEXITSOL((*tableexitsol)), SCIP_DECL_TABLEOUTPUT((*tableoutput)), SCIP_TABLEDATA *tabledata, int position, SCIP_STAGE earlieststage)
Definition: table.c:121
SCIP_Bool initialized
Definition: struct_table.h:50
common defines and data types used in all packages of SCIP
struct BMS_BlkMem BMS_BLKMEM
Definition: memory.h:430
#define SCIP_ALLOC(x)
Definition: def.h:395
SCIP_RETCODE SCIPsetAddBoolParam(SCIP_SET *set, SCIP_MESSAGEHDLR *messagehdlr, BMS_BLKMEM *blkmem, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: set.c:2998
#define SCIP_DECL_TABLEOUTPUT(x)
Definition: type_table.h:113
#define SCIP_DECL_TABLEEXITSOL(x)
Definition: type_table.h:104
SCIP callable library.
struct SCIP_TableData SCIP_TABLEDATA
Definition: type_table.h:49
memory allocation routines