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-2014 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 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  /** default constructor */
64  SCIP* scip, /**< SCIP data structure */
65  const char* name, /**< name of relaxator */
66  const char* desc, /**< description of relaxator */
67  int priority, /**< priority of the relaxator (negative: after LP, non-negative: before LP) */
68  int freq /**< frequency for calling relaxator */
69  )
70  : scip_(scip),
71  scip_name_(0),
72  scip_desc_(0),
73  scip_priority_(priority),
74  scip_freq_(freq)
75  {
76  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
77  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
78  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
79  }
80 
81  /** destructor */
82  virtual ~ObjRelax()
83  {
84  /* the macro SCIPfreeMemoryArray does not need the first argument: */
85  /*lint --e{64}*/
88  }
89 
90  /** destructor of relaxator to free user data (called when SCIP is exiting)
91  *
92  * @see SCIP_DECL_RELAXFREE(x) in @ref type_relax.h
93  */
94  virtual SCIP_DECL_RELAXFREE(scip_free)
95  { /*lint --e{715}*/
96  return SCIP_OKAY;
97  }
98 
99  /** initialization method of relaxator (called after problem was transformed)
100  *
101  * @see SCIP_DECL_RELAXINIT(x) in @ref type_relax.h
102  */
103  virtual SCIP_DECL_RELAXINIT(scip_init)
104  { /*lint --e{715}*/
105  return SCIP_OKAY;
106  }
107 
108  /** deinitialization method of relaxator (called before transformed problem is freed)
109  *
110  * @see SCIP_DECL_RELAXEXIT(x) in @ref type_relax.h
111  */
112  virtual SCIP_DECL_RELAXEXIT(scip_exit)
113  { /*lint --e{715}*/
114  return SCIP_OKAY;
115  }
116 
117  /** solving process initialization method of relaxator (called when branch and bound process is about to begin)
118  *
119  * @see SCIP_DECL_RELAXINITSOL(x) in @ref type_relax.h
120  */
121  virtual SCIP_DECL_RELAXINITSOL(scip_initsol)
122  { /*lint --e{715}*/
123  return SCIP_OKAY;
124  }
125 
126  /** solving process deinitialization method of relaxator (called before branch and bound process data is freed)
127  *
128  * @see SCIP_DECL_RELAXEXITSOL(x) in @ref type_relax.h
129  */
130  virtual SCIP_DECL_RELAXEXITSOL(scip_exitsol)
131  { /*lint --e{715}*/
132  return SCIP_OKAY;
133  }
134 
135  /** execution method of relaxator
136  *
137  * @see SCIP_DECL_RELAXEXEC(x) in @ref type_relax.h
138  */
139  virtual SCIP_DECL_RELAXEXEC(scip_exec) = 0;
140 };
141 
142 } /* namespace scip */
143 
144 
145 
146 /** creates the relaxator for the given relaxator object and includes it in SCIP
147  *
148  * The method should be called in one of the following ways:
149  *
150  * 1. The user is resposible of deleting the object:
151  * SCIP_CALL( SCIPcreate(&scip) );
152  * ...
153  * MyRelax* myrelax = new MyRelax(...);
154  * SCIP_CALL( SCIPincludeObjRelax(scip, &myrelax, FALSE) );
155  * ...
156  * SCIP_CALL( SCIPfree(&scip) );
157  * delete myrelax; // delete relax AFTER SCIPfree() !
158  *
159  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
160  * SCIP_CALL( SCIPcreate(&scip) );
161  * ...
162  * SCIP_CALL( SCIPincludeObjRelax(scip, new MyRelax(...), TRUE) );
163  * ...
164  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyRelax is called here
165  */
166 extern
168  SCIP* scip, /**< SCIP data structure */
169  scip::ObjRelax* objrelax, /**< relaxator object */
170  SCIP_Bool deleteobject /**< should the relaxator object be deleted when relaxator is freed? */
171  );
172 
173 /** returns the relax object of the given name, or 0 if not existing */
174 extern
176  SCIP* scip, /**< SCIP data structure */
177  const char* name /**< name of relaxator */
178  );
179 
180 /** returns the relax object for the given relaxator */
181 extern
183  SCIP* scip, /**< SCIP data structure */
184  SCIP_RELAX* relax /**< relaxator */
185  );
186 
187 #endif
virtual SCIP_DECL_RELAXINIT(scip_init)
Definition: objrelax.h:103
virtual SCIP_DECL_RELAXEXEC(scip_exec)=0
virtual SCIP_DECL_RELAXFREE(scip_free)
Definition: objrelax.h:94
virtual SCIP_DECL_RELAXEXIT(scip_exit)
Definition: objrelax.h:112
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
virtual SCIP_DECL_RELAXINITSOL(scip_initsol)
Definition: objrelax.h:121
virtual ~ObjRelax()
Definition: objrelax.h:82
definition of base class for all clonable classes
ObjRelax(SCIP *scip, const char *name, const char *desc, int priority, int freq)
Definition: objrelax.h:63
virtual SCIP_DECL_RELAXEXITSOL(scip_exitsol)
Definition: objrelax.h:130
scip::ObjRelax * SCIPgetObjRelax(SCIP *scip, SCIP_RELAX *relax)
scip::ObjRelax * SCIPfindObjRelax(SCIP *scip, const char *name)
SCIP_RETCODE SCIPincludeObjRelax(SCIP *scip, scip::ObjRelax *objrelax, SCIP_Bool deleteobject)
struct Scip SCIP
Definition: type_scip.h:30
char * scip_desc_
Definition: objrelax.h:54
#define SCIP_Bool
Definition: def.h:49
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip.h:19173
struct SCIP_Relax SCIP_RELAX
Definition: type_relax.h:36
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:19178
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 int scip_priority_
Definition: objrelax.h:57
C++ wrapper for relaxation handlers.
Definition: objrelax.h:42
SCIP * scip_
Definition: objrelax.h:48
#define SCIP_CALL_ABORT(x)
Definition: def.h:237
SCIP callable library.