coin-Bcp
BCP_cut.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _BCP_CUT_H
4 #define _BCP_CUT_H
5 
6 // This file is fully docified.
7 
8 //#############################################################################
9 
10 #include "CoinSmartPtr.hpp"
11 #include "BCP_math.hpp"
12 #include "BCP_error.hpp"
13 #include "BCP_enum.hpp"
14 #include "BCP_vector.hpp"
15 #include "BCP_obj_change.hpp"
16 
17 //#############################################################################
18 
19 // Generic cut definition
20 
30 private:
34  BCP_cut();
36  BCP_cut(const BCP_cut&);
38  BCP_cut& operator=(const BCP_cut&);
41 private:
46  int _bcpind;
50  int _eff_cnt;
53 protected:
56  double _lb;
58  double _ub;
61 public:
68  BCP_cut(const double lb, const double ub) :
69  _bcpind(0), _status(BCP_ObjNoInfo), _eff_cnt(0), _lb(lb), _ub(ub) {}
72  virtual ~BCP_cut() {}
78  virtual BCP_object_t obj_type() const = 0;
80  inline int effective_count() const { return _eff_cnt; }
82  inline double lb() const { return _lb; }
84  inline double ub() const { return _ub; }
86  inline int bcpind() const { return _bcpind; }
87 
88  /* *@name Query methods about the status of the variable */
89  /* @{*/
91  inline BCP_obj_status status() const { return _status; }
95  inline bool dont_send_to_pool() const {
96  return _status & BCP_ObjDoNotSendToPool ? true : false;
97  }
100  inline bool is_non_removable() const {
101  return (_status & BCP_ObjNotRemovable) ? true : false;
102  }
106  inline bool is_to_be_removed() const {
107  return (_status & BCP_ObjToBeRemoved) != 0;
108  }
109  /* @}*/
115  inline void set_effective_count(const int cnt) { _eff_cnt = cnt; }
119  _eff_cnt = _eff_cnt <= 0 ? 1 : _eff_cnt + 1;
120  return _eff_cnt;
121  }
125  _eff_cnt = _eff_cnt >= 0 ? -1 : _eff_cnt - 1;
126  return _eff_cnt;
127  }
129  inline void set_lb(const double lb) { _lb = lb; }
131  inline void set_ub(const double ub) { _ub = ub; }
134  inline void change_lb_ub_st(const BCP_obj_change& change) {
135  _lb = change.lb;
136  _ub = change.ub;
137  _status = change.stat;
138  if (_lb < -BCP_DBL_MAX/10 && _ub > BCP_DBL_MAX/10)
139  _status = static_cast<BCP_obj_status>(_status | BCP_ObjInactive);
140  }
142  inline void change_bounds(const double lb, const double ub) {
143  _lb = lb;
144  _ub = ub;
145  if (lb < BCP_DBL_MAX/10 && ub > BCP_DBL_MAX/10)
146  _status = static_cast<BCP_obj_status>(_status | BCP_ObjInactive);
147  }
149  inline void set_bcpind(const int bcpind) { _bcpind = bcpind; }
151  inline void set_bcpind_flip() { _bcpind = -_bcpind; }
152 
153  /* *@name Status modifying methods */
154  /* @{*/
156  inline void set_status(const BCP_obj_status stat) { _status = stat; }
159  inline void dont_send_to_pool(bool flag) {
160  _status = static_cast<BCP_obj_status>(flag ?
163  }
167  inline void make_active() {
168  _status = static_cast<BCP_obj_status>(_status & ~BCP_ObjInactive);
169  }
171  inline void make_non_removable() {
172  _status =
173  static_cast<BCP_obj_status> ((_status & ~BCP_ObjToBeRemoved) |
175  }
178  inline void make_to_be_removed() {
180  }
181  /* @}*/
183 };
184 
185 //#############################################################################
186 //#############################################################################
187 
195 class BCP_cut_core : public BCP_cut {
196 
197 private:
201  BCP_cut_core();
206 public:
211  set_bcpind(x.bcpind());
212  set_status(x.status());
214  }
217  BCP_cut_core(const double lb, const double ub) : BCP_cut(lb, ub) {}
226  inline BCP_object_t obj_type() const { return BCP_CoreObj; }
228 };
229 
230 //#############################################################################
231 
232 // This is the class the user should derive his/her own algorithmic cuts
233 
242 class BCP_cut_algo : public BCP_cut {
243 private:
247  BCP_cut_algo();
249  BCP_cut_algo(const BCP_cut_algo&);
254 public:
259  BCP_cut_algo(const double lb, const double ub) : BCP_cut(lb, ub) {}
261  virtual ~BCP_cut_algo() = 0;
268  inline BCP_object_t obj_type() const { return BCP_AlgoObj; }
270 };
271 
272 //#############################################################################
273 //#############################################################################
274 
279 class BCP_cut_set : public BCP_vec<BCP_cut*> {
280 private:
284  BCP_cut_set(const BCP_cut_set&);
289 public:
304  inline void append(const BCP_vec<BCP_cut*>& x) {
306  }
311  BCP_vec<BCP_cut*>::append(first, last);
312  }
313 
317  void set_lb_ub(const BCP_vec<int>& pos,
325  void set_lb_ub_st(const BCP_vec<BCP_obj_change>& cc);
330  const BCP_vec<BCP_obj_change>& cc);
332 #if 0
333  //--------------------------------------------------------------------------
351  void nonzero_slack(int first_to_check, const double * slacks,
352  const double etol, const int ineff_limit,
353  BCP_vec<int>& coll);
356  void zero_dual(int first_to_check, const double * duals,
357  const double etol, const int ineff_limit,
358  BCP_vec<int>& coll);
360 #endif
361 
363 #if 0
364 
367  void deletable(const int bcutnum, BCP_vec<int>& collection) const;
368 #endif
369 
373  void move_deletable_to_pool(const BCP_vec<int>& deletable_cuts,
374  BCP_vec<BCP_cut*>& pool);
376  //-----------------------------------------------------------------------
377 };
378 
379 #endif
void make_non_removable()
Mark the cut as NotRemovable.
Definition: BCP_cut.hpp:171
BCP_cut(const double lb, const double ub)
The constructor sets the internal index of the cut to zero and the other data members to the given ar...
Definition: BCP_cut.hpp:68
bool dont_send_to_pool() const
Return whether the cut should be sent to the Cut Pool process.
Definition: BCP_cut.hpp:95
void set_effective_count(const int cnt)
Set the effectiveness count to the given value.
Definition: BCP_cut.hpp:115
Abstract base class that defines members common to all types of cuts.
Definition: BCP_cut.hpp:29
This is the class from which the user should derive her own algorithmic cuts.
Definition: BCP_cut.hpp:242
void set_bcpind(const int bcpind)
Set the internal index of the cut.
Definition: BCP_cut.hpp:149
void move_deletable_to_pool(const BCP_vec< int > &deletable_cuts, BCP_vec< BCP_cut * > &pool)
Move the cut pointers whose indices are listed in deletable_cuts into the pool.
void set_lb_ub_st(const BCP_vec< BCP_obj_change > &cc)
Set the lower/upper bound pairs and the stati of the first cc.
The object is to be removed next time when the formulation is compressed.
Definition: BCP_enum.hpp:119
BCP_cut_set & operator=(const BCP_cut_set &)
The assignment operator is declared but not defined to disable it.
Core cuts are the cuts that always stay in the LP formulation.
Definition: BCP_cut.hpp:195
double ub() const
Return the upper bound on the cut.
Definition: BCP_cut.hpp:84
void append(BCP_cut_set::const_iterator first, BCP_cut_set::const_iterator last)
Append the cuts in [first, last) to the end of the cut set.
Definition: BCP_cut.hpp:309
double _ub
Upper bound of the cut.
Definition: BCP_cut.hpp:58
This class is just a collection of pointers to cuts with a number of methods to manipulate these cuts...
Definition: BCP_cut.hpp:279
~BCP_cut_core()
The destructor deletes the object.
Definition: BCP_cut.hpp:219
BCP_cut_algo & operator=(const BCP_cut_algo &)
The assignment operator is declared but not defined to disable it.
The object is not removable from the LP formulation, even if the object becomes inactive.
Definition: BCP_enum.hpp:115
BCP_object_t obj_type() const
Return BCP_AlgoObj indicating that the object is an algorithmic cut.
Definition: BCP_cut.hpp:268
double _lb
Lower bound of the cut.
Definition: BCP_cut.hpp:56
void append(const BCP_vec< BCP_cut * > &x)
Append the cuts in the vector x to the end of the cut set.
Definition: BCP_cut.hpp:304
BCP_cut_core & operator=(const BCP_cut_core &)
The assignment operator is declared but not defined to disable it.
BCP_obj_status
This enumerative constant gives the status of an object (variable or cut).
Definition: BCP_enum.hpp:105
virtual ~BCP_cut_algo()=0
The destructor deletes the object.
BCP_cut_core(const BCP_cut_core &x)
The copy constructor makes a replica of the argument.
Definition: BCP_cut.hpp:210
#define BCP_DBL_MAX
Definition: BCP_math.hpp:6
int decrease_effective_count()
Decrease the effectiveness count by 1 (or to -1 if it was positive).
Definition: BCP_cut.hpp:124
double lb() const
Return the lower bound on the cut.
Definition: BCP_cut.hpp:82
int _bcpind
These data members are used only by BCP, the user need not worry about them.
Definition: BCP_cut.hpp:46
void change_lb_ub_st(const BCP_obj_change &change)
Set the lower/upper bounds and the status of the cut simultaneously to the values given in the data m...
Definition: BCP_cut.hpp:134
bool is_non_removable() const
Return whether the cut marked as NotRemovable.
Definition: BCP_cut.hpp:100
BCP_obj_status stat
void set_bcpind_flip()
Flip the internal index of the variable to its negative.
Definition: BCP_cut.hpp:151
ReferencedObject class.
int increase_effective_count()
Increase the effectiveness count by 1 (or to 1 if it was negative).
Definition: BCP_cut.hpp:118
BCP_cut()
The default constructor is declared but not defined to disable it.
void set_lb(const double lb)
Set the lower bound on the cut.
Definition: BCP_cut.hpp:129
void make_active()
Mark the cut as active.
Definition: BCP_cut.hpp:167
BCP_obj_status status() const
Return the status of the cut.
Definition: BCP_cut.hpp:91
No special information is given about the object.
Definition: BCP_enum.hpp:107
void dont_send_to_pool(bool flag)
Set/unset the flag controlling whether the cut could be sent to the Cut Pool process.
Definition: BCP_cut.hpp:159
The object does not need to be sent to the variable/cut pool.
Definition: BCP_enum.hpp:109
void set_status(const BCP_obj_status stat)
Set the status of the cut.
Definition: BCP_cut.hpp:156
virtual BCP_object_t obj_type() const =0
Return the type of the variable.
The object is inactive.
Definition: BCP_enum.hpp:123
BCP_cut_algo(const double lb, const double ub)
This constructor just sets the data members to the given values.
Definition: BCP_cut.hpp:259
void set_ub(const double ub)
Set the upper bound on the cut.
Definition: BCP_cut.hpp:131
BCP_object_t obj_type() const
Return BCP_CoreObj indicating that the object is a core cut.
Definition: BCP_cut.hpp:226
int effective_count() const
Return the effectiveness count of the cut (only in LP process).
Definition: BCP_cut.hpp:80
Algorithmic object.
Definition: BCP_enum.hpp:53
The class BCP_vec serves the same purpose as the vector class in the standard template library...
Definition: BCP_vector.hpp:24
void change_bounds(const double lb, const double ub)
Change just the lower/upper bounds.
Definition: BCP_cut.hpp:142
BCP_cut_set()
The default constructor creates a cut set with no cuts in it.
Definition: BCP_cut.hpp:293
BCP_cut_core(const double lb, const double ub)
This constructor just sets the data members to the given values.
Definition: BCP_cut.hpp:217
BCP_cut_core()
The default constructor is declared but not defined to disable it.
int _eff_cnt
Effectiveness counter (used only in the LP process).
Definition: BCP_cut.hpp:50
BCP_cut & operator=(const BCP_cut &)
The assignment operator is declared but not defined to disable it.
virtual ~BCP_cut()
The destructor is virtual so that the appropriate destructor is invoked for every cut...
Definition: BCP_cut.hpp:72
void set_lb_ub(const BCP_vec< int > &pos, BCP_vec< double >::const_iterator bounds)
Set the lower/upper bound pairs of the entries given by the contents of pos to the values in [bounds...
~BCP_cut_set()
The destructor empties the cut set.
Definition: BCP_cut.hpp:296
BCP_cut_algo()
The default constructor is declared but not defined to disable it.
void make_to_be_removed()
Mark the cut as ToBeRemoved.
Definition: BCP_cut.hpp:178
bool is_to_be_removed() const
Return whether the cut must be removed from the formulation.
Definition: BCP_cut.hpp:106
int bcpind() const
Return the internal index of the cut.
Definition: BCP_cut.hpp:86
BCP_object_t
This enumerative constant describes the possible types of objects (variables and cuts).
Definition: BCP_enum.hpp:49
Base object.
Definition: BCP_enum.hpp:51
void append(const BCP_vec< T > &x)
Append the entries in x to the end of the vector.
Definition: BCP_vector.hpp:169
BCP_obj_status _status
The status of the cut.
Definition: BCP_cut.hpp:48