Ignore:
Timestamp:
Jun 26, 2007 5:17:15 AM (13 years ago)
Author:
forrest
Message:

trunk from branches/devel

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:externals
      •  

        old new  
        1 MSVisualStudio   https://projects.coin-or.org/svn/MSVisualStudio/trunk/ExternalsDirs/Cbc
        2 BuildTools    https://projects.coin-or.org/svn/BuildTools/stable/0.5
         1MSVisualStudio   https://projects.coin-or.org/svn/MSVisualStudio/branches/devel/ExternalsDirs/Cbc
         2BuildTools    https://projects.coin-or.org/svn/BuildTools/trunk
        33ThirdParty/ASL https://projects.coin-or.org/svn/BuildTools/ThirdParty/ASL/stable/1.0
         4ThirdParty/Blas https://projects.coin-or.org/svn/BuildTools/ThirdParty/Blas/stable/1.0
         5ThirdParty/Lapack https://projects.coin-or.org/svn/BuildTools/ThirdParty/Lapack/stable/1.0
        46Data/Netlib   https://projects.coin-or.org/svn/Data/stable/1.0/Netlib
        57Data/Sample   https://projects.coin-or.org/svn/Data/stable/1.0/Sample
  • trunk/Cbc/examples/CbcCompareUser.cpp

    r180 r640  
    8282{
    8383}
    84 
     84// For moment go to default
     85#if 0
    8586// Returns true if y better than x
    8687bool
     
    179180  }
    180181}
     182#else
     183
     184// Returns true if y better than x
     185bool
     186CbcCompareUser::test (CbcNode * x, CbcNode * y)
     187{
     188  if (weight_==-1.0&&(y->depth()>7||x->depth()>7)) {
     189    // before solution
     190    /* printf("x %d %d %g, y %d %d %g\n",
     191       x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
     192       y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
     193    if (x->numberUnsatisfied() > y->numberUnsatisfied()) {
     194      return true;
     195    } else if (x->numberUnsatisfied() < y->numberUnsatisfied()) {
     196      return false;
     197    } else {
     198      int testX = x->depth();
     199      int testY = y->depth();
     200      if (testX!=testY)
     201        return testX < testY;
     202      else
     203        return equalityTest(x,y); // so ties will be broken in consistent manner
     204    }
     205  } else {
     206    // after solution
     207    double weight = CoinMax(weight_,0.0);
     208    double testX =  x->objectiveValue()+ weight*x->numberUnsatisfied();
     209    double testY = y->objectiveValue() + weight*y->numberUnsatisfied();
     210    if (testX!=testY)
     211      return testX > testY;
     212    else
     213      return equalityTest(x,y); // so ties will be broken in consistent manner
     214  }
     215}
     216// This allows method to change behavior as it is called
     217// after each solution
     218void
     219CbcCompareUser::newSolution(CbcModel * model,
     220                               double objectiveAtContinuous,
     221                               int numberInfeasibilitiesAtContinuous)
     222{
     223  if (model->getSolutionCount()==model->getNumberHeuristicSolutions()&&
     224      model->getSolutionCount()<5&&model->getNodeCount()<500)
     225    return; // solution was got by rounding
     226  // set to get close to this solution
     227  double costPerInteger =
     228    (model->getObjValue()-objectiveAtContinuous)/
     229    ((double) numberInfeasibilitiesAtContinuous);
     230  weight_ = 0.95*costPerInteger;
     231  saveWeight_ = 0.95*weight_;
     232  numberSolutions_++;
     233  if (numberSolutions_>5)
     234    weight_ =0.0; // this searches on objective
     235}
     236// This allows method to change behavior
     237bool
     238CbcCompareUser::every1000Nodes(CbcModel * model, int numberNodes)
     239{
     240  double saveWeight=weight_;
     241  int numberNodes1000 = numberNodes/1000;
     242  if (numberNodes>10000) {
     243    weight_ =0.0; // this searches on objective
     244    // but try a bit of other stuff
     245    if ((numberNodes1000%4)==1)
     246      weight_=saveWeight_;
     247  } else if (numberNodes==1000&&weight_==-2.0) {
     248    weight_=-1.0; // Go to depth first
     249  }
     250  // get size of tree
     251  treeSize_ = model->tree()->size();
     252  if (treeSize_>10000) {
     253    int n1 = model->solver()->getNumRows()+model->solver()->getNumCols();
     254    int n2 = model->numberObjects();
     255    double size = n1*0.1 + n2*2.0;
     256    // set weight to reduce size most of time
     257    if (treeSize_*size>5.0e7)
     258      weight_=-1.0;
     259    else if ((numberNodes1000%4)==0&&treeSize_*size>1.0e6)
     260      weight_=-1.0;
     261    else if ((numberNodes1000%4)==1)
     262      weight_=0.0;
     263    else
     264      weight_=saveWeight_;
     265  }
     266  return (weight_!=saveWeight);
     267}
     268// Returns true if wants code to do scan with alternate criterion
     269bool
     270CbcCompareUser::fullScan() const
     271{
     272  return false;
     273}
     274// This is alternate test function
     275bool
     276CbcCompareUser::alternateTest (CbcNode * x, CbcNode * y)
     277{
     278  // not used
     279  abort();
     280  return false;
     281}
     282#endif
Note: See TracChangeset for help on using the changeset viewer.