10 #include "CoinPragma.hpp"
12 #include "CbcModel.hpp"
57 const double* newSolution,
61 double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
63 const double* x_l = minlp->
x_l();
64 const double* x_u = minlp->
x_u();
67 double smallestFraction = COIN_DBL_MAX;
70 for(
int iIntCol=0; iIntCol<(
int)integerColumns.size(); iIntCol++) {
71 int iColumn = integerColumns[iIntCol];
72 double value=newSolution[iColumn];
73 if (fabs(floor(value+0.5)-value)>integerTolerance) {
74 double below = floor(value);
75 double downFraction = COIN_DBL_MAX;
76 if(below >= x_l[iColumn])
77 downFraction = value-below;
78 double above = ceil(value);
79 double upFraction = COIN_DBL_MAX;
80 if(above <= x_u[iColumn])
81 upFraction = ceil(value)-value;
84 if(downFraction < upFraction) {
85 fraction = downFraction;
87 }
else if(downFraction > upFraction) {
88 fraction = upFraction;
91 double randomNumber = CoinDrand48();
92 if(randomNumber<0.5) {
93 fraction = downFraction;
96 fraction = upFraction;
100 if(fraction<smallestFraction) {
101 smallestFraction = fraction;
102 bestColumn = iColumn;
113 roptions->AddStringOption2(
114 "heuristic_dive_fractional",
115 "if yes runs the Dive Fractional heuristic",
120 roptions->setOptionExtraInfo(
"heuristic_dive_fractional", 63);
HeuristicDive & operator=(const HeuristicDive &rhs)
Assignment operator.
void Initialize(Ipopt::SmartPtr< Ipopt::OptionsList > options)
Initiaize using passed options.
virtual CbcHeuristic * clone() const
Clone.
HeuristicDiveFractional()
Default Constructor.
virtual void selectVariableToBranch(TMINLP2TNLP *minlp, const vector< int > &integerColumns, const double *newSolution, int &bestColumn, int &bestRound)
Selects the next variable to branch on.
const Ipopt::Number * x_l()
Get the current values for the lower bounds.
const Ipopt::Number * x_u()
Get the current values for the upper bounds.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options common to all local search based heuristics.
HeuristicDiveFractional & operator=(const HeuristicDiveFractional &rhs)
Assignment operator.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
virtual void setInternalVariables(TMINLP2TNLP *minlp)
sets internal variables