Scippy

SCIP

Solving Constraint Integer Programs

objpresol.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 objpresol.h
17  * @brief C++ wrapper for presolvers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #ifndef __SCIP_OBJPRESOL_H__
24 #define __SCIP_OBJPRESOL_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 presolvers
35  *
36  * This class defines the interface for presolvers 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 PRESOL "Instructions for implementing a presolver"
40  * - \ref PRESOLVERS "List of available presolvers"
41  * - \ref type_presol.h "Corresponding C interface"
42  */
43 class ObjPresol : public ObjCloneable
44 {
45 public:
46  /*lint --e{1540}*/
47 
48  /** SCIP data structure */
50 
51  /** name of the presolver */
52  char* scip_name_;
53 
54  /** description of the presolver */
55  char* scip_desc_;
56 
57  /** default priority of the presolver */
58  const int scip_priority_;
59 
60  /** default maximal number of presolving rounds the presolver participates in (-1: no limit) */
61  const int scip_maxrounds_;
62 
63  /** should presolver be delayed, if other presolvers found reductions? */
65 
66  /** default constructor */
68  SCIP* scip, /**< SCIP data structure */
69  const char* name, /**< name of presolver */
70  const char* desc, /**< description of presolver */
71  int priority, /**< priority of the presolver */
72  int maxrounds, /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
73  SCIP_Bool delay /**< should presolver be delayed, if other presolvers found reductions? */
74  )
75  : scip_(scip),
76  scip_name_(0),
77  scip_desc_(0),
78  scip_priority_(priority),
79  scip_maxrounds_(maxrounds),
80  scip_delay_(delay)
81  {
82  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
83  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
84  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
85  }
86 
87  /** destructor */
88  virtual ~ObjPresol()
89  {
90  /* the macro SCIPfreeMemoryArray does not need the first argument: */
91  /*lint --e{64}*/
94  }
95 
96  /** destructor of presolver to free user data (called when SCIP is exiting)
97  *
98  * @see SCIP_DECL_PRESOLFREE(x) in @ref type_prop.h
99  */
100  virtual SCIP_DECL_PRESOLFREE(scip_free)
101  { /*lint --e{715}*/
102  return SCIP_OKAY;
103  }
104 
105  /** initialization method of presolver (called after problem was transformed)
106  *
107  * @see SCIP_DECL_PRESOLINIT(x) in @ref type_prop.h
108  */
109  virtual SCIP_DECL_PRESOLINIT(scip_init)
110  { /*lint --e{715}*/
111  return SCIP_OKAY;
112  }
113 
114  /** deinitialization method of presolver (called before transformed problem is freed)
115  *
116  * @see SCIP_DECL_PRESOLEXIT(x) in @ref type_prop.h
117  */
118  virtual SCIP_DECL_PRESOLEXIT(scip_exit)
119  { /*lint --e{715}*/
120  return SCIP_OKAY;
121  }
122 
123  /** presolving initialization method of presolver (called when presolving is about to begin)
124  *
125  * @see SCIP_DECL_PRESOLINITPRE(x) in @ref type_prop.h
126  */
127  virtual SCIP_DECL_PRESOLINITPRE(scip_initpre)
128  { /*lint --e{715}*/
129  return SCIP_OKAY;
130  }
131 
132  /** presolving deinitialization method of presolver (called after presolving has been finished)
133  *
134  * @see SCIP_DECL_PRESOLEXITPRE(x) in @ref type_prop.h
135  */
136  virtual SCIP_DECL_PRESOLEXITPRE(scip_exitpre)
137  { /*lint --e{715}*/
138  return SCIP_OKAY;
139  }
140 
141  /** execution method of presolver
142  *
143  * @see SCIP_DECL_PRESOLEXEC(x) in @ref type_prop.h
144  */
145  virtual SCIP_DECL_PRESOLEXEC(scip_exec) = 0;
146 };
147 
148 } /* namespace scip */
149 
150 
151 
152 /** creates the presolver for the given presolver object and includes it in SCIP
153  *
154  * The method should be called in one of the following ways:
155  *
156  * 1. The user is resposible of deleting the object:
157  * SCIP_CALL( SCIPcreate(&scip) );
158  * ...
159  * MyPresol* mypresol = new MyPresol(...);
160  * SCIP_CALL( SCIPincludeObjPresol(scip, &mypresol, FALSE) );
161  * ...
162  * SCIP_CALL( SCIPfree(&scip) );
163  * delete mypresol; // delete presol AFTER SCIPfree() !
164  *
165  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
166  * SCIP_CALL( SCIPcreate(&scip) );
167  * ...
168  * SCIP_CALL( SCIPincludeObjPresol(scip, new MyPresol(...), TRUE) );
169  * ...
170  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyPresol is called here
171  */
172 extern
174  SCIP* scip, /**< SCIP data structure */
175  scip::ObjPresol* objpresol, /**< presolver object */
176  SCIP_Bool deleteobject /**< should the presolver object be deleted when presolver is freed? */
177  );
178 
179 /** returns the presol object of the given name, or 0 if not existing */
180 extern
182  SCIP* scip, /**< SCIP data structure */
183  const char* name /**< name of presolver */
184  );
185 
186 /** returns the presol object for the given presolver */
187 extern
189  SCIP* scip, /**< SCIP data structure */
190  SCIP_PRESOL* presol /**< presolver */
191  );
192 
193 #endif
virtual SCIP_DECL_PRESOLINITPRE(scip_initpre)
Definition: objpresol.h:127
const int scip_priority_
Definition: objpresol.h:58
virtual ~ObjPresol()
Definition: objpresol.h:88
C++ wrapper for presolvers.
Definition: objpresol.h:43
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
char * scip_desc_
Definition: objpresol.h:55
char * scip_name_
Definition: objpresol.h:52
ObjPresol(SCIP *scip, const char *name, const char *desc, int priority, int maxrounds, SCIP_Bool delay)
Definition: objpresol.h:67
definition of base class for all clonable classes
virtual SCIP_DECL_PRESOLFREE(scip_free)
Definition: objpresol.h:100
const int scip_maxrounds_
Definition: objpresol.h:61
struct Scip SCIP
Definition: type_scip.h:30
#define SCIP_Bool
Definition: def.h:49
scip::ObjPresol * SCIPfindObjPresol(SCIP *scip, const char *name)
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip.h:19173
virtual SCIP_DECL_PRESOLEXEC(scip_exec)=0
SCIP * scip_
Definition: objpresol.h:49
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:19178
scip::ObjPresol * SCIPgetObjPresol(SCIP *scip, SCIP_PRESOL *presol)
Definition of base class for all clonable classes.
Definition: objcloneable.h:38
virtual SCIP_DECL_PRESOLEXITPRE(scip_exitpre)
Definition: objpresol.h:136
virtual SCIP_DECL_PRESOLINIT(scip_init)
Definition: objpresol.h:109
struct SCIP_Presol SCIP_PRESOL
Definition: type_presol.h:36
SCIP_RETCODE SCIPincludeObjPresol(SCIP *scip, scip::ObjPresol *objpresol, SCIP_Bool deleteobject)
const SCIP_Bool scip_delay_
Definition: objpresol.h:64
#define SCIP_CALL_ABORT(x)
Definition: def.h:237
virtual SCIP_DECL_PRESOLEXIT(scip_exit)
Definition: objpresol.h:118
SCIP callable library.