Scippy

SCIP

Solving Constraint Integer Programs

objrelax.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-2019 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 scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objrelax.h
17  * @brief C++ wrapper for relaxation handlers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #ifndef __SCIP_OBJRELAX_H__
24 #define __SCIP_OBJRELAX_H__
25 
26 #include <cstring>
27 
28 #include "scip/scip.h"
29 #include "objscip/objcloneable.h"
30 
31 namespace scip
32 {
33 
34 /** @brief C++ wrapper for relaxation handlers
35  *
36  * This class defines the interface for relaxation handlers implemented in C++. Note that there is a pure virtual
37  * function (this function has to be implemented). This function is: scip_exec().
38  *
39  * - \ref RELAX "Instructions for implementing a relaxation handler"
40  * - \ref type_relax.h "Corresponding C interface"
41  */
42 class ObjRelax : public ObjCloneable
43 {
44 public:
45  /*lint --e{1540}*/
46 
47  /** SCIP data structure */
49 
50  /** name of the relaxator */
51  char* scip_name_;
52 
53  /** description of the relaxator */
54  char* scip_desc_;
55 
56  /** default priority of the relaxator (negative: call after LP, non-negative: call before LP) */
57  const int scip_priority_;
58 
59  /** frequency for calling relaxator */
60  const int scip_freq_;
61 
62  /** does the relaxator contain all cuts in the LP? */
64 
65  /** default constructor */
67  SCIP* scip, /**< SCIP data structure */
68  const char* name, /**< name of relaxator */
69  const char* desc, /**< description of relaxator */
70  int priority, /**< priority of the relaxator (negative: after LP, non-negative: before LP) */
71  int freq, /**< frequency for calling relaxator */
72  SCIP_Bool includeslp /**< Does the relaxator contain all cuts in the LP? */
73  )
74  : scip_(scip),
75  scip_name_(0),
76  scip_desc_(0),
77  scip_priority_(priority),
78  scip_freq_(freq),
79  scip_includeslp_(includeslp)
80  {
81  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
82  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
83  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
84  }
85 
86  /** destructor */
87  virtual ~ObjRelax()
88  {
89  /* the macro SCIPfreeMemoryArray does not need the first argument: */
90  /*lint --e{64}*/
91  SCIPfreeMemoryArray(scip_, &scip_name_);
92  SCIPfreeMemoryArray(scip_, &scip_desc_);
93  }
94 
95  /** destructor of relaxator to free user data (called when SCIP is exiting)
96  *
97  * @see SCIP_DECL_RELAXFREE(x) in @ref type_relax.h
98  */
99  virtual SCIP_DECL_RELAXFREE(scip_free)
100  { /*lint --e{715}*/
101  return SCIP_OKAY;
102  }
103 
104  /** initialization method of relaxator (called after problem was transformed)
105  *
106  * @see SCIP_DECL_RELAXINIT(x) in @ref type_relax.h
107  */
108  virtual SCIP_DECL_RELAXINIT(scip_init)
109  { /*lint --e{715}*/
110  return SCIP_OKAY;
111  }
112 
113  /** deinitialization method of relaxator (called before transformed problem is freed)
114  *
115  * @see SCIP_DECL_RELAXEXIT(x) in @ref type_relax.h
116  */
117  virtual SCIP_DECL_RELAXEXIT(scip_exit)
118  { /*lint --e{715}*/
119  return SCIP_OKAY;
120  }
121 
122  /** solving process initialization method of relaxator (called when branch and bound process is about to begin)
123  *
124  * @see SCIP_DECL_RELAXINITSOL(x) in @ref type_relax.h
125  */
126  virtual SCIP_DECL_RELAXINITSOL(scip_initsol)
127  { /*lint --e{715}*/
128  return SCIP_OKAY;
129  }
130 
131  /** solving process deinitialization method of relaxator (called before branch and bound process data is freed)
132  *
133  * @see SCIP_DECL_RELAXEXITSOL(x) in @ref type_relax.h
134  */
135  virtual SCIP_DECL_RELAXEXITSOL(scip_exitsol)
136  { /*lint --e{715}*/
137  return SCIP_OKAY;
138  }
139 
140  /** execution method of relaxator
141  *
142  * @see SCIP_DECL_RELAXEXEC(x) in @ref type_relax.h
143  */
144  virtual SCIP_DECL_RELAXEXEC(scip_exec) = 0;
145 };
146 
147 } /* namespace scip */
148 
149 
150 
151 /** creates the relaxator for the given relaxator object and includes it in SCIP
152  *
153  * The method should be called in one of the following ways:
154  *
155  * 1. The user is resposible of deleting the object:
156  * SCIP_CALL( SCIPcreate(&scip) );
157  * ...
158  * MyRelax* myrelax = new MyRelax(...);
159  * SCIP_CALL( SCIPincludeObjRelax(scip, &myrelax, FALSE) );
160  * ...
161  * SCIP_CALL( SCIPfree(&scip) );
162  * delete myrelax; // delete relax AFTER SCIPfree() !
163  *
164  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
165  * SCIP_CALL( SCIPcreate(&scip) );
166  * ...
167  * SCIP_CALL( SCIPincludeObjRelax(scip, new MyRelax(...), TRUE) );
168  * ...
169  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyRelax is called here
170  */
173  SCIP* scip, /**< SCIP data structure */
174  scip::ObjRelax* objrelax, /**< relaxator object */
175  SCIP_Bool deleteobject /**< should the relaxator object be deleted when relaxator is freed? */
176  );
177 
178 /** returns the relax object of the given name, or 0 if not existing */
181  SCIP* scip, /**< SCIP data structure */
182  const char* name /**< name of relaxator */
183  );
184 
185 /** returns the relax object for the given relaxator */
188  SCIP* scip, /**< SCIP data structure */
189  SCIP_RELAX* relax /**< relaxator */
190  );
191 
192 #endif
virtual SCIP_DECL_RELAXINIT(scip_init)
Definition: objrelax.h:108
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip_mem.h:65
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip_mem.h:69
virtual SCIP_DECL_RELAXEXEC(scip_exec)=0
#define SCIP_EXPORT
Definition: def.h:98
virtual SCIP_DECL_RELAXFREE(scip_free)
Definition: objrelax.h:99
virtual SCIP_DECL_RELAXEXIT(scip_exit)
Definition: objrelax.h:117
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_EXPORT scip::ObjRelax * SCIPgetObjRelax(SCIP *scip, SCIP_RELAX *relax)
Definition: objrelax.cpp:241
virtual SCIP_DECL_RELAXINITSOL(scip_initsol)
Definition: objrelax.h:126
virtual ~ObjRelax()
Definition: objrelax.h:87
definition of base class for all clonable classes
ObjRelax(SCIP *scip, const char *name, const char *desc, int priority, int freq, SCIP_Bool includeslp)
Definition: objrelax.h:66
SCIP_EXPORT scip::ObjRelax * SCIPfindObjRelax(SCIP *scip, const char *name)
Definition: objrelax.cpp:222
virtual SCIP_DECL_RELAXEXITSOL(scip_exitsol)
Definition: objrelax.h:135
char * scip_desc_
Definition: objrelax.h:54
#define SCIP_Bool
Definition: def.h:70
char * scip_name_
Definition: objrelax.h:51
Definition of base class for all clonable classes.
Definition: objcloneable.h:38
const int scip_freq_
Definition: objrelax.h:60
const SCIP_Bool scip_includeslp_
Definition: objrelax.h:63
const int scip_priority_
Definition: objrelax.h:57
C++ wrapper for relaxation handlers.
Definition: objrelax.h:42
SCIP_EXPORT SCIP_RETCODE SCIPincludeObjRelax(SCIP *scip, scip::ObjRelax *objrelax, SCIP_Bool deleteobject)
Definition: objrelax.cpp:195
SCIP * scip_
Definition: objrelax.h:48
#define SCIP_CALL_ABORT(x)
Definition: def.h:344
SCIP callable library.