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