BonHeuristicDiveFractional.cpp
Go to the documentation of this file.
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"
12 #include "CbcModel.hpp"
13 
14 namespace Bonmin
15 {
17  :
19  {}
20 
22  :
23  HeuristicDive(setup)
24  {
25  Initialize(setup->options());
26  }
27 
29  :
30  HeuristicDive(copy)
31  {}
32 
35  {
36  if (this!=&rhs) {
38  }
39  return *this;
40  }
41 
42  CbcHeuristic *
44  {
45  return new HeuristicDiveFractional(*this);
46  }
47 
48  void
50  {
51  // no variables to set
52  }
53 
54  void
56  const vector<int> & integerColumns,
57  const double* newSolution,
58  int& bestColumn,
59  int& bestRound)
60  {
61  double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
62 
63  const double* x_l = minlp->x_l();
64  const double* x_u = minlp->x_u();
65 
66  // select a fractional variable to bound
67  double smallestFraction = COIN_DBL_MAX;
68  bestColumn = -1;
69  bestRound = -1; // -1 rounds down, +1 rounds up
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;
82  double fraction = 0;
83  int round = 0;
84  if(downFraction < upFraction) {
85  fraction = downFraction;
86  round = -1;
87  } else if(downFraction > upFraction) {
88  fraction = upFraction;
89  round = 1;
90  } else {
91  double randomNumber = CoinDrand48();
92  if(randomNumber<0.5) {
93  fraction = downFraction;
94  round = -1;
95  } else {
96  fraction = upFraction;
97  round = 1;
98  }
99  }
100  if(fraction<smallestFraction) {
101  smallestFraction = fraction;
102  bestColumn = iColumn;
103  bestRound = round;
104  }
105  }
106  }
107 
108  }
109 
110  void
112  roptions->SetRegisteringCategory("Primal Heuristics", RegisteredOptions::BonminCategory);
113  roptions->AddStringOption2(
114  "heuristic_dive_fractional",
115  "if yes runs the Dive Fractional heuristic",
116  "no",
117  "no", "",
118  "yes", "",
119  "");
120  roptions->setOptionExtraInfo("heuristic_dive_fractional", 63);
121  }
122 
123  void
125  }
126 
127 }
HeuristicDive & operator=(const HeuristicDive &rhs)
Assignment operator.
void Initialize(Ipopt::SmartPtr< Ipopt::OptionsList > options)
Initiaize using passed options.
virtual CbcHeuristic * clone() const
Clone.
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.
static int
Definition: OSdtoa.cpp:2173
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