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-2016 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 email to scip@zib.de. */
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  */
46 {
47 public:
48  /*lint --e{1540}*/
49 
50  /** SCIP data structure */
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  */
70 
71  /** default constructor */
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}*/
99  SCIPfreeMemoryArray(scip_, &scip_name_);
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 extern
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 extern
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 extern
222  SCIP* scip, /**< SCIP data structure */
223  SCIP_BRANCHRULE* branchrule /**< branching rule */
224  );
225 
226 #endif
virtual SCIP_DECL_BRANCHEXECLP(scip_execlp)
#define NULL
Definition: lpi_spx.cpp:130
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:20544
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
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:72
definition of base class for all clonable classes
const int scip_priority_
Definition: objbranchrule.h:60
virtual SCIP_DECL_BRANCHFREE(scip_free)
#define SCIP_Bool
Definition: def.h:53
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip.h:20540
virtual ~ObjBranchrule()
Definition: objbranchrule.h:95
SCIP_RETCODE SCIPincludeObjBranchrule(SCIP *scip, scip::ObjBranchrule *objbranchrule, SCIP_Bool deleteobject)
virtual SCIP_DECL_BRANCHINITSOL(scip_initsol)
const int scip_maxdepth_
Definition: objbranchrule.h:63
virtual SCIP_DECL_BRANCHEXECPS(scip_execps)
Definition of base class for all clonable classes.
Definition: objcloneable.h:38
#define SCIP_Real
Definition: def.h:127
scip::ObjBranchrule * SCIPgetObjBranchrule(SCIP *scip, SCIP_BRANCHRULE *branchrule)
virtual SCIP_DECL_BRANCHEXECEXT(scip_execext)
C++ wrapper for branching rules.
Definition: objbranchrule.h:45
#define SCIP_CALL_ABORT(x)
Definition: def.h:245
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:69
SCIP callable library.