Scippy

SCIP

Solving Constraint Integer Programs

objtable.cpp
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 objtable.cpp
17  * @brief C++ wrapper for statistics tables
18  * @author Tristan Gally
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <cassert>
24 
25 #include "objtable.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** display table data */
35 struct SCIP_TableData
36 {
37  scip::ObjTable* objtable; /**< display statistics table object */
38  SCIP_Bool deleteobject; /**< should the statistics table object be deleted when statistics table is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of statistics table
46  */
47 
48 extern "C"
49 {
50 
51 /** copy method for statistics table plugins (called when SCIP copies plugins) */
52 static
53 SCIP_DECL_TABLECOPY(tableCopyObj)
54 { /*lint --e{715}*/
55  SCIP_TABLEDATA* tabledata;
56 
57  assert(scip != NULL);
58 
59  tabledata = SCIPtableGetData(table);
60  assert(tabledata != NULL);
61  assert(tabledata->objtable != NULL);
62  assert(tabledata->objtable->scip_ != scip);
63 
64  if( tabledata->objtable->iscloneable() )
65  {
66  scip::ObjTable* newobjtable;
67  newobjtable = dynamic_cast<scip::ObjTable*> (tabledata->objtable->clone(scip));
68 
69  /* call include method of display column object */
70  SCIP_CALL( SCIPincludeObjTable(scip, newobjtable, TRUE) );
71  }
72 
73  return SCIP_OKAY;
74 }
75 
76 /** destructor of statistics table to free user data (called when SCIP is exiting) */
77 static
78 SCIP_DECL_TABLEFREE(tableFreeObj)
79 { /*lint --e{715}*/
80  SCIP_TABLEDATA* tabledata;
81 
82  tabledata = SCIPtableGetData(table);
83  assert(tabledata != NULL);
84  assert(tabledata->objtable != NULL);
85  assert(tabledata->objtable->scip_ == scip);
86 
87  /* call virtual method of statistics table object */
88  SCIP_CALL( tabledata->objtable->scip_free(scip, table) );
89 
90  /* free statistics table object */
91  if( tabledata->deleteobject )
92  delete tabledata->objtable;
93 
94  /* free statistics table data */
95  delete tabledata;
96  SCIPtableSetData(table, NULL); /*lint !e64*/
97 
98  return SCIP_OKAY;
99 }
100 
101 
102 /** initialization method of statistics table (called after problem was transformed) */
103 static
104 SCIP_DECL_TABLEINIT(tableInitObj)
105 { /*lint --e{715}*/
106  SCIP_TABLEDATA* tabledata;
107 
108  tabledata = SCIPtableGetData(table);
109  assert(tabledata != NULL);
110  assert(tabledata->objtable != NULL);
111  assert(tabledata->objtable->scip_ == scip);
112 
113  /* call virtual method of statistics table object */
114  SCIP_CALL( tabledata->objtable->scip_init(scip, table) );
115 
116  return SCIP_OKAY;
117 }
118 
119 
120 /** deinitialization method of statistics table (called before transformed problem is freed) */
121 static
122 SCIP_DECL_TABLEEXIT(tableExitObj)
123 { /*lint --e{715}*/
124  SCIP_TABLEDATA* tabledata;
125 
126  tabledata = SCIPtableGetData(table);
127  assert(tabledata != NULL);
128  assert(tabledata->objtable != NULL);
129 
130  /* call virtual method of statistics table object */
131  SCIP_CALL( tabledata->objtable->scip_exit(scip, table) );
132 
133  return SCIP_OKAY;
134 }
135 
136 
137 /** solving process initialization method of statistics table (called when branch and bound process is about to begin) */
138 static
139 SCIP_DECL_TABLEINITSOL(tableInitsolObj)
140 { /*lint --e{715}*/
141  SCIP_TABLEDATA* tabledata;
142 
143  tabledata = SCIPtableGetData(table);
144  assert(tabledata != NULL);
145  assert(tabledata->objtable != NULL);
146 
147  /* call virtual method of statistics table object */
148  SCIP_CALL( tabledata->objtable->scip_initsol(scip, table) );
149 
150  return SCIP_OKAY;
151 }
152 
153 
154 /** solving process deinitialization method of statistics table (called before branch and bound process data is freed) */
155 static
156 SCIP_DECL_TABLEEXITSOL(tableExitsolObj)
157 { /*lint --e{715}*/
158  SCIP_TABLEDATA* tabledata;
159 
160  tabledata = SCIPtableGetData(table);
161  assert(tabledata != NULL);
162  assert(tabledata->objtable != NULL);
163 
164  /* call virtual method of statistics table object */
165  SCIP_CALL( tabledata->objtable->scip_exitsol(scip, table) );
166 
167  return SCIP_OKAY;
168 }
169 
170 
171 /** output method of statistics table to output file stream 'file' */
172 static
173 SCIP_DECL_TABLEOUTPUT(tableOutputObj)
174 { /*lint --e{715}*/
175  SCIP_TABLEDATA* tabledata;
176 
177  tabledata = SCIPtableGetData(table);
178  assert(tabledata != NULL);
179  assert(tabledata->objtable != NULL);
180 
181  /* call virtual method of statistics table object */
182  SCIP_CALL( tabledata->objtable->scip_output(scip, table, file) );
183 
184  return SCIP_OKAY;
185 }
186 }
187 
188 
189 
190 /*
191  * statistics table specific interface methods
192  */
193 
194 /** creates the statistics table for the given statistics table object and includes it in SCIP */
196  SCIP* scip, /**< SCIP data structure */
197  scip::ObjTable* objtable, /**< statistics table object */
198  SCIP_Bool deleteobject /**< should the statistics table object be deleted when statistics table is freed? */
199  )
200 {
201  SCIP_TABLEDATA* tabledata;
202 
203  assert(scip != NULL);
204  assert(objtable != NULL);
205 
206  /* create statistics table data */
207  tabledata = new SCIP_TABLEDATA;
208  tabledata->objtable = objtable;
209  tabledata->deleteobject = deleteobject;
210 
211  /* include statistics table */
212  SCIP_CALL( SCIPincludeTable(scip, objtable->scip_name_, objtable->scip_desc_, TRUE,
213  tableCopyObj, tableFreeObj, tableInitObj, tableExitObj, tableInitsolObj,
214  tableExitsolObj, tableOutputObj, tabledata, objtable->scip_position_, objtable->scip_earlieststage_) ); /*lint !e429*/
215 
216  return SCIP_OKAY; /*lint !e429*/
217 }
218 
219 /** returns the statistics table object of the given name, or 0 if not existing */
221  SCIP* scip, /**< SCIP data structure */
222  const char* name /**< name of statistics table */
223  )
224 {
225  SCIP_TABLE* table;
226  SCIP_TABLEDATA* tabledata;
227 
228  table = SCIPfindTable(scip, name);
229  if( table == NULL )
230  return 0;
231 
232  tabledata = SCIPtableGetData(table);
233  assert(tabledata != NULL);
234 
235  return tabledata->objtable;
236 }
237 
238 /** returns the statistics table object for the given statistics table */
240  SCIP* scip, /**< SCIP data structure */
241  SCIP_TABLE* table /**< statistics table */
242  )
243 {
244  SCIP_TABLEDATA* tabledata;
245 
246  assert(scip != NULL);
247  tabledata = SCIPtableGetData(table);
248  assert(tabledata != NULL);
249 
250  return tabledata->objtable;
251 }
static SCIP_DECL_TABLEFREE(tableFreeObj)
Definition: objtable.cpp:78
static SCIP_DECL_TABLEEXITSOL(tableExitsolObj)
Definition: objtable.cpp:156
static SCIP_DECL_TABLEINIT(tableInitObj)
Definition: objtable.cpp:104
SCIP_RETCODE SCIPincludeTable(SCIP *scip, 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: scip_table.c:47
static SCIP_DECL_TABLECOPY(tableCopyObj)
Definition: objtable.cpp:53
scip::ObjTable * SCIPgetObjTable(SCIP *scip, SCIP_TABLE *table)
Definition: objtable.cpp:239
char * scip_desc_
Definition: objtable.h:55
SCIP_TABLE * SCIPfindTable(SCIP *scip, const char *name)
Definition: scip_table.c:85
#define TRUE
Definition: def.h:86
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
SCIP_STAGE scip_earlieststage_
Definition: objtable.h:61
#define NULL
Definition: lpi_spx1.cpp:155
#define SCIP_CALL(x)
Definition: def.h:384
C++ wrapper for statistics tables.
Definition: objtable.h:43
scip::ObjTable * SCIPfindObjTable(SCIP *scip, const char *name)
Definition: objtable.cpp:220
C++ wrapper for statistics tables.
static SCIP_DECL_TABLEINITSOL(tableInitsolObj)
Definition: objtable.cpp:139
#define SCIP_Bool
Definition: def.h:84
char * scip_name_
Definition: objtable.h:52
static SCIP_DECL_TABLEOUTPUT(tableOutputObj)
Definition: objtable.cpp:173
static SCIP_DECL_TABLEEXIT(tableExitObj)
Definition: objtable.cpp:122
SCIP_RETCODE SCIPincludeObjTable(SCIP *scip, scip::ObjTable *objtable, SCIP_Bool deleteobject)
Definition: objtable.cpp:195
const int scip_position_
Definition: objtable.h:58
void SCIPtableSetData(SCIP_TABLE *table, SCIP_TABLEDATA *tabledata)
Definition: table.c:289
SCIP_TABLEDATA * SCIPtableGetData(SCIP_TABLE *table)
Definition: table.c:279
struct SCIP_TableData SCIP_TABLEDATA
Definition: type_table.h:49