Bcp 1.4.4
Loading...
Searching...
No Matches
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
27
28class BCP_var : public Coin::ReferencedObject {
29private:
34 BCP_var();
36 BCP_var(const BCP_var&);
38 BCP_var& operator=(const BCP_var&);
40
41private:
46 int _bcpind;
48 BCP_obj_status _status;
50
51protected:
57 double _obj;
59 double _lb;
61 double _ub;
63
64public:
72 const double obj, const double lb, const double ub) :
73 _bcpind(0), _status(BCP_ObjNoInfo),
75
77 virtual ~BCP_var() {}
79
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 }
105
106 inline bool is_fixed() const {
107 return (_status & BCP_ObjInactive) != 0;
108 }
109
110 inline bool is_fixed_to_zero() const {
111 return (_status & BCP_ObjInactive) && _lb == 0;
112 }
113
115 inline bool is_non_removable() const {
116 return (_status & BCP_ObjNotRemovable) ? true : false;
117 }
118
121 inline bool is_removable() const {
122 return (_status & BCP_ObjNotRemovable) ? false : is_fixed_to_zero();
123 }
124
127 inline bool is_to_be_removed() const {
128 return (_status & BCP_ObjToBeRemoved) != 0;
129 }
130
132
136 inline void test_inactive() {
137 if (_ub - _lb < 1e-8)
138 _status = static_cast<BCP_obj_status>(_status | BCP_ObjInactive);
139 }
140
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;
148 }
149
150 inline void set_ub(const double ub) {
151 _ub = ub;
153 }
154
155 inline void set_lb_ub(const double lb, const double ub) {
156 _lb = lb;
157 _ub = ub;
159 }
160
163 inline void change_lb_ub_st(const BCP_obj_change& change) {
164 _lb = change.lb;
165 _ub = change.ub;
166 _status = change.stat;
168 }
169
170 inline void change_bounds(const double lb, const double ub) {
171 _lb = lb;
172 _ub = ub;
174 }
175
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 ?
189 _status | BCP_ObjDoNotSendToPool :
190 _status & ~BCP_ObjDoNotSendToPool);
191 }
192
195 inline void make_active() {
196 _status = static_cast<BCP_obj_status>(_status & ~BCP_ObjInactive);
197 }
198
199 inline void make_non_removable() {
200 _status =
201 static_cast<BCP_obj_status>((_status & ~BCP_ObjToBeRemoved) |
203 }
204
207 inline void make_to_be_removed() {
208 _status = BCP_ObjToBeRemoved;
209 }
210
211
217 void display(const double val) const;
219};
220
221//#############################################################################
222//#############################################################################
223
229
230class BCP_var_core : public BCP_var {
231private:
235 BCP_var_core();
237 BCP_var_core& operator=(const BCP_var_core&);
239
240public:
244 BCP_var_core(const BCP_var_core& x) :
245 BCP_var(x._var_type, x._obj, x._lb, x._ub) {
246 set_bcpind(x.bcpind());
247 set_status(x.status());
248 }
249
252 const double obj, const double lb, const double ub) :
253 BCP_var(var_type, obj, lb, ub) {}
254
257
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
276
277class BCP_var_algo : public BCP_var {
278private:
282 BCP_var_algo();
284 BCP_var_algo(const BCP_var_algo&);
286 BCP_var_algo& operator=(const BCP_var_algo&);
288
289public:
295 const double obj, const double lb, const double ub) :
296 BCP_var(var_type, obj, lb, ub) {}
297
298 virtual ~BCP_var_algo() = 0;
300
305 inline BCP_object_t obj_type() const { return BCP_AlgoObj; }
307};
308
309//#############################################################################
310//#############################################################################
311
315
316class BCP_var_set : public BCP_vec<BCP_var*> {
317private:
321 BCP_var_set(const BCP_var_set&);
323 BCP_var_set& operator=(const BCP_var_set&);
325
326public:
337
342 inline void append(const BCP_vec<BCP_var*>& x) {
344 }
345
351
355 void set_lb_ub(const BCP_vec<int>& pos,
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_obj_status
This enumerative constant gives the status of an object (variable or cut).
Definition BCP_enum.hpp:105
@ BCP_ObjToBeRemoved
The object is to be removed next time when the formulation is compressed.
Definition BCP_enum.hpp:119
@ BCP_ObjNoInfo
No special information is given about the object.
Definition BCP_enum.hpp:107
@ BCP_ObjDoNotSendToPool
The object does not need to be sent to the variable/cut pool.
Definition BCP_enum.hpp:109
@ BCP_ObjNotRemovable
The object is not removable from the LP formulation, even if the object becomes inactive.
Definition BCP_enum.hpp:115
@ BCP_ObjInactive
The object is inactive.
Definition BCP_enum.hpp:123
BCP_object_t
This enumerative constant describes the possible types of objects (variables and cuts).
Definition BCP_enum.hpp:49
@ BCP_CoreObj
Base object.
Definition BCP_enum.hpp:51
@ BCP_AlgoObj
Algorithmic object.
Definition BCP_enum.hpp:53
BCP_var_t
This enumerative constant describes the integrality type of a variable.
Definition BCP_enum.hpp:161
BCP_obj_status stat
virtual ~BCP_var_algo()=0
The destructor deletes the object.
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_object_t obj_type() const
Return BCP_AlgoObj indicating that the object is an algorithmic variable.
Definition BCP_var.hpp:305
~BCP_var_core()
The destructor deletes the object.
Definition BCP_var.hpp:255
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
BCP_var_core(const BCP_var_core &x)
The copy constructor makes a replica of the argument.
Definition BCP_var.hpp:244
BCP_object_t obj_type() const
Return BCP_CoreObj indicating that the object is a core variable.
Definition BCP_var.hpp:261
~BCP_var_set()
The destructor empties the variable set.
Definition BCP_var.hpp:335
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
BCP_var_set()
The default constructor creates a variable set with no variables in it.
Definition BCP_var.hpp:331
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.
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 deletable(const int bvarnum, BCP_vec< int > &collection)
Collect the indices of the variables marked to be removed.
void set_lb_ub_st(BCP_vec< int >::const_iterator pos, const BCP_vec< BCP_obj_change > &vc)
Set the lower/upper bound pairs and the stati of the entries given by the content of [pos,...
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_var_t _var_type
The integrality type of the variable.
Definition BCP_var.hpp:55
void set_lb_ub(const double lb, const double ub)
Set both lower and upper bounds.
Definition BCP_var.hpp:155
double _obj
The objective coefficient.
Definition BCP_var.hpp:57
int bcpind() const
Return the internal index of the variable.
Definition BCP_var.hpp:93
bool is_to_be_removed() const
Return whether the variable must be removed from the formulation.
Definition BCP_var.hpp:127
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
virtual BCP_object_t obj_type() const =0
Return the type of the variable.
void test_inactive()
Test (and set) whether the var is fixed (inactive)
Definition BCP_var.hpp:136
void make_non_removable()
Mark the variable as NotRemovable.
Definition BCP_var.hpp:199
void set_var_type(const BCP_var_t type)
Set the integrality type of the variable.
Definition BCP_var.hpp:141
void set_obj(const double obj)
Set the objective coefficient.
Definition BCP_var.hpp:143
void set_lb(const double lb)
Set the lower bound.
Definition BCP_var.hpp:145
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
void set_bcpind_flip()
Flip the internal index of the variable to its negative.
Definition BCP_var.hpp:178
double obj() const
Return the objective coefficient.
Definition BCP_var.hpp:87
bool dont_send_to_pool() const
Return whether the variable should be sent to the Variable Pool process.
Definition BCP_var.hpp:102
void set_status(const BCP_obj_status status)
Set the status of the variable.
Definition BCP_var.hpp:183
bool is_fixed() const
Return whether the variable is fixed or not.
Definition BCP_var.hpp:106
void set_ub(const double ub)
Set the upper bound.
Definition BCP_var.hpp:150
void display(const double val) const
Display the object type, internal index, and the value given in the argument.
double _ub
Upper bound on the value the variable can take.
Definition BCP_var.hpp:61
bool is_fixed_to_zero() const
Return whether the variable is fixed to zero or not.
Definition BCP_var.hpp:110
void change_bounds(const double lb, const double ub)
Change the lower and upper bounds to the given values.
Definition BCP_var.hpp:170
void set_bcpind(const int bcpind)
Set the internal index of the variable.
Definition BCP_var.hpp:176
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 make_to_be_removed()
Mark the variable as ToBeRemoved.
Definition BCP_var.hpp:207
virtual ~BCP_var()
The destructor is virtual so that the appropriate destructor is invoked for every variable.
Definition BCP_var.hpp:77
BCP_var_t var_type() const
Return the integrality type of the variable.
Definition BCP_var.hpp:85
void make_active()
Mark the variable as active.
Definition BCP_var.hpp:195
BCP_obj_status status() const
Return the status of the variable.
Definition BCP_var.hpp:98
double ub() const
Return the upper bound.
Definition BCP_var.hpp:91
double lb() const
Return the lower bound.
Definition BCP_var.hpp:89
bool is_non_removable() const
Return whether the variable is marked NotRemovable.
Definition BCP_var.hpp:115
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
double _lb
Lower bound on the value the variable can take.
Definition BCP_var.hpp:59
const BCP_var ** const_iterator
BCP_vec(const size_t n, const_reference value)
void append(const BCP_vec< T > &x)
Append the entries in x to the end of the vector.