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