BonHeuristicDiveMIPFractional.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 {
16 #if 0
18  :
19  HeuristicDiveMIP()
20  {}
21 #endif
22 
24  :
25  HeuristicDiveMIP(setup)
26  {
27  Initialize(setup->options());
28  }
29 
31  :
32  HeuristicDiveMIP(copy)
33  {}
34 
37  {
38  if (this!=&rhs) {
40  }
41  return *this;
42  }
43 
44  CbcHeuristic *
46  {
47  return new HeuristicDiveMIPFractional(*this);
48  }
49 
50  void
52  {
53  // no variables to set
54  }
55 
56  void
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
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
127  }
128 
129 }
HeuristicDiveMIP & operator=(const HeuristicDiveMIP &rhs)
Assignment operator.
void Initialize(Ipopt::SmartPtr< Ipopt::OptionsList > options)
Initiaize using passed options.
virtual void setInternalVariables(TMINLP2TNLP *minlp)
sets internal variables
HeuristicDiveMIPFractional & operator=(const HeuristicDiveMIPFractional &rhs)
Assignment operator.
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.
virtual CbcHeuristic * clone() const
Clone.
static int
Definition: OSdtoa.cpp:2173
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options common to all local search based heuristics.
HeuristicDiveMIPFractional()
Default Constructor.
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 selectVariableToBranch(TMINLP2TNLP *minlp, const vector< int > &integerColumns, const double *newSolution, int &bestColumn, int &bestRound)
Selects the next variable to branch on.