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