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   objpresol.h
17   	 * @brief  C++ wrapper for presolvers
18   	 * @author Tobias Achterberg
19   	 */
20   	
21   	/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22   	
23   	#ifndef __SCIP_OBJPRESOL_H__
24   	#define __SCIP_OBJPRESOL_H__
25   	
26   	#include <cstring>
27   	
28   	#include "scip/scip.h"
29   	#include "objscip/objcloneable.h"
30   	
31   	namespace scip
32   	{
33   	
34   	/** @brief C++ wrapper for presolvers
35   	 *
36   	 *  This class defines the interface for presolvers implemented in C++. Note that there is a pure virtual
37   	 *  function (this function has to be implemented). This function is: scip_exec().
38   	 *
39   	 *  - \ref PRESOL "Instructions for implementing a presolver"
40   	 *  - \ref PRESOLVERS "List of available presolvers"
41   	 *  - \ref type_presol.h "Corresponding C interface"
42   	 */
(1) Event missing_copy_ctor: Class "scip::ObjPresol" owns resources that are freed in its destructor but has no user-written copy constructor.
(2) Event free_resource: The destructor frees member "scip_desc_". [details]
(3) Event free_resource: The destructor frees member "scip_name_". [details]
43   	class ObjPresol : public ObjCloneable
44   	{
45   	public:
46   	   /*lint --e{1540}*/
47   	
48   	   /** SCIP data structure */
49   	   SCIP* scip_;
50   	
51   	   /** name of the presolver */
52   	   char* scip_name_;
53   	
54   	   /** description of the presolver */
55   	   char* scip_desc_;
56   	
57   	   /** default priority of the presolver */
58   	   const int scip_priority_;
59   	
60   	   /** default maximal number of presolving rounds the presolver participates in (-1: no limit) */
61   	   const int scip_maxrounds_;
62   	
63   	   /**< timing mask of the presolver */
64   	   const SCIP_PRESOLTIMING scip_timing_;
65   	
66   	   /** default constructor */
67   	   ObjPresol(
68   	      SCIP*              scip,               /**< SCIP data structure */
69   	      const char*        name,               /**< name of presolver */
70   	      const char*        desc,               /**< description of presolver */
71   	      int                priority,           /**< priority of the presolver */
72   	      int                maxrounds,          /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
73   	      SCIP_PRESOLTIMING  timing              /**< timing mask of the presolver */
74   	      )
75   	      : scip_(scip),
76   	        scip_name_(0),
77   	        scip_desc_(0),
78   	        scip_priority_(priority),
79   	        scip_maxrounds_(maxrounds),
80   	        scip_timing_(timing)
81   	   {
82   	      /* the macro SCIPduplicateMemoryArray does not need the first argument: */
83   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
84   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
85   	   }
86   	
87   	   /** destructor */
88   	   virtual ~ObjPresol()
89   	   {
90   	      /* the macro SCIPfreeMemoryArray does not need the first argument: */
91   	      /*lint --e{64}*/
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_name_". [details]
92   	      SCIPfreeMemoryArray(scip_, &scip_name_);
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_desc_". [details]
93   	      SCIPfreeMemoryArray(scip_, &scip_desc_);
94   	   }
95   	
96   	   /** destructor of presolver to free user data (called when SCIP is exiting)
97   	    *
98   	    *  @see SCIP_DECL_PRESOLFREE(x) in @ref type_prop.h
99   	    */
100  	   virtual SCIP_DECL_PRESOLFREE(scip_free)
101  	   {  /*lint --e{715}*/
102  	      return SCIP_OKAY;
103  	   }
104  	
105  	   /** initialization method of presolver (called after problem was transformed)
106  	    *
107  	    *  @see SCIP_DECL_PRESOLINIT(x) in @ref type_prop.h
108  	    */
109  	   virtual SCIP_DECL_PRESOLINIT(scip_init)
110  	   {  /*lint --e{715}*/
111  	      return SCIP_OKAY;
112  	   }
113  	
114  	   /** deinitialization method of presolver (called before transformed problem is freed)
115  	    *
116  	    *  @see SCIP_DECL_PRESOLEXIT(x) in @ref type_prop.h
117  	    */
118  	   virtual SCIP_DECL_PRESOLEXIT(scip_exit)
119  	   {  /*lint --e{715}*/
120  	      return SCIP_OKAY;
121  	   }
122  	
123  	   /** presolving initialization method of presolver (called when presolving is about to begin)
124  	    *
125  	    *  @see SCIP_DECL_PRESOLINITPRE(x) in @ref type_prop.h
126  	    */
127  	   virtual SCIP_DECL_PRESOLINITPRE(scip_initpre)
128  	   {  /*lint --e{715}*/
129  	      return SCIP_OKAY;
130  	   }
131  	
132  	   /** presolving deinitialization method of presolver (called after presolving has been finished)
133  	    *
134  	    *  @see SCIP_DECL_PRESOLEXITPRE(x) in @ref type_prop.h
135  	    */
136  	   virtual SCIP_DECL_PRESOLEXITPRE(scip_exitpre)
137  	   {  /*lint --e{715}*/
138  	      return SCIP_OKAY;
139  	   }
140  	
141  	   /** execution method of presolver
142  	    *
143  	    *  @see SCIP_DECL_PRESOLEXEC(x) in @ref type_prop.h
144  	    */
145  	   virtual SCIP_DECL_PRESOLEXEC(scip_exec) = 0;
146  	};
147  	
148  	} /* namespace scip */
149  	
150  	
151  	
152  	/** creates the presolver for the given presolver object and includes it in SCIP
153  	 *
154  	 *  The method should be called in one of the following ways:
155  	 *
156  	 *   1. The user is resposible of deleting the object:
157  	 *       SCIP_CALL( SCIPcreate(&scip) );
158  	 *       ...
159  	 *       MyPresol* mypresol = new MyPresol(...);
160  	 *       SCIP_CALL( SCIPincludeObjPresol(scip, &mypresol, FALSE) );
161  	 *       ...
162  	 *       SCIP_CALL( SCIPfree(&scip) );
163  	 *       delete mypresol;    // delete presol AFTER SCIPfree() !
164  	 *
165  	 *   2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
166  	 *       SCIP_CALL( SCIPcreate(&scip) );
167  	 *       ...
168  	 *       SCIP_CALL( SCIPincludeObjPresol(scip, new MyPresol(...), TRUE) );
169  	 *       ...
170  	 *       SCIP_CALL( SCIPfree(&scip) );  // destructor of MyPresol is called here
171  	 */
172  	SCIP_EXPORT
173  	SCIP_RETCODE SCIPincludeObjPresol(
174  	   SCIP*                 scip,               /**< SCIP data structure */
175  	   scip::ObjPresol*      objpresol,          /**< presolver object */
176  	   SCIP_Bool             deleteobject        /**< should the presolver object be deleted when presolver is freed? */
177  	   );
178  	
179  	/** returns the presol object of the given name, or 0 if not existing */
180  	SCIP_EXPORT
181  	scip::ObjPresol* SCIPfindObjPresol(
182  	   SCIP*                 scip,               /**< SCIP data structure */
183  	   const char*           name                /**< name of presolver */
184  	   );
185  	
186  	/** returns the presol object for the given presolver */
187  	SCIP_EXPORT
188  	scip::ObjPresol* SCIPgetObjPresol(
189  	   SCIP*                 scip,               /**< SCIP data structure */
190  	   SCIP_PRESOL*          presol              /**< presolver */
191  	   );
192  	
193  	#endif
194