| 1 |
// Copyright (C) 2007, International Business Machines Corporation and others. |
| 2 |
// All Rights Reserved. |
| 3 |
// This code is published under the Eclipse Public License. |
| 4 |
// |
| 5 |
// Authors : |
| 6 |
// Joao P. Goncalves, International Business Machines Corporation |
| 7 |
// |
| 8 |
// Date : November 12, 2007 |
| 9 |
|
| 10 |
#include "CoinPragma.hpp" |
| 11 |
#include "BonHeuristicDiveMIPFractional.hpp" |
| 12 |
#include "CbcModel.hpp" |
| 13 |
|
| 14 |
namespace Bonmin |
| 15 |
{ |
| 16 |
#if 0 |
| 17 |
HeuristicDiveMIPFractional::HeuristicDiveMIPFractional() |
| 18 |
: |
| 19 |
HeuristicDiveMIP() |
| 20 |
{} |
| 21 |
#endif |
| 22 |
|
| 23 |
HeuristicDiveMIPFractional::HeuristicDiveMIPFractional(BonminSetup * setup) |
| 24 |
: |
| 25 |
HeuristicDiveMIP(setup) |
| 26 |
{ |
| 27 |
Initialize(setup->options()); |
| 28 |
} |
| 29 |
|
| 30 |
HeuristicDiveMIPFractional::HeuristicDiveMIPFractional(const HeuristicDiveMIPFractional ©) |
| 31 |
: |
| 32 |
HeuristicDiveMIP(copy) |
| 33 |
{} |
| 34 |
|
| 35 |
HeuristicDiveMIPFractional & |
| 36 |
HeuristicDiveMIPFractional::operator=( const HeuristicDiveMIPFractional& rhs) |
| 37 |
{ |
| 38 |
if (this!=&rhs) { |
| 39 |
HeuristicDiveMIP::operator=(rhs); |
| 40 |
} |
| 41 |
return *this; |
| 42 |
} |
| 43 |
|
| 44 |
CbcHeuristic * |
| 45 |
HeuristicDiveMIPFractional::clone() const |
| 46 |
{ |
| 47 |
return new HeuristicDiveMIPFractional(*this); |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
HeuristicDiveMIPFractional::setInternalVariables(TMINLP2TNLP* minlp) |
| 52 |
{ |
| 53 |
// no variables to set |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
HeuristicDiveMIPFractional::selectVariableToBranch(TMINLP2TNLP* minlp, |
| 58 |
const vector<int> & integerColumns, |
| 59 |
const double* newSolution, |
| 60 |
int& bestColumn, |
| 61 |
int& bestRound) |
| 62 |
{ |
| 63 |
double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance); |
| 64 |
|
| 65 |
const double* x_l = minlp->x_l(); |
| 66 |
const double* x_u = minlp->x_u(); |
| 67 |
|
| 68 |
// select a fractional variable to bound |
| 69 |
double smallestFraction = COIN_DBL_MAX; |
| 70 |
bestColumn = -1; |
| 71 |
bestRound = -1; // -1 rounds down, +1 rounds up |
| 72 |
for(int iIntCol=0; iIntCol<(int)integerColumns.size(); iIntCol++) { |
| 73 |
int iColumn = integerColumns[iIntCol]; |
| 74 |
double value=newSolution[iColumn]; |
| 75 |
if (fabs(floor(value+0.5)-value)>integerTolerance) { |
| 76 |
double below = floor(value); |
| 77 |
double downFraction = COIN_DBL_MAX; |
| 78 |
if(below >= x_l[iColumn]) |
| 79 |
downFraction = value-below; |
| 80 |
double above = ceil(value); |
| 81 |
double upFraction = COIN_DBL_MAX; |
| 82 |
if(above <= x_u[iColumn]) |
| 83 |
upFraction = ceil(value)-value; |
| 84 |
double fraction = 0; |
| 85 |
int round = 0; |
| 86 |
if(downFraction < upFraction) { |
| 87 |
fraction = downFraction; |
| 88 |
round = -1; |
| 89 |
} else if(downFraction > upFraction) { |
| 90 |
fraction = upFraction; |
| 91 |
round = 1; |
| 92 |
} else { |
| 93 |
double randomNumber = CoinDrand48(); |
| 94 |
if(randomNumber<0.5) { |
| 95 |
fraction = downFraction; |
| 96 |
round = -1; |
| 97 |
} else { |
| 98 |
fraction = upFraction; |
| 99 |
round = 1; |
| 100 |
} |
| 101 |
} |
| 102 |
if(fraction<smallestFraction) { |
| 103 |
smallestFraction = fraction; |
| 104 |
bestColumn = iColumn; |
| 105 |
bestRound = round; |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
void |
| 113 |
HeuristicDiveMIPFractional::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){ |
| 114 |
roptions->SetRegisteringCategory("Primal Heuristics", RegisteredOptions::BonminCategory); |
| 115 |
roptions->AddStringOption2( |
| 116 |
"heuristic_dive_MIP_fractional", |
| 117 |
"if yes runs the Dive MIP Fractional heuristic", |
| 118 |
"no", |
| 119 |
"no", "", |
| 120 |
"yes", "", |
| 121 |
""); |
| 122 |
roptions->setOptionExtraInfo("heuristic_dive_MIP_fractional", 63); |
| 123 |
} |
| 124 |
|
| 125 |
void |
| 126 |
HeuristicDiveMIPFractional::Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options){ |
| 127 |
} |
| 128 |
|
| 129 |
} |