Scippy

SCIP

Solving Constraint Integer Programs

objbranchrule.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 2002-2022 Zuse Institute Berlin */
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 objbranchrule.h
26  * @brief C++ wrapper for branching rules
27  * @author Tobias Achterberg
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #ifndef __SCIP_OBJBRANCHRULE_H__
33 #define __SCIP_OBJBRANCHRULE_H__
34 
35 
36 #include <cassert>
37 #include <cstring>
38 #include <utility>
39 
40 #include "scip/scip.h"
41 #include "objscip/objcloneable.h"
42 
43 namespace scip
44 {
45 
46 /**
47  * @brief C++ wrapper for branching rules
48  *
49  * This class defines the interface for branching rules implemented in C++.
50  *
51  * - \ref BRANCH "Instructions for implementing a branching rule"
52  * - \ref BRANCHINGRULES "List of available branching rules"
53  * - \ref type_branch.h "Corresponding C interface"
54  */
56 {
57 public:
58  /*lint --e{1540}*/
59 
60  /** SCIP data structure */
62 
63  /** name of the branching rule */
64  char* scip_name_;
65 
66  /** description of the branching rule */
67  char* scip_desc_;
68 
69  /** default priority of the branching rule */
70  const int scip_priority_;
71 
72  /** default maximal depth for applying the branching rule */
73  const int scip_maxdepth_;
74 
75  /** default maximal relative distance from current node's dual bound to primal bound
76  * compared to best node's dual bound for applying branching rule
77  * (0.0: only on current best node, 1.0: on all nodes)
78  */
80 
81  /** default constructor */
83  SCIP* scip, /**< SCIP data structure */
84  const char* name, /**< name of branching rule */
85  const char* desc, /**< description of branching rule */
86  int priority, /**< priority of the branching rule */
87  int maxdepth, /**< maximal depth level, up to which this branching rule should be used (or -1) */
88  SCIP_Real maxbounddist /**< maximal relative distance from current node's dual bound to primal bound
89  * compared to best node's dual bound for applying branching rule
90  * (0.0: only on current best node, 1.0: on all nodes) */
91  )
92  : scip_(scip),
93  scip_name_(0),
94  scip_desc_(0),
95  scip_priority_(priority),
96  scip_maxdepth_(maxdepth),
97  scip_maxbounddist_(maxbounddist)
98  {
99  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
100  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
101  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
102  }
103 
104  /** copy constructor */
106  : ObjBranchrule(o.scip_, o.scip_name_, o.scip_desc_, o.scip_priority_, o.scip_maxdepth_, o.scip_maxbounddist_)
107  {
108  }
109 
110  /** move constructor */
112  : scip_(o.scip_),
113  scip_name_(0),
114  scip_desc_(0),
115  scip_priority_(o.scip_priority_),
116  scip_maxdepth_(o.scip_maxdepth_),
117  scip_maxbounddist_(o.scip_maxbounddist_)
118  {
119  std::swap(scip_name_, o.scip_name_);
120  std::swap(scip_desc_, o.scip_desc_);
121  }
122 
123  /** destructor */
124  virtual ~ObjBranchrule()
125  {
126  /* the macro SCIPfreeMemoryArray does not need the first argument: */
127  /*lint --e{64}*/
128  SCIPfreeMemoryArray(scip_, &scip_name_);
129  SCIPfreeMemoryArray(scip_, &scip_desc_);
130  }
131 
132  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
133  ObjBranchrule& operator=(const ObjBranchrule& o) = delete;
134 
135  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
136  ObjBranchrule& operator=(ObjBranchrule&& o) = delete;
137 
138  /** destructor of branching rule to free user data (called when SCIP is exiting)
139  *
140  * @see SCIP_DECL_BRANCHFREE(x) in @ref type_branch.h
141  */
142  virtual SCIP_DECL_BRANCHFREE(scip_free)
143  { /*lint --e{715}*/
144  return SCIP_OKAY;
145  }
146 
147  /** initialization method of branching rule (called after problem was transformed)
148  *
149  * @see SCIP_DECL_BRANCHINIT(x) in @ref type_branch.h
150  */
151  virtual SCIP_DECL_BRANCHINIT(scip_init)
152  { /*lint --e{715}*/
153  return SCIP_OKAY;
154  }
155 
156  /** deinitialization method of branching rule (called before transformed problem is freed)
157  *
158  * @see SCIP_DECL_BRANCHEXIT(x) in @ref type_branch.h
159  */
160  virtual SCIP_DECL_BRANCHEXIT(scip_exit)
161  { /*lint --e{715}*/
162  return SCIP_OKAY;
163  }
164 
165  /** solving process initialization method of branching rule (called when branch and bound process is about to begin)
166  *
167  * @see SCIP_DECL_BRANCHINITSOL(x) in @ref type_branch.h
168  */
169  virtual SCIP_DECL_BRANCHINITSOL(scip_initsol)
170  { /*lint --e{715}*/
171  return SCIP_OKAY;
172  }
173 
174  /** solving process deinitialization method of branching rule (called before branch and bound process data is freed)
175  *
176  * @see SCIP_DECL_BRANCHEXITSOL(x) in @ref type_branch.h
177  */
178  virtual SCIP_DECL_BRANCHEXITSOL(scip_exitsol)
179  { /*lint --e{715}*/
180  return SCIP_OKAY;
181  }
182 
183  /** branching execution method for fractional LP solutions
184  *
185  * @see SCIP_DECL_BRANCHEXECLP(x) in @ref type_branch.h
186  */
187  virtual SCIP_DECL_BRANCHEXECLP(scip_execlp)
188  { /*lint --e{715}*/
189  assert(result != NULL);
190  *result = SCIP_DIDNOTRUN;
191  return SCIP_OKAY;
192  }
193 
194  /** branching execution method for external candidates
195  *
196  * @see SCIP_DECL_BRANCHEXECEXT(x) in @ref type_branch.h
197  */
198  virtual SCIP_DECL_BRANCHEXECEXT(scip_execext)
199  { /*lint --e{715}*/
200  assert(result != NULL);
201  *result = SCIP_DIDNOTRUN;
202  return SCIP_OKAY;
203  }
204 
205  /** branching execution method for not completely fixed pseudo solutions
206  *
207  * @see SCIP_DECL_BRANCHEXECPS(x) in @ref type_branch.h
208  */
209  virtual SCIP_DECL_BRANCHEXECPS(scip_execps)
210  { /*lint --e{715}*/
211  assert(result != NULL);
212  *result = SCIP_DIDNOTRUN;
213  return SCIP_OKAY;
214  }
215 };
216 
217 } /* namespace scip */
218 
219 
220 /** creates the branching rule for the given branching rule object and includes it in SCIP
221  *
222  * The method should be called in one of the following ways:
223  *
224  * 1. The user is resposible of deleting the object:
225  * SCIP_CALL( SCIPcreate(&scip) );
226  * ...
227  * MyBranchrule* mybranchrule = new MyBranchrule(...);
228  * SCIP_CALL( SCIPincludeObjBranchrule(scip, &mybranchrule, FALSE) );
229  * ...
230  * SCIP_CALL( SCIPfree(&scip) );
231  * delete mybranchrule; // delete branchrule AFTER SCIPfree() !
232  *
233  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
234  * SCIP_CALL( SCIPcreate(&scip) );
235  * ...
236  * SCIP_CALL( SCIPincludeObjBranchrule(scip, new MyBranchrule(...), TRUE) );
237  * ...
238  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyBranchrule is called here
239  */
240 SCIP_EXPORT
242  SCIP* scip, /**< SCIP data structure */
243  scip::ObjBranchrule* objbranchrule, /**< branching rule object */
244  SCIP_Bool deleteobject /**< should the branching rule object be deleted when branching rule is freed? */
245  );
246 
247 /** returns the branchrule object of the given name, or 0 if not existing */
248 SCIP_EXPORT
250  SCIP* scip, /**< SCIP data structure */
251  const char* name /**< name of branching rule */
252  );
253 
254 /** returns the branchrule object for the given branching rule */
255 SCIP_EXPORT
257  SCIP* scip, /**< SCIP data structure */
258  SCIP_BRANCHRULE* branchrule /**< branching rule */
259  );
260 
261 #endif
virtual SCIP_DECL_BRANCHEXECLP(scip_execlp)
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
ObjBranchrule(const ObjBranchrule &o)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
virtual SCIP_DECL_BRANCHEXIT(scip_exit)
ObjBranchrule(SCIP *scip, const char *name, const char *desc, int priority, int maxdepth, SCIP_Real maxbounddist)
Definition: objbranchrule.h:82
ObjBranchrule(ObjBranchrule &&o)
definition of base class for all clonable classes
ObjBranchrule & operator=(const ObjBranchrule &o)=delete
const int scip_priority_
Definition: objbranchrule.h:70
#define NULL
Definition: lpi_spx1.cpp:164
virtual SCIP_DECL_BRANCHFREE(scip_free)
#define SCIP_Bool
Definition: def.h:93
virtual ~ObjBranchrule()
SCIP_RETCODE SCIPincludeObjBranchrule(SCIP *scip, scip::ObjBranchrule *objbranchrule, SCIP_Bool deleteobject)
virtual SCIP_DECL_BRANCHINITSOL(scip_initsol)
const int scip_maxdepth_
Definition: objbranchrule.h:73
virtual SCIP_DECL_BRANCHEXECPS(scip_execps)
Definition of base class for all clonable classes.
Definition: objcloneable.h:47
#define SCIP_Real
Definition: def.h:186
scip::ObjBranchrule * SCIPgetObjBranchrule(SCIP *scip, SCIP_BRANCHRULE *branchrule)
virtual SCIP_DECL_BRANCHEXECEXT(scip_execext)
C++ wrapper for branching rules.
Definition: objbranchrule.h:55
#define SCIP_CALL_ABORT(x)
Definition: def.h:372
scip::ObjBranchrule * SCIPfindObjBranchrule(SCIP *scip, const char *name)
virtual SCIP_DECL_BRANCHEXITSOL(scip_exitsol)
virtual SCIP_DECL_BRANCHINIT(scip_init)
const SCIP_Real scip_maxbounddist_
Definition: objbranchrule.h:79
SCIP callable library.