Scippy

SCIP

Solving Constraint Integer Programs

objpresol.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 objpresol.h
26  * @brief C++ wrapper for presolvers
27  * @author Tobias Achterberg
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #ifndef __SCIP_OBJPRESOL_H__
33 #define __SCIP_OBJPRESOL_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 presolvers
45  *
46  * This class defines the interface for presolvers 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 PRESOL "Instructions for implementing a presolver"
50  * - \ref PRESOLVERS "List of available presolvers"
51  * - \ref type_presol.h "Corresponding C interface"
52  */
53 class ObjPresol : public ObjCloneable
54 {
55 public:
56  /*lint --e{1540}*/
57 
58  /** SCIP data structure */
60 
61  /** name of the presolver */
62  char* scip_name_;
63 
64  /** description of the presolver */
65  char* scip_desc_;
66 
67  /** default priority of the presolver */
68  const int scip_priority_;
69 
70  /** default maximal number of presolving rounds the presolver participates in (-1: no limit) */
71  const int scip_maxrounds_;
72 
73  /**< timing mask of the presolver */
75 
76  /** default constructor */
78  SCIP* scip, /**< SCIP data structure */
79  const char* name, /**< name of presolver */
80  const char* desc, /**< description of presolver */
81  int priority, /**< priority of the presolver */
82  int maxrounds, /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
83  SCIP_PRESOLTIMING timing /**< timing mask of the presolver */
84  )
85  : scip_(scip),
86  scip_name_(0),
87  scip_desc_(0),
88  scip_priority_(priority),
89  scip_maxrounds_(maxrounds),
90  scip_timing_(timing)
91  {
92  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
93  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
94  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
95  }
96 
97  /** copy constructor */
98  ObjPresol(const ObjPresol& o)
99  : ObjPresol(o.scip_, o.scip_name_, o.scip_desc_, o.scip_priority_, o.scip_maxrounds_, o.scip_timing_)
100  {
101  }
102 
103  /** move constructor */
105  : scip_(o.scip_),
106  scip_name_(0),
107  scip_desc_(0),
108  scip_priority_(o.scip_priority_),
109  scip_maxrounds_(o.scip_maxrounds_),
110  scip_timing_(o.scip_timing_)
111  {
112  std::swap(scip_name_, o.scip_name_);
113  std::swap(scip_desc_, o.scip_desc_);
114  }
115 
116  /** destructor */
117  virtual ~ObjPresol()
118  {
119  /* the macro SCIPfreeMemoryArray does not need the first argument: */
120  /*lint --e{64}*/
121  SCIPfreeMemoryArray(scip_, &scip_name_);
122  SCIPfreeMemoryArray(scip_, &scip_desc_);
123  }
124 
125  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
126  ObjPresol& operator=(const ObjPresol& o) = delete;
127 
128  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
129  ObjPresol& operator=(ObjPresol&& o) = delete;
130 
131  /** destructor of presolver to free user data (called when SCIP is exiting)
132  *
133  * @see SCIP_DECL_PRESOLFREE(x) in @ref type_prop.h
134  */
135  virtual SCIP_DECL_PRESOLFREE(scip_free)
136  { /*lint --e{715}*/
137  return SCIP_OKAY;
138  }
139 
140  /** initialization method of presolver (called after problem was transformed)
141  *
142  * @see SCIP_DECL_PRESOLINIT(x) in @ref type_prop.h
143  */
144  virtual SCIP_DECL_PRESOLINIT(scip_init)
145  { /*lint --e{715}*/
146  return SCIP_OKAY;
147  }
148 
149  /** deinitialization method of presolver (called before transformed problem is freed)
150  *
151  * @see SCIP_DECL_PRESOLEXIT(x) in @ref type_prop.h
152  */
153  virtual SCIP_DECL_PRESOLEXIT(scip_exit)
154  { /*lint --e{715}*/
155  return SCIP_OKAY;
156  }
157 
158  /** presolving initialization method of presolver (called when presolving is about to begin)
159  *
160  * @see SCIP_DECL_PRESOLINITPRE(x) in @ref type_prop.h
161  */
162  virtual SCIP_DECL_PRESOLINITPRE(scip_initpre)
163  { /*lint --e{715}*/
164  return SCIP_OKAY;
165  }
166 
167  /** presolving deinitialization method of presolver (called after presolving has been finished)
168  *
169  * @see SCIP_DECL_PRESOLEXITPRE(x) in @ref type_prop.h
170  */
171  virtual SCIP_DECL_PRESOLEXITPRE(scip_exitpre)
172  { /*lint --e{715}*/
173  return SCIP_OKAY;
174  }
175 
176  /** execution method of presolver
177  *
178  * @see SCIP_DECL_PRESOLEXEC(x) in @ref type_prop.h
179  */
180  virtual SCIP_DECL_PRESOLEXEC(scip_exec) = 0;
181 };
182 
183 } /* namespace scip */
184 
185 
186 
187 /** creates the presolver for the given presolver object and includes it in SCIP
188  *
189  * The method should be called in one of the following ways:
190  *
191  * 1. The user is resposible of deleting the object:
192  * SCIP_CALL( SCIPcreate(&scip) );
193  * ...
194  * MyPresol* mypresol = new MyPresol(...);
195  * SCIP_CALL( SCIPincludeObjPresol(scip, &mypresol, FALSE) );
196  * ...
197  * SCIP_CALL( SCIPfree(&scip) );
198  * delete mypresol; // delete presol AFTER SCIPfree() !
199  *
200  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
201  * SCIP_CALL( SCIPcreate(&scip) );
202  * ...
203  * SCIP_CALL( SCIPincludeObjPresol(scip, new MyPresol(...), TRUE) );
204  * ...
205  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyPresol is called here
206  */
207 SCIP_EXPORT
209  SCIP* scip, /**< SCIP data structure */
210  scip::ObjPresol* objpresol, /**< presolver object */
211  SCIP_Bool deleteobject /**< should the presolver object be deleted when presolver is freed? */
212  );
213 
214 /** returns the presol object of the given name, or 0 if not existing */
215 SCIP_EXPORT
217  SCIP* scip, /**< SCIP data structure */
218  const char* name /**< name of presolver */
219  );
220 
221 /** returns the presol object for the given presolver */
222 SCIP_EXPORT
224  SCIP* scip, /**< SCIP data structure */
225  SCIP_PRESOL* presol /**< presolver */
226  );
227 
228 #endif
virtual SCIP_DECL_PRESOLINITPRE(scip_initpre)
Definition: objpresol.h:162
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
const int scip_priority_
Definition: objpresol.h:68
virtual ~ObjPresol()
Definition: objpresol.h:117
ObjPresol(SCIP *scip, const char *name, const char *desc, int priority, int maxrounds, SCIP_PRESOLTIMING timing)
Definition: objpresol.h:77
C++ wrapper for presolvers.
Definition: objpresol.h:53
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
const SCIP_PRESOLTIMING scip_timing_
Definition: objpresol.h:74
char * scip_desc_
Definition: objpresol.h:65
char * scip_name_
Definition: objpresol.h:62
ObjPresol & operator=(const ObjPresol &o)=delete
definition of base class for all clonable classes
virtual SCIP_DECL_PRESOLFREE(scip_free)
Definition: objpresol.h:135
const int scip_maxrounds_
Definition: objpresol.h:71
unsigned int SCIP_PRESOLTIMING
Definition: type_timing.h:61
ObjPresol(ObjPresol &&o)
Definition: objpresol.h:104
#define SCIP_Bool
Definition: def.h:91
scip::ObjPresol * SCIPfindObjPresol(SCIP *scip, const char *name)
Definition: objpresol.cpp:235
virtual SCIP_DECL_PRESOLEXEC(scip_exec)=0
SCIP * scip_
Definition: objpresol.h:59
ObjPresol(const ObjPresol &o)
Definition: objpresol.h:98
scip::ObjPresol * SCIPgetObjPresol(SCIP *scip, SCIP_PRESOL *presol)
Definition: objpresol.cpp:254
Definition of base class for all clonable classes.
Definition: objcloneable.h:47
virtual SCIP_DECL_PRESOLEXITPRE(scip_exitpre)
Definition: objpresol.h:171
virtual SCIP_DECL_PRESOLINIT(scip_init)
Definition: objpresol.h:144
SCIP_RETCODE SCIPincludeObjPresol(SCIP *scip, scip::ObjPresol *objpresol, SCIP_Bool deleteobject)
Definition: objpresol.cpp:208
#define SCIP_CALL_ABORT(x)
Definition: def.h:359
virtual SCIP_DECL_PRESOLEXIT(scip_exit)
Definition: objpresol.h:153
SCIP callable library.