coin-Bcp
BCP_var.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_VAR_H
4 #define _BCP_VAR_H
5 
6 // This file is fully docified.
7 
8 //#############################################################################
9 
10 #include "CoinSmartPtr.hpp"
11 #include "BCP_error.hpp"
12 #include "BCP_enum.hpp"
13 #include "BCP_vector.hpp"
14 #include "BCP_obj_change.hpp"
15 
16 //#############################################################################
17 
18 // Generic variable definition.
19 
29 private:
34  BCP_var();
36  BCP_var(const BCP_var&);
38  BCP_var& operator=(const BCP_var&);
41 private:
46  int _bcpind;
51 protected:
57  double _obj;
59  double _lb;
61  double _ub;
64 public:
72  const double obj, const double lb, const double ub) :
74  _var_type(var_type), _obj(obj), _lb(lb), _ub(ub) {}
77  virtual ~BCP_var() {}
83  virtual BCP_object_t obj_type() const = 0;
85  inline BCP_var_t var_type() const { return _var_type; }
87  inline double obj() const { return _obj; }
89  inline double lb() const { return _lb; }
91  inline double ub() const { return _ub; }
93  inline int bcpind() const { return _bcpind; }
94 
98  inline BCP_obj_status status() const { return _status; }
102  inline bool dont_send_to_pool() const {
103  return _status & BCP_ObjDoNotSendToPool ? true : false;
104  }
106  inline bool is_fixed() const {
107  return (_status & BCP_ObjInactive) != 0;
108  }
110  inline bool is_fixed_to_zero() const {
111  return (_status & BCP_ObjInactive) && _lb == 0;
112  }
115  inline bool is_non_removable() const {
116  return (_status & BCP_ObjNotRemovable) ? true : false;
117  }
121  inline bool is_removable() const {
122  return (_status & BCP_ObjNotRemovable) ? false : is_fixed_to_zero();
123  }
127  inline bool is_to_be_removed() const {
128  return (_status & BCP_ObjToBeRemoved) != 0;
129  }
132 
136  inline void test_inactive() {
137  if (_ub - _lb < 1e-8)
138  _status = static_cast<BCP_obj_status>(_status | BCP_ObjInactive);
139  }
141  inline void set_var_type(const BCP_var_t type) { _var_type = type; }
143  inline void set_obj(const double obj) { _obj = obj; }
145  inline void set_lb(const double lb) {
146  _lb = lb;
147  test_inactive();
148  }
150  inline void set_ub(const double ub) {
151  _ub = ub;
152  test_inactive();
153  }
155  inline void set_lb_ub(const double lb, const double ub) {
156  _lb = lb;
157  _ub = ub;
158  test_inactive();
159  }
163  inline void change_lb_ub_st(const BCP_obj_change& change) {
164  _lb = change.lb;
165  _ub = change.ub;
166  _status = change.stat;
167  test_inactive();
168  }
170  inline void change_bounds(const double lb, const double ub) {
171  _lb = lb;
172  _ub = ub;
173  test_inactive();
174  }
176  inline void set_bcpind(const int bcpind) { _bcpind = bcpind; }
178  inline void set_bcpind_flip() { _bcpind = -_bcpind; }
179 
183  inline void set_status(const BCP_obj_status status) { _status = status; }
186  inline void dont_send_to_pool(bool flag) {
187  _status =
188  static_cast<BCP_obj_status>(flag ?
191  }
195  inline void make_active() {
196  _status = static_cast<BCP_obj_status>(_status & ~BCP_ObjInactive);
197  }
199  inline void make_non_removable() {
200  _status =
201  static_cast<BCP_obj_status>((_status & ~BCP_ObjToBeRemoved) |
203  }
207  inline void make_to_be_removed() {
209  }
217  void display(const double val) const;
219 };
220 
221 //#############################################################################
222 //#############################################################################
223 
230 class BCP_var_core : public BCP_var {
231 private:
235  BCP_var_core();
240 public:
245  BCP_var(x._var_type, x._obj, x._lb, x._ub) {
246  set_bcpind(x.bcpind());
247  set_status(x.status());
248  }
252  const double obj, const double lb, const double ub) :
253  BCP_var(var_type, obj, lb, ub) {}
261  inline BCP_object_t obj_type() const { return BCP_CoreObj; }
263 };
264 
265 //#############################################################################
266 
267 // This is the class the user should derive his/her own algorithmic vars
268 
277 class BCP_var_algo : public BCP_var {
278 private:
282  BCP_var_algo();
284  BCP_var_algo(const BCP_var_algo&);
289 public:
295  const double obj, const double lb, const double ub) :
296  BCP_var(var_type, obj, lb, ub) {}
298  virtual ~BCP_var_algo() = 0;
305  inline BCP_object_t obj_type() const { return BCP_AlgoObj; }
307 };
308 
309 //#############################################################################
310 //#############################################################################
311 
316 class BCP_var_set : public BCP_vec<BCP_var*> {
317 private:
321  BCP_var_set(const BCP_var_set&);
326 public:
342  inline void append(const BCP_vec<BCP_var*>& x) {
344  }
349  BCP_vec<BCP_var*>::append(first, last);
350  }
351 
355  void set_lb_ub(const BCP_vec<int>& pos,
363  void set_lb_ub_st(const BCP_vec<BCP_obj_change>& vc);
368  const BCP_vec<BCP_obj_change>& vc);
370  //--------------------------------------------------------------------------
376  void deletable(const int bvarnum, BCP_vec<int>& collection);
377  // *FIXME* shouldn't we keep a local var pool in the lp process and move
378  // deletables to this pool? compare w/ cuts...
380  //--------------------------------------------------------------------------
381 };
382 
383 #endif
BCP_var_algo()
The default constructor is declared but not defined to disable it.
BCP_var()
The default constructor is declared but not defined to disable it.
~BCP_var_core()
The destructor deletes the object.
Definition: BCP_var.hpp:255
void set_ub(const double ub)
Set the upper bound.
Definition: BCP_var.hpp:150
void set_var_type(const BCP_var_t type)
Set the integrality type of the variable.
Definition: BCP_var.hpp:141
bool is_fixed() const
Return whether the variable is fixed or not.
Definition: BCP_var.hpp:106
BCP_var & operator=(const BCP_var &)
The assignment operator is declared but not defined to disable it.
BCP_obj_status _status
The status of the variable.
Definition: BCP_var.hpp:48
virtual ~BCP_var()
The destructor is virtual so that the appropriate destructor is invoked for every variable...
Definition: BCP_var.hpp:77
~BCP_var_set()
The destructor empties the variable set.
Definition: BCP_var.hpp:335
void set_bcpind(const int bcpind)
Set the internal index of the variable.
Definition: BCP_var.hpp:176
The object is to be removed next time when the formulation is compressed.
Definition: BCP_enum.hpp:119
The object is not removable from the LP formulation, even if the object becomes inactive.
Definition: BCP_enum.hpp:115
void make_non_removable()
Mark the variable as NotRemovable.
Definition: BCP_var.hpp:199
void change_lb_ub_st(const BCP_obj_change &change)
Set the lower/upper bounds and the status of the variable simultaneously to the values given in the d...
Definition: BCP_var.hpp:163
BCP_var_core(const BCP_var_t var_type, const double obj, const double lb, const double ub)
This constructor just sets the data members to the given values.
Definition: BCP_var.hpp:251
Core variables are the variables that always stay in the LP formulation.
Definition: BCP_var.hpp:230
BCP_var_core()
The default constructor is declared but not defined to disable it.
virtual ~BCP_var_algo()=0
The destructor deletes the object.
BCP_obj_status
This enumerative constant gives the status of an object (variable or cut).
Definition: BCP_enum.hpp:105
void change_bounds(const double lb, const double ub)
Change the lower and upper bounds to the given values.
Definition: BCP_var.hpp:170
BCP_obj_status stat
double _obj
The objective coefficient.
Definition: BCP_var.hpp:57
double ub() const
Return the upper bound.
Definition: BCP_var.hpp:91
void set_lb_ub(const double lb, const double ub)
Set both lower and upper bounds.
Definition: BCP_var.hpp:155
ReferencedObject class.
BCP_var_algo(const BCP_var_t var_type, const double obj, const double lb, const double ub)
This constructor just sets the data members to the given values.
Definition: BCP_var.hpp:294
BCP_var(const BCP_var_t var_type, const double obj, const double lb, const double ub)
The constructor sets the internal index of the variable to zero and the other data members to the giv...
Definition: BCP_var.hpp:71
BCP_var_core & operator=(const BCP_var_core &)
The assignment operator is declared but not defined to disable it.
BCP_object_t obj_type() const
Return BCP_AlgoObj indicating that the object is an algorithmic variable.
Definition: BCP_var.hpp:305
bool is_fixed_to_zero() const
Return whether the variable is fixed to zero or not.
Definition: BCP_var.hpp:110
BCP_var_t _var_type
The integrality type of the variable.
Definition: BCP_var.hpp:55
double _lb
Lower bound on the value the variable can take.
Definition: BCP_var.hpp:59
No special information is given about the object.
Definition: BCP_enum.hpp:107
BCP_var_set & operator=(const BCP_var_set &)
The assignment operator is declared but not defined to disable it.
double obj() const
Return the objective coefficient.
Definition: BCP_var.hpp:87
BCP_object_t obj_type() const
Return BCP_CoreObj indicating that the object is a core variable.
Definition: BCP_var.hpp:261
The object does not need to be sent to the variable/cut pool.
Definition: BCP_enum.hpp:109
The object is inactive.
Definition: BCP_enum.hpp:123
bool is_removable() const
Return whether the variable is removable from the formulation at the time of the query.
Definition: BCP_var.hpp:121
void display(const double val) const
Display the object type, internal index, and the value given in the argument.
BCP_var_t var_type() const
Return the integrality type of the variable.
Definition: BCP_var.hpp:85
bool is_non_removable() const
Return whether the variable is marked NotRemovable.
Definition: BCP_var.hpp:115
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...
Abstract base class that defines members common to all types of variables.
Definition: BCP_var.hpp:28
void make_active()
Mark the variable as active.
Definition: BCP_var.hpp:195
bool dont_send_to_pool() const
Return whether the variable should be sent to the Variable Pool process.
Definition: BCP_var.hpp:102
int bcpind() const
Return the internal index of the variable.
Definition: BCP_var.hpp:93
Algorithmic object.
Definition: BCP_enum.hpp:53
BCP_obj_status status() const
Return the status of the variable.
Definition: BCP_var.hpp:98
This class is just a collection of pointers to variables with a number of methods to manipulate these...
Definition: BCP_var.hpp:316
This is the class from which the user should derive her own algorithmic variables.
Definition: BCP_var.hpp:277
The class BCP_vec serves the same purpose as the vector class in the standard template library...
Definition: BCP_vector.hpp:24
void deletable(const int bvarnum, BCP_vec< int > &collection)
Collect the indices of the variables marked to be removed.
void set_obj(const double obj)
Set the objective coefficient.
Definition: BCP_var.hpp:143
int _bcpind
The internal, unique index of the variable.
Definition: BCP_var.hpp:46
double lb() const
Return the lower bound.
Definition: BCP_var.hpp:89
void append(BCP_var_set::const_iterator first, BCP_var_set::const_iterator last)
Append the variables in [first, last) to the end of the variable set.
Definition: BCP_var.hpp:347
void append(const BCP_vec< BCP_var * > &x)
Append the variables in the vector x to the end of the variable set.
Definition: BCP_var.hpp:342
double _ub
Upper bound on the value the variable can take.
Definition: BCP_var.hpp:61
void set_lb(const double lb)
Set the lower bound.
Definition: BCP_var.hpp:145
BCP_var_algo & operator=(const BCP_var_algo &)
The assignment operator is declared but not defined to disable it.
void test_inactive()
Test (and set) whether the var is fixed (inactive)
Definition: BCP_var.hpp:136
void set_bcpind_flip()
Flip the internal index of the variable to its negative.
Definition: BCP_var.hpp:178
void set_status(const BCP_obj_status status)
Set the status of the variable.
Definition: BCP_var.hpp:183
BCP_var_set()
The default constructor creates a variable set with no variables in it.
Definition: BCP_var.hpp:331
BCP_object_t
This enumerative constant describes the possible types of objects (variables and cuts).
Definition: BCP_enum.hpp:49
virtual BCP_object_t obj_type() const =0
Return the type of the variable.
BCP_var_core(const BCP_var_core &x)
The copy constructor makes a replica of the argument.
Definition: BCP_var.hpp:244
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
void make_to_be_removed()
Mark the variable as ToBeRemoved.
Definition: BCP_var.hpp:207
void set_lb_ub_st(const BCP_vec< BCP_obj_change > &vc)
Set the lower/upper bound pairs and the stati of the first cc.
BCP_var_t
This enumerative constant describes the integrality type of a variable.
Definition: BCP_enum.hpp:161
bool is_to_be_removed() const
Return whether the variable must be removed from the formulation.
Definition: BCP_var.hpp:127
void dont_send_to_pool(bool flag)
Set/unset the flag controlling whether the variable could be sent to the Variable Pool process...
Definition: BCP_var.hpp:186