Changeset 1180


Ignore:
Timestamp:
Jul 2, 2009 12:30:17 PM (10 years ago)
Author:
forrest
Message:

changes for global cuts

Location:
trunk/Cbc/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcCutGenerator.cpp

    r1173 r1180  
    2626// Default Constructor
    2727CbcCutGenerator::CbcCutGenerator ()
    28   : model_(NULL),
     28  : timeInCutGenerator_(0.0),
     29    model_(NULL),
    2930    generator_(NULL),
     31    generatorName_(NULL),
    3032    whenCutGenerator_(-1),
    3133    whenCutGeneratorInSub_(-100),
     
    3335    depthCutGenerator_(-1),
    3436    depthCutGeneratorInSub_(-1),
    35     generatorName_(NULL),
    36     normal_(true),
    37     atSolution_(false),
    38     whenInfeasible_(false),
    39     mustCallAgain_(false),
    40     switchedOff_(false),
    41     globalCutsAtRoot_(false),
    42     timing_(false),
    43     timeInCutGenerator_(0.0),
    4437    inaccuracy_(0),
    4538    numberTimes_(0),
     
    4841    numberCutsActive_(0),
    4942    numberCutsAtRoot_(0),
    50     numberActiveCutsAtRoot_(0)
     43    numberActiveCutsAtRoot_(0),
     44    switches_(1)
    5145{
    5246}
     
    5953                                 int switchOffIfLessThan)
    6054  :
     55    timeInCutGenerator_(0.0),
    6156    depthCutGenerator_(whatDepth),
    6257    depthCutGeneratorInSub_(whatDepthInSub),
    63     mustCallAgain_(false),
    64     switchedOff_(false),
    65     globalCutsAtRoot_(false),
    66     timing_(false),
    67     timeInCutGenerator_(0.0),
    6858    inaccuracy_(0),
    6959    numberTimes_(0),
     
    7262    numberCutsActive_(0),
    7363    numberCutsAtRoot_(0),
    74     numberActiveCutsAtRoot_(0)
    75 {
    76   if (howOften<-1000) {
    77     globalCutsAtRoot_=true;
     64    numberActiveCutsAtRoot_(0),
     65    switches_(1)
     66{
     67  if (howOften<-2000) {
     68    setGlobalCuts(true);
     69    howOften+=2000;
     70  } else if (howOften<-1000) {
     71    setGlobalCutsAtRoot(true);
    7872    howOften+=1000;
    7973  }
     
    8175  generator_=generator->clone();
    8276  generator_->refreshSolver(model_->solver());
     77  setNeedsOptimalBasis(generator_->needsOptimalBasis());
    8378  whenCutGenerator_=howOften;
    8479  whenCutGeneratorInSub_ = howOftenInSub;
     
    8883  else
    8984    generatorName_ = strdup("Unknown");
    90   normal_=normal;
    91   atSolution_=atSolution;
    92   whenInfeasible_=infeasible;
     85  setNormal(normal);
     86  setAtSolution(atSolution);
     87  setWhenInfeasible(infeasible);
    9388}
    9489
     
    105100  depthCutGeneratorInSub_ = rhs.depthCutGeneratorInSub_;
    106101  generatorName_=strdup(rhs.generatorName_);
    107   normal_=rhs.normal_;
    108   atSolution_=rhs.atSolution_;
    109   whenInfeasible_=rhs.whenInfeasible_;
    110   mustCallAgain_ = rhs.mustCallAgain_;
    111   switchedOff_ = rhs.switchedOff_;
    112   globalCutsAtRoot_ = rhs.globalCutsAtRoot_;
    113   timing_ = rhs.timing_;
     102  switches_ = rhs.switches_;
    114103  timeInCutGenerator_ = rhs.timeInCutGenerator_;
    115104  inaccuracy_ = rhs.inaccuracy_;
     
    138127    depthCutGeneratorInSub_ = rhs.depthCutGeneratorInSub_;
    139128    generatorName_=strdup(rhs.generatorName_);
    140     normal_=rhs.normal_;
    141     atSolution_=rhs.atSolution_;
    142     whenInfeasible_=rhs.whenInfeasible_;
    143     mustCallAgain_ = rhs.mustCallAgain_;
    144     switchedOff_ = rhs.switchedOff_;
    145     globalCutsAtRoot_ = rhs.globalCutsAtRoot_;
    146     timing_ = rhs.timing_;
     129    switches_ = rhs.switches_;
    147130    timeInCutGenerator_ = rhs.timeInCutGenerator_;
    148131    inaccuracy_ = rhs.inaccuracy_;
     
    229212#endif
    230213    double time1=0.0;
    231     if (timing_)
     214    if (timing())
    232215      time1 = CoinCpuTime();
    233216    //#define CBC_DEBUG
     
    243226    info.inTree = node!=NULL;
    244227    info.randomNumberGenerator=randomNumberGenerator;
    245     info.options=(globalCutsAtRoot_) ? 8 : 0;
     228    info.options=(globalCutsAtRoot()) ? 8 : 0;
     229    if (globalCuts())
     230      info.options |=16;
    246231    incrementNumberTimesEntered();
    247232    CglProbing* generator =
     
    258243      bool doCuts=false;
    259244      if (info2&&!depth) {
    260         info2->options=(globalCutsAtRoot_) ? 8 : 0;
     245        info2->options=(globalCutsAtRoot()) ? 8 : 0;
    261246        info2->level = depth;
    262247        info2->pass = pass;
     
    810795    }
    811796#endif
    812     if (timing_)
     797    if (timing())
    813798      timeInCutGenerator_ += CoinCpuTime()-time1;
    814799#if 0
  • trunk/Cbc/src/CbcCutGenerator.hpp

    r1173 r1180  
    156156  /// Get whether the cut generator should be called in the normal place
    157157  inline bool normal() const
    158   { return normal_;}
     158  { return (switches_&1)!=0;}
    159159  /// Set whether the cut generator should be called in the normal place
    160160  inline void setNormal(bool value)
    161   { normal_=value;}
     161  { switches_&=~1;switches_ |= value ? 1 : 0;}
    162162  /// Get whether the cut generator should be called when a solution is found
    163163  inline bool atSolution() const
    164   { return atSolution_;}
     164  { return (switches_&2)!=0;}
    165165  /// Set whether the cut generator should be called when a solution is found
    166166  inline void setAtSolution(bool value)
    167   { atSolution_=value;}
     167  { switches_&=~2;switches_ |= value ? 2 : 0;}
    168168  /** Get whether the cut generator should be called when the subproblem is
    169169      found to be infeasible.
    170170  */
    171171  inline bool whenInfeasible() const
    172   { return whenInfeasible_;}
     172  { return (switches_&4)!=0;}
    173173  /** Set whether the cut generator should be called when the subproblem is
    174174      found to be infeasible.
    175175  */
    176176  inline void setWhenInfeasible(bool value)
    177   { whenInfeasible_=value;}
     177  { switches_&=~4;switches_ |= value ? 4 : 0;}
    178178  /// Get whether the cut generator is being timed
    179179  inline bool timing() const
    180   { return timing_;}
     180  { return (switches_&64)!=0;}
    181181  /// Set whether the cut generator is being timed
    182182  inline void setTiming(bool value)
    183   { timing_=value; timeInCutGenerator_=0.0;}
     183  { switches_&=~64;switches_ |= value ? 64 : 0; timeInCutGenerator_=0.0;}
    184184  /// Return time taken in cut generator
    185185  inline double timeInCutGenerator() const
     
    224224  /// Say if optimal basis needed
    225225  inline bool needsOptimalBasis() const
    226   { return generator_->needsOptimalBasis();}
     226  { return (switches_&128)!=0;}
     227  /// Set if optimal basis needed
     228  inline void setNeedsOptimalBasis(bool yesNo)
     229  { switches_&=~128;switches_ |= yesNo ? 128 : 0;}
    227230  /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
    228231  inline bool mustCallAgain() const
    229   { return mustCallAgain_;}
     232  { return (switches_&8)!=0;}
    230233  /// Set whether generator MUST be called again if any cuts (i.e. ignore break from loop)
    231234  inline void setMustCallAgain(bool yesNo)
    232   { mustCallAgain_=yesNo;}
     235  { switches_&=~8;switches_ |= yesNo ? 8 : 0;}
    233236  /// Whether generator switched off for moment
    234237  inline bool switchedOff() const
    235   { return switchedOff_;}
     238  { return (switches_&16)!=0;}
    236239  /// Set whether generator switched off for moment
    237240  inline void setSwitchedOff(bool yesNo)
    238   { switchedOff_=yesNo;}
     241  { switches_&=~16;switches_ |= yesNo ? 16 : 0;}
    239242  /// Number of cuts generated at root
    240243  inline int numberCutsAtRoot() const
     
    253256 
    254257private:
     258  /**@name Private gets and sets */
     259  //@{
     260  /// Whether global cuts at root
     261  inline bool globalCutsAtRoot() const
     262  { return (switches_&32)!=0;}
     263  /// Set whether global cuts at root
     264  inline void setGlobalCutsAtRoot(bool yesNo)
     265  { switches_&=~32;switches_ |= yesNo ? 32 : 0;}
     266  /// Whether global cuts
     267  inline bool globalCuts() const
     268  { return (switches_&256)!=0;}
     269  /// Set whether global cuts
     270  inline void setGlobalCuts(bool yesNo)
     271  { switches_&=~256;switches_ |= yesNo ? 256 : 0;}
     272  //@}
     273  /// Time in cut generator
     274  double timeInCutGenerator_;
    255275  /// The client model
    256276  CbcModel *model_;
     
    258278  // The CglCutGenerator object
    259279  CglCutGenerator * generator_;
     280
     281  /// Name of generator
     282  char * generatorName_;
    260283
    261284  /** Number of nodes between calls to the CglCutGenerator::generateCuts
     
    282305  int depthCutGeneratorInSub_;
    283306
    284   /// Name of generator
    285   char * generatorName_;
    286 
    287   /// Whether to call the generator in the normal place
    288   bool normal_;
    289 
    290   /// Whether to call the generator when a new solution is found
    291   bool atSolution_;
    292 
    293   /// Whether to call generator when a subproblem is found to be infeasible
    294   bool whenInfeasible_;
    295   /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
    296   bool mustCallAgain_;
    297   /// Temporary switch off marker
    298   bool switchedOff_;
    299   /// Create global cuts (at root)
    300   bool globalCutsAtRoot_;
    301   /// Whether call generator being timed
    302   bool timing_;
    303   /// Time in cut generator
    304   double timeInCutGenerator_;
    305307  /// Level of cut inaccuracy (0 means exact e.g. cliques)
    306308  int inaccuracy_;
     
    317319  /// Number of cuts active at root
    318320  int numberActiveCutsAtRoot_;
     321  /// Switches - see gets and sets
     322  int switches_;
    319323};
    320324/** Abstract cut modifier base class
  • trunk/Cbc/src/CbcLinked.cpp

    r1173 r1180  
    75727572      int nRow=0;
    75737573      double obj=objectiveOffset;
    7574       CoinZeroN(rowActivity,nRow);
     7574      // nRow is zero? CoinZeroN(rowActivity,nRow);
    75757575      for (iColumn=0;iColumn<numJ;iColumn++) {
    75767576        int iValue = stack[iColumn];
  • trunk/Cbc/src/CbcModel.cpp

    r1176 r1180  
    10061006    }
    10071007    delete [] coeffMultiplier;
    1008     increment *= scaleFactor;
    10091008/*
    10101009  If the increment beats the current value for objective change, install it.
     
    10191018        }
    10201019        value /= multiplier ;
     1020        value *= scaleFactor;
    10211021        //trueIncrement=CoinMax(cutoff,value);;
    10221022        if (value*0.999 > cutoff)
     
    80258025                  double * saveUpper)
    80268026{
     8027#ifdef CBC_STATISTICS
     8028  void cbc_resolve_check(const OsiSolverInterface * solver);
     8029  cbc_resolve_check(solver_);
     8030#endif
    80278031  // We may have deliberately added in violated cuts - check to avoid message
    80288032  int iRow;
     
    1080610810    int save = clpSimplex->specialOptions();
    1080710811    clpSimplex->setSpecialOptions(save|0x11000000); // say is Cbc (and in branch and bound)
     10812    int save2=clpSolver->specialOptions();
     10813    if (false&&(save2&2048)==0) {
     10814      // see if worthwhile crunching
     10815      int nFixed=0;
     10816      const double * columnLower = clpSimplex->columnLower();
     10817      const double * columnUpper = clpSimplex->columnUpper();
     10818      for (int i=0;i<numberIntegers_;i++) {
     10819        int iColumn = integerVariable_[i];
     10820        if (columnLower[iColumn]==columnUpper[iColumn])
     10821          nFixed++;
     10822      }
     10823      if (nFixed*20<clpSimplex->numberColumns()) {
     10824        double d=nFixed;
     10825        printf("%d fixed out of %d - ratio %g\n",
     10826               nFixed,
     10827               clpSimplex->numberColumns(),
     10828               d/clpSimplex->numberColumns());
     10829        clpSolver->setSpecialOptions(save2|2048);
     10830      }
     10831    }
    1080810832    clpSolver->resolve();
     10833    clpSolver->setSpecialOptions(save2);
    1080910834#ifdef CLP_INVESTIGATE
    1081010835    if (clpSimplex->numberIterations()>1000)
     
    1196711992        = dynamic_cast<OsiClpSolverInterface *> (solver_);
    1196811993      if ((clpSolver||(specialOptions_&16384)!=0)&&fastNodeDepth_<-1
    11969           &&!parentModel_) {
     11994          &&(specialOptions_&2048)==0) {
    1197011995#define FATHOM_BIAS -2
    1197111996        if (numberNodes_==1) {
     
    1199812023        if((specialOptions_&16384)!=0)
    1199912024          numberNodesBeforeFathom = 0;
    12000         if (node->depth()>=go_fathom &&!parentModel_
     12025        if (node->depth()>=go_fathom &&(specialOptions_&2048)==0
    1200112026            //if (node->depth()>=FATHOM_BIAS-fastNodeDepth_&&!parentModel_
    1200212027            &&numberNodes_>=numberNodesBeforeFathom) {
     
    1203812063            numberExtraNodes_ += info->numberNodesExplored_;
    1203912064            numberExtraIterations_ += info->numberIterations_;
     12065            if (info->numberNodesExplored_>10000)
     12066              fastNodeDepth_ --;
    1204012067            if (info->nNodes_<0) {
    1204112068              // we gave up
  • trunk/Cbc/src/CbcSolver.cpp

    r1176 r1180  
    495495  // Set up likely cut generators and defaults
    496496  parameters_[whichParam(PREPROCESS,numberParameters_,parameters_)].setCurrentOption("sos");
    497   parameters_[whichParam(MIPOPTIONS,numberParameters_,parameters_)].setIntValue(1025);
     497  parameters_[whichParam(MIPOPTIONS,numberParameters_,parameters_)].setIntValue(1057);
    498498  parameters_[whichParam(CUTPASSINTREE,numberParameters_,parameters_)].setIntValue(1);
    499499  parameters_[whichParam(MOREMIPOPTIONS,numberParameters_,parameters_)].setIntValue(-1);
     
    32263226  // Set up likely cut generators and defaults
    32273227  parameters[whichParam(PREPROCESS,numberParameters,parameters)].setCurrentOption("sos");
    3228   parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(1025);
     3228  parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(1057);
    32293229  parameters[whichParam(CUTPASSINTREE,numberParameters,parameters)].setIntValue(1);
    32303230  parameters[whichParam(MOREMIPOPTIONS,numberParameters,parameters)].setIntValue(-1);
     
    65456545              int accuracyFlag[20];
    65466546              int numberGenerators=0;
    6547               int translate[]={-100,-1,-99,-98,1,-1001,-1099,1,1,1,-1};
     6547              int translate[]={-100,-1,-99,-98,1,-1098,-1099,1,1,1,-1};
    65486548              if (probingAction) {
    65496549                probingGen.setMaxProbeRoot(CoinMin(2000,babModel_->solver()->getNumCols()));
     
    68126812              // Used to be automatically set
    68136813              int mipOptions = parameters_[whichParam(MIPOPTIONS,numberParameters_,parameters_)].intValue()%10000;
    6814               if (mipOptions!=(1025)) {
     6814              if (mipOptions!=(1057)) {
    68156815                sprintf(generalPrint,"mip options %d",mipOptions);
    68166816                generalMessageHandler->message(CLP_GENERAL,generalMessages)
     
    78717871#elif CBC_OTHER_SOLVER==1
    78727872#endif
    7873                 if (experimentFlag>=1||strategyFlag>=2) {
    7874                   if (babModel_->solver()->getNumCols()<200&&
    7875                       babModel_->solver()->getNumRows()<40)
    7876                     babModel_->setFastNodeDepth(-9);
     7873                if ((experimentFlag>=1||strategyFlag>=1)&&babModel_->fastNodeDepth()==-1) {
     7874                  if (babModel_->solver()->getNumCols()+
     7875                      babModel_->solver()->getNumRows()<500)
     7876                    babModel_->setFastNodeDepth(-12);
    78777877                }
    78787878                int heurOptions=parameters_[whichParam(HOPTIONS,numberParameters_,parameters_)].intValue();
     
    78877887                  if (denseCode<0)
    78887888                    denseCode=40;
    7889                   if (smallCode<0)
     7889                  if (smallCode<0&&!lpSolver->factorization()->isDenseOrSmall())
    78907890                    smallCode=40;
    78917891                }
     
    79007900                //lpSolver->factorization()->goDense();
    79017901                //}
     7902#ifdef CLP_OSL
     7903                if (lpSolver->factorization()->goOslThreshold()>1000) {
     7904                  // use osl in gomory (may not if CglGomory decides not to)
     7905                  int numberGenerators = babModel_->numberCutGenerators();
     7906                  for (int iGenerator=0;iGenerator<numberGenerators;
     7907                       iGenerator++) {
     7908                    CbcCutGenerator * generator = babModel_->cutGenerator(iGenerator);
     7909                    CglGomory * gomory = dynamic_cast<CglGomory *>
     7910                      (generator->generator());
     7911                    if (gomory)
     7912                      gomory->useAlternativeFactorization();
     7913                  }
     7914                }
     7915#endif
    79027916#endif
    79037917#endif
     
    80578071                  lpSolver = osiclp->getModelPtr();
    80588072                  lpSolver->setSpecialOptions(lpSolver->specialOptions()|IN_BRANCH_AND_BOUND); // say is Cbc (and in branch and bound)
     8073#ifdef CLP_OSL
     8074                  if (lpSolver->factorization()->goOslThreshold()>1000) {
     8075                    // use osl in gomory (may not if CglGomory decides not to)
     8076                    int numberGenerators = model_.numberCutGenerators();
     8077                    for (int iGenerator=0;iGenerator<numberGenerators;
     8078                         iGenerator++) {
     8079                      CbcCutGenerator * generator = model_.cutGenerator(iGenerator);
     8080                      CglGomory * gomory = dynamic_cast<CglGomory *>
     8081                        (generator->generator());
     8082                      if (gomory)
     8083                        gomory->useAlternativeFactorization();
     8084                    }
     8085                  }
     8086#endif
    80598087                }
    80608088#endif
     
    1018010208                      if (lengthName)
    1018110209                        fprintf(fp,format,rowNames[iRow].c_str());
    10182                       fprintf(fp,"%15.8g        %15.8g\n",primalRowSolution[iRow],
     10210                      fprintf(fp," %15.8g        %15.8g\n",primalRowSolution[iRow],
    1018310211                              dualRowSolution[iRow]);
    1018410212                    }
     
    1022410252                        if (lengthName)
    1022510253                          fprintf(fp,format,columnNames[iColumn].c_str());
    10226                         fprintf(fp,"%15.8g        %15.8g\n",
     10254                        fprintf(fp," %15.8g        %15.8g\n",
    1022710255                                primalColumnSolution[iColumn],
    1022810256                                dualColumnSolution[iColumn]);
     
    1023210260                          sprintf(temp,format,columnNames[iColumn].c_str());
    1023310261                        else
    10234                           sprintf(temp,"%7d ",iColumn);
    10235                         sprintf(temp+strlen(temp),",%15.8g",
     10262                          sprintf(temp,"%7d",iColumn);
     10263                        sprintf(temp+strlen(temp),", %15.8g",
    1023610264                                primalColumnSolution[iColumn]);
    1023710265                        int n=strlen(temp);
  • trunk/Cbc/src/CoinSolve.cpp

    r1175 r1180  
    233233//#############################################################################
    234234// void CbcClpUnitTest (const CbcModel & saveModel);
     235#ifdef CBC_STATISTICS
     236int osi_crunch=0;
     237static int cbc_resolve=0;
     238int osi_primal=0;
     239int osi_dual=0;
     240int osi_hot=0;
     241void cbc_resolve_check(const OsiSolverInterface * solver)
     242{
     243  cbc_resolve++;
     244  printf("R %d stats %d %d %d\n",
     245         cbc_resolve,solver->getNumRows(),solver->getNumCols(),
     246         solver->getMatrixByCol()->getNumElements());
     247  if ((cbc_resolve%1000)==0)
     248    printf("RR %d resolve crunch %d primal %d dual %d hot %d\n",
     249           cbc_resolve,osi_crunch,osi_primal,osi_dual,osi_hot);
     250}
     251#endif
    235252int main (int argc, const char *argv[])
    236253{
     
    270287#ifdef CLP_DEBUG_MALLOC
    271288  clp_memory(1);
     289#endif
     290#ifdef CBC_STATISTICS
    272291#endif
    273292  if (returnCode!=777) {
  • trunk/Cbc/src/unitTestClp.cpp

    r1176 r1180  
    262262      continue;
    263263    }
     264    CoinDrand48(true,1234567);
     265    //printf("RAND1 %g %g\n",CoinDrand48(true,1234567),model->randomNumberGenerator()->randomDouble());
     266    //printf("RAND1 %g\n",CoinDrand48(true,1234567));
    264267    model->solver()->readMps(fn.c_str(),"") ;
    265268    assert(model->getNumRows() == nRows[m]) ;
     
    507510    setCutAndHeuristicOptions(*model);
    508511    if (si) {
    509 #ifdef CLP_MULTIPLE_FACTORIZATIONS   
    510       int denseCode = stuff ? static_cast<int> (stuff[4]) : -1;
    511       int smallCode = stuff ? static_cast<int> (stuff[10]) : -1;
     512#ifdef CLP_MULTIPLE_FACTORIZATIONS
     513      if (!modelC->factorization()->isDenseOrSmall()) {
     514        int denseCode = stuff ? static_cast<int> (stuff[4]) : -1;
     515        int smallCode = stuff ? static_cast<int> (stuff[10]) : -1;
     516        if (stuff&&stuff[8]>=1) {
     517          if (denseCode<0)
     518            denseCode=40;
     519          if (smallCode<0)
     520            smallCode=40;
     521        }
     522        if (denseCode>0)
     523          modelC->factorization()->setGoDenseThreshold(denseCode);
     524        if (smallCode>0)
     525          modelC->factorization()->setGoSmallThreshold(smallCode);
     526        if (denseCode>=modelC->numberRows()) {
     527          //printf("problem going dense\n");
     528          //modelC->factorization()->goDenseOrSmall(modelC->numberRows());
     529        }
     530      }
     531#endif
    512532      if (stuff&&stuff[8]>=1) {
    513         if (denseCode<0)
    514           denseCode=40;
    515         if (smallCode<0)
    516           smallCode=40;
    517       }
    518       if (denseCode>0)
    519         modelC->factorization()->setGoDenseThreshold(denseCode);
    520       if (smallCode>0)
    521         modelC->factorization()->setGoSmallThreshold(smallCode);
    522       if (denseCode>=modelC->numberRows()) {
    523         //printf("problem going dense\n");
    524         //modelC->factorization()->goDenseOrSmall(modelC->numberRows());
    525       }
    526 #endif
    527       if (stuff&&stuff[8]>=1) {
    528         if (modelC->numberColumns()+modelC->numberRows()<=500&&
     533        if (modelC->numberColumns()+modelC->numberRows()<=100000&&
    529534            model->fastNodeDepth()==-1)
    530           model->setFastNodeDepth(-12);
     535          model->setFastNodeDepth(-7);
    531536      }
    532537    }
Note: See TracChangeset for help on using the changeset viewer.