- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Bcps-0.91.0/Bcps/src/BcpsBranchObject.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Branch, Constrain and Price Software (BiCePS)    *
    00003  *                                                                           *
    00004  * BiCePS is distributed under the Common Public License as part of the      *
    00005  * COIN-OR repository (http://www.coin-or.org).                              *
    00006  *                                                                           *
    00007  * Authors:                                                                  *
    00008  *                                                                           *
    00009  *          Yan Xu, Lehigh University                                        *
    00010  *          Ted Ralphs, Lehigh University                                    *
    00011  *                                                                           *
    00012  * Conceptual Design:                                                        *
    00013  *                                                                           *
    00014  *          Yan Xu, Lehigh University                                        *
    00015  *          Ted Ralphs, Lehigh University                                    *
    00016  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
    00017  *          Matthew Saltzman, Clemson University                             *
    00018  *                                                                           *
    00019  * Copyright (C) 2001-2009, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00020  * All Rights Reserved.                                                      *
    00021  *===========================================================================*/
    00022
    00023
    00024 //#############################################################################
    00025 // Borrow ideas from COIN/Cbc
    00026 //#############################################################################
    00027
    00028
    00029 #ifndef BcpsBranchObject_h_
    00030 #define BcpsBranchObject_h_
    00031
    00032 #include "BcpsModel.h"
    00033
    00034 #include "Alps.h"
    00035 #include "AlpsEncoded.h"
    00036
    00037
    00038 //#############################################################################
    00039
    00040
    00047 class BcpsBranchObject {
    00048
    00049  protected:
    00050
    00052     int type_;
    00053
    00055     BcpsModel *model_;
    00056
    00060     int objectIndex_;
    00061
    00069     double upScore_;
    00070
    00072     double downScore_;
    00074
    00078     int direction_;
    00079
    00082     double value_;
    00083
    00085     int numBranchesLeft_;
    00087
    00088  public:
    00089
    00091     BcpsBranchObject()
    00092         :
    00093         type_(0),
    00094         model_(NULL),
    00095         objectIndex_(-1),
    00096         upScore_(0),
    00097         downScore_(0),
    00098         direction_(0),
    00099         value_(0.0),
    00100         numBranchesLeft_(0)
    00101         {}
    00102
    00104     BcpsBranchObject(BcpsModel * model,
    00105                      int objectIndex,
    00106                      int direction ,
    00107                      double value)
    00108         :
    00109         type_(0),
    00110         model_(model),
    00111         objectIndex_(objectIndex),
    00112         upScore_(0),
    00113         downScore_(0),
    00114         direction_(direction),
    00115         value_(value),
    00116         numBranchesLeft_(2)
    00117         {}
    00118
    00120     BcpsBranchObject(BcpsModel * model,
    00121                      int objectIndex,
    00122                      int upScore,
    00123                      double downScore,
    00124                      int direction ,
    00125                      double value)
    00126         :
    00127         type_(0),
    00128         model_(model),
    00129         objectIndex_(objectIndex),
    00130         upScore_(upScore),
    00131         downScore_(downScore),
    00132         direction_(direction),
    00133         value_(value),
    00134         numBranchesLeft_(2)
    00135         {}
    00136
    00138     BcpsBranchObject (const BcpsBranchObject &);
    00139
    00141     virtual ~BcpsBranchObject() { /* Do nothing */}
    00142
    00144     BcpsBranchObject & operator = ( const BcpsBranchObject& rhs);
    00145
    00147     virtual BcpsBranchObject * clone() const = 0;
    00148
    00150     int getType() { return type_; }
    00151
    00153     void setType(int t) { type_ = t; }
    00154
    00156     virtual int numBranches() const { return 2; }
    00157
    00159     virtual int numBranchesLeft() const { return numBranchesLeft_; }
    00160
    00163     // THINK: what's the use of normalBranch?
    00164     virtual double branch(bool normalBranch = false) = 0;
    00165
    00167     virtual void print(bool normalBranch) {}
    00168
    00170     virtual bool boundBranch() const { return true; }
    00171
    00173     inline int getObjectIndex() const { return objectIndex_; }
    00174
    00176     inline void setObjectIndex(int ind) {  objectIndex_ = ind; }
    00177
    00179     inline double getUpScore() const { return upScore_; }
    00180
    00182     inline void setUpScore(double score) { upScore_ = score; }
    00183
    00185     inline double getDownScore() const { return downScore_; }
    00186
    00188     inline void setDownScore(double score) { downScore_ = score; }
    00189
    00191     inline int getDirection() const { return direction_; }
    00192
    00194     inline void setDirection(int direction) { direction_ = direction; }
    00195
    00197     inline double getValue() const { return value_; }
    00198
    00200     inline BcpsModel * model() const { return  model_; }
    00201
    00202  protected:
    00203
    00205     AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const {
    00206         AlpsReturnStatus status = AlpsReturnStatusOk;
    00207         assert(encoded);
    00208         encoded->writeRep(objectIndex_);
    00209         encoded->writeRep(upScore_);
    00210         encoded->writeRep(downScore_);
    00211         encoded->writeRep(direction_);
    00212         encoded->writeRep(value_);
    00213         encoded->writeRep(numBranchesLeft_);
    00214
    00215         return status;
    00216     }
    00217
    00219     AlpsReturnStatus decodeBcps(AlpsEncoded &encoded) {
    00220         AlpsReturnStatus status = AlpsReturnStatusOk;
    00221
    00222         encoded.readRep(objectIndex_);
    00223         encoded.readRep(upScore_);
    00224         encoded.readRep(downScore_);
    00225         encoded.readRep(direction_);
    00226         encoded.readRep(value_);
    00227         encoded.readRep(numBranchesLeft_);
    00228
    00229         return status;
    00230     }
    00231
    00232  public:
    00233
    00235     virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
    00236         AlpsReturnStatus status = AlpsReturnStatusOk;
    00237         // Should never be called.
    00238         assert(0);
    00239         return status;
    00240     }
    00241
    00243     virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
    00244         AlpsReturnStatus status = AlpsReturnStatusOk;
    00245         // Should never be called.
    00246         assert(0);
    00247         return status;
    00248     }
    00249
    00250 };
    00251
    00252 #endif