Changeset 1286 for branches/sandbox/Cbc/src/CbcHeuristicDiveFractional.cpp
 Timestamp:
 Nov 9, 2009 6:33:07 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/sandbox/Cbc/src/CbcHeuristicDiveFractional.cpp
r1271 r1286 11 11 12 12 // Default Constructor 13 CbcHeuristicDiveFractional::CbcHeuristicDiveFractional() 14 :CbcHeuristicDive()13 CbcHeuristicDiveFractional::CbcHeuristicDiveFractional() 14 : CbcHeuristicDive() 15 15 { 16 16 } … … 18 18 // Constructor from model 19 19 CbcHeuristicDiveFractional::CbcHeuristicDiveFractional(CbcModel & model) 20 :CbcHeuristicDive(model)20 : CbcHeuristicDive(model) 21 21 { 22 22 } 23 23 24 // Destructor 24 // Destructor 25 25 CbcHeuristicDiveFractional::~CbcHeuristicDiveFractional () 26 26 { … … 31 31 CbcHeuristicDiveFractional::clone() const 32 32 { 33 return new CbcHeuristicDiveFractional(*this);33 return new CbcHeuristicDiveFractional(*this); 34 34 } 35 35 36 36 // Create C++ lines to get to current state 37 void 38 CbcHeuristicDiveFractional::generateCpp( FILE * fp) 37 void 38 CbcHeuristicDiveFractional::generateCpp( FILE * fp) 39 39 { 40 CbcHeuristicDiveFractional other;41 fprintf(fp,"0#include \"CbcHeuristicDiveFractional.hpp\"\n");42 fprintf(fp,"3 CbcHeuristicDiveFractional heuristicDiveFractional(*cbcModel);\n");43 CbcHeuristic::generateCpp(fp,"heuristicDiveFractional");44 fprintf(fp,"3 cbcModel>addHeuristic(&heuristicDiveFractional);\n");40 CbcHeuristicDiveFractional other; 41 fprintf(fp, "0#include \"CbcHeuristicDiveFractional.hpp\"\n"); 42 fprintf(fp, "3 CbcHeuristicDiveFractional heuristicDiveFractional(*cbcModel);\n"); 43 CbcHeuristic::generateCpp(fp, "heuristicDiveFractional"); 44 fprintf(fp, "3 cbcModel>addHeuristic(&heuristicDiveFractional);\n"); 45 45 } 46 46 47 // Copy constructor 47 // Copy constructor 48 48 CbcHeuristicDiveFractional::CbcHeuristicDiveFractional(const CbcHeuristicDiveFractional & rhs) 49 :50 CbcHeuristicDive(rhs)49 : 50 CbcHeuristicDive(rhs) 51 51 { 52 52 } 53 53 54 // Assignment operator 55 CbcHeuristicDiveFractional & 56 CbcHeuristicDiveFractional::operator=( const CbcHeuristicDiveFractional & rhs)54 // Assignment operator 55 CbcHeuristicDiveFractional & 56 CbcHeuristicDiveFractional::operator=( const CbcHeuristicDiveFractional & rhs) 57 57 { 58 if (this!=&rhs) {59 CbcHeuristicDive::operator=(rhs);60 }61 return *this;58 if (this != &rhs) { 59 CbcHeuristicDive::operator=(rhs); 60 } 61 return *this; 62 62 } 63 63 64 64 bool 65 65 CbcHeuristicDiveFractional::selectVariableToBranch(OsiSolverInterface* solver, 66 67 68 66 const double* newSolution, 67 int& bestColumn, 68 int& bestRound) 69 69 { 70 int numberIntegers = model_>numberIntegers();71 const int * integerVariable = model_>integerVariable();72 double integerTolerance = model_>getDblParam(CbcModel::CbcIntegerTolerance);70 int numberIntegers = model_>numberIntegers(); 71 const int * integerVariable = model_>integerVariable(); 72 double integerTolerance = model_>getDblParam(CbcModel::CbcIntegerTolerance); 73 73 74 bestColumn = 1;75 bestRound = 1; // 1 rounds down, +1 rounds up76 double bestFraction = DBL_MAX;77 bool allTriviallyRoundableSoFar = true;78 for (int i=0; i<numberIntegers; i++) {79 int iColumn = integerVariable[i];80 double value=newSolution[iColumn];81 double fraction=valuefloor(value);82 int round = 0;83 if (fabs(floor(value+0.5)value)>integerTolerance) {84 if (allTriviallyRoundableSoFar(downLocks_[i]>0&&upLocks_[i]>0)) {74 bestColumn = 1; 75 bestRound = 1; // 1 rounds down, +1 rounds up 76 double bestFraction = DBL_MAX; 77 bool allTriviallyRoundableSoFar = true; 78 for (int i = 0; i < numberIntegers; i++) { 79 int iColumn = integerVariable[i]; 80 double value = newSolution[iColumn]; 81 double fraction = value  floor(value); 82 int round = 0; 83 if (fabs(floor(value + 0.5)  value) > integerTolerance) { 84 if (allTriviallyRoundableSoFar  (downLocks_[i] > 0 && upLocks_[i] > 0)) { 85 85 86 if (allTriviallyRoundableSoFar&&downLocks_[i]>0&&upLocks_[i]>0) {87 88 89 86 if (allTriviallyRoundableSoFar && downLocks_[i] > 0 && upLocks_[i] > 0) { 87 allTriviallyRoundableSoFar = false; 88 bestFraction = DBL_MAX; 89 } 90 90 91 // the variable cannot be rounded 92 if(fraction < 0.5) 93 round = 1; 94 else { 95 round = 1; 96 fraction = 1.0  fraction; 97 } 98 99 // if variable is not binary, penalize it 100 if(!solver>isBinary(iColumn)) 101 fraction *= 1000.0; 102 103 if(fraction < bestFraction) { 104 bestColumn = iColumn; 105 bestFraction = fraction; 106 bestRound = round; 107 } 108 } 91 // the variable cannot be rounded 92 if (fraction < 0.5) 93 round = 1; 94 else { 95 round = 1; 96 fraction = 1.0  fraction; 97 } 98 99 // if variable is not binary, penalize it 100 if (!solver>isBinary(iColumn)) 101 fraction *= 1000.0; 102 103 if (fraction < bestFraction) { 104 bestColumn = iColumn; 105 bestFraction = fraction; 106 bestRound = round; 107 } 108 } 109 } 109 110 } 110 } 111 return allTriviallyRoundableSoFar; 111 return allTriviallyRoundableSoFar; 112 112 }
Note: See TracChangeset
for help on using the changeset viewer.