Scippy

SCIP

Solving Constraint Integer Programs

objcutsel.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 objcutsel.h
26  * @brief C++ wrapper for cut selectors
27  * @author Felipe Serrano
28  * @author Mark Turner
29  */
30 
31 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32 
33 #ifndef __SCIP_OBJCUTSEL_H__
34 #define __SCIP_OBJCUTSEL_H__
35 
36 #include <cstring>
37 #include <utility>
38 
39 #include "scip/scip.h"
40 #include "objscip/objcloneable.h"
41 
42 namespace scip
43 {
44 
45 /** @brief C++ wrapper for cut selectors
46  *
47  * This class defines the interface for cut selectors implemented in C++.
48  *
49  * - \ref CUTSEL "Instructions for implementing a cut selector"
50  * - \ref CUTSELECTORS "List of available cut selectors"
51  * - \ref type_cutsel.h "Corresponding C interface"
52  */
53 class ObjCutsel : public ObjCloneable
54 {
55 public:
56  /*lint --e{1540}*/
57 
58  /** SCIP data structure */
60 
61  /** name of the cut selector */
62  char* scip_name_;
63 
64  /** description of the cut selector */
65  char* scip_desc_;
66 
67  /** priority of the cut selector */
68  const int scip_priority_;
69 
70  /** default constructor */
72  SCIP* scip, /**< SCIP data structure */
73  const char* name, /**< name of cut selector */
74  const char* desc, /**< description of cut selector */
75  int priority /**< priority of the cut */
76  )
77  : scip_(scip),
78  scip_name_(0),
79  scip_desc_(0),
80  scip_priority_(priority)
81  {
82  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
83  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
84  }
85 
86  /** copy constructor */
87  ObjCutsel(const ObjCutsel& o) : ObjCutsel(o.scip_, o.scip_name_, o.scip_desc_, o.scip_priority_) {}
88 
89  /** move constructor */
90  ObjCutsel(ObjCutsel&& o) : scip_(o.scip_), scip_name_(0), scip_desc_(0), scip_priority_(o.scip_priority_)
91  {
92  std::swap(scip_name_, o.scip_name_);
93  std::swap(scip_desc_, o.scip_desc_);
94  }
95 
96  /** destructor */
97  virtual ~ObjCutsel()
98  {
99  /*lint --e{64}*/
100  SCIPfreeMemoryArray(scip_, &scip_name_);
101  SCIPfreeMemoryArray(scip_, &scip_desc_);
102  }
103 
104  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
105  ObjCutsel& operator=(const ObjCutsel& o) = delete;
106 
107  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
108  ObjCutsel& operator=(ObjCutsel&& o) = delete;
109 
110  /** destructor of cut selector to free user data (called when SCIP is exiting)
111  *
112  * @see SCIP_DECL_CUTSELFREE(x) in @ref type_cutsel.h
113  */
114  virtual SCIP_DECL_CUTSELFREE(scip_free)
115  { /*lint --e{715}*/
116  return SCIP_OKAY;
117  }
118 
119  /** initialization method of cut selector (called after problem was transformed)
120  *
121  * @see SCIP_DECL_CUTSELINIT(x) in @ref type_cutsel.h
122  */
123  virtual SCIP_DECL_CUTSELINIT(scip_init)
124  { /*lint --e{715}*/
125  return SCIP_OKAY;
126  }
127 
128  /** deinitialization method of cut selector (called before transformed problem is freed)
129  *
130  * @see SCIP_DECL_CUTSELEXIT(x) in @ref type_cutsel.h
131  */
132  virtual SCIP_DECL_CUTSELEXIT(scip_exit)
133  { /*lint --e{715}*/
134  return SCIP_OKAY;
135  }
136 
137  /** solving process initialization method of cut selector (called when branch and bound process is about to begin)
138  *
139  * @see SCIP_DECL_CUTSELINITSOL(x) in @ref type_cutsel.h
140  */
141  virtual SCIP_DECL_CUTSELINITSOL(scip_initsol)
142  { /*lint --e{715}*/
143  return SCIP_OKAY;
144  }
145 
146  /** solving process deinitialization method of cut selector (called before branch and bound process data is freed)
147  *
148  * @see SCIP_DECL_CUTSELEXITSOL(x) in @ref type_cutsel.h
149  */
150  virtual SCIP_DECL_CUTSELEXITSOL(scip_exitsol)
151  { /*lint --e{715}*/
152  return SCIP_OKAY;
153  }
154 
155  /** cut selection method of cut selector
156  *
157  * @see SCIP_DECL_CUTSELSELECT(x) in @ref type_cutsel.h
158  */
159  virtual SCIP_DECL_CUTSELSELECT(scip_select) = 0;
160 };
161 
162 } /* namespace scip */
163 
164 
165 
166 /** creates the cut selector for the given cut selector object and includes it in SCIP
167  *
168  * The method should be called in one of the following ways:
169  *
170  * 1. The user is responsible for deleting the object:
171  * SCIP_CALL( SCIPcreate(&scip) );
172  * ...
173  * MyCutsel* mycutsel = new MyCutsel(...);
174  * SCIP_CALL( SCIPincludeObjCutsel(scip, &mycutsel, FALSE) );
175  * ...
176  * SCIP_CALL( SCIPfree(&scip) );
177  * delete mycutsel; // delete cutsel AFTER SCIPfree() !
178  *
179  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
180  * SCIP_CALL( SCIPcreate(&scip) );
181  * ...
182  * SCIP_CALL( SCIPincludeObjCutsel(scip, new MyCutsel(...), TRUE) );
183  * ...
184  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyCutsel is called here
185  */
186 SCIP_EXPORT
188  SCIP* scip, /**< SCIP data structure */
189  scip::ObjCutsel* objcutsel, /**< cut selector object */
190  SCIP_Bool deleteobject /**< should the cut selector object be deleted when cut selector is freed? */
191  );
192 
193 /** returns the cutsel object of the given name, or 0 if not existing */
194 SCIP_EXPORT
196  SCIP* scip, /**< SCIP data structure */
197  const char* name /**< name of cut selector */
198  );
199 
200 /** returns the cutsel object for the given cut selector */
201 SCIP_EXPORT
203  SCIP* scip, /**< SCIP data structure */
204  SCIP_CUTSEL* cutsel /**< cut selector */
205  );
206 
207 #endif
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
scip::ObjCutsel * SCIPgetObjCutsel(SCIP *scip, SCIP_CUTSEL *cutsel)
Definition: objcutsel.cpp:253
virtual SCIP_DECL_CUTSELINIT(scip_init)
Definition: objcutsel.h:123
scip::ObjCutsel * SCIPfindObjCutsel(SCIP *scip, const char *name)
Definition: objcutsel.cpp:234
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
virtual SCIP_DECL_CUTSELEXIT(scip_exit)
Definition: objcutsel.h:132
const int scip_priority_
Definition: objcutsel.h:68
char * scip_name_
Definition: objcutsel.h:62
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
ObjCutsel(ObjCutsel &&o)
Definition: objcutsel.h:90
ObjCutsel & operator=(const ObjCutsel &o)=delete
definition of base class for all clonable classes
SCIP * scip_
Definition: objcutsel.h:59
virtual SCIP_DECL_CUTSELEXITSOL(scip_exitsol)
Definition: objcutsel.h:150
SCIP_RETCODE SCIPincludeObjCutsel(SCIP *scip, scip::ObjCutsel *objcutsel, SCIP_Bool deleteobject)
Definition: objcutsel.cpp:206
#define SCIP_Bool
Definition: def.h:91
C++ wrapper for cut selectors.
Definition: objcutsel.h:53
virtual SCIP_DECL_CUTSELINITSOL(scip_initsol)
Definition: objcutsel.h:141
char * scip_desc_
Definition: objcutsel.h:65
ObjCutsel(const ObjCutsel &o)
Definition: objcutsel.h:87
Definition of base class for all clonable classes.
Definition: objcloneable.h:47
virtual SCIP_DECL_CUTSELFREE(scip_free)
Definition: objcutsel.h:114
virtual SCIP_DECL_CUTSELSELECT(scip_select)=0
virtual ~ObjCutsel()
Definition: objcutsel.h:97
ObjCutsel(SCIP *scip, const char *name, const char *desc, int priority)
Definition: objcutsel.h:71
#define SCIP_CALL_ABORT(x)
Definition: def.h:359
SCIP callable library.