Changeset 1347 for branches/sandbox


Ignore:
Timestamp:
Dec 3, 2009 5:11:02 PM (10 years ago)
Author:
EdwinStraver
Message:

Combined CbcSimpleInteger? and CbcIntegerBranchingObject?
Combined CbcSimpleIntegerDynamicPseudoCost? and CbcIntegerPseudoCostBranchingObject?

Location:
branches/sandbox/Cbc
Files:
4 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • branches/sandbox/Cbc/MSVisualStudio/v9/libCbc/libCbc.vcproj

    r1346 r1347  
    796796                        </File>
    797797                        <File
    798                                 RelativePath="..\..\..\src\CbcIntegerBranchingObject.cpp"
    799                                 >
    800                         </File>
    801                         <File
    802                                 RelativePath="..\..\..\src\CbcIntegerPseudoCostBranchingObject.cpp"
    803                                 >
    804                         </File>
    805                         <File
    806798                                RelativePath="..\..\..\src\CbcLinked.cpp"
    807799                                >
     
    13101302                        </File>
    13111303                        <File
    1312                                 RelativePath="..\..\..\src\CbcIntegerBranchingObject.hpp"
    1313                                 >
    1314                         </File>
    1315                         <File
    1316                                 RelativePath="..\..\..\src\CbcIntegerPseudoCostBranchingObject.hpp"
    1317                                 >
    1318                         </File>
    1319                         <File
    13201304                                RelativePath="..\..\..\src\CbcLinked.hpp"
    13211305                                >
  • branches/sandbox/Cbc/src/CbcBranchActual.hpp

    r1346 r1347  
    1111#include "CbcSimpleInteger.hpp"
    1212#include "CbcNWay.hpp"
    13 #include "CbcIntegerBranchingObject.hpp"
    1413#include "CbcSimpleIntegerPseudoCost.hpp"
    15 #include "CbcIntegerPseudoCostBranchingObject.hpp"
    1614#include "CbcSOSBranchingObject.hpp"
    1715#include "CbcNWayBranchingObject.hpp"
  • branches/sandbox/Cbc/src/CbcBranchDynamic.hpp

    r1308 r1347  
    55#define CbcBranchDynamic_H
    66
    7 #include "CbcBranchActual.hpp"
    87#include "CoinPackedMatrix.hpp"
    98#include "CbcSimpleIntegerDynamicPseudoCost.hpp"
    109#include "CbcDynamicPseudoCostBranchingObject.hpp"
     10#include "CbcBranchActual.hpp"
    1111
    1212/** Branching decision dynamic class
  • branches/sandbox/Cbc/src/CbcDynamicPseudoCostBranchingObject.hpp

    r1308 r1347  
    33#define CbcDynamicPseudoCostBranchingObject_H
    44
     5//#include "CbcSimpleIntegerDynamicPseudoCost.hpp"
    56#include "CbcBranchDynamic.hpp"
    6 
    77/** Simple branching object for an integer variable with pseudo costs
    88
  • branches/sandbox/Cbc/src/CbcSimpleInteger.cpp

    r1293 r1347  
    251251    abort();
    252252}
     253
     254//##############################################################################
     255
     256// Default Constructor
     257CbcIntegerBranchingObject::CbcIntegerBranchingObject()
     258        : CbcBranchingObject()
     259{
     260    down_[0] = 0.0;
     261    down_[1] = 0.0;
     262    up_[0] = 0.0;
     263    up_[1] = 0.0;
     264#ifdef FUNNY_BRANCHING
     265    variables_ = NULL;
     266    newBounds_ = NULL;
     267    numberExtraChangedBounds_ = 0;
     268#endif
     269}
     270// Useful constructor
     271CbcIntegerBranchingObject::CbcIntegerBranchingObject (CbcModel * model,
     272        int variable, int way , double value)
     273        : CbcBranchingObject(model, variable, way, value)
     274{
     275    int iColumn = variable;
     276    assert (model_->solver()->getNumCols() > 0);
     277    down_[0] = model_->solver()->getColLower()[iColumn];
     278    down_[1] = floor(value_);
     279    up_[0] = ceil(value_);
     280    up_[1] = model->getColUpper()[iColumn];
     281#ifdef FUNNY_BRANCHING
     282    variables_ = NULL;
     283    newBounds_ = NULL;
     284    numberExtraChangedBounds_ = 0;
     285#endif
     286}
     287// Does part of constructor
     288void
     289CbcIntegerBranchingObject::fillPart (int variable,
     290                                     int way , double value)
     291{
     292    //originalObject_=NULL;
     293    branchIndex_ = 0;
     294    value_ = value;
     295    numberBranches_ = 2;
     296    //model_= model;
     297    //originalCbcObject_=NULL;
     298    variable_ = variable;
     299    way_ = way;
     300    int iColumn = variable;
     301    down_[0] = model_->solver()->getColLower()[iColumn];
     302    down_[1] = floor(value_);
     303    up_[0] = ceil(value_);
     304    up_[1] = model_->getColUpper()[iColumn];
     305}
     306// Useful constructor for fixing
     307CbcIntegerBranchingObject::CbcIntegerBranchingObject (CbcModel * model,
     308        int variable, int way,
     309        double lowerValue,
     310        double upperValue)
     311        : CbcBranchingObject(model, variable, way, lowerValue)
     312{
     313    setNumberBranchesLeft(1);
     314    down_[0] = lowerValue;
     315    down_[1] = upperValue;
     316    up_[0] = lowerValue;
     317    up_[1] = upperValue;
     318#ifdef FUNNY_BRANCHING
     319    variables_ = NULL;
     320    newBounds_ = NULL;
     321    numberExtraChangedBounds_ = 0;
     322#endif
     323}
     324
     325
     326// Copy constructor
     327CbcIntegerBranchingObject::CbcIntegerBranchingObject ( const CbcIntegerBranchingObject & rhs) : CbcBranchingObject(rhs)
     328{
     329    down_[0] = rhs.down_[0];
     330    down_[1] = rhs.down_[1];
     331    up_[0] = rhs.up_[0];
     332    up_[1] = rhs.up_[1];
     333#ifdef FUNNY_BRANCHING
     334    numberExtraChangedBounds_ = rhs.numberExtraChangedBounds_;
     335    int size = numberExtraChangedBounds_ * (sizeof(double) + sizeof(int));
     336    char * temp = new char [size];
     337    newBounds_ = (double *) temp;
     338    variables_ = (int *) (newBounds_ + numberExtraChangedBounds_);
     339
     340    int i ;
     341    for (i = 0; i < numberExtraChangedBounds_; i++) {
     342        variables_[i] = rhs.variables_[i];
     343        newBounds_[i] = rhs.newBounds_[i];
     344    }
     345#endif
     346}
     347
     348// Assignment operator
     349CbcIntegerBranchingObject &
     350CbcIntegerBranchingObject::operator=( const CbcIntegerBranchingObject & rhs)
     351{
     352    if (this != &rhs) {
     353        CbcBranchingObject::operator=(rhs);
     354        down_[0] = rhs.down_[0];
     355        down_[1] = rhs.down_[1];
     356        up_[0] = rhs.up_[0];
     357        up_[1] = rhs.up_[1];
     358#ifdef FUNNY_BRANCHING
     359        delete [] newBounds_;
     360        numberExtraChangedBounds_ = rhs.numberExtraChangedBounds_;
     361        int size = numberExtraChangedBounds_ * (sizeof(double) + sizeof(int));
     362        char * temp = new char [size];
     363        newBounds_ = (double *) temp;
     364        variables_ = (int *) (newBounds_ + numberExtraChangedBounds_);
     365
     366        int i ;
     367        for (i = 0; i < numberExtraChangedBounds_; i++) {
     368            variables_[i] = rhs.variables_[i];
     369            newBounds_[i] = rhs.newBounds_[i];
     370        }
     371#endif
     372    }
     373    return *this;
     374}
     375CbcBranchingObject *
     376CbcIntegerBranchingObject::clone() const
     377{
     378    return (new CbcIntegerBranchingObject(*this));
     379}
     380
     381
     382// Destructor
     383CbcIntegerBranchingObject::~CbcIntegerBranchingObject ()
     384{
     385    // for debugging threads
     386    way_ = -23456789;
     387#ifdef FUNNY_BRANCHING
     388    delete [] newBounds_;
     389#endif
     390}
     391
     392/*
     393  Perform a branch by adjusting the bounds of the specified variable. Note
     394  that each arm of the branch advances the object to the next arm by
     395  advancing the value of way_.
     396
     397  Providing new values for the variable's lower and upper bounds for each
     398  branching direction gives a little bit of additional flexibility and will
     399  be easily extensible to multi-way branching.
     400  Returns change in guessed objective on next branch
     401*/
     402double
     403CbcIntegerBranchingObject::branch()
     404{
     405    // for debugging threads
     406    if (way_ < -1 || way_ > 100000) {
     407        printf("way %d, left %d, iCol %d, variable %d\n",
     408               way_, numberBranchesLeft(),
     409               originalCbcObject_->columnNumber(), variable_);
     410        assert (way_ != -23456789);
     411    }
     412    decrementNumberBranchesLeft();
     413    if (down_[1] == -COIN_DBL_MAX)
     414        return 0.0;
     415    int iColumn = originalCbcObject_->columnNumber();
     416    assert (variable_ == iColumn);
     417    double olb, oub ;
     418    olb = model_->solver()->getColLower()[iColumn] ;
     419    oub = model_->solver()->getColUpper()[iColumn] ;
     420    //#define TIGHTEN_BOUNDS
     421#ifndef TIGHTEN_BOUNDS
     422#ifdef COIN_DEVELOP
     423    if (olb != down_[0] || oub != up_[1]) {
     424        if (way_ > 0)
     425            printf("branching up on var %d: [%g,%g] => [%g,%g] - other [%g,%g]\n",
     426                   iColumn, olb, oub, up_[0], up_[1], down_[0], down_[1]) ;
     427        else
     428            printf("branching down on var %d: [%g,%g] => [%g,%g] - other [%g,%g]\n",
     429                   iColumn, olb, oub, down_[0], down_[1], up_[0], up_[1]) ;
     430    }
     431#endif
     432#endif
     433    if (way_ < 0) {
     434#ifdef CBC_DEBUG
     435        { double olb, oub ;
     436            olb = model_->solver()->getColLower()[iColumn] ;
     437            oub = model_->solver()->getColUpper()[iColumn] ;
     438            printf("branching down on var %d: [%g,%g] => [%g,%g]\n",
     439                   iColumn, olb, oub, down_[0], down_[1]) ;
     440        }
     441#endif
     442#ifndef TIGHTEN_BOUNDS
     443        model_->solver()->setColLower(iColumn, down_[0]);
     444#else
     445        model_->solver()->setColLower(iColumn, CoinMax(down_[0], olb));
     446#endif
     447        model_->solver()->setColUpper(iColumn, down_[1]);
     448        //#define CBC_PRINT2
     449#ifdef CBC_PRINT2
     450        printf("%d branching down has bounds %g %g", iColumn, down_[0], down_[1]);
     451#endif
     452#ifdef FUNNY_BRANCHING
     453        // branch - do extra bounds
     454        for (int i = 0; i < numberExtraChangedBounds_; i++) {
     455            int variable = variables_[i];
     456            if ((variable&0x40000000) != 0) {
     457                // for going down
     458                int k = variable & 0x3fffffff;
     459                assert (k != iColumn);
     460                if ((variable&0x80000000) == 0) {
     461                    // lower bound changing
     462#ifdef CBC_PRINT2
     463                    printf(" extra for %d changes lower from %g to %g",
     464                           k, model_->solver()->getColLower()[k], newBounds_[i]);
     465#endif
     466                    model_->solver()->setColLower(k, newBounds_[i]);
     467                } else {
     468                    // upper bound changing
     469#ifdef CBC_PRINT2
     470                    printf(" extra for %d changes upper from %g to %g",
     471                           k, model_->solver()->getColUpper()[k], newBounds_[i]);
     472#endif
     473                    model_->solver()->setColUpper(k, newBounds_[i]);
     474                }
     475            }
     476        }
     477#endif
     478#ifdef CBC_PRINT2
     479        printf("\n");
     480#endif
     481        way_ = 1;
     482    } else {
     483#ifdef CBC_DEBUG
     484        { double olb, oub ;
     485            olb = model_->solver()->getColLower()[iColumn] ;
     486            oub = model_->solver()->getColUpper()[iColumn] ;
     487            printf("branching up on var %d: [%g,%g] => [%g,%g]\n",
     488                   iColumn, olb, oub, up_[0], up_[1]) ;
     489        }
     490#endif
     491        model_->solver()->setColLower(iColumn, up_[0]);
     492#ifndef TIGHTEN_BOUNDS
     493        model_->solver()->setColUpper(iColumn, up_[1]);
     494#else
     495        model_->solver()->setColUpper(iColumn, CoinMin(up_[1], oub));
     496#endif
     497#ifdef CBC_PRINT2
     498        printf("%d branching up has bounds %g %g", iColumn, up_[0], up_[1]);
     499#endif
     500#ifdef FUNNY_BRANCHING
     501        // branch - do extra bounds
     502        for (int i = 0; i < numberExtraChangedBounds_; i++) {
     503            int variable = variables_[i];
     504            if ((variable&0x40000000) == 0) {
     505                // for going up
     506                int k = variable & 0x3fffffff;
     507                assert (k != iColumn);
     508                if ((variable&0x80000000) == 0) {
     509                    // lower bound changing
     510#ifdef CBC_PRINT2
     511                    printf(" extra for %d changes lower from %g to %g",
     512                           k, model_->solver()->getColLower()[k], newBounds_[i]);
     513#endif
     514                    model_->solver()->setColLower(k, newBounds_[i]);
     515                } else {
     516                    // upper bound changing
     517#ifdef CBC_PRINT2
     518                    printf(" extra for %d changes upper from %g to %g",
     519                           k, model_->solver()->getColUpper()[k], newBounds_[i]);
     520#endif
     521                    model_->solver()->setColUpper(k, newBounds_[i]);
     522                }
     523            }
     524        }
     525#endif
     526#ifdef CBC_PRINT2
     527        printf("\n");
     528#endif
     529        way_ = -1;        // Swap direction
     530    }
     531    double nlb = model_->solver()->getColLower()[iColumn];
     532    double nub = model_->solver()->getColUpper()[iColumn];
     533    if (nlb < olb) {
     534#ifndef NDEBUG
     535        printf("bad lb change for column %d from %g to %g\n", iColumn, olb, nlb);
     536#endif
     537        model_->solver()->setColLower(iColumn, CoinMin(olb, nub));
     538        nlb = olb;
     539    }
     540    if (nub > oub) {
     541#ifndef NDEBUG
     542        printf("bad ub change for column %d from %g to %g\n", iColumn, oub, nub);
     543#endif
     544        model_->solver()->setColUpper(iColumn, CoinMax(oub, nlb));
     545    }
     546#ifndef NDEBUG
     547    if (nlb < olb + 1.0e-8 && nub > oub - 1.0e-8 && false)
     548        printf("bad null change for column %d - bounds %g,%g\n", iColumn, olb, oub);
     549#endif
     550    return 0.0;
     551}
     552/* Update bounds in solver as in 'branch' and update given bounds.
     553   branchState is -1 for 'down' +1 for 'up' */
     554void
     555CbcIntegerBranchingObject::fix(OsiSolverInterface * /*solver*/,
     556                               double * lower, double * upper,
     557                               int branchState) const
     558{
     559    int iColumn = originalCbcObject_->columnNumber();
     560    assert (variable_ == iColumn);
     561    if (branchState < 0) {
     562        model_->solver()->setColLower(iColumn, down_[0]);
     563        lower[iColumn] = down_[0];
     564        model_->solver()->setColUpper(iColumn, down_[1]);
     565        upper[iColumn] = down_[1];
     566    } else {
     567        model_->solver()->setColLower(iColumn, up_[0]);
     568        lower[iColumn] = up_[0];
     569        model_->solver()->setColUpper(iColumn, up_[1]);
     570        upper[iColumn] = up_[1];
     571    }
     572}
     573#ifdef FUNNY_BRANCHING
     574// Deactivate bounds for branching
     575void
     576CbcIntegerBranchingObject::deactivate()
     577{
     578    down_[1] = -COIN_DBL_MAX;
     579}
     580int
     581CbcIntegerBranchingObject::applyExtraBounds(int iColumn, double lower, double upper, int way)
     582{
     583    // branch - do bounds
     584
     585    int i;
     586    int found = 0;
     587    if (variable_ == iColumn) {
     588        printf("odd applyExtra %d\n", iColumn);
     589        if (way < 0) {
     590            down_[0] = CoinMax(lower, down_[0]);
     591            down_[1] = CoinMin(upper, down_[1]);
     592            assert (down_[0] <= down_[1]);
     593        } else {
     594            up_[0] = CoinMax(lower, up_[0]);
     595            up_[1] = CoinMin(upper, up_[1]);
     596            assert (up_[0] <= up_[1]);
     597        }
     598        return 0;
     599    }
     600    int check = (way < 0) ? 0x40000000 : 0;
     601    double newLower = lower;
     602    double newUpper = upper;
     603    for (i = 0; i < numberExtraChangedBounds_; i++) {
     604        int variable = variables_[i];
     605        if ((variable&0x40000000) == check) {
     606            int k = variable & 0x3fffffff;
     607            if (k == iColumn) {
     608                if ((variable&0x80000000) == 0) {
     609                    // lower bound changing
     610                    found |= 1;
     611                    newBounds_[i] = CoinMax(lower, newBounds_[i]);
     612                    newLower = newBounds_[i];
     613                } else {
     614                    // upper bound changing
     615                    found |= 2;
     616                    newBounds_[i] = CoinMin(upper, newBounds_[i]);
     617                    newUpper = newBounds_[i];
     618                }
     619            }
     620        }
     621    }
     622    int nAdd = 0;
     623    if ((found&2) == 0) {
     624        // need to add new upper
     625        nAdd++;
     626    }
     627    if ((found&1) == 0) {
     628        // need to add new lower
     629        nAdd++;
     630    }
     631    if (nAdd) {
     632        int size = (numberExtraChangedBounds_ + nAdd) * (sizeof(double) + sizeof(int));
     633        char * temp = new char [size];
     634        double * newBounds = (double *) temp;
     635        int * variables = (int *) (newBounds + numberExtraChangedBounds_ + nAdd);
     636
     637        int i ;
     638        for (i = 0; i < numberExtraChangedBounds_; i++) {
     639            variables[i] = variables_[i];
     640            newBounds[i] = newBounds_[i];
     641        }
     642        delete [] newBounds_;
     643        newBounds_ = newBounds;
     644        variables_ = variables;
     645        if ((found&2) == 0) {
     646            // need to add new upper
     647            int variable = iColumn | 0x80000000;
     648            variables_[numberExtraChangedBounds_] = variable;
     649            newBounds_[numberExtraChangedBounds_++] = newUpper;
     650        }
     651        if ((found&1) == 0) {
     652            // need to add new lower
     653            int variable = iColumn;
     654            variables_[numberExtraChangedBounds_] = variable;
     655            newBounds_[numberExtraChangedBounds_++] = newLower;
     656        }
     657    }
     658
     659    return (newUpper >= newLower) ? 0 : 1;
     660}
     661#endif
     662// Print what would happen
     663void
     664CbcIntegerBranchingObject::print()
     665{
     666    int iColumn = originalCbcObject_->columnNumber();
     667    assert (variable_ == iColumn);
     668    if (way_ < 0) {
     669        {
     670            double olb, oub ;
     671            olb = model_->solver()->getColLower()[iColumn] ;
     672            oub = model_->solver()->getColUpper()[iColumn] ;
     673            printf("CbcInteger would branch down on var %d (int var %d): [%g,%g] => [%g,%g]\n",
     674                   iColumn, variable_, olb, oub, down_[0], down_[1]) ;
     675        }
     676    } else {
     677        {
     678            double olb, oub ;
     679            olb = model_->solver()->getColLower()[iColumn] ;
     680            oub = model_->solver()->getColUpper()[iColumn] ;
     681            printf("CbcInteger would branch up on var %d (int var %d): [%g,%g] => [%g,%g]\n",
     682                   iColumn, variable_, olb, oub, up_[0], up_[1]) ;
     683        }
     684    }
     685}
     686
     687/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     688    same type and must have the same original object, but they may have
     689    different feasible regions.
     690    Return the appropriate CbcRangeCompare value (first argument being the
     691    sub/superset if that's the case). In case of overlap (and if \c
     692    replaceIfOverlap is true) replace the current branching object with one
     693    whose feasible region is the overlap.
     694   */
     695CbcRangeCompare
     696CbcIntegerBranchingObject::compareBranchingObject
     697(const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     698{
     699    const CbcIntegerBranchingObject* br =
     700        dynamic_cast<const CbcIntegerBranchingObject*>(brObj);
     701    assert(br);
     702    double* thisBd = way_ < 0 ? down_ : up_;
     703    const double* otherBd = br->way_ < 0 ? br->down_ : br->up_;
     704    return CbcCompareRanges(thisBd, otherBd, replaceIfOverlap);
     705}
  • branches/sandbox/Cbc/src/CbcSimpleInteger.hpp

    r1293 r1347  
    44#define CbcSimpleInteger_H
    55
    6 #include "CbcIntegerBranchingObject.hpp"
     6/** Simple branching object for an integer variable
     7
     8  This object can specify a two-way branch on an integer variable. For each
     9  arm of the branch, the upper and lower bounds on the variable can be
     10  independently specified.
     11
     12  Variable_ holds the index of the integer variable in the integerVariable_
     13  array of the model.
     14*/
     15
     16class CbcIntegerBranchingObject : public CbcBranchingObject {
     17
     18public:
     19
     20    /// Default constructor
     21    CbcIntegerBranchingObject ();
     22
     23    /** Create a standard floor/ceiling branch object
     24
     25      Specifies a simple two-way branch. Let \p value = x*. One arm of the
     26      branch will be lb <= x <= floor(x*), the other ceil(x*) <= x <= ub.
     27      Specify way = -1 to set the object state to perform the down arm first,
     28      way = 1 for the up arm.
     29    */
     30    CbcIntegerBranchingObject (CbcModel *model, int variable,
     31                               int way , double value) ;
     32
     33    /** Create a degenerate branch object
     34
     35      Specifies a `one-way branch'. Calling branch() for this object will
     36      always result in lowerValue <= x <= upperValue. Used to fix a variable
     37      when lowerValue = upperValue.
     38    */
     39
     40    CbcIntegerBranchingObject (CbcModel *model, int variable, int way,
     41                               double lowerValue, double upperValue) ;
     42
     43    /// Copy constructor
     44    CbcIntegerBranchingObject ( const CbcIntegerBranchingObject &);
     45
     46    /// Assignment operator
     47    CbcIntegerBranchingObject & operator= (const CbcIntegerBranchingObject& rhs);
     48
     49    /// Clone
     50    virtual CbcBranchingObject * clone() const;
     51
     52    /// Destructor
     53    virtual ~CbcIntegerBranchingObject ();
     54
     55    /// Does part of constructor
     56    void fillPart ( int variable, int way , double value) ;
     57    using CbcBranchingObject::branch ;
     58    /** \brief Sets the bounds for the variable according to the current arm
     59           of the branch and advances the object state to the next arm.
     60           Returns change in guessed objective on next branch
     61    */
     62    virtual double branch();
     63    /** Update bounds in solver as in 'branch' and update given bounds.
     64        branchState is -1 for 'down' +1 for 'up' */
     65    virtual void fix(OsiSolverInterface * solver,
     66                     double * lower, double * upper,
     67                     int branchState) const ;
     68
     69#if 0
     70    // No need to override. Default works fine.
     71    /** Reset every information so that the branching object appears to point to
     72        the previous child. This method does not need to modify anything in any
     73        solver. */
     74    virtual void previousBranch();
     75#endif
     76
     77    using CbcBranchingObject::print ;
     78    /** \brief Print something about branch - only if log level high
     79    */
     80    virtual void print();
     81
     82    /// Lower and upper bounds for down branch
     83    inline const double * downBounds() const {
     84        return down_;
     85    }
     86    /// Lower and upper bounds for up branch
     87    inline const double * upBounds() const {
     88        return up_;
     89    }
     90    /// Set lower and upper bounds for down branch
     91    inline void setDownBounds(const double bounds[2]) {
     92        memcpy(down_, bounds, 2*sizeof(double));
     93    }
     94    /// Set lower and upper bounds for up branch
     95    inline void setUpBounds(const double bounds[2]) {
     96        memcpy(up_, bounds, 2*sizeof(double));
     97    }
     98#ifdef FUNNY_BRANCHING
     99    /** Which variable (top bit if upper bound changing,
     100        next bit if on down branch */
     101    inline const int * variables() const {
     102        return variables_;
     103    }
     104    // New bound
     105    inline const double * newBounds() const {
     106        return newBounds_;
     107    }
     108    /// Number of bound changes
     109    inline int numberExtraChangedBounds() const {
     110        return numberExtraChangedBounds_;
     111    }
     112    /// Just apply extra bounds to one variable - COIN_DBL_MAX ignore
     113    int applyExtraBounds(int iColumn, double lower, double upper, int way) ;
     114    /// Deactivate bounds for branching
     115    void deactivate();
     116    /// Are active bounds for branching
     117    inline bool active() const {
     118        return (down_[1] != -COIN_DBL_MAX);
     119    }
     120#endif
     121
     122    /** Return the type (an integer identifier) of \c this */
     123    virtual int type() const {
     124        return 100;
     125    }
     126
     127    /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     128        same type and must have the same original object, but they may have
     129        different feasible regions.
     130        Return the appropriate CbcRangeCompare value (first argument being the
     131        sub/superset if that's the case). In case of overlap (and if \c
     132        replaceIfOverlap is true) replace the current branching object with one
     133        whose feasible region is the overlap.
     134     */
     135    virtual CbcRangeCompare compareBranchingObject
     136    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
     137
     138protected:
     139    /// Lower [0] and upper [1] bounds for the down arm (way_ = -1)
     140    double down_[2];
     141    /// Lower [0] and upper [1] bounds for the up arm (way_ = 1)
     142    double up_[2];
     143#ifdef FUNNY_BRANCHING
     144    /** Which variable (top bit if upper bound changing)
     145        next bit if changing on down branch only */
     146    int * variables_;
     147    // New bound
     148    double * newBounds_;
     149    /// Number of Extra bound changes
     150    int numberExtraChangedBounds_;
     151#endif
     152};
     153
    7154/// Define a single integer class
    8155
  • branches/sandbox/Cbc/src/CbcSimpleIntegerDynamicPseudoCost.cpp

    r1308 r1347  
    12771277    }
    12781278}
     1279
     1280//##############################################################################
     1281
     1282// Default Constructor
     1283CbcIntegerPseudoCostBranchingObject::CbcIntegerPseudoCostBranchingObject()
     1284        : CbcIntegerBranchingObject()
     1285{
     1286    changeInGuessed_ = 1.0e-5;
     1287}
     1288
     1289// Useful constructor
     1290CbcIntegerPseudoCostBranchingObject::CbcIntegerPseudoCostBranchingObject (CbcModel * model,
     1291        int variable, int way , double value)
     1292        : CbcIntegerBranchingObject(model, variable, way, value)
     1293{
     1294}
     1295// Useful constructor for fixing
     1296CbcIntegerPseudoCostBranchingObject::CbcIntegerPseudoCostBranchingObject (CbcModel * model,
     1297        int variable, int way,
     1298        double lowerValue,
     1299        double /*upperValue*/)
     1300        : CbcIntegerBranchingObject(model, variable, way, lowerValue)
     1301{
     1302    changeInGuessed_ = 1.0e100;
     1303}
     1304
     1305
     1306// Copy constructor
     1307CbcIntegerPseudoCostBranchingObject::CbcIntegerPseudoCostBranchingObject (
     1308    const CbcIntegerPseudoCostBranchingObject & rhs)
     1309        : CbcIntegerBranchingObject(rhs)
     1310{
     1311    changeInGuessed_ = rhs.changeInGuessed_;
     1312}
     1313
     1314// Assignment operator
     1315CbcIntegerPseudoCostBranchingObject &
     1316CbcIntegerPseudoCostBranchingObject::operator=( const CbcIntegerPseudoCostBranchingObject & rhs)
     1317{
     1318    if (this != &rhs) {
     1319        CbcIntegerBranchingObject::operator=(rhs);
     1320        changeInGuessed_ = rhs.changeInGuessed_;
     1321    }
     1322    return *this;
     1323}
     1324CbcBranchingObject *
     1325CbcIntegerPseudoCostBranchingObject::clone() const
     1326{
     1327    return (new CbcIntegerPseudoCostBranchingObject(*this));
     1328}
     1329
     1330
     1331// Destructor
     1332CbcIntegerPseudoCostBranchingObject::~CbcIntegerPseudoCostBranchingObject ()
     1333{
     1334}
     1335
     1336/*
     1337  Perform a branch by adjusting the bounds of the specified variable. Note
     1338  that each arm of the branch advances the object to the next arm by
     1339  advancing the value of way_.
     1340
     1341  Providing new values for the variable's lower and upper bounds for each
     1342  branching direction gives a little bit of additional flexibility and will
     1343  be easily extensible to multi-way branching.
     1344  Returns change in guessed objective on next branch
     1345*/
     1346double
     1347CbcIntegerPseudoCostBranchingObject::branch()
     1348{
     1349    CbcIntegerBranchingObject::branch();
     1350    return changeInGuessed_;
     1351}
     1352
     1353/** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     1354    same type and must have the same original object, but they may have
     1355    different feasible regions.
     1356    Return the appropriate CbcRangeCompare value (first argument being the
     1357    sub/superset if that's the case). In case of overlap (and if \c
     1358    replaceIfOverlap is true) replace the current branching object with one
     1359    whose feasible region is the overlap.
     1360*/
     1361CbcRangeCompare
     1362CbcIntegerPseudoCostBranchingObject::compareBranchingObject
     1363(const CbcBranchingObject* brObj, const bool replaceIfOverlap)
     1364{
     1365    const CbcIntegerPseudoCostBranchingObject* br =
     1366        dynamic_cast<const CbcIntegerPseudoCostBranchingObject*>(brObj);
     1367    assert(br);
     1368    double* thisBd = way_ < 0 ? down_ : up_;
     1369    const double* otherBd = br->way_ < 0 ? br->down_ : br->up_;
     1370    return CbcCompareRanges(thisBd, otherBd, replaceIfOverlap);
     1371}
  • branches/sandbox/Cbc/src/CbcSimpleIntegerDynamicPseudoCost.hpp

    r1308 r1347  
    33#define CbcSimpleIntegerDynamicPseudoCost_H
    44
    5 #include "CbcBranchDynamic.hpp"
     5#include "CbcSimpleInteger.hpp"
    66
    77#define TYPERATIO 0.9
     
    371371    int method_;
    372372};
    373 
     373/** Simple branching object for an integer variable with pseudo costs
     374
     375  This object can specify a two-way branch on an integer variable. For each
     376  arm of the branch, the upper and lower bounds on the variable can be
     377  independently specified.
     378
     379  Variable_ holds the index of the integer variable in the integerVariable_
     380  array of the model.
     381*/
     382
     383class CbcIntegerPseudoCostBranchingObject : public CbcIntegerBranchingObject {
     384
     385public:
     386
     387    /// Default constructor
     388    CbcIntegerPseudoCostBranchingObject ();
     389
     390    /** Create a standard floor/ceiling branch object
     391
     392      Specifies a simple two-way branch. Let \p value = x*. One arm of the
     393      branch will be is lb <= x <= floor(x*), the other ceil(x*) <= x <= ub.
     394      Specify way = -1 to set the object state to perform the down arm first,
     395      way = 1 for the up arm.
     396    */
     397    CbcIntegerPseudoCostBranchingObject (CbcModel *model, int variable,
     398                                         int way , double value) ;
     399
     400    /** Create a degenerate branch object
     401
     402      Specifies a `one-way branch'. Calling branch() for this object will
     403      always result in lowerValue <= x <= upperValue. Used to fix a variable
     404      when lowerValue = upperValue.
     405    */
     406
     407    CbcIntegerPseudoCostBranchingObject (CbcModel *model, int variable, int way,
     408                                         double lowerValue, double upperValue) ;
     409
     410    /// Copy constructor
     411    CbcIntegerPseudoCostBranchingObject ( const CbcIntegerPseudoCostBranchingObject &);
     412
     413    /// Assignment operator
     414    CbcIntegerPseudoCostBranchingObject & operator= (const CbcIntegerPseudoCostBranchingObject& rhs);
     415
     416    /// Clone
     417    virtual CbcBranchingObject * clone() const;
     418
     419    /// Destructor
     420    virtual ~CbcIntegerPseudoCostBranchingObject ();
     421
     422    using CbcBranchingObject::branch ;
     423    /** \brief Sets the bounds for the variable according to the current arm
     424           of the branch and advances the object state to the next arm.
     425           This version also changes guessed objective value
     426    */
     427    virtual double branch();
     428
     429    /// Change in guessed
     430    inline double changeInGuessed() const {
     431        return changeInGuessed_;
     432    }
     433    /// Set change in guessed
     434    inline void setChangeInGuessed(double value) {
     435        changeInGuessed_ = value;
     436    }
     437
     438    /** Return the type (an integer identifier) of \c this */
     439    virtual int type() const {
     440        return 101;
     441    }
     442
     443    /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
     444        same type and must have the same original object, but they may have
     445        different feasible regions.
     446        Return the appropriate CbcRangeCompare value (first argument being the
     447        sub/superset if that's the case). In case of overlap (and if \c
     448        replaceIfOverlap is true) replace the current branching object with one
     449        whose feasible region is the overlap.
     450     */
     451    virtual CbcRangeCompare compareBranchingObject
     452    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
     453
     454protected:
     455    /// Change in guessed objective value for next branch
     456    double changeInGuessed_;
     457};
    374458#endif
  • branches/sandbox/Cbc/src/CbcSimpleIntegerPseudoCost.cpp

    r1293 r1347  
    1616#include "CbcMessage.hpp"
    1717#include "CbcSimpleIntegerPseudoCost.hpp"
     18#include "CbcSimpleIntegerDynamicPseudoCost.hpp"
    1819#include "CbcBranchActual.hpp"
    1920#include "CoinSort.hpp"
  • branches/sandbox/Cbc/src/Makefile.am

    r1346 r1347  
    7272        CbcHeuristicRandRound.cpp CbcHeuristicRandRound.hpp \
    7373        CbcHeuristicRINS.cpp CbcHeuristicRINS.hpp \
    74         CbcIntegerBranchingObject.cpp CbcIntegerBranchingObject.hpp \
    75         CbcIntegerPseudoCostBranchingObject.cpp \
    76         CbcIntegerPseudoCostBranchingObject.hpp \
    7774        CbcLotsize.cpp CbcLotsize.hpp \
    7875        CbcMessage.cpp CbcMessage.hpp \
     
    395392        CbcHeuristicRandRound.hpp \
    396393        CbcHeuristicRINS.hpp \
    397         CbcIntegerBranchingObject.hpp \
    398         CbcIntegerPseudoCostBranchingObject.hpp \
    399394        CbcLotsize.hpp \
    400395        CbcMessage.hpp \
  • branches/sandbox/Cbc/src/Makefile.in

    r1346 r1347  
    180180        CbcHeuristicFPump.lo CbcHeuristicGreedy.lo \
    181181        CbcHeuristicLocal.lo CbcHeuristicPivotAndFix.lo \
    182         CbcHeuristicRandRound.lo CbcHeuristicRINS.lo \
    183         CbcIntegerBranchingObject.lo \
    184         CbcIntegerPseudoCostBranchingObject.lo CbcLotsize.lo \
     182        CbcHeuristicRandRound.lo CbcHeuristicRINS.lo CbcLotsize.lo \
    185183        CbcMessage.lo CbcModel.lo CbcNode.lo CbcNodeInfo.lo CbcNWay.lo \
    186184        CbcNWayBranchingObject.lo CbcObject.lo CbcObjectUpdateData.lo \
     
    574572        CbcHeuristicRandRound.cpp CbcHeuristicRandRound.hpp \
    575573        CbcHeuristicRINS.cpp CbcHeuristicRINS.hpp \
    576         CbcIntegerBranchingObject.cpp CbcIntegerBranchingObject.hpp \
    577         CbcIntegerPseudoCostBranchingObject.cpp \
    578         CbcIntegerPseudoCostBranchingObject.hpp \
    579574        CbcLotsize.cpp CbcLotsize.hpp \
    580575        CbcMessage.cpp CbcMessage.hpp \
     
    760755        CbcHeuristicRandRound.hpp \
    761756        CbcHeuristicRINS.hpp \
    762         CbcIntegerBranchingObject.hpp \
    763         CbcIntegerPseudoCostBranchingObject.hpp \
    764757        CbcLotsize.hpp \
    765758        CbcMessage.hpp \
     
    955948@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcHeuristicRINS.Plo@am__quote@
    956949@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcHeuristicRandRound.Plo@am__quote@
    957 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcIntegerBranchingObject.Plo@am__quote@
    958 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcIntegerPseudoCostBranchingObject.Plo@am__quote@
    959950@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcLinked.Plo@am__quote@
    960951@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CbcLotsize.Plo@am__quote@
Note: See TracChangeset for help on using the changeset viewer.