1    	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2    	/*                                                                           */
3    	/*                  This file is part of the program and library             */
4    	/*         SCIP --- Solving Constraint Integer Programs                      */
5    	/*                                                                           */
6    	/*  Copyright (c) 2002-2023 Zuse Institute Berlin (ZIB)                      */
7    	/*                                                                           */
8    	/*  Licensed under the Apache License, Version 2.0 (the "License");          */
9    	/*  you may not use this file except in compliance with the License.         */
10   	/*  You may obtain a copy of the License at                                  */
11   	/*                                                                           */
12   	/*      http://www.apache.org/licenses/LICENSE-2.0                           */
13   	/*                                                                           */
14   	/*  Unless required by applicable law or agreed to in writing, software      */
15   	/*  distributed under the License is distributed on an "AS IS" BASIS,        */
16   	/*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17   	/*  See the License for the specific language governing permissions and      */
18   	/*  limitations under the License.                                           */
19   	/*                                                                           */
20   	/*  You should have received a copy of the Apache-2.0 license                */
21   	/*  along with SCIP; see the file LICENSE. If not visit scipopt.org.         */
22   	/*                                                                           */
23   	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24   	
25   	/**@file   objpricer.h
26   	 * @brief  C++ wrapper for variable pricers
27   	 * @author Tobias Achterberg
28   	 */
29   	
30   	/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31   	
32   	#ifndef __SCIP_OBJPRICER_H__
33   	#define __SCIP_OBJPRICER_H__
34   	
35   	#include <cstring>
36   	#include <utility>
37   	
38   	#include "scip/scip.h"
39   	#include "objscip/objprobcloneable.h"
40   	
41   	namespace scip
42   	{
43   	
44   	/** @brief C++ wrapper for variable pricer
45   	 *
46   	 *  This class defines the interface for variable pricer implemented in C++. Note that there is a pure virtual
47   	 *  function (this function has to be implemented). This function is: scip_redcost().
48   	 *
49   	 *  - \ref PRICER "Instructions for implementing a variable pricer"
50   	 *  - \ref type_pricer.h "Corresponding C interface"
51   	 */
52   	class ObjPricer : public ObjProbCloneable
53   	{
54   	public:
55   	   /*lint --e{1540}*/
56   	
57   	   /** SCIP data structure */
58   	   SCIP* scip_;
59   	
60   	   /** name of the variable pricer */
61   	   char* scip_name_;
62   	
63   	   /** description of the variable pricer */
64   	   char* scip_desc_;
65   	
66   	   /** default priority of the variable pricer */
67   	   const int scip_priority_;
68   	
69   	   /** should the pricer be delayed until no other pricers or already existing problem variables with negative reduced
70   	    *  costs are found?
71   	    */
72   	   const SCIP_Bool scip_delay_;
73   	
74   	   /** default constructor */
75   	   ObjPricer(
76   	      SCIP*              scip,               /**< SCIP data structure */
77   	      const char*        name,               /**< name of variable pricer */
78   	      const char*        desc,               /**< description of variable pricer */
79   	      int                priority,           /**< priority of the variable pricer */
80   	      SCIP_Bool          delay               /**< should the pricer be delayed until no other pricers or already existing
81   	                                              *   problem variables with negative reduced costs are found?
82   	                                              *   if this is set to FALSE it may happen that the pricer produces columns
83   	                                              *   that already exist in the problem (which are also priced in by the
84   	                                              *   default problem variable pricing in the same round)
85   	                                              */
86   	      )
87   	      : scip_(scip),
88   	        scip_name_(0),
89   	        scip_desc_(0),
90   	        scip_priority_(priority),
91   	        scip_delay_(delay)
92   	   {
93   	      /* the macro SCIPduplicateMemoryArray does not need the first argument: */
94   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
95   	      SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
96   	   }
97   	
98   	   /** copy constructor */
99   	   ObjPricer(const ObjPricer& o) : ObjPricer(o.scip_, o.scip_name_, o.scip_desc_, o.scip_priority_, o.scip_delay_) {}
100  	
101  	   /** move constructor */
102  	   ObjPricer(ObjPricer&& o)
103  	       : scip_(o.scip_), scip_name_(0), scip_desc_(0), scip_priority_(o.scip_priority_), scip_delay_(o.scip_delay_)
104  	   {
105  	      std::swap(scip_name_, o.scip_name_);
106  	      std::swap(scip_desc_, o.scip_desc_);
107  	   }
108  	
109  	   /** destructor */
110  	   virtual ~ObjPricer()
111  	   {
112  	      /* the macro SCIPfreeMemoryArray does not need the first argument: */
113  	      /*lint --e{64}*/
114  	      SCIPfreeMemoryArray(scip_, &scip_name_);
115  	      SCIPfreeMemoryArray(scip_, &scip_desc_);
116  	   }
117  	
118  	   /** assignment of polymorphic classes causes slicing and is therefore disabled. */
119  	   ObjPricer& operator=(const ObjPricer& o) = delete;
120  	
121  	   /** assignment of polymorphic classes causes slicing and is therefore disabled. */
122  	   ObjPricer& operator=(ObjPricer&& o) = delete;
123  	
124  	   /** destructor of variable pricer to free user data (called when SCIP is exiting)
125  	    *
126  	    *  @see SCIP_DECL_PRICERFREE(x) in @ref type_pricer.h
127  	    */
128  	   virtual SCIP_DECL_PRICERFREE(scip_free)
129  	   {  /*lint --e{715}*/
130  	      return SCIP_OKAY;
131  	   }
132  	
133  	   /** initialization method of variable pricer (called after problem was transformed)
134  	    *
135  	    *  @see SCIP_DECL_PRICERINIT(x) in @ref type_pricer.h
136  	    */
137  	   virtual SCIP_DECL_PRICERINIT(scip_init)
138  	   {  /*lint --e{715}*/
139  	      return SCIP_OKAY;
140  	   }
141  	
142  	   /** deinitialization method of variable pricer (called before transformed problem is freed)
143  	    *
144  	    *  @see SCIP_DECL_PRICEREXIT(x) in @ref type_pricer.h
145  	    */
146  	   virtual SCIP_DECL_PRICEREXIT(scip_exit)
147  	   {  /*lint --e{715}*/
148  	      return SCIP_OKAY;
149  	   }
150  	
151  	   /** solving process initialization method of variable pricer (called when branch and bound process is about to begin)
152  	    *
153  	    *  @see SCIP_DECL_PRICERINITSOL(x) in @ref type_pricer.h
154  	    */
155  	   virtual SCIP_DECL_PRICERINITSOL(scip_initsol)
156  	   {  /*lint --e{715}*/
157  	      return SCIP_OKAY;
158  	   }
159  	
160  	   /** solving process deinitialization method of variable pricer (called before branch and bound process data is freed)
161  	    *
162  	    *  @see SCIP_DECL_PRICEREXITSOL(x) in @ref type_pricer.h
163  	    */
164  	   virtual SCIP_DECL_PRICEREXITSOL(scip_exitsol)
165  	   {  /*lint --e{715}*/
166  	      return SCIP_OKAY;
167  	   }
168  	
169  	   /** reduced cost pricing method of variable pricer for feasible LPs
170  	    *
171  	    *  @see SCIP_DECL_PRICERREDCOST(x) in @ref type_pricer.h
172  	    */
173  	   virtual SCIP_DECL_PRICERREDCOST(scip_redcost) = 0;
174  	
175  	   /** farkas pricing method of variable pricer for infeasible LPs
176  	    *
177  	    *  @see SCIP_DECL_PRICERFARKAS(x) in @ref type_pricer.h
178  	    */
179  	   virtual SCIP_DECL_PRICERFARKAS(scip_farkas)
180  	   {  /*lint --e{715}*/
181  	      return SCIP_OKAY;
182  	   }
183  	};
184  	
185  	} /* namespace scip */
186  	
187  	
188  	
189  	/** creates the variable pricer for the given variable pricer object and includes it in SCIP
190  	 *
191  	 *  The method should be called in one of the following ways:
192  	 *
193  	 *   1. The user is resposible of deleting the object:
194  	 *       SCIP_CALL( SCIPcreate(&scip) );
195  	 *       ...
196  	 *       MyPricer* mypricer = new MyPricer(...);
197  	 *       SCIP_CALL( SCIPincludeObjPricer(scip, &mypricer, FALSE) );
198  	 *       ...
199  	 *       SCIP_CALL( SCIPfree(&scip) );
200  	 *       delete mypricer;    // delete pricer AFTER SCIPfree() !
201  	 *
202  	 *   2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
203  	 *       SCIP_CALL( SCIPcreate(&scip) );
204  	 *       ...
205  	 *       SCIP_CALL( SCIPincludeObjPricer(scip, new MyPricer(...), TRUE) );
206  	 *       ...
207  	 *       SCIP_CALL( SCIPfree(&scip) );  // destructor of MyPricer is called here
208  	 */
209  	SCIP_EXPORT
210  	SCIP_RETCODE SCIPincludeObjPricer(
211  	   SCIP*                 scip,               /**< SCIP data structure */
212  	   scip::ObjPricer*      objpricer,          /**< variable pricer object */
213  	   SCIP_Bool             deleteobject        /**< should the pricer object be deleted when pricer is freed? */
214  	   );
215  	
216  	/** returns the variable pricer object of the given name, or 0 if not existing */
217  	SCIP_EXPORT
218  	scip::ObjPricer* SCIPfindObjPricer(
219  	   SCIP*                 scip,               /**< SCIP data structure */
220  	   const char*           name                /**< name of variable pricer */
221  	   );
222  	
223  	/** returns the variable pricer object for the given pricer */
224  	SCIP_EXPORT
225  	scip::ObjPricer* SCIPgetObjPricer(
226  	   SCIP*                 scip,               /**< SCIP data structure */
227  	   SCIP_PRICER*          pricer              /**< pricer */
228  	   );
229  	
230  	#endif
231