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