Ignore:
Timestamp:
Dec 4, 2009 10:01:00 AM (10 years ago)
Author:
EdwinStraver
Message:

Combined CbcSOS with CbcSOSBranchingObject
Combined CbcNWay with CbcNWayBranchingObject
Combined CbcFollowOn? with CbcFixingBranchingObject?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sandbox/Cbc/src/CbcFollowOn.cpp

    r1293 r1350  
    357357    return branch;
    358358}
     359
     360//##############################################################################
     361
     362// Default Constructor
     363CbcFixingBranchingObject::CbcFixingBranchingObject()
     364        : CbcBranchingObject()
     365{
     366    numberDown_ = 0;
     367    numberUp_ = 0;
     368    downList_ = NULL;
     369    upList_ = NULL;
     370}
     371
     372// Useful constructor
     373CbcFixingBranchingObject::CbcFixingBranchingObject (CbcModel * model,
     374        int way ,
     375        int numberOnDownSide, const int * down,
     376        int numberOnUpSide, const int * up)
     377        : CbcBranchingObject(model, 0, way, 0.5)
     378{
     379    numberDown_ = numberOnDownSide;
     380    numberUp_ = numberOnUpSide;
     381    downList_ = CoinCopyOfArray(down, numberDown_);
     382    upList_ = CoinCopyOfArray(up, numberUp_);
     383}
     384
     385// Copy constructor
     386CbcFixingBranchingObject::CbcFixingBranchingObject ( const CbcFixingBranchingObject & rhs) : CbcBranchingObject(rhs)
     387{
     388    numberDown_ = rhs.numberDown_;
     389    numberUp_ = rhs.numberUp_;
     390    downList_ = CoinCopyOfArray(rhs.downList_, numberDown_);
     391    upList_ = CoinCopyOfArray(rhs.upList_, numberUp_);
     392}
     393
     394// Assignment operator
     395CbcFixingBranchingObject &
     396CbcFixingBranchingObject::operator=( const CbcFixingBranchingObject & rhs)
     397{
     398    if (this != &rhs) {
     399        CbcBranchingObject::operator=(rhs);
     400        delete [] downList_;
     401        delete [] upList_;
     402        numberDown_ = rhs.numberDown_;
     403        numberUp_ = rhs.numberUp_;
     404        downList_ = CoinCopyOfArray(rhs.downList_, numberDown_);
     405        upList_ = CoinCopyOfArray(rhs.upList_, numberUp_);
     406    }
     407    return *this;
     408}
     409CbcBranchingObject *
     410CbcFixingBranchingObject::clone() const
     411{
     412    return (new CbcFixingBranchingObject(*this));
     413}
     414
     415
     416// Destructor
     417CbcFixingBranchingObject::~CbcFixingBranchingObject ()
     418{
     419    delete [] downList_;
     420    delete [] upList_;
     421}
     422double
     423CbcFixingBranchingObject::branch()
     424{
     425    decrementNumberBranchesLeft();
     426    OsiSolverInterface * solver = model_->solver();
     427    const double * columnLower = solver->getColLower();
     428    int i;
     429    // *** for way - up means fix all those in up section
     430    if (way_ < 0) {
     431#ifdef FULL_PRINT
     432        printf("Down Fix ");
     433#endif
     434        //printf("Down Fix %d\n",numberDown_);
     435        for (i = 0; i < numberDown_; i++) {
     436            int iColumn = downList_[i];
     437            model_->solver()->setColUpper(iColumn, columnLower[iColumn]);
     438#ifdef FULL_PRINT
     439            printf("Setting bound on %d to lower bound\n", iColumn);
     440#endif
     441        }
     442        way_ = 1;         // Swap direction
     443    } else {
     444#ifdef FULL_PRINT
     445        printf("Up Fix ");
     446#endif
     447        //printf("Up Fix %d\n",numberUp_);
     448        for (i = 0; i < numberUp_; i++) {
     449            int iColumn = upList_[i];
     450            model_->solver()->setColUpper(iColumn, columnLower[iColumn]);
     451#ifdef FULL_PRINT
     452            printf("Setting bound on %d to lower bound\n", iColumn);
     453#endif
     454        }
     455        way_ = -1;        // Swap direction
     456    }
     457#ifdef FULL_PRINT
     458    printf("\n");
     459#endif
     460    return 0.0;
     461}
     462void
     463CbcFixingBranchingObject::print()
     464{
     465    int i;
     466    // *** for way - up means fix all those in up section
     467    if (way_ < 0) {
     468        printf("Down Fix ");
     469        for (i = 0; i < numberDown_; i++) {
     470            int iColumn = downList_[i];
     471            printf("%d ", iColumn);
     472        }
     473    } else {
     474        printf("Up Fix ");
     475        for (i = 0; i < numberUp_; i++) {
     476            int iColumn = upList_[i];
     477            printf("%d ", iColumn);
     478        }
     479    }
     480    printf("\n");
     481}
     482
     483/** Compare the original object of \c this with the original object of \c
     484    brObj. Assumes that there is an ordering of the original objects.
     485    This method should be invoked only if \c this and brObj are of the same
     486    type.
     487    Return negative/0/positive depending on whether \c this is
     488    smaller/same/larger than the argument.
     489*/
     490int
     491CbcFixingBranchingObject::compareOriginalObject
     492(const CbcBranchingObject* /*brObj*/) const
     493{
     494    throw("must implement");
     495}
     496
     497/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     498    same type and must have the same original object, but they may have
     499    different feasible regions.
     500    Return the appropriate CbcRangeCompare value (first argument being the
     501    sub/superset if that's the case). In case of overlap (and if \c
     502    replaceIfOverlap is true) replace the current branching object with one
     503    whose feasible region is the overlap.
     504   */
     505CbcRangeCompare
     506CbcFixingBranchingObject::compareBranchingObject
     507(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
     508{
     509#if 0 //ndef NDEBUG
     510    const CbcFixingBranchingObject* br =
     511        dynamic_cast<const CbcFixingBranchingObject*>(brObj);
     512    assert(br);
     513#endif
     514    // If two FixingBranchingObject's have the same base object then it's pretty
     515    // much guaranteed
     516    throw("must implement");
     517}
     518
     519//##############################################################################
Note: See TracChangeset for help on using the changeset viewer.