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