Scippy

SCIP

Solving Constraint Integer Programs

objpricer.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2018 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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objpricer.h
17  * @brief C++ wrapper for variable pricers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #ifndef __SCIP_OBJPRICER_H__
24 #define __SCIP_OBJPRICER_H__
25 
26 #include <cstring>
27 
28 #include "scip/scip.h"
30 
31 namespace scip
32 {
33 
34 /** @brief C++ wrapper for variable pricer
35  *
36  * This class defines the interface for variable pricer implemented in C++. Note that there is a pure virtual
37  * function (this function has to be implemented). This function is: scip_redcost().
38  *
39  * - \ref PRICER "Instructions for implementing a variable pricer"
40  * - \ref type_pricer.h "Corresponding C interface"
41  */
43 {
44 public:
45  /*lint --e{1540}*/
46 
47  /** SCIP data structure */
49 
50  /** name of the variable pricer */
51  char* scip_name_;
52 
53  /** description of the variable pricer */
54  char* scip_desc_;
55 
56  /** default priority of the variable pricer */
57  const int scip_priority_;
58 
59  /** should the pricer be delayed until no other pricers or already existing problem variables with negative reduced
60  * costs are found?
61  */
63 
64  /** default constructor */
66  SCIP* scip, /**< SCIP data structure */
67  const char* name, /**< name of variable pricer */
68  const char* desc, /**< description of variable pricer */
69  int priority, /**< priority of the variable pricer */
70  SCIP_Bool delay /**< should the pricer be delayed until no other pricers or already existing
71  * problem variables with negative reduced costs are found?
72  * if this is set to FALSE it may happen that the pricer produces columns
73  * that already exist in the problem (which are also priced in by the
74  * default problem variable pricing in the same round)
75  */
76  )
77  : scip_(scip),
78  scip_name_(0),
79  scip_desc_(0),
80  scip_priority_(priority),
81  scip_delay_(delay)
82  {
83  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
84  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
85  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
86  }
87 
88  /** destructor */
89  virtual ~ObjPricer()
90  {
91  /* the macro SCIPfreeMemoryArray does not need the first argument: */
92  /*lint --e{64}*/
93  SCIPfreeMemoryArray(scip_, &scip_name_);
94  SCIPfreeMemoryArray(scip_, &scip_desc_);
95  }
96 
97  /** destructor of variable pricer to free user data (called when SCIP is exiting)
98  *
99  * @see SCIP_DECL_PRICERFREE(x) in @ref type_pricer.h
100  */
101  virtual SCIP_DECL_PRICERFREE(scip_free)
102  { /*lint --e{715}*/
103  return SCIP_OKAY;
104  }
105 
106  /** initialization method of variable pricer (called after problem was transformed)
107  *
108  * @see SCIP_DECL_PRICERINIT(x) in @ref type_pricer.h
109  */
110  virtual SCIP_DECL_PRICERINIT(scip_init)
111  { /*lint --e{715}*/
112  return SCIP_OKAY;
113  }
114 
115  /** deinitialization method of variable pricer (called before transformed problem is freed)
116  *
117  * @see SCIP_DECL_PRICEREXIT(x) in @ref type_pricer.h
118  */
119  virtual SCIP_DECL_PRICEREXIT(scip_exit)
120  { /*lint --e{715}*/
121  return SCIP_OKAY;
122  }
123 
124  /** solving process initialization method of variable pricer (called when branch and bound process is about to begin)
125  *
126  * @see SCIP_DECL_PRICERINITSOL(x) in @ref type_pricer.h
127  */
128  virtual SCIP_DECL_PRICERINITSOL(scip_initsol)
129  { /*lint --e{715}*/
130  return SCIP_OKAY;
131  }
132 
133  /** solving process deinitialization method of variable pricer (called before branch and bound process data is freed)
134  *
135  * @see SCIP_DECL_PRICEREXITSOL(x) in @ref type_pricer.h
136  */
137  virtual SCIP_DECL_PRICEREXITSOL(scip_exitsol)
138  { /*lint --e{715}*/
139  return SCIP_OKAY;
140  }
141 
142  /** reduced cost pricing method of variable pricer for feasible LPs
143  *
144  * @see SCIP_DECL_PRICERREDCOST(x) in @ref type_pricer.h
145  */
146  virtual SCIP_DECL_PRICERREDCOST(scip_redcost) = 0;
147 
148  /** farkas pricing method of variable pricer for infeasible LPs
149  *
150  * @see SCIP_DECL_PRICERFARKAS(x) in @ref type_pricer.h
151  */
152  virtual SCIP_DECL_PRICERFARKAS(scip_farkas)
153  { /*lint --e{715}*/
154  return SCIP_OKAY;
155  }
156 };
157 
158 } /* namespace scip */
159 
160 
161 
162 /** creates the variable pricer for the given variable pricer object and includes it in SCIP
163  *
164  * The method should be called in one of the following ways:
165  *
166  * 1. The user is resposible of deleting the object:
167  * SCIP_CALL( SCIPcreate(&scip) );
168  * ...
169  * MyPricer* mypricer = new MyPricer(...);
170  * SCIP_CALL( SCIPincludeObjPricer(scip, &mypricer, FALSE) );
171  * ...
172  * SCIP_CALL( SCIPfree(&scip) );
173  * delete mypricer; // delete pricer AFTER SCIPfree() !
174  *
175  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
176  * SCIP_CALL( SCIPcreate(&scip) );
177  * ...
178  * SCIP_CALL( SCIPincludeObjPricer(scip, new MyPricer(...), TRUE) );
179  * ...
180  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyPricer is called here
181  */
182 extern
184  SCIP* scip, /**< SCIP data structure */
185  scip::ObjPricer* objpricer, /**< variable pricer object */
186  SCIP_Bool deleteobject /**< should the pricer object be deleted when pricer is freed? */
187  );
188 
189 /** returns the variable pricer object of the given name, or 0 if not existing */
190 extern
192  SCIP* scip, /**< SCIP data structure */
193  const char* name /**< name of variable pricer */
194  );
195 
196 /** returns the variable pricer object for the given pricer */
197 extern
199  SCIP* scip, /**< SCIP data structure */
200  SCIP_PRICER* pricer /**< pricer */
201  );
202 
203 #endif
Definition of base class for all clonable classes which define problem data.
C++ wrapper for variable pricer.
Definition: objpricer.h:42
virtual SCIP_DECL_PRICERREDCOST(scip_redcost)=0
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:84
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:88
SCIP * scip_
Definition: objpricer.h:48
virtual ~ObjPricer()
Definition: objpricer.h:89
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
virtual SCIP_DECL_PRICERINITSOL(scip_initsol)
Definition: objpricer.h:128
SCIP_RETCODE SCIPincludeObjPricer(SCIP *scip, scip::ObjPricer *objpricer, SCIP_Bool deleteobject)
Definition: objpricer.cpp:212
virtual SCIP_DECL_PRICERFARKAS(scip_farkas)
Definition: objpricer.h:152
char * scip_desc_
Definition: objpricer.h:54
virtual SCIP_DECL_PRICERFREE(scip_free)
Definition: objpricer.h:101
#define SCIP_Bool
Definition: def.h:62
ObjPricer(SCIP *scip, const char *name, const char *desc, int priority, SCIP_Bool delay)
Definition: objpricer.h:65
char * scip_name_
Definition: objpricer.h:51
Definition of base class for all clonable classes which define problem data.
virtual SCIP_DECL_PRICERINIT(scip_init)
Definition: objpricer.h:110
scip::ObjPricer * SCIPfindObjPricer(SCIP *scip, const char *name)
Definition: objpricer.cpp:240
const SCIP_Bool scip_delay_
Definition: objpricer.h:62
const int scip_priority_
Definition: objpricer.h:57
#define SCIP_CALL_ABORT(x)
Definition: def.h:330
virtual SCIP_DECL_PRICEREXIT(scip_exit)
Definition: objpricer.h:119
virtual SCIP_DECL_PRICEREXITSOL(scip_exitsol)
Definition: objpricer.h:137
SCIP callable library.
scip::ObjPricer * SCIPgetObjPricer(SCIP *scip, SCIP_PRICER *pricer)
Definition: objpricer.cpp:259