Changeset 2102


Ignore:
Timestamp:
Dec 15, 2014 10:45:52 AM (4 years ago)
Author:
forrest
Message:

add option to RENS

Location:
stable/2.8/Cbc/src
Files:
3 edited

Legend:

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

    r1902 r2102  
    3333    whereFrom_ = 256 + 1;
    3434}
    35 
    3635// Constructor with model - assumed before cuts
    3736
     
    8786    int returnCode = 0;
    8887    const double * bestSolution = model_->bestSolution();
     88    bool returnNow=false;
    8989    if ((numberTries_&&(rensType_&16)==0) || numberTries_>1 || (when() < 2 && bestSolution))
     90      returnNow=true;;
     91    // If 32 bit set then do once with bestSolution
     92    if ((rensType_&32)!=0&&bestSolution)
     93      returnNow=false;
     94    if (returnNow)
    9095        return 0;
     96    // switch off next time if bestSolution
     97    if (bestSolution) {
     98      if ((rensType_&32)!=0)
     99        rensType_ &= ~32; // switch off but leave bestSolution
     100      else
     101        bestSolution=NULL; // null bestSolution so won't use
     102    }
    91103    numberTries_++;
     104#ifdef HEURISTIC_INFORM
     105    printf("Entering heuristic %s - nRuns %d numCould %d when %d\n",
     106           heuristicName(),numRuns_,numCouldRun_,when_);
     107#endif
    92108    double saveFractionSmall=fractionSmall_;
    93109    OsiSolverInterface * solver = model_->solver();
     
    736752    int numberAtBound = 0;
    737753    int numberContinuous = numberColumns - numberIntegers;
    738 
     754    /*
     755      0 - allow fixing
     756      1 - don't allow fixing
     757     */
     758    char * marked = new char [numberColumns];
     759    memset(marked,0,numberColumns);
     760    if (bestSolution) {
     761      for (i = 0; i < numberIntegers; i++) {
     762        int iColumn = integerVariable[i];
     763        double value = currentSolution[iColumn];
     764        double lower = colLower[iColumn];
     765        double upper = colUpper[iColumn];
     766        value = CoinMax(value, lower);
     767        value = CoinMin(value, upper);
     768        if (fabs(bestSolution[iColumn]-value)>0.999)
     769          marked[iColumn]=1;
     770      }
     771    }
     772    if ((rensType_&(64|128))!=0&&model_->objects()) {
     773      int lowPriority=-COIN_INT_MAX;
     774      int highPriority=COIN_INT_MAX;
     775      for (i = 0; i < numberIntegers; i++) {
     776        int priority=model_->priority(i);
     777        lowPriority=CoinMax(lowPriority,priority);
     778        highPriority=CoinMin(highPriority,priority);
     779      }
     780      if (highPriority<lowPriority) {
     781        int keepPriority=((rensType_&64)!=0) ? highPriority : lowPriority;
     782        for (i = 0; i < numberIntegers; i++) {
     783          int iColumn = integerVariable[i];
     784          int priority=model_->priority(i);
     785          if (priority==keepPriority)
     786            marked[iColumn]=1;
     787        }
     788      }
     789    }
    739790    for (i = 0; i < numberIntegers; i++) {
    740791        int iColumn = integerVariable[i];
     
    745796        value = CoinMin(value, upper);
    746797        double djValue=dj[iColumn]*direction;
     798        bool dontFix=marked[iColumn]!=0;
    747799#define RENS_FIX_ONLY_LOWER
    748800#ifndef RENS_FIX_ONLY_LOWER
    749801        if (fabs(value - floor(value + 0.5)) < 1.0e-8) {
    750802            value = floor(value + 0.5);
     803            if (dontFix) {
     804              continue;
     805            }
    751806            if (value == lower || value == upper)
    752807                numberAtBound++;
     
    763818                floor(value + 0.5) == lower &&
    764819            djValue > djTolerance ) {
     820            if (dontFix) {
     821              continue;
     822            }
    765823          value = floor(value + 0.5);
    766824          numberAtBound++;
     
    772830                   -djValue > djTolerance && (djTolerance > 0.0||type==2)) {
    773831          value = floor(value + 0.5);
     832            if (dontFix) {
     833              continue;
     834            }
    774835          numberAtBound++;
    775836          newSolver->setColLower(iColumn, value);
     
    794855#endif
    795856    }
     857    delete [] marked;
    796858    delete [] dj;
    797859    if (numberFixed > numberIntegers / 5) {
  • stable/2.8/Cbc/src/CbcHeuristicRENS.hpp

    r1902 r2102  
    6767        3 - fix on 0.01*average dj
    6868        add 16 to allow two tries
     69        32 - if solution exists use to keep more variables
     70        64 - if priorities keep high priority
     71        128 - if priorities keep low priority
    6972    */
    7073    int rensType_;
  • stable/2.8/Cbc/src/CbcSolver.cpp

    r2085 r2102  
    657657    parameters_[whichParam(CBC_PARAM_STR_FPUMP, numberParameters_, parameters_)].setCurrentOption("on");
    658658    parameters_[whichParam(CBC_PARAM_STR_GREEDY, numberParameters_, parameters_)].setCurrentOption("on");
    659     parameters_[whichParam(CBC_PARAM_STR_COMBINE, numberParameters_, parameters_)].setCurrentOption("on");
     659    parameters_[whichParam(CBC_PARAM_STR_COMBINE, numberParameters_, parameters_)].setCurrentOption("off");
    660660    parameters_[whichParam(CBC_PARAM_STR_CROSSOVER2, numberParameters_, parameters_)].setCurrentOption("off");
    661661    parameters_[whichParam(CBC_PARAM_STR_PIVOTANDCOMPLEMENT, numberParameters_, parameters_)].setCurrentOption("off");
     
    97829782    parameters[whichParam(CBC_PARAM_STR_FPUMP, numberParameters, parameters)].setCurrentOption("on");
    97839783    parameters[whichParam(CBC_PARAM_STR_GREEDY, numberParameters, parameters)].setCurrentOption("on");
    9784     parameters[whichParam(CBC_PARAM_STR_COMBINE, numberParameters, parameters)].setCurrentOption("on");
     9784    parameters[whichParam(CBC_PARAM_STR_COMBINE, numberParameters, parameters)].setCurrentOption("off");
    97859785    parameters[whichParam(CBC_PARAM_STR_CROSSOVER2, numberParameters, parameters)].setCurrentOption("off");
    97869786    parameters[whichParam(CBC_PARAM_STR_PIVOTANDCOMPLEMENT, numberParameters, parameters)].setCurrentOption("off");
Note: See TracChangeset for help on using the changeset viewer.