Debian Codegraph @

Bonmin/src/CbcBonmin/Heuristics/BonHeuristicDiveFractional.cpp

raw
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 "BonHeuristicDiveFractional.hpp"
12 #include "CbcModel.hpp"
13
14 namespace Bonmin
15 {
16 HeuristicDiveFractional::HeuristicDiveFractional()
17 :
18 HeuristicDive()
19 {}
20
21 HeuristicDiveFractional::HeuristicDiveFractional(BonminSetup * setup)
22 :
23 HeuristicDive(setup)
24 {
25 Initialize(setup->options());
26 }
27
28 HeuristicDiveFractional::HeuristicDiveFractional(const HeuristicDiveFractional &copy)
29 :
30 HeuristicDive(copy)
31 {}
32
33 HeuristicDiveFractional &
34 HeuristicDiveFractional::operator=( const HeuristicDiveFractional& rhs)
35 {
36 if (this!=&rhs) {
37 HeuristicDive::operator=(rhs);
38 }
39 return *this;
40 }
41
42 CbcHeuristic *
43 HeuristicDiveFractional::clone() const
44 {
45 return new HeuristicDiveFractional(*this);
46 }
47
48 void
49 HeuristicDiveFractional::setInternalVariables(TMINLP2TNLP* minlp)
50 {
51 // no variables to set
52 }
53
54 void
55 HeuristicDiveFractional::selectVariableToBranch(TMINLP2TNLP* minlp,
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
111 HeuristicDiveFractional::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
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
124 HeuristicDiveFractional::Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options){
125 }
126
127 }