 Timestamp:
 Jan 22, 2019 4:42:21 AM (20 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcSOS.cpp
r2467 r2475 483 483 for (j = 0; j < firstNonZero; j++) { 484 484 int iColumn = members_[j]; 485 assert (lower[iColumn]<=0.0); 486 assert (upper[iColumn]>=0.0); 485 487 solver>setColLower(iColumn, 0.0); 486 488 solver>setColUpper(iColumn, 0.0); … … 488 490 for (j = lastNonZero + 1; j < numberMembers_; j++) { 489 491 int iColumn = members_[j]; 492 assert (lower[iColumn]<=0.0); 493 assert (upper[iColumn]>=0.0); 490 494 solver>setColLower(iColumn, 0.0); 491 495 solver>setColUpper(iColumn, 0.0); … … 534 538 const double *lower = solver>getColLower(); 535 539 const double *upper = solver>getColUpper(); 536 int firstNonFixed = 1;537 int lastNonFixed = 1;538 540 int firstNonZero = 1; 539 541 int lastNonZero = 1; … … 542 544 for (j = 0; j < numberMembers_; j++) { 543 545 int iColumn = members_[j]; 544 if (upper[iColumn]  oddValues_) { 545 double value = CoinMax(lower[iColumn], solution[iColumn]); 546 sum += value; 547 if (firstNonFixed < 0) 548 firstNonFixed = j; 549 lastNonFixed = j; 550 if (fabs(value) > integerTolerance) { 551 weight += weights_[j] * value; 552 if (firstNonZero < 0) 553 firstNonZero = j; 554 lastNonZero = j; 555 } 556 } 557 } 558 assert(lastNonZero  firstNonZero >= sosType_); 546 double value = CoinMax(lower[iColumn], solution[iColumn]); 547 value = CoinMin(upper[iColumn], value); 548 sum += value; 549 if (fabs(value) > integerTolerance) { 550 weight += weights_[j] * value; 551 if (firstNonZero < 0) 552 firstNonZero = j; 553 lastNonZero = j; 554 } 555 } 556 assert (lastNonZero  firstNonZero >= sosType_) ; 559 557 // find where to branch 560 558 if (!oddValues_) 561 559 weight /= sum; 562 560 else 563 weight = 0.5 * (weights_[firstNonZero] +weights_[lastNonZero]);561 weight = 0.5*(weights_[firstNonZero]+weights_[lastNonZero]); 564 562 int iWhere; 565 563 double separator = 0.0; 566 564 for (iWhere = firstNonZero; iWhere < lastNonZero; iWhere++) 567 if (weight < weights_[iWhere +1])565 if (weight < weights_[iWhere+1]) 568 566 break; 569 // If we are dealing with really oddly scaled problems 567 // If we are dealing with really oddly scaled problems 570 568 // was assert (iWhere<lastNonZero); 571 if (iWhere ==lastNonZero)569 if (iWhere==lastNonZero) 572 570 iWhere; 573 571 if (sosType_ == 1) { 574 572 // SOS 1 575 separator = 0.5 * (weights_[iWhere] + weights_[iWhere +1]);573 separator = 0.5 * (weights_[iWhere] + weights_[iWhere+1]); 576 574 } else { 577 575 // SOS 2 578 if (iWhere == firstNonFixed) 579 iWhere++; 580 ; 581 if (iWhere == lastNonFixed  1) 582 iWhere = lastNonFixed  2; 583 separator = weights_[iWhere + 1]; 584 } 576 if (iWhere == firstNonZero) 577 iWhere++;; 578 if (iWhere == lastNonZero  1) 579 iWhere = lastNonZero  2; 580 separator = weights_[iWhere+1]; 581 } 582 #ifndef NDEBUG 583 double sum1 = 0.0; 584 double sum2 = 0.0; 585 bool firstLot=true; 586 for (j = 0; j < numberMembers_; j++) { 587 int iColumn = members_[j]; 588 double value = CoinMax(lower[iColumn], solution[iColumn]); 589 value = CoinMin(upper[iColumn], value); 590 if (fabs(value) < integerTolerance) 591 value=0.0; 592 if (firstLot) { 593 if (sosType_ == 1 && weights_[j]>separator) { 594 firstLot=false; 595 } else if (sosType_ == 2 && weights_[j]==separator) { 596 firstLot=false; 597 value = 0.0; // dont count 598 } 599 } 600 if (firstLot) 601 sum1 += value; 602 else 603 sum2 += value; 604 } 605 assert (sum1!=0.0 && sum2!=0.0 ); 606 #endif 585 607 // create object 586 608 CbcBranchingObject *branch; … … 719 741 #endif 720 742 OsiSolverInterface *solver = model_>solver(); 721 const double *upper = solver>getColUpper(); 722 int firstNonFixed = 1; 723 int lastNonFixed = 1; 743 const double * lower = solver>getColLower(); 744 const double * upper = solver>getColUpper(); 724 745 int firstNonZero = 1; 725 746 int lastNonZero = 1; 726 747 double weight = 0.0; 727 748 double sum = 0.0; 728 double * fix = new double[numberMembers_];729 int * which = new int[numberMembers_];749 double * fix = new double[numberMembers_]; 750 int * which = new int[numberMembers_]; 730 751 for (j = 0; j < numberMembers_; j++) { 731 752 int iColumn = members_[j]; … … 733 754 fix[j] = 0.0; 734 755 which[j] = iColumn; 735 if (upper[iColumn]  oddValues_) { 736 double value = CoinMax(0.0, solution[iColumn]); 737 sum += value; 738 if (firstNonFixed < 0) 739 firstNonFixed = j; 740 lastNonFixed = j; 741 if (value > integerTolerance) { 742 weight += weights_[j] * value; 743 if (firstNonZero < 0) 744 firstNonZero = j; 745 lastNonZero = j; 746 } 747 } 748 } 749 assert(lastNonZero  firstNonZero >= sosType_); 756 double value = CoinMax(lower[iColumn], solution[iColumn]); 757 value = CoinMin(upper[iColumn], value); 758 sum += value; 759 if (fabs(value) > integerTolerance) { 760 weight += weights_[j] * value; 761 if (firstNonZero < 0) 762 firstNonZero = j; 763 lastNonZero = j; 764 } 765 } 766 assert (lastNonZero  firstNonZero >= sosType_) ; 750 767 // find where to branch 751 768 if (!oddValues_) 752 769 weight /= sum; 753 770 else 754 weight = 0.5 * (weights_[firstNonZero] +weights_[lastNonZero]);771 weight = 0.5*(weights_[firstNonZero]+weights_[lastNonZero]); 755 772 // down branch fixes ones above weight to 0 756 773 int iWhere; … … 758 775 int iUpEnd = 0; 759 776 for (iWhere = firstNonZero; iWhere < lastNonZero; iWhere++) 760 if (weight < weights_[iWhere +1])777 if (weight < weights_[iWhere+1]) 761 778 break; 762 779 if (sosType_ == 1) { … … 766 783 } else { 767 784 // SOS 2 768 if (iWhere == firstNonFixed) 769 iWhere++; 770 ; 771 if (iWhere == lastNonFixed  1) 772 iWhere = lastNonFixed  2; 785 if (iWhere == firstNonZero) 786 iWhere++;; 787 if (iWhere == lastNonZero  1) 788 iWhere = lastNonZero  2; 773 789 iUpEnd = iWhere + 1; 774 790 iDownStart = iUpEnd + 1; … … 899 915 printf("%d (%g,%g) ", which[i], weights[i], solution[which[i]]); 900 916 #endif 901 solver>setColLower(which[i], 0.0);902 solver>setColUpper(which[i], 0.0);917 solver>setColLower(which[i], CoinMin(0.0,upper[which[i]])); 918 solver>setColUpper(which[i], CoinMax(0.0,lower[which[i]])); 903 919 } 904 920 way_ = 1; // Swap direction … … 912 928 printf("%d (%g,%g) ", which[i], weights[i], solution[which[i]]); 913 929 #endif 914 solver>setColLower(which[i], 0.0);915 solver>setColUpper(which[i], 0.0);930 solver>setColLower(which[i], CoinMin(0.0,upper[which[i]])); 931 solver>setColUpper(which[i], CoinMax(0.0,lower[which[i]])); 916 932 } 917 933 }
Note: See TracChangeset
for help on using the changeset viewer.