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