BcpsObject.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Branch, Constrain and Price Software (BiCePS) *
3  * *
4  * BiCePS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Ted Ralphs, Lehigh University *
11  * *
12  * Conceptual Design: *
13  * *
14  * Yan Xu, Lehigh University *
15  * Ted Ralphs, Lehigh University *
16  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17  * Matthew Saltzman, Clemson University *
18  * *
19  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
20  * All Rights Reserved. *
21  *===========================================================================*/
22 
23 #ifndef BcpsObject_h_
24 #define BcpsObject_h_
25 
26 #include "Alps.h"
27 #include "AlpsKnowledge.h"
28 
29 #include "Bcps.h"
30 
31 class BcpsModel;
32 class BcpsBranchObject;
33 
34 //#############################################################################
35 
36 #define BCPS_NONREMOVALBE 0x0001
37 #define BCPS_BRACNEDON 0x0010
38 #define BCPS_SENDABLE 0x0100
39 
40 //#############################################################################
41 
45 typedef char BcpsIntegral_t;
48 //#############################################################################
51 //#############################################################################
52 
58 };
59 
60 //#############################################################################
62 //#############################################################################
63 
65  BCPS_CORE = 0,
68 };
69 
70 //#############################################################################
74 //#############################################################################
75 
76 class BcpsObject : public AlpsKnowledge {
77 
78  protected:
79 
82 
85 
91 
95 
97  // branched on? non-removable ? can it be sent to the pool?
98  // do we need it at all?
99  int status_;
100 
102  double lbHard_;
103 
105  double ubHard_;
106 
108  double lbSoft_;
109 
111  double ubSoft_;
112 
114  double hashValue_;
115 
118 
121 
122  public:
123 
125  :
126  objectIndex_(-1),
128  intType_('C'),
130  status_(0),
131  lbHard_(0.0),
132  ubHard_(0.0),
133  lbSoft_(0.0),
134  ubSoft_(0.0),
135  hashValue_(0.0),
136  numInactive_(0),
138  {}
139 
140  BcpsObject(double lbh, double ubh, double lbs, double ubs)
141  :
142  objectIndex_(-1),
144  intType_('C'),
146  status_(0),
147  lbHard_(lbh),
148  ubHard_(ubh),
149  lbSoft_(lbs),
150  ubSoft_(ubs),
151  hashValue_(0.0),
152  numInactive_(0),
154  {}
155 
156  virtual ~BcpsObject() {}
157 
159  BcpsObject (const BcpsObject & rhs) {
161  repType_ = rhs.repType_;
162  intType_ = rhs.intType_;
164  status_ = rhs.status_;
165  lbHard_ = rhs.lbHard_;
166  ubHard_ = rhs.ubHard_;
167  lbSoft_ = rhs.lbSoft_;
168  ubSoft_ = rhs.ubSoft_;
169  hashValue_ = rhs.hashValue_;
172  }
173 
175  BcpsObject & operator = ( const BcpsObject& rhs);
176 
178  virtual BcpsObject * clone() const {
179  BcpsObject * be = NULL;
180  return be;
181  }
182 
185  inline int getObjectIndex() const { return objectIndex_; }
186  inline BcpsObjRep_t getRepType() const { return repType_; }
187  inline BcpsIntegral_t getIntType() const { return intType_; }
188  inline BcpsValidRegion getValidRegion() const { return validRegion_; }
189  inline int getStatus() const { return status_; }
190  inline double getLbHard() const { return lbHard_; }
191  inline double getUbHard() const { return ubHard_; }
192  inline double getLbSoft() const { return lbSoft_; }
193  inline double getUbSoft() const { return ubSoft_; }
194  inline int getNumInactive() const { return numInactive_; }
195  inline double getEffectiveness() const { return effectiveness_; }
200  inline void setObjectIndex(int ind) { objectIndex_ = ind; }
201  inline void setRepType(BcpsObjRep_t rt) { repType_ = rt; }
202  inline void setIntType(BcpsIntegral_t it) { intType_ = it; }
203  inline void setValidRegion(BcpsValidRegion val) { validRegion_ = val;}
204  inline void setStatus(int st) { status_ |= st; }
205  inline void setLbHard(double lb) { lbHard_ = lb; }
206  inline void setUbHard(double ub) { ubHard_ = ub; }
207  inline void setLbSoft(double lb) { lbSoft_ = lb; }
208  inline void setUbSoft(double ub) { ubSoft_ = ub; }
209  inline void setNumInactive(int num) { numInactive_ = num; }
210  inline void setEffectiveness(double eff) { effectiveness_= eff; }
215  virtual void hashing(BcpsModel *model=NULL) { hashValue_ = 0.0; }
216  double hashValue() const { return hashValue_; }
231  virtual double infeasibility(BcpsModel *m, int &preferredWay) const {
232  return 0.0;
233  }
234 
236  virtual void feasibleRegion(BcpsModel *m) {}
237 
241  virtual BcpsBranchObject * createBranchObject(BcpsModel *m, int way) const{
242  BcpsBranchObject *be = NULL;
243  return be;
244  }
245 
253  BcpsBranchObject * temp = NULL;
254  return temp;
255  }
256 
264  BcpsBranchObject * temp = NULL;
265  return temp;
266  }
267 
271  virtual void resetBounds(BcpsModel *m) {}
272 
275  virtual bool boundBranch(BcpsModel *m) const { return true; }
276 
278  virtual void floorCeiling(double &floorValue,
279  double &ceilingValue,
280  double value,
281  double tolerance) const;
282 
284  virtual double upEstimate() const { return 1.0e-5; }
285 
287  virtual double downEstimate() const { return 1.0e-5; }
288 
289  virtual void printDesc() {}
290 
291  protected:
292 
296  encoded->writeRep(objectIndex_);
297  encoded->writeRep(repType_);
298  encoded->writeRep(intType_);
299  encoded->writeRep(validRegion_);
300  encoded->writeRep(status_);
301  encoded->writeRep(lbHard_);
302  encoded->writeRep(ubHard_);
303  encoded->writeRep(lbSoft_);
304  encoded->writeRep(ubSoft_);
305  encoded->writeRep(hashValue_);
306  return status;
307  }
308 
312  encoded.readRep(objectIndex_);
313  encoded.readRep(repType_);
314  encoded.readRep(intType_);
315  encoded.readRep(validRegion_);
316  encoded.readRep(status_);
317  encoded.readRep(lbHard_);
318  encoded.readRep(ubHard_);
319  encoded.readRep(lbSoft_);
320  encoded.readRep(ubSoft_);
321  encoded.readRep(hashValue_);
322  return status;
323  }
324 
325 protected:
326 
327  public:
328 
329  using AlpsKnowledge::encode ;
331  virtual AlpsReturnStatus encode(AlpsEncoded *encoded) {
333  assert(0);
334  return status;
335  }
336 
338  virtual AlpsKnowledge* decode(AlpsEncoded& encoded) const {
339  AlpsKnowledge* know = NULL;
340  assert(0);
341  return know;
342  }
343 };
344 
345 
346 //#############################################################################
347 
348 
350 
351 
352 //#############################################################################
353 
354 
355 class BcpsConstraint : public BcpsObject {
356 
357  public:
360 
362  BcpsConstraint(double lbh, double ubh, double lbs, double ubs)
363  :
364  BcpsObject(lbh, ubh, lbs, ubs)
366 
368  virtual ~BcpsConstraint() {}
369 
372  :
373  BcpsObject(rhs)
374  {}
375 
376  inline virtual BcpsObject_t getObjType() const { return BCPS_CON_OBJECT; }
377 };
378 
379 
380 //#############################################################################
381 
382 
383 class BcpsVariable : public BcpsObject {
384  public:
387 
389  BcpsVariable(double lbh, double ubh, double lbs, double ubs)
390  :
391  BcpsObject(lbh, ubh, lbs, ubs)
393 
395  virtual ~BcpsVariable() {}
396 
399  :
400  BcpsObject(rhs)
401  {}
402 
403  inline virtual BcpsObject_t getObjType() const { return BCPS_VAR_OBJECT; }
404 };
405 
406 
407 //#############################################################################
408 
409 #endif
BcpsObjRep_t repType_
Core, indexed, or algorithmic.
Definition: BcpsObject.h:84
int objectIndex_
Global index of this object.
Definition: BcpsObject.h:81
BcpsIntegral_t getIntType() const
Return the value of the appropriate field.
Definition: BcpsObject.h:187
void setUbHard(double ub)
Set the appropriate property.
Definition: BcpsObject.h:206
double ubHard_
The upper bound of the object when it was first created.
Definition: BcpsObject.h:105
BcpsVariable(const BcpsVariable &rhs)
Copy constructor.
Definition: BcpsObject.h:398
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
Decode a constraint from an encoded object.
Definition: BcpsObject.h:338
virtual BcpsBranchObject * preferredNewFeasible(BcpsModel *m) const
Given a valid solution (with reduced costs, etc.), return a branching object which would give a new f...
Definition: BcpsObject.h:252
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
void setValidRegion(BcpsValidRegion val)
Set the appropriate property.
Definition: BcpsObject.h:203
BcpsValidRegion
Definition: Bcps.h:44
void setEffectiveness(double eff)
Set the appropriate property.
Definition: BcpsObject.h:210
void setUbSoft(double ub)
Set the appropriate property.
Definition: BcpsObject.h:208
BcpsVariable()
Default constructor.
Definition: BcpsObject.h:386
virtual double infeasibility(BcpsModel *m, int &preferredWay) const
Infeasibility of the object This is some measure of the infeasibility of the object.
Definition: BcpsObject.h:231
BcpsValidRegion getValidRegion() const
Return the value of the appropriate field.
Definition: BcpsObject.h:188
void setNumInactive(int num)
Set the appropriate property.
Definition: BcpsObject.h:209
AlpsReturnStatus
Definition: Alps.h:118
virtual bool boundBranch(BcpsModel *m) const
Return true if branches created by object will modify variable bounds.
Definition: BcpsObject.h:275
double getEffectiveness() const
Return the value of the appropriate field.
Definition: BcpsObject.h:195
BcpsObject(double lbh, double ubh, double lbs, double ubs)
Definition: BcpsObject.h:140
virtual BcpsBranchObject * notPreferredNewFeasible(BcpsModel *m) const
Given a valid solution (with reduced costs, etc.), return a branching object which would give a new f...
Definition: BcpsObject.h:263
virtual double downEstimate() const
Return "down" estimate.
Definition: BcpsObject.h:287
virtual BcpsBranchObject * createBranchObject(BcpsModel *m, int way) const
Create a branching object and indicate which way to branch first.
Definition: BcpsObject.h:241
BcpsVariable(double lbh, double ubh, double lbs, double ubs)
Useful constructor.
Definition: BcpsObject.h:389
BcpsObject & operator=(const BcpsObject &rhs)
Assignment operator.
A class for describing the objects that comprise a BCPS subproblem.
Definition: BcpsObject.h:76
BcpsConstraint()
Default constructor.
Definition: BcpsObject.h:359
char BcpsIntegral_t
typedef's for various integral types.
Definition: BcpsObject.h:45
#define ALPS_DBL_MAX
Definition: Alps.h:143
virtual void floorCeiling(double &floorValue, double &ceilingValue, double value, double tolerance) const
Returns floor and ceiling i.e.
BcpsBranchObject contains the member data required when choosing branching entities and excuting actu...
virtual void resetBounds(BcpsModel *m)
Reset variable bounds to their original values.
Definition: BcpsObject.h:271
BcpsObject * BcpsObject_p
Definition: BcpsObject.h:349
virtual ~BcpsObject()
Definition: BcpsObject.h:156
virtual ~BcpsVariable()
Destructor.
Definition: BcpsObject.h:395
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
double getLbHard() const
Return the value of the appropriate field.
Definition: BcpsObject.h:190
double getUbSoft() const
Return the value of the appropriate field.
Definition: BcpsObject.h:193
int getObjectIndex() const
Return the value of the appropriate field.
Definition: BcpsObject.h:185
BcpsObjRep_t getRepType() const
Return the value of the appropriate field.
Definition: BcpsObject.h:186
int getNumInactive() const
Return the value of the appropriate field.
Definition: BcpsObject.h:194
BcpsObject_t
The possible types of an object: primal or dual (i.e., variable or constraint.
Definition: BcpsObject.h:53
double getLbSoft() const
Return the value of the appropriate field.
Definition: BcpsObject.h:192
double effectiveness_
Effectiveness: nonnegative value.
Definition: BcpsObject.h:120
BcpsObjRep_t
The possible representations types of an object.
Definition: BcpsObject.h:64
virtual double upEstimate() const
Return "up" estimate.
Definition: BcpsObject.h:284
double getUbHard() const
Return the value of the appropriate field.
Definition: BcpsObject.h:191
virtual BcpsObject_t getObjType() const
Definition: BcpsObject.h:403
AlpsReturnStatus encodeBcpsObject(AlpsEncoded *encoded) const
Pack Bcps part to a encode object.
Definition: BcpsObject.h:294
double lbSoft_
The current lower bound of the object.
Definition: BcpsObject.h:108
BcpsIntegral_t intType_
The integrality type of the object, i.e., what values it can take up between the specified bounds...
Definition: BcpsObject.h:90
virtual void hashing(BcpsModel *model=NULL)
Hashing.
Definition: BcpsObject.h:215
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
void setIntType(BcpsIntegral_t it)
Set the appropriate property.
Definition: BcpsObject.h:202
virtual void printDesc()
Definition: BcpsObject.h:289
BcpsValidRegion validRegion_
Valid in the whole tree or only the subtree rooted at the node that generate this object...
Definition: BcpsObject.h:94
virtual BcpsObject_t getObjType() const
Definition: BcpsObject.h:376
double lbHard_
The lower bound of the object when it was first created.
Definition: BcpsObject.h:102
int status_
The status of the object.
Definition: BcpsObject.h:99
virtual void feasibleRegion(BcpsModel *m)
Look at the current solution and set bounds to match the solution.
Definition: BcpsObject.h:236
virtual ~BcpsConstraint()
Desctructor constructor.
Definition: BcpsObject.h:368
BcpsConstraint(const BcpsConstraint &rhs)
Copy constructor.
Definition: BcpsObject.h:371
BcpsObject(const BcpsObject &rhs)
Copy constructor.
Definition: BcpsObject.h:159
void setStatus(int st)
Set the appropriate property.
Definition: BcpsObject.h:204
void setRepType(BcpsObjRep_t rt)
Set the appropriate property.
Definition: BcpsObject.h:201
double hashValue_
The hash value of this object.
Definition: BcpsObject.h:114
void setObjectIndex(int ind)
Set the appropriate property.
Definition: BcpsObject.h:200
int getStatus() const
Return the value of the appropriate field.
Definition: BcpsObject.h:189
AlpsReturnStatus decodeBcpsObject(AlpsEncoded &encoded)
Unpack Bcps part from a encode object.
Definition: BcpsObject.h:310
BcpsConstraint(double lbh, double ubh, double lbs, double ubs)
Useful constructor.
Definition: BcpsObject.h:362
virtual AlpsEncoded * encode() const
This method should encode the content of the object and return a pointer to the encoded form...
void setLbHard(double lb)
Set the appropriate property.
Definition: BcpsObject.h:205
virtual BcpsObject * clone() const
Clone an enity.
Definition: BcpsObject.h:178
double ubSoft_
The current upper bound of the object.
Definition: BcpsObject.h:111
void setLbSoft(double lb)
Set the appropriate property.
Definition: BcpsObject.h:207
void setType(KnowledgeType t)
Definition: AlpsKnowledge.h:72
virtual AlpsReturnStatus encode(AlpsEncoded *encoded)
Pack into a encode object.
Definition: BcpsObject.h:331
double hashValue() const
Hashing.
Definition: BcpsObject.h:216
int numInactive_
Number of inactive when in formulation.
Definition: BcpsObject.h:117