Ignore:
Timestamp:
Dec 18, 2006 9:39:29 AM (14 years ago)
Author:
forrest
Message:

mostly for rins

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Cbc/src/CbcHeuristic.cpp

    r439 r502  
    2525CbcHeuristic::CbcHeuristic()
    2626  :model_(NULL),
    27    when_(2)
    28 {
     27   when_(2),
     28   numberNodes_(200),
     29   fractionSmall_(1.0)
     30{
     31  // As CbcHeuristic virtual need to modify .cpp if above change
    2932}
    3033
     
    3336:
    3437  model_(&model),
    35   when_(2)
    36 {
    37 }
     38  when_(2),
     39  numberNodes_(200),
     40  fractionSmall_(1.0)
     41{
     42  // As CbcHeuristic virtual need to modify .cpp if above change
     43}
     44// Copy constructor
     45CbcHeuristic::CbcHeuristic(const CbcHeuristic & rhs)
     46:
     47  model_(rhs.model_),
     48  when_(rhs.when_),
     49  numberNodes_(rhs.numberNodes_),
     50  fractionSmall_(rhs.fractionSmall_)
     51{
     52}
     53// Assignment operator
     54CbcHeuristic &
     55CbcHeuristic::operator=( const CbcHeuristic& rhs)
     56{
     57  if (this!=&rhs) {
     58    model_ = rhs.model_;
     59    when_ = rhs.when_;
     60    numberNodes_ = rhs.numberNodes_;
     61    fractionSmall_ = rhs.fractionSmall_;
     62  }
     63  return *this;
     64}
     65
    3866// Resets stuff if model changes
    3967void
     
    4371}
    4472
     73// Create C++ lines to get to current state
     74void
     75CbcHeuristic::generateCpp( FILE * fp, const char * heuristic)
     76{
     77  // hard coded as CbcHeuristic virtual
     78  if (when_!=2)
     79    fprintf(fp,"3  %s.setWhen(%d);\n",heuristic,when_);
     80  else
     81    fprintf(fp,"4  %s.setWhen(%d);\n",heuristic,when_);
     82  if (numberNodes_!=200)
     83    fprintf(fp,"3  %s.setNumberNodes(%d);\n",heuristic,numberNodes_);
     84  else
     85    fprintf(fp,"4  %s.setNumberNodes(%d);\n",heuristic,numberNodes_);
     86  if (fractionSmall_!=1.0)
     87    fprintf(fp,"3  %s.setFractionSmall(%g);\n",heuristic,fractionSmall_);
     88  else
     89    fprintf(fp,"4  %s.setFractionSmall(%g);\n",heuristic,fractionSmall_);
     90}
    4591// Destructor
    4692CbcHeuristic::~CbcHeuristic ()
     
    90136      if (logLevel>1)
    91137        printf("Pre-processing says infeasible\n");
    92       returnCode=0; // so will be infeasible
     138      returnCode=2; // so will be infeasible
    93139    } else {
     140      // see if too big
     141      double before = solver->getNumRows()+solver->getNumCols();
     142      double after = solver2->getNumRows()+solver2->getNumCols();
     143      printf("before %d rows %d columns, after %d rows %d columns\n",
     144             solver->getNumRows(),solver->getNumCols(),
     145             solver2->getNumRows(),solver2->getNumCols());
     146      if (after>fractionSmall_*before)
     147        return 0;
    94148      solver2->resolve();
    95149      CbcModel model(*solver2);
     
    120174      if (model.getMinimizationObjValue()<CoinMin(cutoff,1.0e30)) {
    121175        // solution
    122         returnCode=1;
     176        returnCode=model.isProvenOptimal() ? 3 : 1;
    123177        // post process
    124178        process.postProcess(*model.solver());
     
    135189      } else {
    136190        // no good
    137         returnCode=0; // so will be infeasible
     191        returnCode=model.isProvenInfeasible() ? 2 : 0; // so will be infeasible
    138192      }
    139193    }
    140194  } else {
    141     returnCode=0;
     195    returnCode=2; // infeasible finished
    142196  }
    143197  return returnCode;
     
    181235  fprintf(fp,"0#include \"CbcHeuristic.hpp\"\n");
    182236  fprintf(fp,"3  CbcRounding rounding(*cbcModel);\n");
     237  CbcHeuristic::generateCpp(fp,"rounding");
    183238  if (seed_!=other.seed_)
    184239    fprintf(fp,"3  rounding.setSeed(%d);\n",seed_);
     
    196251  seed_(rhs.seed_)
    197252{
    198   setWhen(rhs.when());
     253}
     254
     255// Assignment operator
     256CbcRounding &
     257CbcRounding::operator=( const CbcRounding& rhs)
     258{
     259  if (this!=&rhs) {
     260    CbcHeuristic::operator=(rhs);
     261    matrix_ = rhs.matrix_;
     262    matrixByRow_ = rhs.matrixByRow_;
     263    seed_ = rhs.seed_;
     264  }
     265  return *this;
    199266}
    200267
     
    907974  fprintf(fp,"0#include \"CbcHeuristic.hpp\"\n");
    908975  fprintf(fp,"3  CbcSerendipity serendipity(*cbcModel);\n");
     976  CbcHeuristic::generateCpp(fp,"serendipity");
    909977  fprintf(fp,"3  cbcModel->addHeuristic(&serendipity);\n");
    910978}
     
    915983  CbcHeuristic(rhs)
    916984{
     985}
     986
     987// Assignment operator
     988CbcSerendipity &
     989CbcSerendipity::operator=( const CbcSerendipity& rhs)
     990{
     991  if (this!=&rhs) {
     992    CbcHeuristic::operator=(rhs);
     993  }
     994  return *this;
    917995}
    918996
Note: See TracChangeset for help on using the changeset viewer.