00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "CoinPragma.hpp"
00011 #include "BonHeuristicDiveMIPFractional.hpp"
00012 #include "CbcModel.hpp"
00013
00014 namespace Bonmin
00015 {
00016 #if 0
00017 HeuristicDiveMIPFractional::HeuristicDiveMIPFractional()
00018 :
00019 HeuristicDiveMIP()
00020 {}
00021 #endif
00022
00023 HeuristicDiveMIPFractional::HeuristicDiveMIPFractional(BonminSetup * setup)
00024 :
00025 HeuristicDiveMIP(setup)
00026 {
00027 Initialize(setup->options());
00028 }
00029
00030 HeuristicDiveMIPFractional::HeuristicDiveMIPFractional(const HeuristicDiveMIPFractional ©)
00031 :
00032 HeuristicDiveMIP(copy)
00033 {}
00034
00035 HeuristicDiveMIPFractional &
00036 HeuristicDiveMIPFractional::operator=( const HeuristicDiveMIPFractional& rhs)
00037 {
00038 if (this!=&rhs) {
00039 HeuristicDiveMIP::operator=(rhs);
00040 }
00041 return *this;
00042 }
00043
00044 CbcHeuristic *
00045 HeuristicDiveMIPFractional::clone() const
00046 {
00047 return new HeuristicDiveMIPFractional(*this);
00048 }
00049
00050 void
00051 HeuristicDiveMIPFractional::setInternalVariables(TMINLP2TNLP* minlp)
00052 {
00053
00054 }
00055
00056 void
00057 HeuristicDiveMIPFractional::selectVariableToBranch(TMINLP2TNLP* minlp,
00058 const vector<int> & integerColumns,
00059 const double* newSolution,
00060 int& bestColumn,
00061 int& bestRound)
00062 {
00063 double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
00064
00065 const double* x_l = minlp->x_l();
00066 const double* x_u = minlp->x_u();
00067
00068
00069 double smallestFraction = COIN_DBL_MAX;
00070 bestColumn = -1;
00071 bestRound = -1;
00072 for(int iIntCol=0; iIntCol<(int)integerColumns.size(); iIntCol++) {
00073 int iColumn = integerColumns[iIntCol];
00074 double value=newSolution[iColumn];
00075 if (fabs(floor(value+0.5)-value)>integerTolerance) {
00076 double below = floor(value);
00077 double downFraction = COIN_DBL_MAX;
00078 if(below >= x_l[iColumn])
00079 downFraction = value-below;
00080 double above = ceil(value);
00081 double upFraction = COIN_DBL_MAX;
00082 if(above <= x_u[iColumn])
00083 upFraction = ceil(value)-value;
00084 double fraction = 0;
00085 int round = 0;
00086 if(downFraction < upFraction) {
00087 fraction = downFraction;
00088 round = -1;
00089 } else if(downFraction > upFraction) {
00090 fraction = upFraction;
00091 round = 1;
00092 } else {
00093 double randomNumber = CoinDrand48();
00094 if(randomNumber<0.5) {
00095 fraction = downFraction;
00096 round = -1;
00097 } else {
00098 fraction = upFraction;
00099 round = 1;
00100 }
00101 }
00102 if(fraction<smallestFraction) {
00103 smallestFraction = fraction;
00104 bestColumn = iColumn;
00105 bestRound = round;
00106 }
00107 }
00108 }
00109
00110 }
00111
00112 void
00113 HeuristicDiveMIPFractional::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
00114 roptions->SetRegisteringCategory("Primal Heuristics", RegisteredOptions::BonminCategory);
00115 roptions->AddStringOption2(
00116 "heuristic_dive_MIP_fractional",
00117 "if yes runs the Dive MIP Fractional heuristic",
00118 "no",
00119 "no", "",
00120 "yes", "",
00121 "");
00122 roptions->setOptionExtraInfo("heuristic_dive_MIP_fractional", 63);
00123 }
00124
00125 void
00126 HeuristicDiveMIPFractional::Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options){
00127 }
00128
00129 }