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   objrelax.h
17   	 * @brief  C++ wrapper for relaxation handlers
18   	 * @author Tobias Achterberg
19   	 */
20   	
21   	/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22   	
23   	#ifndef __SCIP_OBJRELAX_H__
24   	#define __SCIP_OBJRELAX_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 relaxation handlers
35   	 *
36   	 *  This class defines the interface for relaxation handlers 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 RELAX "Instructions for implementing a relaxation handler"
40   	 *  - \ref type_relax.h "Corresponding C interface"
41   	 */
(1) Event missing_copy_ctor: Class "scip::ObjRelax" 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]
42   	class ObjRelax : public ObjCloneable
43   	{
44   	public:
45   	   /*lint --e{1540}*/
46   	
47   	   /** SCIP data structure */
48   	   SCIP* scip_;
49   	
50   	   /** name of the relaxator */
51   	   char* scip_name_;
52   	
53   	   /** description of the relaxator */
54   	   char* scip_desc_;
55   	
56   	   /** default priority of the relaxator (negative: call after LP, non-negative: call before LP) */
57   	   const int scip_priority_;
58   	
59   	   /** frequency for calling relaxator */
60   	   const int scip_freq_;
61   	
62   	   /** does the relaxator contain all cuts in the LP? */
63   	   const SCIP_Bool scip_includeslp_;
64   	
65   	   /** default constructor */
66   	   ObjRelax(
67   	      SCIP*              scip,               /**< SCIP data structure */
68   	      const char*        name,               /**< name of relaxator */
69   	      const char*        desc,               /**< description of relaxator */
70   	      int                priority,           /**< priority of the relaxator (negative: after LP, non-negative: before LP) */
71   	      int                freq,               /**< frequency for calling relaxator */
72   	      SCIP_Bool          includeslp          /**< Does the relaxator contain all cuts in the LP? */
73   	      )
74   	      : scip_(scip),
75   	        scip_name_(0),
76   	        scip_desc_(0),
77   	        scip_priority_(priority),
78   	        scip_freq_(freq),
79   	        scip_includeslp_(includeslp)
80   	   {
81   	      /* the macro SCIPduplicateMemoryArray does not need the first argument: */
82   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
83   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
84   	   }
85   	
86   	   /** destructor */
87   	   virtual ~ObjRelax()
88   	   {
89   	      /* the macro SCIPfreeMemoryArray does not need the first argument: */
90   	      /*lint --e{64}*/
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_name_". [details]
91   	      SCIPfreeMemoryArray(scip_, &scip_name_);
(1) Event freed_arg: "BMSfreeMemory_call" frees parameter "this->scip_desc_". [details]
92   	      SCIPfreeMemoryArray(scip_, &scip_desc_);
93   	   }
94   	
95   	   /** destructor of relaxator to free user data (called when SCIP is exiting)
96   	    *
97   	    *  @see SCIP_DECL_RELAXFREE(x) in @ref type_relax.h
98   	    */
99   	   virtual SCIP_DECL_RELAXFREE(scip_free)
100  	   {  /*lint --e{715}*/
101  	      return SCIP_OKAY;
102  	   }
103  	
104  	   /** initialization method of relaxator (called after problem was transformed)
105  	    *
106  	    *  @see SCIP_DECL_RELAXINIT(x) in @ref type_relax.h
107  	    */
108  	   virtual SCIP_DECL_RELAXINIT(scip_init)
109  	   {  /*lint --e{715}*/
110  	      return SCIP_OKAY;
111  	   }
112  	
113  	   /** deinitialization method of relaxator (called before transformed problem is freed)
114  	    *
115  	    *  @see SCIP_DECL_RELAXEXIT(x) in @ref type_relax.h
116  	    */
117  	   virtual SCIP_DECL_RELAXEXIT(scip_exit)
118  	   {  /*lint --e{715}*/
119  	      return SCIP_OKAY;
120  	   }
121  	
122  	   /** solving process initialization method of relaxator (called when branch and bound process is about to begin)
123  	    *
124  	    *  @see SCIP_DECL_RELAXINITSOL(x) in @ref type_relax.h
125  	    */
126  	   virtual SCIP_DECL_RELAXINITSOL(scip_initsol)
127  	   {  /*lint --e{715}*/
128  	      return SCIP_OKAY;
129  	   }
130  	
131  	   /** solving process deinitialization method of relaxator (called before branch and bound process data is freed)
132  	    *
133  	    *  @see SCIP_DECL_RELAXEXITSOL(x) in @ref type_relax.h
134  	    */
135  	   virtual SCIP_DECL_RELAXEXITSOL(scip_exitsol)
136  	   {  /*lint --e{715}*/
137  	      return SCIP_OKAY;
138  	   }
139  	
140  	   /** execution method of relaxator
141  	    *
142  	    *  @see SCIP_DECL_RELAXEXEC(x) in @ref type_relax.h
143  	    */
144  	   virtual SCIP_DECL_RELAXEXEC(scip_exec) = 0;
145  	};
146  	
147  	} /* namespace scip */
148  	
149  	
150  	
151  	/** creates the relaxator for the given relaxator object and includes it in SCIP
152  	 *
153  	 *  The method should be called in one of the following ways:
154  	 *
155  	 *   1. The user is resposible of deleting the object:
156  	 *       SCIP_CALL( SCIPcreate(&scip) );
157  	 *       ...
158  	 *       MyRelax* myrelax = new MyRelax(...);
159  	 *       SCIP_CALL( SCIPincludeObjRelax(scip, &myrelax, FALSE) );
160  	 *       ...
161  	 *       SCIP_CALL( SCIPfree(&scip) );
162  	 *       delete myrelax;    // delete relax AFTER SCIPfree() !
163  	 *
164  	 *   2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
165  	 *       SCIP_CALL( SCIPcreate(&scip) );
166  	 *       ...
167  	 *       SCIP_CALL( SCIPincludeObjRelax(scip, new MyRelax(...), TRUE) );
168  	 *       ...
169  	 *       SCIP_CALL( SCIPfree(&scip) );  // destructor of MyRelax is called here
170  	 */
171  	SCIP_EXPORT
172  	SCIP_RETCODE SCIPincludeObjRelax(
173  	   SCIP*                 scip,               /**< SCIP data structure */
174  	   scip::ObjRelax*  objrelax,           /**< relaxator object */
175  	   SCIP_Bool             deleteobject        /**< should the relaxator object be deleted when relaxator is freed? */
176  	   );
177  	
178  	/** returns the relax object of the given name, or 0 if not existing */
179  	SCIP_EXPORT
180  	scip::ObjRelax* SCIPfindObjRelax(
181  	   SCIP*                 scip,               /**< SCIP data structure */
182  	   const char*           name                /**< name of relaxator */
183  	   );
184  	
185  	/** returns the relax object for the given relaxator */
186  	SCIP_EXPORT
187  	scip::ObjRelax* SCIPgetObjRelax(
188  	   SCIP*                 scip,               /**< SCIP data structure */
189  	   SCIP_RELAX*           relax               /**< relaxator */
190  	   );
191  	
192  	#endif
193