Scippy

SCIP

Solving Constraint Integer Programs

objtable.h
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 email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objtable.h
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 #ifndef __SCIP_OBJTABLE_H__
24 #define __SCIP_OBJTABLE_H__
25 
26 #include <cstring>
27 
28 #include "scip/scip.h"
29 #include "objscip/objcloneable.h"
30 namespace scip
31 {
32 
33 /**
34  * @brief C++ wrapper for statistics tables
35  *
36  * This class defines the interface for statistics tables implemented in C++. Note that there is a pure virtual function
37  * (this function has to be implemented). This function is: scip_output().
38  *
39  * - \ref TABLE "Instructions for implementing a statistics table"
40  * - \ref TABLES "List of available statistics tables"
41  * - \ref type_table.h "Corresponding C interface"
42  */
43 class ObjTable : public ObjCloneable
44 {
45 public:
46  /*lint --e{1540}*/
47 
48  /** SCIP data structure */
50 
51  /** name of the statistics tables */
52  char* scip_name_;
53 
54  /** description of the statistics table */
55  char* scip_desc_;
56 
57  /** position of the statistics table */
58  const int scip_position_;
59 
60  /** output of the statistics table is only printed from this stage onwards */
62 
63  /** default constructor */
65  SCIP* scip, /**< SCIP data structure */
66  const char* name, /**< name of statistics table */
67  const char* desc, /**< description of statistics table */
68  int position, /**< position of statistics table */
69  SCIP_STAGE earlieststage /**< output of the statistics table is only printed from this stage onwards */
70  )
71  : scip_(scip),
72  scip_name_(0),
73  scip_desc_(0),
74  scip_position_(position),
75  scip_earlieststage_(earlieststage)
76  {
77  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
78  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
79  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
80  }
81 
82  /** destructor */
83  virtual ~ObjTable()
84  {
85  /* the macro SCIPfreeMemoryArray does not need the first argument: */
86  /*lint --e{64}*/
87  SCIPfreeMemoryArray(scip_, &scip_name_);
88  SCIPfreeMemoryArray(scip_, &scip_desc_);
89  }
90 
91  /** destructor of statistics table to free user data (called when SCIP is exiting)
92  *
93  * @see SCIP_DECL_TABLEFREE(x) in @ref type_disp.h
94  */
95  virtual SCIP_DECL_TABLEFREE(scip_free)
96  { /*lint --e{715}*/
97  return SCIP_OKAY;
98  }
99 
100  /** initialization method of statistics table (called after problem was transformed)
101  *
102  * @see SCIP_DECL_TABLEINIT(x) in @ref type_table.h
103  */
104  virtual SCIP_DECL_TABLEINIT(scip_init)
105  { /*lint --e{715}*/
106  return SCIP_OKAY;
107  }
108 
109  /** deinitialization method of statistics table (called before transformed problem is freed)
110  *
111  * @see SCIP_DECL_TABLEEXIT(x) in @ref type_table.h
112  */
113  virtual SCIP_DECL_TABLEEXIT(scip_exit)
114  { /*lint --e{715}*/
115  return SCIP_OKAY;
116  }
117 
118  /** solving process initialization method of statistics table (called when branch and bound process is about to begin)
119  *
120  * @see SCIP_DECL_TABLEINITSOL(x) in @ref type_table.h
121  */
122  virtual SCIP_DECL_TABLEINITSOL(scip_initsol)
123  { /*lint --e{715}*/
124  return SCIP_OKAY;
125  }
126 
127  /** solving process deinitialization method of statistics table (called before branch and bound process data is freed)
128  *
129  * @see SCIP_DECL_TABLEEXITSOL(x) in @ref type_table.h
130  */
131  virtual SCIP_DECL_TABLEEXITSOL(scip_exitsol)
132  { /*lint --e{715}*/
133  return SCIP_OKAY;
134  }
135 
136  /** output method of statistics table to output file stream 'file'
137  *
138  * @see SCIP_DECL_TABLEOUTPUT(x) in @ref type_table.h
139  */
140  virtual SCIP_DECL_TABLEOUTPUT(scip_output) = 0;
141 };
142 
143 } /* namespace scip */
144 
145 
146 
147 /** creates the statistics table for the given statistics table object and includes it in SCIP
148  *
149  * The method should be called in one of the following ways:
150  *
151  * 1. The user is resposible of deleting the object:
152  * SCIP_CALL( SCIPcreate(&scip) );
153  * ...
154  * MyTable* mytable = new MyTable(...);
155  * SCIP_CALL( SCIPincludeObjTable(scip, &mytable, FALSE) );
156  * ...
157  * SCIP_CALL( SCIPfree(&scip) );
158  * delete mytable; // delete table AFTER SCIPfree() !
159  *
160  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
161  * SCIP_CALL( SCIPcreate(&scip) );
162  * ...
163  * SCIP_CALL( SCIPincludeObjTable(scip, new MyTable(...), TRUE) );
164  * ...
165  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyTable is called here
166  */
167 extern
169  SCIP* scip, /**< SCIP data structure */
170  scip::ObjTable* objtable, /**< statistics table object */
171  SCIP_Bool deleteobject /**< should the statistics table object be deleted when statistics table is freed? */
172  );
173 
174 /** returns the statistics table object of the given name, or 0 if not existing */
175 extern
177  SCIP* scip, /**< SCIP data structure */
178  const char* name /**< name of statistics table */
179  );
180 
181 /** returns the statistics table object for the given statistics table */
182 extern
184  SCIP* scip, /**< SCIP data structure */
185  SCIP_TABLE* table /**< statistics table */
186  );
187 
188 #endif
ObjTable(SCIP *scip, const char *name, const char *desc, int position, SCIP_STAGE earlieststage)
Definition: objtable.h:64
char * scip_desc_
Definition: objtable.h:55
virtual ~ObjTable()
Definition: objtable.h:83
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
virtual SCIP_DECL_TABLEFREE(scip_free)
Definition: objtable.h:95
definition of base class for all clonable classes
SCIP_STAGE scip_earlieststage_
Definition: objtable.h:61
virtual SCIP_DECL_TABLEINIT(scip_init)
Definition: objtable.h:104
virtual SCIP_DECL_TABLEEXIT(scip_exit)
Definition: objtable.h:113
SCIP * scip_
Definition: objtable.h:49
virtual SCIP_DECL_TABLEOUTPUT(scip_output)=0
SCIP_RETCODE SCIPincludeObjTable(SCIP *scip, scip::ObjTable *objtable, SCIP_Bool deleteobject)
Definition: objtable.cpp:195
C++ wrapper for statistics tables.
Definition: objtable.h:43
#define SCIP_Bool
Definition: def.h:61
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip.h:22565
char * scip_name_
Definition: objtable.h:52
virtual SCIP_DECL_TABLEINITSOL(scip_initsol)
Definition: objtable.h:122
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:22569
Definition of base class for all clonable classes.
Definition: objcloneable.h:38
const int scip_position_
Definition: objtable.h:58
enum SCIP_Stage SCIP_STAGE
Definition: type_set.h:50
scip::ObjTable * SCIPgetObjTable(SCIP *scip, SCIP_TABLE *table)
Definition: objtable.cpp:239
#define SCIP_CALL_ABORT(x)
Definition: def.h:329
SCIP callable library.
scip::ObjTable * SCIPfindObjTable(SCIP *scip, const char *name)
Definition: objtable.cpp:220
virtual SCIP_DECL_TABLEEXITSOL(scip_exitsol)
Definition: objtable.h:131