Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • stable/2.8/Cbc/src/CbcCutGenerator.cpp

    r1675 r1883  
    5050        numberActiveCutsAtRoot_(0),
    5151        numberShortCutsAtRoot_(0),
    52         switches_(1)
     52        switches_(1),
     53        maximumTries_(-1)
    5354{
    5455}
     
    7374        numberActiveCutsAtRoot_(0),
    7475        numberShortCutsAtRoot_(0),
    75         switches_(1)
     76        switches_(1),
     77        maximumTries_(-1)
    7678{
    7779    if (howOften < -1900) {
     
    111113    generatorName_ = CoinStrdup(rhs.generatorName_);
    112114    switches_ = rhs.switches_;
     115    maximumTries_ = rhs.maximumTries_;
    113116    timeInCutGenerator_ = rhs.timeInCutGenerator_;
    114117    savedCuts_ = rhs.savedCuts_;
     
    141144        generatorName_ = CoinStrdup(rhs.generatorName_);
    142145        switches_ = rhs.switches_;
     146        maximumTries_ = rhs.maximumTries_;
    143147        timeInCutGenerator_ = rhs.timeInCutGenerator_;
    144148        savedCuts_ = rhs.savedCuts_;
     
    202206    if (howOften == -100)
    203207        return false;
     208    int pass = model_->getCurrentPassNumber() - 1;
     209    if (maximumTries_>0) {
     210      // howOften means what it says
     211      if ((pass%howOften)!=0||depth)
     212        return false;
     213      else
     214        howOften=1;
     215    }
    204216    if (howOften > 0)
    205217        howOften = howOften % 1000000;
     
    210222    bool returnCode = false;
    211223    //OsiSolverInterface * solver = model_->solver();
    212     int pass = model_->getCurrentPassNumber() - 1;
    213224    // Reset cuts on first pass
    214225    if (!pass)
     
    287298        CglProbing* generator =
    288299            dynamic_cast<CglProbing*>(generator_);
     300        //if (!depth&&!pass)
     301        //printf("Cut generator %s when %d\n",generatorName_,whenCutGenerator_);
    289302        if (!generator) {
    290303            // Pass across model information in case it could be useful
     
    11191132        }
    11201133#endif
    1121         {
    1122             int numberRowCutsAfter = cs.sizeRowCuts() ;
    1123             if (numberRowCutsBefore < numberRowCutsAfter) {
    1124                 for (int k = numberRowCutsBefore; k < numberRowCutsAfter; k++) {
    1125                     OsiRowCut thisCut = cs.rowCut(k) ;
    1126                     int n = thisCut.row().getNumElements();
    1127                     numberElements_ += n;
    1128                 }
     1134        int numberRowCutsAfter = cs.sizeRowCuts() ;
     1135        int numberColumnCutsAfter = cs.sizeColCuts() ;
     1136        if (numberRowCutsBefore < numberRowCutsAfter) {
     1137            for (int k = numberRowCutsBefore; k < numberRowCutsAfter; k++) {
     1138                OsiRowCut thisCut = cs.rowCut(k) ;
     1139                int n = thisCut.row().getNumElements();
     1140                numberElements_ += n;
     1141            }
    11291142#ifdef JJF_ZERO
    1130                 printf("generator %s generated %d row cuts\n",
    1131                        generatorName_, numberRowCutsAfter - numberRowCutsBefore);
    1132 #endif
    1133                 numberCuts_ += numberRowCutsAfter - numberRowCutsBefore;
    1134             }
    1135             int numberColumnCutsAfter = cs.sizeColCuts() ;
    1136             if (numberColumnCutsBefore < numberColumnCutsAfter) {
     1143            printf("generator %s generated %d row cuts\n",
     1144                   generatorName_, numberRowCutsAfter - numberRowCutsBefore);
     1145#endif
     1146            numberCuts_ += numberRowCutsAfter - numberRowCutsBefore;
     1147        }
     1148        if (numberColumnCutsBefore < numberColumnCutsAfter) {
    11371149#ifdef JJF_ZERO
    1138                 printf("generator %s generated %d column cuts\n",
    1139                        generatorName_, numberColumnCutsAfter - numberColumnCutsBefore);
    1140 #endif
    1141                 numberColumnCuts_ += numberColumnCutsAfter - numberColumnCutsBefore;
    1142             }
     1150            printf("generator %s generated %d column cuts\n",
     1151                   generatorName_, numberColumnCutsAfter - numberColumnCutsBefore);
     1152#endif
     1153            numberColumnCuts_ += numberColumnCutsAfter - numberColumnCutsBefore;
    11431154        }
    11441155        if (timing())
    11451156            timeInCutGenerator_ += CoinCpuTime() - time1;
    1146 #ifdef JJF_ZERO
    11471157        // switch off if first time and no good
    1148         if (node == NULL && !pass) {
    1149             if (cs.sizeCuts() - cutsBefore < CoinAbs(switchOffIfLessThan_)) {
    1150                 whenCutGenerator_ = -99;
    1151                 whenCutGeneratorInSub_ = -200;
     1158        if (node == NULL && !pass ) {
     1159            if (numberRowCutsAfter - numberRowCutsBefore
     1160                < switchOffIfLessThan_ /*&& numberCuts_ < switchOffIfLessThan_*/) {
     1161              // switch off
     1162              maximumTries_ = 0;
     1163              whenCutGenerator_=-100;
     1164              //whenCutGenerator_ = -100;
     1165              //whenCutGeneratorInSub_ = -200;
    11521166            }
    11531167        }
    1154 #endif
     1168        if (maximumTries_>0) {
     1169          maximumTries_--;
     1170          if (!maximumTries_)
     1171            whenCutGenerator_=-100;
     1172        }
    11551173    }
    11561174    return returnCode;
     
    11821200{
    11831201    depthCutGeneratorInSub_ = value;
     1202}
     1203// Add in statistics from other
     1204void
     1205CbcCutGenerator::addStatistics(const CbcCutGenerator * other)
     1206{
     1207  // Time in cut generator
     1208  timeInCutGenerator_ += other->timeInCutGenerator_;
     1209  // Number times cut generator entered
     1210  numberTimes_ += other->numberTimes_;
     1211  // Total number of cuts added
     1212  numberCuts_ += other->numberCuts_;
     1213  // Total number of elements added
     1214  numberElements_ += other->numberElements_;
     1215  // Total number of column cuts added
     1216  numberColumnCuts_ += other->numberColumnCuts_;
     1217  // Total number of cuts active after (at end of n cut passes at each node)
     1218  numberCutsActive_ += other->numberCutsActive_;
     1219  // Number of cuts generated at root
     1220  numberCutsAtRoot_ += other->numberCutsAtRoot_;
     1221  // Number of cuts active at root
     1222  numberActiveCutsAtRoot_ += other->numberActiveCutsAtRoot_;
     1223  // Number of short cuts at root
     1224  numberShortCutsAtRoot_ += other->numberShortCutsAtRoot_;
     1225}
     1226// Scale back statistics by factor
     1227void
     1228CbcCutGenerator::scaleBackStatistics(int factor)
     1229{
     1230  // leave time
     1231  // Number times cut generator entered
     1232  numberTimes_ = (numberTimes_+factor-1)/factor;
     1233  // Total number of cuts added
     1234  numberCuts_ = (numberCuts_+factor-1)/factor;
     1235  // Total number of elements added
     1236  numberElements_ = (numberElements_+factor-1)/factor;
     1237  // Total number of column cuts added
     1238  numberColumnCuts_ = (numberColumnCuts_+factor-1)/factor;
     1239  // Total number of cuts active after (at end of n cut passes at each node)
     1240  numberCutsActive_ = (numberCutsActive_+factor-1)/factor;
     1241  // Number of cuts generated at root
     1242  numberCutsAtRoot_ = (numberCutsAtRoot_+factor-1)/factor;
     1243  // Number of cuts active at root
     1244  numberActiveCutsAtRoot_ = (numberActiveCutsAtRoot_+factor-1)/factor;
     1245  // Number of short cuts at root
     1246  numberShortCutsAtRoot_ = (numberShortCutsAtRoot_+factor-1)/factor;
    11841247}
    11851248// Create C++ lines to get to current state
Note: See TracChangeset for help on using the changeset viewer.