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-2017 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 email to 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 /** creates a statistics table */
64  SCIP_TABLE** table, /**< pointer to store statistics table */
65  SCIP_SET* set, /**< global SCIP settings */
66  SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
67  BMS_BLKMEM* blkmem, /**< block memory for parameter settings */
68  const char* name, /**< name of statistics table */
69  const char* desc, /**< description of statistics table */
70  SCIP_Bool active, /**< should the table be activated by default? */
71  SCIP_DECL_TABLECOPY ((*tablecopy)), /**< copy method of statistics table or NULL if you don't want to copy your plugin into sub-SCIPs */
72  SCIP_DECL_TABLEFREE ((*tablefree)), /**< destructor of statistics table */
73  SCIP_DECL_TABLEINIT ((*tableinit)), /**< initialize statistics table */
74  SCIP_DECL_TABLEEXIT ((*tableexit)), /**< deinitialize statistics table */
75  SCIP_DECL_TABLEINITSOL ((*tableinitsol)), /**< solving process initialization method of statistics table */
76  SCIP_DECL_TABLEEXITSOL ((*tableexitsol)), /**< solving process deinitialization method of statistics table */
77  SCIP_DECL_TABLEOUTPUT ((*tableoutput)), /**< output method */
78  SCIP_TABLEDATA* tabledata, /**< display statistics table */
79  int position, /**< position of statistics table */
80  SCIP_STAGE earlieststage /**< output of the statistics table is only printed from this stage onwards */
81  )
82 {
83  char paramname[SCIP_MAXSTRLEN];
84  char paramdesc[SCIP_MAXSTRLEN];
85 
86  assert(table != NULL);
87  assert(name != NULL);
88  assert(desc != NULL);
89  assert(tableoutput != NULL);
90 
91  SCIP_ALLOC( BMSallocMemory(table) );
92  SCIP_ALLOC( BMSduplicateMemoryArray(&(*table)->name, name, strlen(name)+1) );
93  SCIP_ALLOC( BMSduplicateMemoryArray(&(*table)->desc, desc, strlen(desc)+1) );
94  (*table)->tablecopy = tablecopy;
95  (*table)->tablefree = tablefree;
96  (*table)->tableinit = tableinit;
97  (*table)->tableexit = tableexit;
98  (*table)->tableinitsol = tableinitsol;
99  (*table)->tableexitsol = tableexitsol;
100  (*table)->tableoutput = tableoutput;
101  (*table)->tabledata = tabledata;
102  (*table)->position = position;
103  (*table)->earlieststage = earlieststage;
104  (*table)->initialized = FALSE;
105  (*table)->active = active;
106 
107  /* add parameters */
108  (void) SCIPsnprintf(paramname, SCIP_MAXSTRLEN, "table/%s/active", name);
109  (void) SCIPsnprintf(paramdesc, SCIP_MAXSTRLEN, "is statistics table <%s> active", name);
110  SCIP_CALL( SCIPsetAddBoolParam(set, messagehdlr, blkmem, paramname, paramdesc,
111  &(*table)->active, FALSE, active, NULL, NULL) );
112 
113  return SCIP_OKAY;
114 }
115 
116 /** frees memory of statistics table */
118  SCIP_TABLE** table, /**< pointer to statistics table data structure */
119  SCIP_SET* set /**< global SCIP settings */
120  )
121 {
122  assert(table != NULL);
123  assert(*table != NULL);
124  assert(!(*table)->initialized);
125  assert(set != NULL);
126 
127  /* call destructor of statistics table */
128  if( (*table)->tablefree != NULL )
129  {
130  SCIP_CALL( (*table)->tablefree(set->scip, *table) );
131  }
132 
133  BMSfreeMemoryArray(&(*table)->name);
134  BMSfreeMemoryArray(&(*table)->desc);
135  BMSfreeMemory(table);
136 
137  return SCIP_OKAY;
138 }
139 
140 /** initializes statistics table */
142  SCIP_TABLE* table, /**< statistics table */
143  SCIP_SET* set /**< global SCIP settings */
144  )
145 {
146  assert(table != NULL);
147  assert(set != NULL);
148 
149  if( table->initialized )
150  {
151  SCIPerrorMessage("statistics table <%s> already initialized\n", table->name);
152  return SCIP_INVALIDCALL;
153  }
154 
155  if( table->tableinit != NULL )
156  {
157  SCIP_CALL( table->tableinit(set->scip, table) );
158  }
159  table->initialized = TRUE;
160 
161  return SCIP_OKAY;
162 }
163 
164 /** deinitializes statistics table */
166  SCIP_TABLE* table, /**< statistics table */
167  SCIP_SET* set /**< global SCIP settings */
168  )
169 {
170  assert(table != NULL);
171  assert(set != NULL);
172 
173  if( !table->initialized )
174  {
175  SCIPerrorMessage("statistics table <%s> not initialized\n", table->name);
176  return SCIP_INVALIDCALL;
177  }
178 
179  if( table->tableexit != NULL )
180  {
181  SCIP_CALL( table->tableexit(set->scip, table) );
182  }
183  table->initialized = FALSE;
184 
185  return SCIP_OKAY;
186 }
187 
188 /** informs statistics table that the branch and bound process is being started */
190  SCIP_TABLE* table, /**< statistics table */
191  SCIP_SET* set /**< global SCIP settings */
192  )
193 {
194  assert(table != NULL);
195  assert(set != NULL);
196 
197  /* call solving process initialization method of statistics table */
198  if( table->tableinitsol != NULL )
199  {
200  SCIP_CALL( table->tableinitsol(set->scip, table) );
201  }
202 
203  return SCIP_OKAY;
204 }
205 
206 /** informs statistics table that the branch and bound process data is being freed */
208  SCIP_TABLE* table, /**< statistics table */
209  SCIP_SET* set /**< global SCIP settings */
210  )
211 {
212  assert(table != NULL);
213  assert(set != NULL);
214 
215  /* call solving process deinitialization method of statistics table */
216  if( table->tableexitsol != NULL )
217  {
218  SCIP_CALL( table->tableexitsol(set->scip, table) );
219  }
220 
221  return SCIP_OKAY;
222 }
223 
224 /** output statistics table to screen */
226  SCIP_TABLE* table, /**< statistics table */
227  SCIP_SET* set, /**< global SCIP settings */
228  FILE* file /**< output file (or NULL for standard output) */
229  )
230 {
231  assert(table != NULL);
232  assert(table->tableoutput != NULL);
233  assert(set != NULL);
234 
235  SCIP_CALL( table->tableoutput(set->scip, table, file) );
236 
237  return SCIP_OKAY;
238 }
239 
240 /** gets user data of statistics table */
242  SCIP_TABLE* table /**< statistics table */
243  )
244 {
245  assert(table != NULL);
246 
247  return table->tabledata;
248 }
249 
250 /** sets user data of statistics table; user has to free old data in advance! */
252  SCIP_TABLE* table, /**< statistics table */
253  SCIP_TABLEDATA* tabledata /**< new statistics table user data */
254  )
255 {
256  assert(table != NULL);
257 
258  table->tabledata = tabledata;
259 }
260 
261 /** gets name of statistics table */
262 const char* SCIPtableGetName(
263  SCIP_TABLE* table /**< statistics table */
264  )
265 {
266  assert(table != NULL);
267 
268  return table->name;
269 }
270 
271 /** gets description of statistics table */
272 const char* SCIPtableGetDesc(
273  SCIP_TABLE* table /**< statistics table */
274  )
275 {
276  assert(table != NULL);
277 
278  return table->desc;
279 }
280 
281 /** gets position of statistics table */
283  SCIP_TABLE* table /**< statistics table */
284  )
285 {
286  assert(table != NULL);
287 
288  return table->position;
289 }
290 
291 /** gets earliest stage of statistics table */
293  SCIP_TABLE* table /**< statistics table */
294  )
295 {
296  assert(table != NULL);
297 
298  return table->earlieststage;
299 }
300 
301 /** is statistics table currently active? */
303  SCIP_TABLE* table /**< statistics table */
304  )
305 {
306  assert(table != NULL);
307 
308  return table->active;
309 }
310 
311 /** is statistics table initialized? */
313  SCIP_TABLE* table /**< statistics table */
314  )
315 {
316  assert(table != NULL);
317 
318  return table->initialized;
319 }
char * name
Definition: struct_table.h:38
#define SCIP_DECL_TABLEINITSOL(x)
Definition: type_table.h:88
SCIP_RETCODE SCIPtableInitsol(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:189
SCIP_Bool SCIPtableIsActive(SCIP_TABLE *table)
Definition: table.c:302
SCIP_Bool active
Definition: struct_table.h:51
#define SCIP_MAXSTRLEN
Definition: def.h:259
SCIP_TABLEDATA * tabledata
Definition: struct_table.h:47
internal methods for displaying statistics tables
SCIP_RETCODE SCIPtableFree(SCIP_TABLE **table, SCIP_SET *set)
Definition: table.c:117
#define FALSE
Definition: def.h:64
const char * SCIPtableGetName(SCIP_TABLE *table)
Definition: table.c:262
#define SCIP_DECL_TABLEFREE(x)
Definition: type_table.h:61
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10011
#define TRUE
Definition: def.h:63
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:292
SCIP_STAGE earlieststage
Definition: struct_table.h:49
int SCIPtableGetPosition(SCIP_TABLE *table)
Definition: table.c:282
SCIP_Bool SCIPtableIsInitialized(SCIP_TABLE *table)
Definition: table.c:312
const char * SCIPtableGetDesc(SCIP_TABLE *table)
Definition: table.c:272
#define BMSfreeMemoryArray(ptr)
Definition: memory.h:129
#define SCIPerrorMessage
Definition: pub_message.h:45
SCIP_RETCODE SCIPtableInit(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:141
char * desc
Definition: struct_table.h:39
SCIP_RETCODE SCIPtableOutput(SCIP_TABLE *table, SCIP_SET *set, FILE *file)
Definition: table.c:225
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:350
#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:61
SCIP_RETCODE SCIPtableExitsol(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:207
#define SCIP_DECL_TABLECOPY(x)
Definition: type_table.h:53
#define SCIPsetDebugMsg
Definition: set.h:1913
#define SCIP_DECL_TABLEEXIT(x)
Definition: type_table.h:77
SCIP_RETCODE SCIPtableCopyInclude(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:45
#define SCIP_DECL_TABLEINIT(x)
Definition: type_table.h:69
SCIP_RETCODE SCIPtableExit(SCIP_TABLE *table, SCIP_SET *set)
Definition: table.c:165
void SCIPtableSetData(SCIP_TABLE *table, SCIP_TABLEDATA *tabledata)
Definition: table.c:251
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:241
#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:63
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:361
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:2791
#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