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

- File List
- File Members

# /home/coin/SVN-release/Blis-0.91.2/Bcps/examples/Blis/BlisBranchObjectInt.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Bcps Linear Solver (BLIS).                       *
    00003  *                                                                           *
    00004  * BLIS 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  *                                                                           *
    00020  * Copyright (C) 2001-2005, International Business Machines                  *
    00021  * Corporation, Lehigh University, Yan Xu, Ted Ralphs, Matthew Salzman and   *
    00022  * others. All Rights Reserved.                                              *
    00023  *===========================================================================*/
    00024
    00025
    00026 //#############################################################################
    00027 // Borrow ideas from COIN/Cbc
    00028 //#############################################################################
    00029
    00030
    00031 #include "BcpsBranchObject.h"
    00032
    00033 #include "BlisModel.h"
    00034
    00035
    00036 //#############################################################################
    00037
    00038
    00039 class BlisBranchObjectInt : public BcpsBranchObject {
    00040
    00041  protected:
    00042
    00045     double down_[2];
    00046
    00049     double up_[2];
    00050
    00051  public:
    00052
    00054     BlisBranchObjectInt()
    00055         :
    00056         BcpsBranchObject()
    00057         {
    00058             type_ = BLIS_BO_INT;
    00059             down_[0] = 0.0;
    00060             down_[1] = 0.0;
    00061             up_[0] = 0.0;
    00062             up_[1] = 0.0;
    00063         }
    00064
    00070     BlisBranchObjectInt(BlisModel * model,
    00071                         int varInd,
    00072                         int direction,
    00073                         double value)
    00074         :
    00075         BcpsBranchObject(model, varInd, direction, value)
    00076         {
    00077             type_ = BLIS_BO_INT;
    00078             int iColumn = model->getIntVars()[objectIndex_];
    00079             down_[0] = model->solver()->getColLower()[iColumn];
    00080             down_[1] = floor(value_);
    00081             up_[0] = ceil(value_);
    00082             up_[1] = model->getColUpper()[iColumn];
    00083         }
    00084
    00092     BlisBranchObjectInt(BlisModel * model,
    00093                         int varInd,
    00094                         int intScore,
    00095                         double dblScore,
    00096                         int direction,
    00097                         double value)
    00098         :
    00099         BcpsBranchObject(model, varInd, intScore, dblScore, direction, value)
    00100         {
    00101             type_ = BLIS_BO_INT;
    00102             int iColumn = model->getIntVars()[objectIndex_];
    00103             down_[0] = model->solver()->getColLower()[iColumn];
    00104             down_[1] = floor(value_);
    00105             up_[0] = ceil(value_);
    00106             up_[1] = model->getColUpper()[iColumn];
    00107         }
    00108
    00114     BlisBranchObjectInt(BlisModel * model,
    00115                         int varInd,
    00116                         int direction,
    00117                         double lowerValue,
    00118                         double upperValue)
    00119         :
    00120         BcpsBranchObject(model, varInd, direction, lowerValue)
    00121         {
    00122             type_ = BLIS_BO_INT;
    00123             numBranchesLeft_ = 1;
    00124             down_[0] = lowerValue;
    00125             down_[1] = upperValue;
    00126             up_[0] = lowerValue;
    00127             up_[1] = upperValue;
    00128         }
    00129
    00131     BlisBranchObjectInt(const BlisBranchObjectInt &);
    00132
    00134     BlisBranchObjectInt & operator = (const BlisBranchObjectInt& rhs);
    00135
    00137     virtual BcpsBranchObject * clone() const {
    00138         return (new BlisBranchObjectInt(*this));
    00139     }
    00140
    00142     virtual ~BlisBranchObjectInt() {}
    00143
    00147     virtual double branch(bool normalBranch = false);
    00148
    00150     virtual void print(bool normalBranch);
    00151
    00153     const double *getDown() const { return down_; }
    00154
    00156     const double *getUp() const { return up_; }
    00157
    00158  protected:
    00159
    00161     AlpsReturnStatus encodeBlis(AlpsEncoded *encoded) const {
    00162         assert(encoded);
    00163         AlpsReturnStatus status = AlpsReturnStatusOk;
    00164         int j;
    00165         // TODO: N-way.
    00166         for (j = 0; j < 2; ++j) {
    00167             encoded->writeRep(down_[j]);
    00168         }
    00169         for (j = 0; j < 2; ++j) {
    00170             encoded->writeRep(up_[j]);
    00171         }
    00172
    00173         return status;
    00174     }
    00175
    00177     AlpsReturnStatus decodeBlis(AlpsEncoded &encoded) {
    00178         AlpsReturnStatus status = AlpsReturnStatusOk;
    00179         int j;
    00180         // TODO: N-way.
    00181         for (j = 0; j < 2; ++j) {
    00182             encoded.readRep(down_[j]);
    00183         }
    00184         for (j = 0; j < 2; ++j) {
    00185             encoded.readRep(up_[j]);
    00186         }
    00187
    00188         return status;
    00189     }
    00190
    00191  public:
    00192
    00194     virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
    00195         AlpsReturnStatus status = AlpsReturnStatusOk;
    00196
    00197         status = encodeBcps(encoded);
    00198         status = encodeBlis(encoded);
    00199
    00200         return status;
    00201     }
    00202
    00204     virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
    00205
    00206         AlpsReturnStatus status = AlpsReturnStatusOk;
    00207
    00208         status = decodeBcps(encoded);
    00209         status = decodeBlis(encoded);
    00210
    00211         return status;
    00212     }
    00213
    00214 };
    00215