Changeset 391 for trunk/Cbc/src/CoinSolve.cpp
- Timestamp:
- Jun 29, 2006 10:44:34 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CoinSolve.cpp
r369 r391 492 492 double * solutionIn = NULL; 493 493 int * prioritiesIn = NULL; 494 int numberSOS = 0; 495 int * sosStart = NULL; 496 int * sosIndices = NULL; 497 char * sosType = NULL; 498 double * sosReference = NULL; 499 int * sosPriority=NULL; 494 500 #ifdef COIN_HAS_ASL 495 501 ampl_info info; … … 1681 1687 double timeLeft = babModel->getMaximumSeconds(); 1682 1688 int numberOriginalColumns = babModel->solver()->getNumCols(); 1683 #ifdef COIN_HAS_ASL1684 if (usingAmpl&&info.numberSos&&doSOS) {1685 // SOS1686 assert (!preProcess); // do later1687 int numberSOS = info.numberSos;1688 int numberIntegers = babModel->numberIntegers();1689 int numberColumns = babModel->getNumCols();1690 /* model may not have created objects1691 If none then create1692 */1693 if (!numberIntegers||!babModel->numberObjects()) {1694 int type = (pseudoUp) ? 1 : 0;1695 babModel->findIntegers(true,type);1696 numberIntegers = babModel->numberIntegers();1697 }1698 // Do sets and priorities1699 CbcObject ** objects = new CbcObject * [numberSOS];1700 const int * starts = info.sosStart;1701 const int * which = info.sosIndices;1702 const char * type = info.sosType;1703 const double * weight = info.sosReference;1704 // see if any priorities1705 int i;1706 bool gotPriorities=false;1707 int * priorities=info.priorities;1708 if (priorities) {1709 for (i=0;i<numberColumns;i++) {1710 if (priorities[i]) {1711 gotPriorities=true;1712 break;1713 }1714 }1715 }1716 priorities=info.sosPriority;1717 if (priorities) {1718 for (i=0;i<numberSOS;i++) {1719 if (priorities[i]) {1720 gotPriorities=true;1721 break;1722 }1723 }1724 }1725 int iSOS;1726 for (iSOS =0;iSOS<numberSOS;iSOS++) {1727 int iStart = starts[iSOS];1728 int n=starts[iSOS+1]-iStart;1729 objects[iSOS] = new CbcSOS(babModel,n,which+iStart,weight+iStart,1730 iSOS,type[iSOS]);1731 // higher for set1732 objects[iSOS]->setPriority(10);1733 if (gotPriorities&&info.sosPriority&&info.sosPriority[iSOS])1734 objects[iSOS]->setPriority(info.sosPriority[iSOS]);1735 }1736 babModel->addObjects(numberSOS,objects);1737 for (iSOS=0;iSOS<numberSOS;iSOS++)1738 delete objects[iSOS];1739 delete [] objects;1740 }1741 #endif1742 1689 if (preProcess==6) { 1743 1690 // use strategy instead … … 1765 1712 int translate[]={9999,0,0,-1,2,3}; 1766 1713 process.messageHandler()->setLogLevel(babModel->logLevel()); 1714 #ifdef COIN_HAS_ASL 1715 if (info.numberSos&&doSOS&&usingAmpl) { 1716 // SOS 1717 numberSOS = info.numberSos; 1718 sosStart = info.sosStart; 1719 sosIndices = info.sosIndices; 1720 } 1721 #endif 1722 if (numberSOS&&doSOS) { 1723 // SOS 1724 int numberColumns = saveSolver->getNumCols(); 1725 char * prohibited = new char[numberColumns]; 1726 memset(prohibited,0,numberColumns); 1727 int n=sosStart[numberSOS]; 1728 for (int i=0;i<n;i++) { 1729 int iColumn = sosIndices[i]; 1730 prohibited[iColumn]=1; 1731 } 1732 process.passInProhibited(prohibited,numberColumns); 1733 delete [] prohibited; 1734 } 1767 1735 solver2 = process.preProcessNonDefault(*saveSolver,translate[preProcess],10); 1768 1736 // Tell solver we are not in Branch and Cut … … 2045 2013 solutionIn=info.primalSolution; 2046 2014 prioritiesIn = info.priorities; 2015 if (info.numberSos&&doSOS) { 2016 // SOS 2017 numberSOS = info.numberSos; 2018 sosStart = info.sosStart; 2019 sosIndices = info.sosIndices; 2020 sosType = info.sosType; 2021 sosReference = info.sosReference; 2022 sosPriority = info.sosPriority; 2023 } 2047 2024 } 2048 2025 #endif … … 2135 2112 delete objects[iSOS]; 2136 2113 delete [] objects; 2137 } else if (priorities||branchDirection||pseudoDown||pseudoUp ) {2114 } else if (priorities||branchDirection||pseudoDown||pseudoUp||numberSOS) { 2138 2115 // do anyway for priorities etc 2139 2116 int numberIntegers = babModel->numberIntegers(); … … 2144 2121 int type = (pseudoUp) ? 1 : 0; 2145 2122 babModel->findIntegers(true,type); 2123 } 2124 if (numberSOS) { 2125 // Do sets and priorities 2126 CbcObject ** objects = new CbcObject * [numberSOS]; 2127 int iSOS; 2128 if (originalColumns) { 2129 // redo sequence numbers 2130 int numberColumns = babModel->getNumCols(); 2131 int nOld = originalColumns[numberColumns-1]+1; 2132 int * back = new int[nOld]; 2133 int i; 2134 for (i=0;i<nOld;i++) 2135 back[i]=-1; 2136 for (i=0;i<numberColumns;i++) 2137 back[originalColumns[i]]=i; 2138 // Really need better checks 2139 int nMissing=0; 2140 int n=sosStart[numberSOS]; 2141 for (i=0;i<n;i++) { 2142 int iColumn = sosIndices[i]; 2143 int jColumn = back[iColumn]; 2144 if (jColumn>=0) 2145 sosIndices[i] = jColumn; 2146 else 2147 nMissing++; 2148 } 2149 delete [] back; 2150 if (nMissing) 2151 printf("%d SOS variables vanished due to pre processing? - check validity?\n",nMissing); 2152 } 2153 for (iSOS =0;iSOS<numberSOS;iSOS++) { 2154 int iStart = sosStart[iSOS]; 2155 int n=sosStart[iSOS+1]-iStart; 2156 objects[iSOS] = new CbcSOS(babModel,n,sosIndices+iStart,sosReference+iStart, 2157 iSOS,sosType[iSOS]); 2158 if (sosPriority) 2159 objects[iSOS]->setPriority(sosPriority[iSOS]); 2160 else if (!prioritiesIn) 2161 objects[iSOS]->setPriority(10); // rather than 1000 2162 } 2163 babModel->addObjects(numberSOS,objects); 2164 for (iSOS=0;iSOS<numberSOS;iSOS++) 2165 delete objects[iSOS]; 2166 delete [] objects; 2146 2167 } 2147 2168 CbcObject ** objects = babModel->objects(); … … 2191 2212 free(prioritiesIn); 2192 2213 prioritiesIn=NULL; 2214 free(sosStart); 2215 sosStart=NULL; 2216 free(sosIndices); 2217 sosIndices=NULL; 2218 free(sosType); 2219 sosType=NULL; 2220 free(sosReference); 2221 sosReference=NULL; 2222 free(sosPriority); 2223 sosPriority=NULL; 2193 2224 #ifdef COIN_HAS_ASL 2194 2225 } … … 2362 2393 #endif 2363 2394 } else { 2364 std::cout<<"Model strengthen d - now has "<<clpSolver->getNumRows()2395 std::cout<<"Model strengthened - now has "<<clpSolver->getNumRows() 2365 2396 <<" rows"<<std::endl; 2366 2397 } … … 2389 2420 free(prioritiesIn); 2390 2421 prioritiesIn=NULL; 2422 free(sosStart); 2423 sosStart=NULL; 2424 free(sosIndices); 2425 sosIndices=NULL; 2426 free(sosType); 2427 sosType=NULL; 2428 free(sosReference); 2429 sosReference=NULL; 2430 free(sosPriority); 2431 sosPriority=NULL; 2391 2432 #ifdef COIN_HAS_ASL 2392 2433 }
Note: See TracChangeset
for help on using the changeset viewer.