Changeset 2308
 Timestamp:
 Oct 26, 2016 7:34:38 AM (23 months ago)
 Location:
 trunk/Cbc/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcHeuristic.cpp
r2280 r2308 35 35 #include "CbcBranchActual.hpp" 36 36 #include "CbcCutGenerator.hpp" 37 #include "CoinMpsIO.hpp" 37 38 //============================================================================== 38 39 … … 744 745 } 745 746 #ifdef COIN_HAS_CLP 746 OsiClpSolverInterface * osiclp= dynamic_cast< OsiClpSolverInterface*> (solver);747 if ( osiclp && (osiclp>specialOptions()&65536) == 0) {747 OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver); 748 if (clpSolver && (clpSolver>specialOptions()&65536) == 0) { 748 749 // go faster stripes 749 if ( osiclp>getNumRows() < 300 && osiclp>getNumCols() < 500) {750 osiclp>setupForRepeatedUse(2, 0);750 if (clpSolver>getNumRows() < 300 && clpSolver>getNumCols() < 500) { 751 clpSolver>setupForRepeatedUse(2, 0); 751 752 } else { 752 osiclp>setupForRepeatedUse(0, 0);753 clpSolver>setupForRepeatedUse(0, 0); 753 754 } 754 755 // Turn this off if you get problems 755 756 // Used to be automatically set 756 osiclp>setSpecialOptions(osiclp>specialOptions()  (128 + 64  128));757 ClpSimplex * lpSolver = osiclp>getModelPtr();757 clpSolver>setSpecialOptions(clpSolver>specialOptions()  (128 + 64  128)); 758 ClpSimplex * lpSolver = clpSolver>getModelPtr(); 758 759 lpSolver>setSpecialOptions(lpSolver>specialOptions()  0x01000000); // say is Cbc (and in branch and bound) 759 760 lpSolver>setSpecialOptions(lpSolver>specialOptions()  … … 949 950 process.setApplicationData(const_cast<double *>(debugger>optimalSolution())); 950 951 } 952 } 953 #endif 954 #ifdef COIN_HAS_CLP 955 OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver); 956 // See if SOS 957 if (clpSolver&&clpSolver>numberSOS()) { 958 // SOS 959 int numberSOS = clpSolver>numberSOS(); 960 const CoinSet * setInfo = clpSolver>setInfo(); 961 int *sosStart = new int [numberSOS+1]; 962 char *sosType = new char [numberSOS]; 963 int i; 964 int nTotal = 0; 965 sosStart[0] = 0; 966 for ( i = 0; i < numberSOS; i++) { 967 int type = setInfo[i].setType(); 968 int n = setInfo[i].numberEntries(); 969 sosType[i] = static_cast<char>(type); 970 nTotal += n; 971 sosStart[i+1] = nTotal; 972 } 973 int * sosIndices = new int[nTotal]; 974 double * sosReference = new double [nTotal]; 975 for (i = 0; i < numberSOS; i++) { 976 int n = setInfo[i].numberEntries(); 977 const int * which = setInfo[i].which(); 978 const double * weights = setInfo[i].weights(); 979 int base = sosStart[i]; 980 for (int j = 0; j < n; j++) { 981 int k = which[j]; 982 sosIndices[j+base] = k; 983 sosReference[j+base] = weights ? weights[j] : static_cast<double> (j); 984 } 985 } 986 int numberColumns = solver>getNumCols(); 987 char * prohibited = new char[numberColumns]; 988 memset(prohibited, 0, numberColumns); 989 int n = sosStart[numberSOS]; 990 for (int i = 0; i < n; i++) { 991 int iColumn = sosIndices[i]; 992 prohibited[iColumn] = 1; 993 } 994 delete [] sosIndices; 995 delete [] sosReference; 996 delete [] sosStart; 997 delete [] sosType; 998 process.passInProhibited(prohibited, numberColumns); 999 delete [] prohibited; 951 1000 } 952 1001 #endif … … 1439 1488 #endif 1440 1489 //if (fractionSmall_ < 1000000.0) 1441 1490 process.postProcess(*model.solver()); 1442 1491 if (solver>isProvenOptimal() && solver>getObjValue()*solver>getObjSense() < cutoff) { 1443 1492 // Solution now back in solver … … 1446 1495 numberColumns*sizeof(double)); 1447 1496 newSolutionValue = model.getMinimizationObjValue(); 1497 #ifdef COIN_HAS_CLP 1498 if (clpSolver) { 1499 if (clpSolver && clpSolver>numberSOS()) { 1500 // SOS 1501 int numberSOS = clpSolver>numberSOS(); 1502 const CoinSet * setInfo = clpSolver>setInfo(); 1503 int i; 1504 for ( i = 0; i < numberSOS; i++) { 1505 int type = setInfo[i].setType(); 1506 int n = setInfo[i].numberEntries(); 1507 const int * which = setInfo[i].which(); 1508 int first = 1; 1509 int last = 1; 1510 for (int j = 0; j < n; j++) { 1511 int iColumn = which[j]; 1512 if (fabs(newSolution[iColumn]) > 1.0e7) { 1513 last = j; 1514 if (first < 0) 1515 first = j; 1516 } 1517 } 1518 assert (last  first < type); 1519 for (int j = 0; j < n; j++) { 1520 if (j < first  j > last) { 1521 int iColumn = which[j]; 1522 // do I want to fix?? 1523 solver>setColLower(iColumn, 0.0); 1524 solver>setColUpper(iColumn, 0.0); 1525 newSolution[iColumn]=0.0; 1526 } 1527 } 1528 } 1529 } 1530 } 1531 #endif 1448 1532 } else { 1449 1533 // odd  but no good … … 3212 3296 probabilities_[numberHeuristics_1] = 1.000001; 3213 3297 } 3214 
trunk/Cbc/src/CbcSolver.cpp
r2290 r2308 6573 6573 babModel_>addCutGenerator(&storedAmpl, 1, "Stored"); 6574 6574 } 6575 #endif 6576 #ifdef SOS_AS_CUTS 6577 #ifdef COIN_HAS_CLP 6578 /* SOS as cuts 6579 Could be a bit more sophisticated e.g. only non duplicates 6580 Could do something for SOS 2? 6581 */ 6582 { 6583 OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (babModel_>solver()); 6584 if (clpSolver && clpSolver>numberSOS()) { 6585 // SOS 6586 int numberSOS = clpSolver>numberSOS(); 6587 const CoinSet * setInfo = clpSolver>setInfo(); 6588 CglStored sosCuts; 6589 const double * lower = clpSolver>getColLower(); 6590 const double * upper = clpSolver>getColUpper(); 6591 // Start Cliques 6592 // sizes 6593 int nEls=0; 6594 for (int i = 0; i < numberSOS; i++) 6595 nEls += setInfo[i].numberEntries(); 6596 double * els = new double[nEls+2*numberSOS]; 6597 for (int i=0;i<nEls;i++) 6598 els[i]=1.0; 6599 double * lo = els+nEls; 6600 double * up = lo+numberSOS; 6601 // need to get rid of sos 6602 ClpSimplex * fakeSimplex = 6603 new ClpSimplex(*clpSolver>getModelPtr()); 6604 #if 0 6605 int numberRows=fakeSimplex>numberRows(); 6606 int * starts = 6607 new int[CoinMax(numberSOS+1,numberRows)]; 6608 int * columns = new int[nEls]; 6609 for (int i=0;i<numberRows;i++) 6610 starts[i]=i; 6611 fakeSimplex>deleteRows(numberRows,starts); 6612 #else 6613 int * starts = 6614 new int[numberSOS+1]; 6615 int * columns = new int[nEls]; 6616 #endif 6617 int nAdded=0; 6618 starts[0]=0; 6619 nEls=0; 6620 6621 // just SOS 1 with 01 6622 for (int i = 0; i < numberSOS; i++) { 6623 int type = setInfo[i].setType(); 6624 if (type==2) 6625 continue; 6626 int n = setInfo[i].numberEntries(); 6627 const int * which = setInfo[i].which(); 6628 for (int j=0;j<n;j++) { 6629 int iColumn=which[j]; 6630 if (lower[iColumn]upper[iColumn]!=1.0) { 6631 n=1; 6632 break; // no good 6633 } 6634 } 6635 if (n>0) { 6636 memcpy(columns+nEls,which,n*sizeof(int)); 6637 lo[nAdded]=COIN_DBL_MAX; 6638 up[nAdded]=1.0; 6639 nAdded++; 6640 nEls += n; 6641 starts[nAdded]=nEls; 6642 } 6643 } 6644 if (nAdded) 6645 fakeSimplex>addRows(nAdded, 6646 lo,up, 6647 starts,columns,els); 6648 if (nAdded) { 6649 OsiClpSolverInterface fakeSolver(fakeSimplex); 6650 CglFakeClique fakeGen(&fakeSolver,false); 6651 fakeGen.setStarCliqueReport(false); 6652 fakeGen.setRowCliqueReport(false); 6653 fakeGen.setMinViolation(0.05); 6654 babModel_>addCutGenerator(&fakeGen, 1, "SosCuts"); 6655 //fakeSimplex>writeMps("bad.mps",0,1); 6656 //sosCuts.setProbingInfo(new 6657 // CglTreeProbingInfo(&fakeSolver)); 6658 } 6659 delete fakeSimplex; 6660 // End Cliques 6661 // Start Stored 6662 nAdded=0; 6663 for (int i = 0; i < numberSOS; i++) { 6664 int type = setInfo[i].setType(); 6665 int n = setInfo[i].numberEntries(); 6666 const int * which = setInfo[i].which(); 6667 double rhs=0.0; 6668 double previous=0.0; 6669 for (int j=0;j<n;j++) { 6670 int iColumn=which[j]; 6671 if (lower[iColumn]) { 6672 n=1; 6673 break; // no good 6674 } 6675 rhs=CoinMax(upper[iColumn]+previous,rhs); 6676 if (type==2) 6677 previous=upper[iColumn]; 6678 } 6679 if (n>0) { 6680 sosCuts.addCut(0.0,rhs, 6681 n, which,els); 6682 nAdded++; 6683 } 6684 } 6685 if (nAdded) 6686 babModel_>addCutGenerator(&sosCuts, 1, "SosCuts2"); 6687 // End Stored 6688 delete [] els; 6689 delete [] columns; 6690 delete [] starts; 6691 } 6692 } 6693 #endif 6575 6694 #endif 6576 6695 if (useSolution > 1) {
Note: See TracChangeset
for help on using the changeset viewer.