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