Scippy

SCIP

Solving Constraint Integer Programs

objconshdlr.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 objconshdlr.h
17  * @brief C++ wrapper for constraint handlers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #ifndef __SCIP_OBJCONSHDLR_H__
24 #define __SCIP_OBJCONSHDLR_H__
25 
26 
27 #include <cassert>
28 #include <cstring>
29 
30 #include "scip/scip.h"
32 
33 namespace scip
34 {
35 
36 /**
37  * @brief C++ wrapper for constraint handlers
38  *
39  * This class defines the interface for constraint handlers implemented in C++. Note that there are pure virtual
40  * functions (these have to be implemented). These functions are: scip_trans(), scip_enfolp(), scip_enfops(),
41  * scip_check(), and scip_lock().
42  *
43  * - \ref CONS "Instructions for implementing a constraint handler"
44  * - \ref CONSHDLRS "List of available constraint handlers"
45  * - \ref type_cons.h "Corresponding C interface"
46  */
48 {
49 public:
50  /*lint --e{1540}*/
51 
52  /** SCIP data structure */
54 
55  /** name of the constraint handler */
56  char* scip_name_;
57 
58  /** description of the constraint handler */
59  char* scip_desc_;
60 
61  /** default separation priority of the constraint handler */
62  const int scip_sepapriority_;
63 
64  /** default enforcing priority of the constraint handler */
65  const int scip_enfopriority_;
66 
67  /** default checking priority of the constraint handler */
69 
70  /** default separation frequency of the constraint handler */
71  const int scip_sepafreq_;
72 
73  /** default propagation frequency of the constraint handler */
74  const int scip_propfreq_;
75 
76  /** default frequency of the constraint handler for eager evaluations in separation, propagation and enforcement */
77  const int scip_eagerfreq_;
78 
79  /** maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
80  const int scip_maxprerounds_;
81 
82  /** should separation method be delayed, if other separators found cuts? */
84 
85  /** should propagation method be delayed, if other propagators found reductions? */
87 
88  /** should the constraint handler be skipped, if no constraints are available? */
90 
91  /** positions in the node solving loop where propagation method of constraint handler should be executed */
92  const unsigned int scip_proptiming_;
93 
94  /**< timing mask of the constraint handler's presolving method */
95  const unsigned int scip_presoltiming_;
96 
97  /** default constructor */
99  SCIP* scip, /**< SCIP data structure */
100  const char* name, /**< name of constraint handler */
101  const char* desc, /**< description of constraint handler */
102  int sepapriority, /**< priority of the constraint handler for separation */
103  int enfopriority, /**< priority of the constraint handler for constraint enforcing */
104  int checkpriority, /**< priority of the constraint handler for checking infeasibility (and propagation) */
105  int sepafreq, /**< frequency for separating cuts; zero means to separate only in the root node */
106  int propfreq, /**< frequency for propagating domains; zero means only preprocessing propagation */
107  int eagerfreq, /**< frequency for using all instead of only the useful constraints in separation,
108  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
109  int maxprerounds, /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
110  SCIP_Bool delaysepa, /**< should separation method be delayed, if other separators found cuts? */
111  SCIP_Bool delayprop, /**< should propagation method be delayed, if other propagators found reductions? */
112  SCIP_Bool needscons, /**< should the constraint handler be skipped, if no constraints are available? */
113  unsigned int proptiming, /**< positions in the node solving loop where propagation method of constraint handlers should be executed */
114  unsigned int presoltiming /**< timing mask of the constraint handler's presolving method */
115  )
116  : scip_(scip),
117  scip_name_(0),
118  scip_desc_(0),
119  scip_sepapriority_(sepapriority),
120  scip_enfopriority_(enfopriority),
121  scip_checkpriority_(checkpriority),
122  scip_sepafreq_(sepafreq),
123  scip_propfreq_(propfreq),
124  scip_eagerfreq_(eagerfreq),
125  scip_maxprerounds_(maxprerounds),
126  scip_delaysepa_(delaysepa),
127  scip_delayprop_(delayprop),
128  scip_needscons_(needscons),
129  scip_proptiming_(proptiming),
130  scip_presoltiming_(presoltiming)
131  {
132  /* the macro SCIPduplicateMemoryArray does not need the first argument: */
133  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_name_, name, std::strlen(name)+1) );
134  SCIP_CALL_ABORT( SCIPduplicateMemoryArray(scip_, &scip_desc_, desc, std::strlen(desc)+1) );
135  }
136 
137  /** destructor */
138  virtual ~ObjConshdlr()
139  {
140  /* the macro SCIPfreeMemoryArray does not need the first argument: */
141  /*lint --e{64}*/
142  SCIPfreeMemoryArray(scip_, &scip_name_);
143  SCIPfreeMemoryArray(scip_, &scip_desc_);
144  }
145 
146  /** destructor of constraint handler to free user data (called when SCIP is exiting)
147  *
148  * @see SCIP_DECL_CONSFREE(x) in @ref type_cons.h
149  */
150  virtual SCIP_DECL_CONSFREE(scip_free)
151  { /*lint --e{715}*/
152  return SCIP_OKAY;
153  }
154 
155  /** initialization method of constraint handler (called after problem has been transformed)
156  *
157  * @see SCIP_DECL_CONSINIT(x) in @ref type_cons.h
158  */
159  virtual SCIP_DECL_CONSINIT(scip_init)
160  { /*lint --e{715}*/
161  return SCIP_OKAY;
162  }
163 
164  /** deinitialization method of constraint handler (called before transformed problem is freed)
165  *
166  * @see SCIP_DECL_CONSEXIT(x) in @ref type_cons.h
167  */
168  virtual SCIP_DECL_CONSEXIT(scip_exit)
169  { /*lint --e{715}*/
170  return SCIP_OKAY;
171  }
172 
173  /** presolving initialization method of constraint handler (called when presolving is about to begin)
174  *
175  * @see SCIP_DECL_CONSINITPRE(x) in @ref type_cons.h
176  */
177  virtual SCIP_DECL_CONSINITPRE(scip_initpre)
178  { /*lint --e{715}*/
179  return SCIP_OKAY;
180  }
181 
182  /** presolving deinitialization method of constraint handler (called after presolving has been finished)
183  *
184  * @see SCIP_DECL_CONSEXITPRE(x) in @ref type_cons.h
185  */
186  virtual SCIP_DECL_CONSEXITPRE(scip_exitpre)
187  { /*lint --e{715}*/
188  return SCIP_OKAY;
189  }
190 
191  /** solving process initialization method of constraint handler (called when branch and bound process is about to begin)
192  *
193  * @see SCIP_DECL_CONSINITSOL(x) in @ref type_cons.h
194  */
195  virtual SCIP_DECL_CONSINITSOL(scip_initsol)
196  { /*lint --e{715}*/
197  return SCIP_OKAY;
198  }
199 
200  /** solving process deinitialization method of constraint handler (called before branch and bound process data is freed)
201  *
202  * @see SCIP_DECL_CONSEXITSOL(x) in @ref type_cons.h
203  */
204  virtual SCIP_DECL_CONSEXITSOL(scip_exitsol)
205  { /*lint --e{715}*/
206  return SCIP_OKAY;
207  }
208 
209  /** frees specific constraint data
210  *
211  * @see SCIP_DECL_CONSDELETE(x) in @ref type_cons.h
212  */
213  virtual SCIP_DECL_CONSDELETE(scip_delete)
214  { /*lint --e{715}*/
215  return SCIP_OKAY;
216  }
217 
218  /** transforms constraint data into data belonging to the transformed problem
219  *
220  * @see SCIP_DECL_CONSTRANS(x) in @ref type_cons.h
221  */
222  virtual SCIP_DECL_CONSTRANS(scip_trans) = 0;
223 
224  /** LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved)
225  *
226  * @see SCIP_DECL_CONSINITLP(x) in @ref type_cons.h
227  */
228  virtual SCIP_DECL_CONSINITLP(scip_initlp)
229  { /*lint --e{715}*/
230  return SCIP_OKAY;
231  }
232 
233  /** separation method of constraint handler for LP solution
234  *
235  * @see SCIP_DECL_CONSSEPALP(x) in @ref type_cons.h
236  */
237  virtual SCIP_DECL_CONSSEPALP(scip_sepalp)
238  { /*lint --e{715}*/
239  assert(result != NULL);
240  *result = SCIP_DIDNOTRUN;
241  return SCIP_OKAY;
242  }
243 
244  /** separation method of constraint handler for arbitrary primal solution
245  *
246  * @see SCIP_DECL_CONSSEPASOL(x) in @ref type_cons.h
247  */
248  virtual SCIP_DECL_CONSSEPASOL(scip_sepasol)
249  { /*lint --e{715}*/
250  assert(result != NULL);
251  *result = SCIP_DIDNOTRUN;
252  return SCIP_OKAY;
253  }
254 
255  /** constraint enforcing method of constraint handler for LP solutions
256  *
257  * @see SCIP_DECL_CONSENFOLP(x) in @ref type_cons.h
258  */
259  virtual SCIP_DECL_CONSENFOLP(scip_enfolp) = 0;
260 
261  /** constraint enforcing method of constraint handler for pseudo solutions
262  *
263  * @see SCIP_DECL_CONSENFOPS(x) in @ref type_cons.h
264  */
265  virtual SCIP_DECL_CONSENFOPS(scip_enfops) = 0;
266 
267  /** feasibility check method of constraint handler for primal solutions
268  *
269  * @see SCIP_DECL_CONSCHECK(x) in @ref type_cons.h
270  */
271  virtual SCIP_DECL_CONSCHECK(scip_check) = 0;
272 
273  /** domain propagation method of constraint handler
274  *
275  * @see SCIP_DECL_CONSPROP(x) in @ref type_cons.h
276  */
277  virtual SCIP_DECL_CONSPROP(scip_prop)
278  { /*lint --e{715}*/
279  assert(result != NULL);
280  *result = SCIP_DIDNOTRUN;
281  return SCIP_OKAY;
282  }
283 
284  /** presolving method of constraint handler
285  *
286  * @see SCIP_DECL_CONSPRESOL(x) in @ref type_cons.h
287  */
288  virtual SCIP_DECL_CONSPRESOL(scip_presol)
289  { /*lint --e{715}*/
290  assert(result != NULL);
291  *result = SCIP_DIDNOTRUN;
292  return SCIP_OKAY;
293  }
294 
295  /** propagation conflict resolving method of constraint handler
296  *
297  * @see SCIP_DECL_CONSRESPROP(x) in @ref type_cons.h
298  */
299  virtual SCIP_DECL_CONSRESPROP(scip_resprop)
300  { /*lint --e{715}*/
301  assert(result != NULL);
302  *result = SCIP_DIDNOTFIND;
303  return SCIP_OKAY;
304  }
305 
306  /** variable rounding lock method of constraint handler
307  *
308  * @see SCIP_DECL_CONSLOCK(x) in @ref type_cons.h
309  */
310  virtual SCIP_DECL_CONSLOCK(scip_lock) = 0;
311 
312  /** constraint activation notification method of constraint handler
313  *
314  * @see SCIP_DECL_CONSACTIVE(x) in @ref type_cons.h
315  */
316  virtual SCIP_DECL_CONSACTIVE(scip_active)
317  { /*lint --e{715}*/
318  return SCIP_OKAY;
319  }
320 
321  /** constraint deactivation notification method of constraint handler
322  *
323  * @see SCIP_DECL_CONSDEACTIVE(x) in @ref type_cons.h
324  */
325  virtual SCIP_DECL_CONSDEACTIVE(scip_deactive)
326  { /*lint --e{715}*/
327  return SCIP_OKAY;
328  }
329 
330  /** constraint enabling notification method of constraint handler
331  *
332  * @see SCIP_DECL_CONSENABLE(x) in @ref type_cons.h
333  */
334  virtual SCIP_DECL_CONSENABLE(scip_enable)
335  { /*lint --e{715}*/
336  return SCIP_OKAY;
337  }
338 
339  /** constraint disabling notification method of constraint handler
340  *
341  * @see SCIP_DECL_CONSDISABLE(x) in @ref type_cons.h
342  */
343  virtual SCIP_DECL_CONSDISABLE(scip_disable)
344  { /*lint --e{715}*/
345  return SCIP_OKAY;
346  }
347 
348  /** variable deletion method of constraint handler
349  *
350  * @see SCIP_DECL_CONSDELVARS(x) in @ref type_cons.h
351  */
352  virtual SCIP_DECL_CONSDELVARS(scip_delvars)
353  { /*lint --e{715}*/
354  return SCIP_OKAY;
355  }
356 
357  /** constraint display method of constraint handler
358  *
359  * @see SCIP_DECL_CONSPRINT(x) in @ref type_cons.h
360  */
361  virtual SCIP_DECL_CONSPRINT(scip_print)
362  { /*lint --e{715}*/
363  if ( file == NULL )
364  fprintf(stdout, "constraint handler <%s> does not support printing constraints\n", SCIPconshdlrGetName(conshdlr));
365  else
366  fprintf(file, "constraint handler <%s> does not support printing constraints\n", SCIPconshdlrGetName(conshdlr));
367  return SCIP_OKAY;
368  }
369 
370  /** constraint copying method of constraint handler
371  *
372  * @see SCIP_DECL_CONSCOPY(x) in @ref type_cons.h
373  */
374  virtual SCIP_DECL_CONSCOPY(scip_copy)
375  { /*lint --e{715}*/
376  *valid = FALSE;
377  return SCIP_OKAY;
378  }
379 
380  /** constraint parsing method of constraint handler
381  *
382  * @see SCIP_DECL_CONSPARSE(x) in @ref type_cons.h
383  */
384  virtual SCIP_DECL_CONSPARSE(scip_parse)
385  { /*lint --e{715}*/
386  return SCIP_OKAY;
387  }
388 
389  /** constraint method of constraint handler which returns the variables (if possible)
390  *
391  * @see SCIP_DECL_CONSGETVARS(x) in @ref type_cons.h
392  */
393  virtual SCIP_DECL_CONSGETVARS(scip_getvars)
394  { /*lint --e{715}*/
395 
396  (*success) = FALSE;
397 
398  return SCIP_OKAY;
399  }
400 
401  /** constraint method of constraint handler which returns the number of variables (if possible)
402  *
403  * @see SCIP_DECL_CONSGETNVARS(x) in @ref type_cons.h
404  */
405  virtual SCIP_DECL_CONSGETNVARS(scip_getnvars)
406  { /*lint --e{715}*/
407 
408  (*nvars) = 0;
409  (*success) = FALSE;
410 
411  return SCIP_OKAY;
412  }
413 
414  /** constraint handler method to suggest dive bound changes during the generic diving algorithm
415  *
416  * @see SCIP_DECL_CONSGETDIVEBDCHGS(x) in @ref type_cons.h
417  */
418  virtual SCIP_DECL_CONSGETDIVEBDCHGS(scip_getdivebdchgs)
419  { /*lint --e{715}*/
420 
421  (*success) = FALSE;
422 
423  return SCIP_OKAY;
424  }
425 };
426 
427 } /* namespace scip */
428 
429 
430 
431 /** creates the constraint handler for the given constraint handler object and includes it in SCIP
432  *
433  * The method should be called in one of the following ways:
434  *
435  * 1. The user is resposible of deleting the object:
436  * SCIP_CALL( SCIPcreate(&scip) );
437  * ...
438  * MyConshdlr* myconshdlr = new MyConshdlr(...);
439  * SCIP_CALL( SCIPincludeObjConshdlr(scip, &myconshdlr, FALSE) );
440  * ...
441  * SCIP_CALL( SCIPfree(&scip) );
442  * delete myconshdlr; // delete conshdlr AFTER SCIPfree() !
443  *
444  * 2. The object pointer is passed to SCIP and deleted by SCIP in the SCIPfree() call:
445  * SCIP_CALL( SCIPcreate(&scip) );
446  * ...
447  * SCIP_CALL( SCIPincludeObjConshdlr(scip, new MyConshdlr(...), TRUE) );
448  * ...
449  * SCIP_CALL( SCIPfree(&scip) ); // destructor of MyConshdlr is called here
450  */
451 extern
453  SCIP* scip, /**< SCIP data structure */
454  scip::ObjConshdlr* objconshdlr, /**< constraint handler object */
455  SCIP_Bool deleteobject /**< should the constraint handler object be deleted when conshdlr is freed? */
456  );
457 
458 /** returns the conshdlr object of the given name, or 0 if not existing */
459 extern
461  SCIP* scip, /**< SCIP data structure */
462  const char* name /**< name of constraint handler */
463  );
464 
465 /** returns the conshdlr object for the given constraint handler */
466 extern
468  SCIP* scip, /**< SCIP data structure */
469  SCIP_CONSHDLR* conshdlr /**< constraint handler */
470  );
471 
472 #endif
virtual SCIP_DECL_CONSPARSE(scip_parse)
Definition: objconshdlr.h:384
Definition of base class for all clonable classes which define problem data.
virtual ~ObjConshdlr()
Definition: objconshdlr.h:138
const SCIP_Bool scip_delaysepa_
Definition: objconshdlr.h:83
const int scip_eagerfreq_
Definition: objconshdlr.h:77
const SCIP_Bool scip_needscons_
Definition: objconshdlr.h:89
#define NULL
Definition: lpi_spx.cpp:130
const int scip_propfreq_
Definition: objconshdlr.h:74
virtual SCIP_DECL_CONSEXITPRE(scip_exitpre)
Definition: objconshdlr.h:186
scip::ObjConshdlr * SCIPgetObjConshdlr(SCIP *scip, SCIP_CONSHDLR *conshdlr)
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:20544
virtual SCIP_DECL_CONSDELVARS(scip_delvars)
Definition: objconshdlr.h:352
virtual SCIP_DECL_CONSENABLE(scip_enable)
Definition: objconshdlr.h:334
virtual SCIP_DECL_CONSENFOLP(scip_enfolp)=0
#define FALSE
Definition: def.h:56
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
virtual SCIP_DECL_CONSGETDIVEBDCHGS(scip_getdivebdchgs)
Definition: objconshdlr.h:418
virtual SCIP_DECL_CONSINITSOL(scip_initsol)
Definition: objconshdlr.h:195
scip::ObjConshdlr * SCIPfindObjConshdlr(SCIP *scip, const char *name)
virtual SCIP_DECL_CONSRESPROP(scip_resprop)
Definition: objconshdlr.h:299
virtual SCIP_DECL_CONSINIT(scip_init)
Definition: objconshdlr.h:159
virtual SCIP_DECL_CONSEXIT(scip_exit)
Definition: objconshdlr.h:168
virtual SCIP_DECL_CONSPRINT(scip_print)
Definition: objconshdlr.h:361
virtual SCIP_DECL_CONSLOCK(scip_lock)=0
ObjConshdlr(SCIP *scip, const char *name, const char *desc, int sepapriority, int enfopriority, int checkpriority, int sepafreq, int propfreq, int eagerfreq, int maxprerounds, SCIP_Bool delaysepa, SCIP_Bool delayprop, SCIP_Bool needscons, unsigned int proptiming, unsigned int presoltiming)
Definition: objconshdlr.h:98
virtual SCIP_DECL_CONSPRESOL(scip_presol)
Definition: objconshdlr.h:288
virtual SCIP_DECL_CONSSEPALP(scip_sepalp)
Definition: objconshdlr.h:237
virtual SCIP_DECL_CONSDISABLE(scip_disable)
Definition: objconshdlr.h:343
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:3897
const int scip_maxprerounds_
Definition: objconshdlr.h:80
const int scip_sepapriority_
Definition: objconshdlr.h:62
virtual SCIP_DECL_CONSCHECK(scip_check)=0
const SCIP_Bool scip_delayprop_
Definition: objconshdlr.h:86
virtual SCIP_DECL_CONSPROP(scip_prop)
Definition: objconshdlr.h:277
virtual SCIP_DECL_CONSTRANS(scip_trans)=0
#define SCIP_Bool
Definition: def.h:53
virtual SCIP_DECL_CONSDELETE(scip_delete)
Definition: objconshdlr.h:213
#define SCIPduplicateMemoryArray(scip, ptr, source, num)
Definition: scip.h:20540
virtual SCIP_DECL_CONSGETNVARS(scip_getnvars)
Definition: objconshdlr.h:405
virtual SCIP_DECL_CONSDEACTIVE(scip_deactive)
Definition: objconshdlr.h:325
const int scip_sepafreq_
Definition: objconshdlr.h:71
virtual SCIP_DECL_CONSSEPASOL(scip_sepasol)
Definition: objconshdlr.h:248
C++ wrapper for constraint handlers.
Definition: objconshdlr.h:47
Definition of base class for all clonable classes which define problem data.
SCIP_RETCODE SCIPincludeObjConshdlr(SCIP *scip, scip::ObjConshdlr *objconshdlr, SCIP_Bool deleteobject)
const unsigned int scip_proptiming_
Definition: objconshdlr.h:92
const int scip_checkpriority_
Definition: objconshdlr.h:68
virtual SCIP_DECL_CONSINITPRE(scip_initpre)
Definition: objconshdlr.h:177
virtual SCIP_DECL_CONSCOPY(scip_copy)
Definition: objconshdlr.h:374
virtual SCIP_DECL_CONSACTIVE(scip_active)
Definition: objconshdlr.h:316
virtual SCIP_DECL_CONSGETVARS(scip_getvars)
Definition: objconshdlr.h:393
const unsigned int scip_presoltiming_
Definition: objconshdlr.h:95
virtual SCIP_DECL_CONSEXITSOL(scip_exitsol)
Definition: objconshdlr.h:204
virtual SCIP_DECL_CONSENFOPS(scip_enfops)=0
#define SCIP_CALL_ABORT(x)
Definition: def.h:245
const int scip_enfopriority_
Definition: objconshdlr.h:65
virtual SCIP_DECL_CONSFREE(scip_free)
Definition: objconshdlr.h:150
virtual SCIP_DECL_CONSINITLP(scip_initlp)
Definition: objconshdlr.h:228
SCIP callable library.