Ignore:
Timestamp:
Sep 15, 2006 4:55:05 PM (13 years ago)
Author:
forrest
Message:

many changes

File:
1 edited

Legend:

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

    r310 r424  
    4444    numberTimesUpInfeasible_(0),
    4545    numberBeforeTrust_(0),
     46    numberTimesDownLocalFixed_(0),
     47    numberTimesUpLocalFixed_(0),
     48    numberTimesDownTotalFixed_(0.0),
     49    numberTimesUpTotalFixed_(0.0),
     50    numberTimesProbingTotal_(0),
    4651    method_(0)
    4752{
     
    7378    numberTimesUpInfeasible_(0),
    7479    numberBeforeTrust_(0),
     80    numberTimesDownLocalFixed_(0),
     81    numberTimesUpLocalFixed_(0),
     82    numberTimesDownTotalFixed_(0.0),
     83    numberTimesUpTotalFixed_(0.0),
     84    numberTimesProbingTotal_(0),
    7585    method_(0)
    7686{
     
    132142    numberTimesUpInfeasible_(0),
    133143    numberBeforeTrust_(0),
     144    numberTimesDownLocalFixed_(0),
     145    numberTimesUpLocalFixed_(0),
     146    numberTimesDownTotalFixed_(0.0),
     147    numberTimesUpTotalFixed_(0.0),
     148    numberTimesProbingTotal_(0),
    134149    method_(0)
    135150{
     
    185200   numberTimesUpInfeasible_(rhs.numberTimesUpInfeasible_),
    186201   numberBeforeTrust_(rhs.numberBeforeTrust_),
     202   numberTimesDownLocalFixed_(rhs.numberTimesDownLocalFixed_),
     203   numberTimesUpLocalFixed_(rhs.numberTimesUpLocalFixed_),
     204   numberTimesDownTotalFixed_(rhs.numberTimesDownTotalFixed_),
     205   numberTimesUpTotalFixed_(rhs.numberTimesUpTotalFixed_),
     206   numberTimesProbingTotal_(rhs.numberTimesProbingTotal_),
    187207   method_(rhs.method_)
    188208
     
    223243    numberTimesUpInfeasible_ = rhs.numberTimesUpInfeasible_;
    224244    numberBeforeTrust_ = rhs.numberBeforeTrust_;
     245    numberTimesDownLocalFixed_ = rhs.numberTimesDownLocalFixed_;
     246    numberTimesUpLocalFixed_ = rhs.numberTimesUpLocalFixed_;
     247    numberTimesDownTotalFixed_ = rhs.numberTimesDownTotalFixed_;
     248    numberTimesUpTotalFixed_ = rhs.numberTimesUpTotalFixed_;
     249    numberTimesProbingTotal_ = rhs.numberTimesProbingTotal_;
    225250    method_=rhs.method_;
    226251  }
     
    326351    below = above -1;
    327352  }
    328 #define INFEAS
    329 #ifdef INFEAS
     353#define INFEAS 1
     354#if INFEAS==1
    330355  double distanceToCutoff=0.0;
    331356  double objectiveValue = model_->getCurrentMinimizationObjValue();
     
    341366  sum = sumDownCost_;
    342367  number = numberTimesDown_;
    343 #ifdef INFEAS
     368#if INFEAS==1
    344369  sum += numberTimesDownInfeasible_*(distanceToCutoff/(downCost+1.0e-12));
     370  number += numberTimesDownInfeasible_;
    345371#endif
    346372  if (number>0)
     
    351377  sum = sumUpCost_;
    352378  number = numberTimesUp_;
    353 #ifdef INFEAS
     379#if INFEAS==1
    354380  sum += numberTimesUpInfeasible_*(distanceToCutoff/(upCost+1.0e-12));
     381  number += numberTimesUpInfeasible_;
    355382#endif
    356383  if (number>0)
     
    399426    //returnValue = 2.0*returnValue + 0.1;
    400427    //}
     428    if (method_==1) {
     429      // probing
     430      // average
     431      double up=1.0e-15;
     432      double down=1.0e-15;
     433      if (numberTimesProbingTotal_) {
     434        up += numberTimesUpTotalFixed_/((double) numberTimesProbingTotal_);
     435        down += numberTimesDownTotalFixed_/((double) numberTimesProbingTotal_);
     436      }
     437      returnValue = 1 + 10.0*CoinMin(numberTimesDownLocalFixed_,numberTimesUpLocalFixed_) +
     438        CoinMin(down,up);
     439      returnValue *= 1.0e-3;
     440    }
    401441    return CoinMax(returnValue,1.0e-15);
    402442  }
     
    452492  double downCost = CoinMax((value-below)*downDynamicPseudoCost_,0.0);
    453493  return downCost;
     494}
     495// Pass in probing information
     496void
     497CbcSimpleIntegerDynamicPseudoCost::setProbingInformation(int fixedDown, int fixedUp)
     498{
     499  numberTimesProbingTotal_++;
     500  numberTimesDownLocalFixed_ = fixedDown;
     501  numberTimesDownTotalFixed_ += fixedDown;
     502  numberTimesUpLocalFixed_ = fixedUp;
     503  numberTimesUpTotalFixed_ += fixedUp;
    454504}
    455505// Print
     
    712762  CbcDynamicPseudoCostBranchingObject * branchingObject =
    713763    dynamic_cast<CbcDynamicPseudoCostBranchingObject *>(object_);
    714   assert (branchingObject);
     764  if (!branchingObject) {
     765    delete object_;
     766    object_=NULL;
     767    return;
     768  }
    715769  CbcSimpleIntegerDynamicPseudoCost *  object = branchingObject->object();
    716770  double change = CoinMax(0.0,objectiveValue-originalValue);
     
    740794  int way = object_->way();
    741795  double value = object_->value();
    742 #define TYPE2
     796#define TYPE2 1
     797#define TYPERATIO 0.9
    743798  if (way<0) {
    744799    // down
    745800    if (feasible) {
     801      //printf("(down change %g value down %g ",change,value-floor(value));
    746802      object->incrementNumberTimesDown();
    747803      object->addToSumDownChange(1.0e-30+value-floor(value));
    748804      object->addToSumDownDecrease(originalUnsatisfied-unsatisfied);
    749 #ifndef TYPE2
     805#if TYPE2==0
    750806      object->addToSumDownCost(change/(1.0e-30+(value-floor(value))));
    751807      object->setDownDynamicPseudoCost(object->sumDownCost()/(double) object->numberTimesDown());
    752 #else
     808#elif TYPE2==1
    753809      object->addToSumDownCost(change);
    754810      object->setDownDynamicPseudoCost(object->sumDownCost()/object->sumDownChange());
     811#elif TYPE2==2
     812      object->addToSumDownCost(change*TYPERATIO+(1.0-TYPERATIO)*change/(1.0e-30+(value-floor(value))));
     813      object->setDownDynamicPseudoCost(object->sumDownCost()*(TYPERATIO/object->sumDownChange()+(1.0-TYPERATIO)/(double) object->numberTimesDown()));
    755814#endif
    756815    } else {
     816      //printf("(down infeasible value down %g ",change,value-floor(value));
    757817      object->incrementNumberTimesDownInfeasible();
     818#if INFEAS==2
     819      double distanceToCutoff=0.0;
     820      double objectiveValue = model->getCurrentMinimizationObjValue();
     821      distanceToCutoff =  model->getCutoff()  - originalValue;
     822      if (distanceToCutoff<1.0e20)
     823        change = distanceToCutoff*2.0;
     824      else
     825        change = object->downDynamicPseudoCost()*(value-floor(value))*10.0;
     826      change = CoinMax(1.0e-12*(1.0+fabs(originalValue)),change);
     827      object->incrementNumberTimesDown();
     828      object->addToSumDownChange(1.0e-30+value-floor(value));
     829      object->addToSumDownDecrease(originalUnsatisfied-unsatisfied);
     830#if TYPE2==0
     831      object->addToSumDownCost(change/(1.0e-30+(value-floor(value))));
     832      object->setDownDynamicPseudoCost(object->sumDownCost()/(double) object->numberTimesDown());
     833#elif TYPE2==1
     834      object->addToSumDownCost(change);
     835      object->setDownDynamicPseudoCost(object->sumDownCost()/object->sumDownChange());
     836#elif TYPE2==2
     837      object->addToSumDownCost(change*TYPERATIO+(1.0-TYPERATIO)*change/(1.0e-30+(value-floor(value))));
     838      object->setDownDynamicPseudoCost(object->sumDownCost()*(TYPERATIO/object->sumDownChange()+(1.0-TYPERATIO)/(double) object->numberTimesDown()));
     839#endif
     840#endif
    758841    }
    759842  } else {
    760843    // up
    761844    if (feasible) {
     845      //printf("(up change %g value down %g ",change,ceil(value)-value);
    762846      object->incrementNumberTimesUp();
    763847      object->addToSumUpChange(1.0e-30+ceil(value)-value);
    764848      object->addToSumUpDecrease(unsatisfied-originalUnsatisfied);
    765 #ifndef TYPE2
     849#if TYPE2==0
    766850      object->addToSumUpCost(change/(1.0e-30+(ceil(value)-value)));
    767851      object->setUpDynamicPseudoCost(object->sumUpCost()/(double) object->numberTimesUp());
    768 #else
     852#elif TYPE2==1
    769853      object->addToSumUpCost(change);
    770854      object->setUpDynamicPseudoCost(object->sumUpCost()/object->sumUpChange());
     855#elif TYPE2==2
     856      object->addToSumUpCost(change*TYPERATIO+(1.0-TYPERATIO)*change/(1.0e-30+(ceil(value)-value)));
     857      object->setUpDynamicPseudoCost(object->sumUpCost()*(TYPERATIO/object->sumUpChange()+(1.0-TYPERATIO)/(double) object->numberTimesUp()));
    771858#endif
    772859    } else {
     860      //printf("(up infeasible value down %g ",change,ceil(value)-value);
    773861      object->incrementNumberTimesUpInfeasible();
    774     }
    775   }
     862#if INFEAS==2
     863      double distanceToCutoff=0.0;
     864      double objectiveValue = model->getCurrentMinimizationObjValue();
     865      distanceToCutoff =  model->getCutoff()  - originalValue;
     866      if (distanceToCutoff<1.0e20)
     867        change = distanceToCutoff*2.0;
     868      else
     869        change = object->upDynamicPseudoCost()*(ceil(value)-value)*10.0;
     870      change = CoinMax(1.0e-12*(1.0+fabs(originalValue)),change);
     871      object->incrementNumberTimesUp();
     872      object->addToSumUpChange(1.0e-30+ceil(value)-value);
     873      object->addToSumUpDecrease(unsatisfied-originalUnsatisfied);
     874#if TYPE2==0
     875      object->addToSumUpCost(change/(1.0e-30+(ceil(value)-value)));
     876      object->setUpDynamicPseudoCost(object->sumUpCost()/(double) object->numberTimesUp());
     877#elif TYPE2==1
     878      object->addToSumUpCost(change);
     879      object->setUpDynamicPseudoCost(object->sumUpCost()/object->sumUpChange());
     880#elif TYPE2==2
     881      object->addToSumUpCost(change*TYPERATIO+(1.0-TYPERATIO)*change/(1.0e-30+(ceil(value)-value)));
     882      object->setUpDynamicPseudoCost(object->sumUpCost()*(TYPERATIO/object->sumUpChange()+(1.0-TYPERATIO)/(double) object->numberTimesUp()));
     883#endif
     884#endif
     885    }
     886  }
     887  //object->print();
    776888  delete object_;
    777889  object_=NULL;
     
    875987    CbcDynamicPseudoCostBranchingObject * branchingObject =
    876988      dynamic_cast<CbcDynamicPseudoCostBranchingObject *>(thisOne);
    877     assert (branchingObject);
    878     CbcSimpleIntegerDynamicPseudoCost *  object = branchingObject->object();
    879     double separator = object->upDownSeparator();
    880     if (separator>0.0) {
    881       const double * solution = thisOne->model()->testSolution();
    882       double valueVariable = solution[object->columnNumber()];
    883       betterWay = (valueVariable-floor(valueVariable)>=separator) ? 1 : -1;
     989    if (branchingObject) {
     990      CbcSimpleIntegerDynamicPseudoCost *  object = branchingObject->object();
     991      double separator = object->upDownSeparator();
     992      if (separator>0.0) {
     993        const double * solution = thisOne->model()->testSolution();
     994        double valueVariable = solution[object->columnNumber()];
     995        betterWay = (valueVariable-floor(valueVariable)>=separator) ? 1 : -1;
     996      }
    884997    }
    885998    bestCriterion_ = value;
Note: See TracChangeset for help on using the changeset viewer.