Scippy

SCIP

Solving Constraint Integer Programs

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