Changeset 511 for trunk


Ignore:
Timestamp:
Jan 11, 2007 10:03:58 AM (13 years ago)
Author:
forrest
Message:

printing

Location:
trunk/Cbc/src
Files:
2 edited

Legend:

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

    r310 r511  
    123123    typeCuts_=1; // may as well so we don't have to deal with refine
    124124  if (!number01&&!typeCuts_) {
    125     printf("** No 0-1 variables and local search only on 0-1 - switching off\n");
     125    if (model_->messageHandler()->logLevel()>0)
     126      printf("** No 0-1 variables and local search only on 0-1 - switching off\n");
    126127    typeCuts_=-1;
    127128  } else {
    128     std::string type;
    129     if (all01) {
    130       printf("%d 0-1 variables normal local  cuts\n",
    131              number01);
    132     } else if (typeCuts_) {
    133       printf("%d 0-1 variables, %d other - general integer local cuts\n",
    134              number01,numberIntegers-number01);
    135     } else {
    136       printf("%d 0-1 variables, %d other - local cuts but just on 0-1 variables\n",
    137              number01,numberIntegers-number01);
    138     }
    139     printf("maximum diversifications %d, initial cutspace %d, max time %d seconds, max nodes %d\n",
    140            maxDiversification_,range_,timeLimit_,nodeLimit_);
     129    if (model_->messageHandler()->logLevel()>0) {
     130      std::string type;
     131      if (all01) {
     132        printf("%d 0-1 variables normal local  cuts\n",
     133               number01);
     134      } else if (typeCuts_) {
     135        printf("%d 0-1 variables, %d other - general integer local cuts\n",
     136               number01,numberIntegers-number01);
     137      } else {
     138        printf("%d 0-1 variables, %d other - local cuts but just on 0-1 variables\n",
     139               number01,numberIntegers-number01);
     140      }
     141      printf("maximum diversifications %d, initial cutspace %d, max time %d seconds, max nodes %d\n",
     142             maxDiversification_,range_,timeLimit_,nodeLimit_);
     143    }
    141144  }
    142145  int numberColumns = model_->getNumCols();
     
    328331// Return the top node of the heap
    329332CbcNode *
    330 CbcTreeLocal::top() {
     333CbcTreeLocal::top() const{
    331334#ifdef CBC_DEBUG
    332335  int smallest=9999999;
     
    343346    smallestD=min(smallestD,dd);
    344347  }
    345   printf("smallest %d, largest %d, top %d\n",smallest,largest,
    346          nodes_.front()->nodeInfo()->nodeNumber());
    347   printf("smallestD %g, largestD %g, top %g\n",smallestD,largestD,nodes_.front()->objectiveValue());
     348  if (model_->messageHandler()->logLevel()>0) {
     349    printf("smallest %d, largest %d, top %d\n",smallest,largest,
     350           nodes_.front()->nodeInfo()->nodeNumber());
     351    printf("smallestD %g, largestD %g, top %g\n",smallestD,largestD,nodes_.front()->objectiveValue());
     352  }
    348353#endif
    349354  return nodes_.front();
     
    362367      // we came in with solution
    363368      model_->globalCuts()->insert(cut_);
    364       printf("initial cut - rhs %g %g\n",
    365              cut_.lb(),cut_.ub());
     369      if (model_->messageHandler()->logLevel()>0)
     370        printf("initial cut - rhs %g %g\n",
     371               cut_.lb(),cut_.ub());
    366372      searchType_=1;
    367373    } else {
     
    374380  nodes_.push_back(x);
    375381#ifdef CBC_DEBUG
    376   printf("pushing node onto heap %d %x %x\n",
    377          x->nodeInfo()->nodeNumber(),x,x->nodeInfo());
     382  if (model_->messageHandler()->logLevel()>0)
     383    printf("pushing node onto heap %d %x %x\n",
     384           x->nodeInfo()->nodeNumber(),x,x->nodeInfo());
    378385#endif
    379386  push_heap(nodes_.begin(), nodes_.end(), comparison_);
     
    388395// Test if empty - does work if so
    389396bool
    390 CbcTreeLocal::empty()  
     397CbcTreeLocal::empty()
    391398{
    392399  if (typeCuts_<0)
     
    432439
    433440  double increment = model_->getDblParam(CbcModel::CbcCutoffIncrement) ;
    434   printf("local state %d after %d nodes and %d seconds, new solution %g, best solution %g, k was %g\n",
    435          state,
    436          model_->getNodeCount()-startNode_,
    437          (int) CoinCpuTime()-startTime_,
    438          model_->getCutoff()+increment,bestCutoff_+increment,rhs_);
     441  if (model_->messageHandler()->logLevel()>0)
     442    printf("local state %d after %d nodes and %d seconds, new solution %g, best solution %g, k was %g\n",
     443           state,
     444           model_->getNodeCount()-startNode_,
     445           (int) CoinCpuTime()-startTime_,
     446           model_->getCutoff()+increment,bestCutoff_+increment,rhs_);
    439447  saveNumberSolutions_ = model_->getSolutionCount();
    440448  bool finished=false;
     
    478486          typeCuts_=-1; // make sure can't start again
    479487        model_->setCutoff(bestCutoff_);
    480         printf("Exiting local search with current set of cuts\n");
     488        if (model_->messageHandler()->logLevel()>0)
     489          printf("Exiting local search with current set of cuts\n");
    481490        rhs_=1.0e100;
    482491        // Can now stop on gap
     
    608617      lastTry=true;
    609618      model_->setCutoff(bestCutoff_);
    610       printf("Exiting local search with current set of cuts\n");
     619      if (model_->messageHandler()->logLevel()>0)
     620        printf("Exiting local search with current set of cuts\n");
    611621      rhs_=1.0e100;
    612622      // Can now stop on gap
     
    624634      int n = global->sizeRowCuts();
    625635      OsiRowCut * rowCut = global->rowCutPtr(n-1);
    626       printf("inserting cut - now %d cuts, rhs %g %g, cutspace %g, diversification %d\n",
    627              n,rowCut->lb(),rowCut->ub(),rhs_,diversification_);
     636      if (model_->messageHandler()->logLevel()>0)
     637        printf("inserting cut - now %d cuts, rhs %g %g, cutspace %g, diversification %d\n",
     638               n,rowCut->lb(),rowCut->ub(),rhs_,diversification_);
    628639      const OsiRowCutDebugger *debugger = model_->solver()->getRowCutDebuggerAlways() ;
    629640      if (debugger) {
     
    633644      for (int i=0;i<n;i++) {
    634645        rowCut = global->rowCutPtr(i);
    635         printf("%d - rhs %g %g\n",
    636                i,rowCut->lb(),rowCut->ub());
     646        if (model_->messageHandler()->logLevel()>0)
     647          printf("%d - rhs %g %g\n",
     648                 i,rowCut->lb(),rowCut->ub());
    637649      }
    638650    }
     
    748760    }
    749761    if (maxValue<rhs-primalTolerance) {
    750       printf("slack cut\n");
     762      if (model_->messageHandler()->logLevel()>0)
     763        printf("slack cut\n");
    751764      goodSolution=1;
    752765    }
     
    755768    rowCut.setUb(rhs);   
    756769    rowCut.setGloballyValid();
     770    if (model_->messageHandler()->logLevel()>0)
    757771    printf("Cut size: %i Cut rhs: %g\n",cut.getNumElements(), rhs);
    758772#ifdef CBC_DEBUG
    759     int k;
    760     for (k=0; k<cut.getNumElements(); k++){
    761       printf("%i    %g ",cut.getIndices()[k], cut.getElements()[k]);
    762       if ((k+1)%5==0)
     773    if (model_->messageHandler()->logLevel()>0) {
     774      int k;
     775      for (k=0; k<cut.getNumElements(); k++){
     776        printf("%i    %g ",cut.getIndices()[k], cut.getElements()[k]);
     777        if ((k+1)%5==0)
     778          printf("\n");
     779      }
     780      if (k%5!=0)
    763781        printf("\n");
    764782    }
    765     if (k%5!=0)
    766       printf("\n");
    767783#endif
    768784    return goodSolution;
    769785  } else {
    770     printf("Not a good solution\n");
     786    if (model_->messageHandler()->logLevel()>0)
     787      printf("Not a good solution\n");
    771788    return -1;
    772789  }
     
    804821  }
    805822  // replace by other way
    806   printf("reverseCut - changing cut %d out of %d, old rhs %g %g ",
    807          i,n,rowCut->lb(),rowCut->ub());
     823  if (model_->messageHandler()->logLevel()>0)
     824    printf("reverseCut - changing cut %d out of %d, old rhs %g %g ",
     825           i,n,rowCut->lb(),rowCut->ub());
    808826  rowCut->setLb(rowCut->ub()+smallest-bias);
    809827  rowCut->setUb(COIN_DBL_MAX);
    810   printf("new rhs %g %g, bias %g smallest %g ",
    811          rowCut->lb(),rowCut->ub(),bias,smallest);
     828  if (model_->messageHandler()->logLevel()>0)
     829    printf("new rhs %g %g, bias %g smallest %g ",
     830           rowCut->lb(),rowCut->ub(),bias,smallest);
    812831  const OsiRowCutDebugger *debugger = model_->solver()->getRowCutDebuggerAlways() ;
    813832  if (debugger) {
     
    833852  assert (i<n);
    834853  // delete last cut
    835   printf("deleteCut - deleting cut %d out of %d, rhs %g %g\n",
    836          i,n,rowCut->lb(),rowCut->ub());
     854  if (model_->messageHandler()->logLevel()>0)
     855    printf("deleteCut - deleting cut %d out of %d, rhs %g %g\n",
     856           i,n,rowCut->lb(),rowCut->ub());
    837857  global->eraseRowCut(i);
    838858}
    839 
    840 
    841 
     859// Create C++ lines to get to current state
     860void
     861CbcTreeLocal::generateCpp( FILE * fp)
     862{
     863  CbcTreeLocal other;
     864  fprintf(fp,"0#include \"CbcTreeLocal.hpp\"\n");
     865  fprintf(fp,"5  CbcTreeLocal localTree(cbcModel,NULL);\n");
     866  if (range_!=other.range_)
     867    fprintf(fp,"5  localTree.setRange(%d);\n",range_);
     868  if (typeCuts_!=other.typeCuts_)
     869    fprintf(fp,"5  localTree.setTypeCuts(%d);\n",typeCuts_);
     870  if (maxDiversification_!=other.maxDiversification_)
     871    fprintf(fp,"5  localTree.setMaxDiversification(%d);\n",maxDiversification_);
     872  if (timeLimit_!=other.timeLimit_)
     873    fprintf(fp,"5  localTree.setTimeLimit(%d);\n",timeLimit_);
     874  if (nodeLimit_!=other.nodeLimit_)
     875    fprintf(fp,"5  localTree.setNodeLimit(%d);\n",nodeLimit_);
     876  if (refine_!=other.refine_)
     877    fprintf(fp,"5  localTree.setRefine(%s);\n",refine_ ? "true" : "false");
     878  fprintf(fp,"5  cbcModel->passInTreeHandler(localTree);\n");
     879}
     880
     881
     882
  • trunk/Cbc/src/CbcTreeLocal.hpp

    r186 r511  
    6868  /// Clone
    6969  virtual CbcTree * clone() const;
     70  /// Create C++ lines to get to current state
     71  virtual void generateCpp( FILE * fp) ;
    7072
    7173/*! \name Heap access and maintenance methods */
     
    7375
    7476  /// Return the top node of the heap
    75   virtual CbcNode * top();
     77  virtual CbcNode * top() const;
    7678
    7779  /// Add a node to the heap
     
    99101  /// Pass in solution (so can be used after heuristic)
    100102  void passInSolution(const double * solution, double solutionValue);
     103  // range i.e. k
     104  inline int range() const
     105  { return range_;};
     106  // setrange i.e. k
     107  inline void setRange(int value)
     108  { range_ = value;};
     109  // Type of cuts - 0=just 0-1, 1=all
     110  inline int typeCuts() const
     111  { return typeCuts_;};
     112  // Type of cuts - 0=just 0-1, 1=all
     113  inline void setTypeCuts(int value)
     114  { typeCuts_ = value;};
     115  // maximum number of diversifications
     116  inline int maxDiversification() const
     117  { return maxDiversification_;};
     118  // maximum number of diversifications
     119  inline void setMaxDiversification(int value)
     120  { maxDiversification_ = value;};
     121  // time limit per subtree
     122  inline int timeLimit() const
     123  { return timeLimit_;};
     124  // time limit per subtree
     125  inline void setTimeLimit(int value)
     126  { timeLimit_ = value;};
     127  // node limit for subtree
     128  inline int nodeLimit() const
     129  { return nodeLimit_;};
     130  // node limit for subtree
     131  inline void setNodeLimit(int value)
     132  { nodeLimit_ = value;};
     133  // Whether to do refinement step
     134  inline bool refine() const
     135  { return refine_;};
     136  // Whether to do refinement step
     137  inline void setRefine(bool yesNo)
     138    { refine_ = yesNo;};
    101139
    102140//@}
Note: See TracChangeset for help on using the changeset viewer.