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.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   	 */
(1) Event missing_assign: Class "scip::ObjTable" owns resources that are freed in its destructor but has no user-written assignment operator.
(2) Event free_resource: The destructor frees member "scip_desc_". [details]
(3) Event free_resource: The destructor frees member "scip_name_". [details]
43   	class ObjTable : public ObjCloneable
44   	{
45   	public:
46   	   /*lint --e{1540}*/
47   	
48   	   /** SCIP data structure */
49   	   SCIP* scip_;
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 */
61   	   SCIP_STAGE scip_earlieststage_;
62   	
63   	   /** default constructor */
64   	   ObjTable(
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}*/
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_name_". [details]
87   	      SCIPfreeMemoryArray(scip_, &scip_name_);
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_desc_". [details]
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  	SCIP_EXPORT
168  	SCIP_RETCODE SCIPincludeObjTable(
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  	SCIP_EXPORT
176  	scip::ObjTable* SCIPfindObjTable(
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  	SCIP_EXPORT
183  	scip::ObjTable* SCIPgetObjTable(
184  	   SCIP*                 scip,               /**< SCIP data structure */
185  	   SCIP_TABLE*           table               /**< statistics table */
186  	   );
187  	
188  	#endif
189