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   objprop.h
17   	 * @brief  C++ wrapper for propagators
18   	 * @author Tobias Achterberg
19   	 */
20   	
21   	/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22   	
23   	#ifndef __SCIP_OBJPROP_H__
24   	#define __SCIP_OBJPROP_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 propagators
35   	 *
36   	 *  This class defines the interface for propagators 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 PROP "Instructions for implementing a propagator"
40   	 *  - \ref PROPAGATORS "List of available propagators"
41   	 *  - \ref type_prop.h "Corresponding C interface"
42   	 */
(1) Event missing_assign: Class "scip::ObjProp" 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 ObjProp : public ObjCloneable
44   	{
45   	public:
46   	   /*lint --e{1540}*/
47   	
48   	   /** SCIP data structure */
49   	   SCIP* scip_;
50   	
51   	   /** name of the propagator */
52   	   char* scip_name_;
53   	
54   	   /** description of the propagator */
55   	   char* scip_desc_;
56   	
57   	   /** default priority of the propagator */
58   	   const int scip_priority_;
59   	
60   	   /** frequency for calling propagator */
61   	   const int scip_freq_;
62   	
63   	   /** should propagator be delayed, if other propagators found reductions? */
64   	   const SCIP_Bool scip_delay_;
65   	
66   	   /** positions in the node solving loop where propagator should be executed */
67   	   const SCIP_PROPTIMING scip_timingmask_;
68   	
69   	   /** default presolving priority of the propagator */
70   	   const int scip_presol_priority_;
71   	
72   	   /** frequency for calling propagator */
73   	   const int scip_presol_maxrounds_;
74   	
75   	   /**< timing mask of the propagator's presolving method */
76   	   const SCIP_PRESOLTIMING scip_presol_timing_;
77   	
78   	
79   	   /** default constructor */
80   	   ObjProp(
81   	      SCIP*              scip,               /**< SCIP data structure */
82   	      const char*        name,               /**< name of propagator */
83   	      const char*        desc,               /**< description of propagator */
84   	      int                priority,           /**< priority of the propagator */
85   	      int                freq,               /**< frequency for calling propagator */
86   	      SCIP_Bool          delay,              /**< should propagator be delayed, if other propagators found reductions? */
87   	      SCIP_PROPTIMING    timingmask,         /**< positions in the node solving loop where propagator should be executed */
88   	      int                presolpriority,     /**< presolving priority of the propagator (>= 0: before, < 0: after constraint handlers) */
89   	      int                presolmaxrounds,    /**< maximal number of presolving rounds the propagator participates in (-1: no limit) */
90   	      SCIP_PRESOLTIMING  presoltiming        /**< timing mask of the propagator's presolving method */
91   	      )
92   	      : scip_(scip),
93   	        scip_name_(0),
94   	        scip_desc_(0),
95   	        scip_priority_(priority),
96   	        scip_freq_(freq),
97   	        scip_delay_(delay),
98   	        scip_timingmask_(timingmask),
99   	        scip_presol_priority_(presolpriority),
100  	        scip_presol_maxrounds_(presolmaxrounds),
101  	        scip_presol_timing_(presoltiming)
102  	   {
103  	      /* the macro SCIPduplicateMemoryArray does not need the first argument: */
104  	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
105  	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
106  	   }
107  	
108  	   /** destructor */
109  	   virtual ~ObjProp()
110  	   {
111  	      /* the macro SCIPfreeMemoryArray does not need the first argument: */
112  	      /*lint --e{64}*/
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_name_". [details]
113  	      SCIPfreeMemoryArray(scip_, &scip_name_);
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_desc_". [details]
114  	      SCIPfreeMemoryArray(scip_, &scip_desc_);
115  	   }
116  	
117  	   /** destructor of propagator to free user data (called when SCIP is exiting)
118  	    *
119  	    *  @see SCIP_DECL_PROPFREE(x) in @ref type_prop.h
120  	    */
121  	   virtual SCIP_DECL_PROPFREE(scip_free)
122  	   {  /*lint --e{715}*/
123  	      return SCIP_OKAY;
124  	   }
125  	
126  	   /** initialization method of propagator (called after problem was transformed)
127  	    *
128  	    *  @see SCIP_DECL_PROPINIT(x) in @ref type_prop.h
129  	    */
130  	   virtual SCIP_DECL_PROPINIT(scip_init)
131  	   {  /*lint --e{715}*/
132  	      return SCIP_OKAY;
133  	   }
134  	
135  	   /** deinitialization method of propagator (called before transformed problem is freed)
136  	    *
137  	    *  @see SCIP_DECL_PROPEXIT(x) in @ref type_prop.h
138  	    */
139  	   virtual SCIP_DECL_PROPEXIT(scip_exit)
140  	   {  /*lint --e{715}*/
141  	      return SCIP_OKAY;
142  	   }
143  	
144  	   /** presolving initialization method of propagator (called when presolving is about to begin)
145  	    *
146  	    *  @see SCIP_DECL_PROPINITPRE(x) in @ref type_prop.h
147  	    */
148  	   virtual SCIP_DECL_PROPINITPRE(scip_initpre)
149  	   {  /*lint --e{715}*/
150  	      return SCIP_OKAY;
151  	   }
152  	
153  	   /** presolving deinitialization method of propagator (called after presolving has been finished)
154  	    *
155  	    *  @see SCIP_DECL_PROPEXITPRE(x) in @ref type_prop.h
156  	    */
157  	   virtual SCIP_DECL_PROPEXITPRE(scip_exitpre)
158  	   {  /*lint --e{715}*/
159  	      return SCIP_OKAY;
160  	   }
161  	
162  	   /** solving process initialization method of propagator (called when branch and bound process is about to begin)
163  	    *
164  	    *  @see SCIP_DECL_PROPINITSOL(x) in @ref type_prop.h
165  	    */
166  	   virtual SCIP_DECL_PROPINITSOL(scip_initsol)
167  	   {  /*lint --e{715}*/
168  	      return SCIP_OKAY;
169  	   }
170  	
171  	   /** solving process deinitialization method of propagator (called before branch and bound process data is freed)
172  	    *
173  	    *  @see SCIP_DECL_PROPEXITSOL(x) in @ref type_prop.h
174  	    */
175  	   virtual SCIP_DECL_PROPEXITSOL(scip_exitsol)
176  	   {  /*lint --e{715}*/
177  	      return SCIP_OKAY;
178  	   }
179  	
180  	   /** presolving method of propagator
181  	    *
182  	    *  @see SCIP_DECL_PROPPRESOL(x) in @ref type_prop.h
183  	    */
184  	   virtual SCIP_DECL_PROPPRESOL(scip_presol)
185  	   {  /*lint --e{715}*/
186  	      assert(result != NULL);
187  	      *result = SCIP_DIDNOTRUN;
188  	      return SCIP_OKAY;
189  	   }
190  	
191  	   /** execution method of propagator
192  	    *
193  	    *  @see SCIP_DECL_PROPEXEC(x) in @ref type_prop.h
194  	    */
195  	   virtual SCIP_DECL_PROPEXEC(scip_exec) = 0;
196  	
197  	   /** propagation conflict resolving method of propagator
198  	    *
199  	    *  @see SCIP_DECL_PROPRESPROP(x) in @ref type_prop.h
200  	    */
201  	   virtual SCIP_DECL_PROPRESPROP(scip_resprop)
202  	   {  /*lint --e{715}*/
203  	
204  	      /* set result pointer to indicate the propagation was not resolved */
205  	      assert(result != NULL);
206  	      (*result) = SCIP_DIDNOTFIND;
207  	
208  	      return SCIP_OKAY;
209  	   }
210  	};
211  	
212  	} /* namespace scip */
213  	
214  	
215  	
216  	/** creates the propagator for the given propagator object and includes it in SCIP
217  	 *
218  	 *  The method should be called in one of the following ways:
219  	 *
220  	 *   1. The user is resposible of deleting the object:
221  	 *       SCIP_CALL( SCIPcreate(&scip) );
222  	 *       ...
223  	 *       MyProp* myprop = new MyProp(...);
224  	 *       SCIP_CALL( SCIPincludeObjProp(scip, &myprop, FALSE) );
225  	 *       ...
226  	 *       SCIP_CALL( SCIPfree(&scip) );
227  	 *       delete myprop;    // delete prop AFTER SCIPfree() !
228  	 *
229  	 *   2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
230  	 *       SCIP_CALL( SCIPcreate(&scip) );
231  	 *       ...
232  	 *       SCIP_CALL( SCIPincludeObjProp(scip, new MyProp(...), TRUE) );
233  	 *       ...
234  	 *       SCIP_CALL( SCIPfree(&scip) );  // destructor of MyProp is called here
235  	 */
236  	SCIP_EXPORT
237  	SCIP_RETCODE SCIPincludeObjProp(
238  	   SCIP*                 scip,               /**< SCIP data structure */
239  	   scip::ObjProp*        objprop,            /**< propagator object */
240  	   SCIP_Bool             deleteobject        /**< should the propagator object be deleted when propagator is freed? */
241  	   );
242  	
243  	/** returns the prop object of the given name, or 0 if not existing */
244  	SCIP_EXPORT
245  	scip::ObjProp* SCIPfindObjProp(
246  	   SCIP*                 scip,               /**< SCIP data structure */
247  	   const char*           name                /**< name of propagator */
248  	   );
249  	
250  	/** returns the prop object for the given propagator */
251  	SCIP_EXPORT
252  	scip::ObjProp* SCIPgetObjProp(
253  	   SCIP*                 scip,               /**< SCIP data structure */
254  	   SCIP_PROP*            prop                /**< propagator */
255  	   );
256  	
257  	#endif
258