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