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