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-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 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  */
43 class ObjProp : public ObjCloneable
44 {
45 public:
46  /*lint --e{1540}*/
47 
48  /** SCIP data structure */
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? */
65 
66  /** positions in the node solving loop where propagator should be executed */
68 
69  /** default presolving priority of the propagator */
71 
72  /** frequency for calling propagator */
74 
75  /**< timing mask of the propagator's presolving method */
77 
78 
79  /** default constructor */
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}*/
113  SCIPfreeMemoryArray(scip_, &scip_name_);
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 extern
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 extern
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 extern
253  SCIP* scip, /**< SCIP data structure */
254  SCIP_PROP* prop /**< propagator */
255  );
256 
257 #endif
const SCIP_PRESOLTIMING scip_presol_timing_
Definition: objprop.h:76
virtual SCIP_DECL_PROPEXEC(scip_exec)=0
virtual SCIP_DECL_PROPFREE(scip_free)
Definition: objprop.h:121
#define NULL
Definition: def.h:239
const SCIP_Bool scip_delay_
Definition: objprop.h:64
SCIP_RETCODE SCIPincludeObjProp(SCIP *scip, scip::ObjProp *objprop, SCIP_Bool deleteobject)
Definition: objprop.cpp:267
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:84
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:88
C++ wrapper for propagators.
Definition: objprop.h:43
virtual ~ObjProp()
Definition: objprop.h:109
char * scip_desc_
Definition: objprop.h:55
virtual SCIP_DECL_PROPEXITSOL(scip_exitsol)
Definition: objprop.h:175
virtual SCIP_DECL_PROPINITSOL(scip_initsol)
Definition: objprop.h:166
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
const int scip_priority_
Definition: objprop.h:58
const int scip_freq_
Definition: objprop.h:61
definition of base class for all clonable classes
virtual SCIP_DECL_PROPPRESOL(scip_presol)
Definition: objprop.h:184
virtual SCIP_DECL_PROPRESPROP(scip_resprop)
Definition: objprop.h:201
char * scip_name_
Definition: objprop.h:52
virtual SCIP_DECL_PROPEXIT(scip_exit)
Definition: objprop.h:139
SCIP * scip_
Definition: objprop.h:49
const SCIP_PROPTIMING scip_timingmask_
Definition: objprop.h:67
unsigned int SCIP_PRESOLTIMING
Definition: type_timing.h:52
scip::ObjProp * SCIPgetObjProp(SCIP *scip, SCIP_PROP *prop)
Definition: objprop.cpp:314
#define SCIP_Bool
Definition: def.h:62
const int scip_presol_maxrounds_
Definition: objprop.h:73
virtual SCIP_DECL_PROPINITPRE(scip_initpre)
Definition: objprop.h:148
const int scip_presol_priority_
Definition: objprop.h:70
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:80
unsigned int SCIP_PROPTIMING
Definition: type_timing.h:66
virtual SCIP_DECL_PROPINIT(scip_init)
Definition: objprop.h:130
Definition of base class for all clonable classes.
Definition: objcloneable.h:38
scip::ObjProp * SCIPfindObjProp(SCIP *scip, const char *name)
Definition: objprop.cpp:295
virtual SCIP_DECL_PROPEXITPRE(scip_exitpre)
Definition: objprop.h:157
#define SCIP_CALL_ABORT(x)
Definition: def.h:330
SCIP callable library.