Scippy

SCIP

Solving Constraint Integer Programs

objbenderscut.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 objbenderscut.h
26  * @brief C++ wrapper for Benders' decomposition cuts
27  * @author Stephen J. Maher
28  */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #ifndef __SCIP_OBJBENDERSCUT_H__
33 #define __SCIP_OBJBENDERSCUT_H__
34 
35 
36 #include <cassert>
37 #include <cstring>
38 #include <utility>
39 
40 #include "scip/scip.h"
41 #include "objscip/objcloneable.h"
42 #include "objscip/objbenders.h"
43 
44 namespace scip
45 {
46 
47 /**
48  * @brief C++ wrapper for Benders' decomposition cut
49  *
50  * This class defines the interface for the Benders' decomposition cuts implemented in C++. Note that there is
51  * a pure virtual function (this must be implemented). This function is: benderscut_exec().
52  *
53  * - \ref BENDERSCUT "Instructions for implementing a Benders' decomposition plugin"
54  * - \ref BENDERSCUTS "List of available Benders' decomposition plugins"
55  * - \ref type_benderscut.h "Corresponding C interface"
56  */
58 {
59 public:
60  /*lint --e{1540}*/
61 
62  /** SCIP data structure */
64 
65  /** name of the Benders' decomposition cut */
66  char* scip_name_;
67 
68  /** description of the Benders' decomposition cut */
69  char* scip_desc_;
70 
71  /** the priority of the Benders' decomposition cut */
72  const int scip_priority_;
73 
74  /** is the Benders' decomposition cut generated from the LP relaxation of the subproblem */
76 
77  /** default constructor */
79  SCIP* scip, /**< SCIP data structure */
80  const char* name, /**< name of Benders' decomposition */
81  const char* desc, /**< description of Benders' decomposition */
82  int priority, /**< priority of the Benders' decomposition */
83  SCIP_Bool islpcut /**< is the cut generated from the LP relaxation */
84  )
85  : scip_(scip),
86  scip_name_(0),
87  scip_desc_(0),
88  scip_priority_(priority),
89  scip_islpcut_(islpcut)
90  {
91  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
92  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
93  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
94  }
95 
96  /** copy constructor */
98  : ObjBenderscut(o.scip_, o.scip_name_, o.scip_desc_, o.scip_priority_, o.scip_islpcut_)
99  {
100  }
101 
102  /** move constructor */
104  : scip_(o.scip_), scip_name_(0), scip_desc_(0), scip_priority_(o.scip_priority_), scip_islpcut_(o.scip_islpcut_)
105  {
106  std::swap(scip_name_, o.scip_name_);
107  std::swap(scip_desc_, o.scip_desc_);
108  }
109 
110  /** destructor */
111  virtual ~ObjBenderscut()
112  {
113  /* the macro SCIPfreeMemoryArray does not need the first argument: */
114  /*lint --e{64}*/
115  SCIPfreeMemoryArray(scip_, &scip_name_);
116  SCIPfreeMemoryArray(scip_, &scip_desc_);
117  }
118 
119  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
120  ObjBenderscut& operator=(const ObjBenderscut& o) = delete;
121 
122  /** assignment of polymorphic classes causes slicing and is therefore disabled. */
123  ObjBenderscut& operator=(ObjBenderscut&& o) = delete;
124 
125  /** copy method for compression plugins (called when SCIP copies plugins)
126  *
127  * @see SCIP_DECL_BENDERSCUTCOPY(x) in @ref type_benders.h
128  */
129  virtual SCIP_DECL_BENDERSCUTCOPY(scip_copy)
130  { /*lint --e{715}*/
131  return SCIP_OKAY;
132  }
133 
134  /** destructor of Benders' decomposition cuts to free user data (called when SCIP is exiting)
135  *
136  * @see SCIP_DECL_BENDERSCUTFREE(x) in @ref type_benders.h
137  */
138  virtual SCIP_DECL_BENDERSCUTFREE(scip_free)
139  { /*lint --e{715}*/
140  return SCIP_OKAY;
141  }
142 
143  /** initialization method of Benders' decomposition cuts (called after problem was transformed)
144  *
145  * @see SCIP_DECL_BENDERSCUTINIT(x) in @ref type_benders.h
146  */
147  virtual SCIP_DECL_BENDERSCUTINIT(scip_init)
148  { /*lint --e{715}*/
149  return SCIP_OKAY;
150  }
151 
152  /** deinitialization method of Benders' decomposition cuts (called before transformed problem is freed)
153  *
154  * @see SCIP_DECL_BENDERSCUTEXIT(x) in @ref type_benders.h
155  */
156  virtual SCIP_DECL_BENDERSCUTEXIT(scip_exit)
157  { /*lint --e{715}*/
158  return SCIP_OKAY;
159  }
160 
161  /** solving process initialization method of Benders' decomposition cuts (called when branch and bound process is about to begin)
162  *
163  * @see SCIP_DECL_BENDERSCUTINITSOL(x) in @ref type_benders.h
164  */
165  virtual SCIP_DECL_BENDERSCUTINITSOL(scip_initsol)
166  { /*lint --e{715}*/
167  return SCIP_OKAY;
168  }
169 
170  /** solving process deinitialization method of Benders' decomposition cuts (called before branch and bound process data is freed)
171  *
172  * This method is called before the branch and bound process is freed.
173  * The Benders' decomposition cuts should use this call to clean up its branch and bound data.
174  *
175  * @see SCIP_DECL_BENDERSCUTEXITSOL(x) in @ref type_benders.h
176  */
177  virtual SCIP_DECL_BENDERSCUTEXITSOL(scip_exitsol)
178  { /*lint --e{715}*/
179  return SCIP_OKAY;
180  }
181 
182  /** execution method of Benders' decomposition cuts technique
183  *
184  * @see SCIP_DECL_BENDERSCUTEXEC(x) in @ref type_benders.h
185  */
186  virtual SCIP_DECL_BENDERSCUTEXEC(scip_exec) = 0;
187 
188 };
189 
190 } /* namespace scip */
191 
192 
193 
194 /** creates the Benders' decomposition cut for the given Benders' decomposition cut object and includes it in SCIP
195  *
196  * The method should be called in one of the following ways:
197  *
198  * 1. The user is responsible for deleting the object:
199  * SCIP_CALL( SCIPcreate(&scip) );
200  * ...
201  * MyBenderscut* mybenderscut = new MyBenderscut(...);
202  * SCIP_CALL( SCIPincludeObjBenderscut(scip, benders, &mybenderscut, FALSE) );
203  * ...
204  * SCIP_CALL( SCIPfree(&scip) );
205  * delete mybenderscut; // delete benderscut AFTER SCIPfree() !
206  *
207  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
208  * SCIP_CALL( SCIPcreate(&scip) );
209  * ...
210  * SCIP_CALL( SCIPincludeObjBenderscut(scip, benders, new MyBenderscut(...), TRUE) );
211  * ...
212  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyBenderscut is called here
213  */
214 SCIP_EXPORT
216  SCIP* scip, /**< SCIP data structure */
217  scip::ObjBenders* objbenders, /**< Benders' decomposition object */
218  scip::ObjBenderscut* objbenderscut, /**< Benders' decomposition cut object */
219  SCIP_Bool deleteobject /**< should the Benders' cut object be deleted when benderscut is freed? */
220  );
221 
222 /** returns the benderscut object of the given name, or 0 if not existing */
223 SCIP_EXPORT
225  scip::ObjBenders* objbenders, /**< Benders' decomposition object */
226  const char* name /**< name of Benders' decomposition cut */
227  );
228 
229 /** returns the benderscut object for the given constraint handler */
230 SCIP_EXPORT
232  SCIP* scip, /**< SCIP data structure */
233  SCIP_BENDERSCUT* benderscut /**< Benders' decomposition cut */
234  );
235 
236 #endif
virtual SCIP_DECL_BENDERSCUTEXIT(scip_exit)
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:76
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:80
C++ wrapper for Benders&#39; decomposition.
virtual SCIP_DECL_BENDERSCUTCOPY(scip_copy)
virtual SCIP_DECL_BENDERSCUTFREE(scip_free)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63
scip::ObjBenderscut * SCIPgetObjBenderscut(SCIP *scip, SCIP_BENDERSCUT *benderscut)
definition of base class for all clonable classes
C++ wrapper for Benders&#39; decomposition plugins.
Definition: objbenders.h:57
SCIP_RETCODE SCIPincludeObjBenderscut(SCIP *scip, scip::ObjBenders *objbenders, scip::ObjBenderscut *objbenderscut, SCIP_Bool deleteobject)
ObjBenderscut(ObjBenderscut &&o)
virtual SCIP_DECL_BENDERSCUTINIT(scip_init)
scip::ObjBenderscut * SCIPfindObjBenderscut(scip::ObjBenders *objbenders, const char *name)
virtual SCIP_DECL_BENDERSCUTINITSOL(scip_initsol)
const SCIP_Bool scip_islpcut_
Definition: objbenderscut.h:75
ObjBenderscut(SCIP *scip, const char *name, const char *desc, int priority, SCIP_Bool islpcut)
Definition: objbenderscut.h:78
#define SCIP_Bool
Definition: def.h:93
ObjBenderscut & operator=(const ObjBenderscut &o)=delete
const int scip_priority_
Definition: objbenderscut.h:72
virtual SCIP_DECL_BENDERSCUTEXEC(scip_exec)=0
Definition of base class for all clonable classes.
Definition: objcloneable.h:47
virtual ~ObjBenderscut()
C++ wrapper for Benders&#39; decomposition cut.
Definition: objbenderscut.h:57
#define SCIP_CALL_ABORT(x)
Definition: def.h:372
SCIP callable library.
virtual SCIP_DECL_BENDERSCUTEXITSOL(scip_exitsol)
ObjBenderscut(const ObjBenderscut &o)
Definition: objbenderscut.h:97