Changeset 2070 for trunk/Cbc/src/CbcSOS.cpp
 Timestamp:
 Sep 8, 2014 5:24:45 AM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcSOS.cpp
r2040 r2070 31 31 CbcSOS::CbcSOS () 32 32 : CbcObject(), 33 members_(NULL), 34 weights_(NULL), 35 shadowEstimateDown_(1.0), 36 shadowEstimateUp_(1.0), 37 downDynamicPseudoRatio_(0.0), 38 upDynamicPseudoRatio_(0.0), 39 numberTimesDown_(0), 40 numberTimesUp_(0), 41 numberMembers_(0), 42 sosType_(1), 43 integerValued_(false) 33 members_(NULL), 34 weights_(NULL), 35 shadowEstimateDown_(1.0), 36 shadowEstimateUp_(1.0), 37 downDynamicPseudoRatio_(0.0), 38 upDynamicPseudoRatio_(0.0), 39 numberTimesDown_(0), 40 numberTimesUp_(0), 41 numberMembers_(0), 42 sosType_(1), 43 integerValued_(false), 44 oddValues_(false) 44 45 { 45 46 } … … 56 57 numberTimesUp_(0), 57 58 numberMembers_(numberMembers), 58 sosType_(type) 59 sosType_(type), 60 oddValues_(false) 59 61 { 60 62 id_ = identifier; … … 74 76 } 75 77 if (numberMembers_) { 78 const OsiSolverInterface * solver = model_>solver(); 79 const double * lower = solver>getColLower(); 80 for (int i = 0; i < numberMembers_; i++) { 81 if (lower[which[i]]<0.0) { 82 oddValues_ = true; // mark as odd 83 } 84 } 85 86 // check >= 0.0 76 87 members_ = new int[numberMembers_]; 77 88 weights_ = new double[numberMembers_]; … … 117 128 sosType_ = rhs.sosType_; 118 129 integerValued_ = rhs.integerValued_; 130 oddValues_ = rhs.oddValues_; 119 131 if (numberMembers_) { 120 132 members_ = new int[numberMembers_]; … … 152 164 sosType_ = rhs.sosType_; 153 165 integerValued_ = rhs.integerValued_; 166 oddValues_ = rhs.oddValues_; 154 167 if (numberMembers_) { 155 168 members_ = new int[numberMembers_]; … … 188 201 OsiSolverInterface * solver = model_>solver(); 189 202 const double * solution = model_>testSolution(); 190 //const double * lower = solver>getColLower();203 const double * lower = solver>getColLower(); 191 204 const double * upper = solver>getColUpper(); 192 205 //double largestValue=0.0; … … 194 207 model_>getDblParam(CbcModel::CbcIntegerTolerance); 195 208 double weight = 0.0; 196 double sum = 0.0; 209 double sum = 0.0; 197 210 198 211 // check bounds etc … … 207 220 if (lastWeight >= weights_[j]  1.0e7) 208 221 throw CoinError("Weights too close together in SOS", "infeasibility", "CbcSOS"); 209 double value = CoinMax( 0.0, solution[iColumn]);222 double value = CoinMax(lower[iColumn], solution[iColumn]); 210 223 sum += value; 211 224 /* … … 216 229 used to calculate either the return value or preferredWay. 217 230 */ 218 if (value > integerTolerance && upper[iColumn]) { 231 if (fabs(value) > integerTolerance && (upper[iColumn] > 0.0  232 oddValues_)) { 219 233 // Possibly due to scaling a fixed variable might slip through 220 234 if (value > upper[iColumn]) { … … 228 242 #endif 229 243 } 244 if (value < lower[iColumn]) { 245 value = lower[iColumn]; 246 // Could change to #ifdef CBC_DEBUG 247 #ifndef NDEBUG 248 if (model_>messageHandler()>logLevel() > 2 && 249 value < lower[iColumn]  integerTolerance) 250 printf("** Variable %d (%d) has value %g and lower bound of %g\n", 251 iColumn, j, value, lower[iColumn]); 252 #endif 253 } 230 254 weight += weights_[j] * value; 231 255 if (firstNonZero < 0) … … 244 268 if (lastNonZero  firstNonZero >= sosType_) { 245 269 // find where to branch 246 assert (sum > 0.0); 247 weight /= sum; 270 if (!oddValues_) 271 weight /= sum; 272 else 273 weight = 0.5*(weights_[firstNonZero]+weights_[lastNonZero]); 248 274 if (info>defaultDual_ >= 0.0 && info>usefulRegion_ && info>columnStart_) { 249 275 assert (sosType_ == 1); … … 443 469 OsiSolverInterface * solver = model_>solver(); 444 470 const double * solution = model_>testSolution(); 445 //const double * lower = solver>getColLower();471 const double * lower = solver>getColLower(); 446 472 const double * upper = solver>getColUpper(); 447 473 double integerTolerance = … … 452 478 for (j = 0; j < numberMembers_; j++) { 453 479 int iColumn = members_[j]; 454 double value = CoinMax( 0.0, solution[iColumn]);480 double value = CoinMax(lower[iColumn], solution[iColumn]); 455 481 sum += value; 456 if ( value > integerTolerance && upper[iColumn]) {482 if (fabs(value) > integerTolerance && (upper[iColumn]  oddValues_)) { 457 483 weight += weights_[j] * value; 458 484 if (firstNonZero < 0) … … 465 491 for (j = 0; j < firstNonZero; j++) { 466 492 int iColumn = members_[j]; 493 solver>setColLower(iColumn, 0.0); 467 494 solver>setColUpper(iColumn, 0.0); 468 495 } 469 496 for (j = lastNonZero + 1; j < numberMembers_; j++) { 470 497 int iColumn = members_[j]; 498 solver>setColLower(iColumn, 0.0); 471 499 solver>setColUpper(iColumn, 0.0); 472 500 } … … 474 502 for (j = 0; j < numberMembers_; j++) { 475 503 int iColumn = members_[j]; 476 solver>setColUpper(iColumn, 0.0); 504 solver>setColUpper(iColumn, 0.0); // make infeasible 477 505 solver>setColLower(iColumn, 1.0); 478 506 } … … 510 538 model_>getDblParam(CbcModel::CbcIntegerTolerance); 511 539 //OsiSolverInterface * solver = model_>solver(); 540 const double * lower = solver>getColLower(); 512 541 const double * upper = solver>getColUpper(); 513 542 int firstNonFixed = 1; … … 519 548 for (j = 0; j < numberMembers_; j++) { 520 549 int iColumn = members_[j]; 521 if (upper[iColumn] ) {522 double value = CoinMax( 0.0, solution[iColumn]);550 if (upper[iColumn]  oddValues_) { 551 double value = CoinMax(lower[iColumn], solution[iColumn]); 523 552 sum += value; 524 553 if (firstNonFixed < 0) 525 554 firstNonFixed = j; 526 555 lastNonFixed = j; 527 if ( value> integerTolerance) {556 if (fabs(value) > integerTolerance) { 528 557 weight += weights_[j] * value; 529 558 if (firstNonZero < 0) … … 535 564 assert (lastNonZero  firstNonZero >= sosType_) ; 536 565 // find where to branch 537 assert (sum > 0.0); 538 weight /= sum; 566 if (!oddValues_) 567 weight /= sum; 568 else 569 weight = 0.5*(weights_[firstNonZero]+weights_[lastNonZero]); 539 570 int iWhere; 540 571 double separator = 0.0; … … 542 573 if (weight < weights_[iWhere+1]) 543 574 break; 575 assert (iWhere<lastNonZero); 544 576 if (sosType_ == 1) { 545 577 // SOS 1 … … 699 731 fix[j] = 0.0; 700 732 which[j] = iColumn; 701 if (upper[iColumn] ) {733 if (upper[iColumn]  oddValues_) { 702 734 double value = CoinMax(0.0, solution[iColumn]); 703 735 sum += value; … … 715 747 assert (lastNonZero  firstNonZero >= sosType_) ; 716 748 // find where to branch 717 assert (sum > 0.0); 718 weight /= sum; 749 if (!oddValues_) 750 weight /= sum; 751 else 752 weight = 0.5*(weights_[firstNonZero]+weights_[lastNonZero]); 719 753 // down branch fixes ones above weight to 0 720 754 int iWhere; … … 854 888 } 855 889 assert (i < numberMembers); 856 for (; i < numberMembers; i++) 890 for (; i < numberMembers; i++) { 891 solver>setColLower(which[i], 0.0); 857 892 solver>setColUpper(which[i], 0.0); 893 } 858 894 way_ = 1; // Swap direction 859 895 } else { 860 896 int i; 861 897 for ( i = 0; i < numberMembers; i++) { 862 if (weights[i] >= separator_) 898 if (weights[i] >= separator_) { 863 899 break; 864 else 900 } else { 901 solver>setColLower(which[i], 0.0); 865 902 solver>setColUpper(which[i], 0.0); 903 } 866 904 } 867 905 assert (i < numberMembers); … … 881 919 void 882 920 CbcSOSBranchingObject::fix(OsiSolverInterface * solver, 883 double * /*lower*/, double * upper,921 double * lower, double * upper, 884 922 int branchState) const 885 923 { … … 898 936 assert (i < numberMembers); 899 937 for (; i < numberMembers; i++) { 938 solver>setColLower(which[i], 0.0); 939 lower[which[i]] = 0.0; 900 940 solver>setColUpper(which[i], 0.0); 901 941 upper[which[i]] = 0.0; … … 907 947 break; 908 948 } else { 949 solver>setColLower(which[i], 0.0); 950 lower[which[i]] = 0.0; 909 951 solver>setColUpper(which[i], 0.0); 910 952 upper[which[i]] = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.