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/CbcNWay.cpp

    r1293 r1350  
    267267    return branch;
    268268}
     269
     270// Default Constructor
     271CbcNWayBranchingObject::CbcNWayBranchingObject()
     272        : CbcBranchingObject()
     273{
     274    order_ = NULL;
     275    object_ = NULL;
     276    numberInSet_ = 0;
     277    way_ = 0;
     278}
     279
     280// Useful constructor
     281CbcNWayBranchingObject::CbcNWayBranchingObject (CbcModel * model,
     282        const CbcNWay * nway,
     283        int number, const int * order)
     284        : CbcBranchingObject(model, nway->id(), -1, 0.5)
     285{
     286    numberBranches_ = number;
     287    order_ = new int [number];
     288    object_ = nway;
     289    numberInSet_ = number;
     290    memcpy(order_, order, number*sizeof(int));
     291}
     292
     293// Copy constructor
     294CbcNWayBranchingObject::CbcNWayBranchingObject ( const CbcNWayBranchingObject & rhs) : CbcBranchingObject(rhs)
     295{
     296    numberInSet_ = rhs.numberInSet_;
     297    object_ = rhs.object_;
     298    if (numberInSet_) {
     299        order_ = new int [numberInSet_];
     300        memcpy(order_, rhs.order_, numberInSet_*sizeof(int));
     301    } else {
     302        order_ = NULL;
     303    }
     304}
     305
     306// Assignment operator
     307CbcNWayBranchingObject &
     308CbcNWayBranchingObject::operator=( const CbcNWayBranchingObject & rhs)
     309{
     310    if (this != &rhs) {
     311        CbcBranchingObject::operator=(rhs);
     312        object_ = rhs.object_;
     313        delete [] order_;
     314        numberInSet_ = rhs.numberInSet_;
     315        if (numberInSet_) {
     316            order_ = new int [numberInSet_];
     317            memcpy(order_, rhs.order_, numberInSet_*sizeof(int));
     318        } else {
     319            order_ = NULL;
     320        }
     321    }
     322    return *this;
     323}
     324CbcBranchingObject *
     325CbcNWayBranchingObject::clone() const
     326{
     327    return (new CbcNWayBranchingObject(*this));
     328}
     329
     330
     331// Destructor
     332CbcNWayBranchingObject::~CbcNWayBranchingObject ()
     333{
     334    delete [] order_;
     335}
     336double
     337CbcNWayBranchingObject::branch()
     338{
     339    int which = branchIndex_;
     340    branchIndex_++;
     341    assert (numberBranchesLeft() >= 0);
     342    if (which == 0) {
     343        // first branch so way_ may mean something
     344        assert (way_ == -1 || way_ == 1);
     345        if (way_ == -1)
     346            which++;
     347    } else if (which == 1) {
     348        // second branch so way_ may mean something
     349        assert (way_ == -1 || way_ == 1);
     350        if (way_ == -1)
     351            which--;
     352        // switch way off
     353        way_ = 0;
     354    }
     355    const double * lower = model_->solver()->getColLower();
     356    const double * upper = model_->solver()->getColUpper();
     357    const int * members = object_->members();
     358    for (int j = 0; j < numberInSet_; j++) {
     359        int iSequence = order_[j];
     360        int iColumn = members[iSequence];
     361        if (j != which) {
     362            model_->solver()->setColUpper(iColumn, lower[iColumn]);
     363            //model_->solver()->setColLower(iColumn,lower[iColumn]);
     364            assert (lower[iColumn] > -1.0e20);
     365            // apply any consequences
     366            object_->applyConsequence(iSequence, -9999);
     367        } else {
     368            model_->solver()->setColLower(iColumn, upper[iColumn]);
     369            //model_->solver()->setColUpper(iColumn,upper[iColumn]);
     370#ifdef FULL_PRINT
     371            printf("Up Fix %d to %g\n", iColumn, upper[iColumn]);
     372#endif
     373            assert (upper[iColumn] < 1.0e20);
     374            // apply any consequences
     375            object_->applyConsequence(iSequence, 9999);
     376        }
     377    }
     378    return 0.0;
     379}
     380void
     381CbcNWayBranchingObject::print()
     382{
     383    printf("NWay - Up Fix ");
     384    const int * members = object_->members();
     385    for (int j = 0; j < way_; j++) {
     386        int iColumn = members[order_[j]];
     387        printf("%d ", iColumn);
     388    }
     389    printf("\n");
     390}
     391
     392/** Compare the original object of \c this with the original object of \c
     393    brObj. Assumes that there is an ordering of the original objects.
     394    This method should be invoked only if \c this and brObj are of the same
     395    type.
     396    Return negative/0/positive depending on whether \c this is
     397    smaller/same/larger than the argument.
     398*/
     399int
     400CbcNWayBranchingObject::compareOriginalObject
     401(const CbcBranchingObject* /*brObj*/) const
     402{
     403    throw("must implement");
     404}
     405
     406/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     407    same type and must have the same original object, but they may have
     408    different feasible regions.
     409    Return the appropriate CbcRangeCompare value (first argument being the
     410    sub/superset if that's the case). In case of overlap (and if \c
     411    replaceIfOverlap is true) replace the current branching object with one
     412    whose feasible region is the overlap.
     413*/
     414CbcRangeCompare
     415CbcNWayBranchingObject::compareBranchingObject
     416(const CbcBranchingObject* /*brObj*/, const bool /*replaceIfOverlap*/)
     417{
     418    throw("must implement");
     419}
Note: See TracChangeset for help on using the changeset viewer.