Changeset 367 for trunk/Cbc/src/CoinSolve.cpp
- Timestamp:
- Jun 12, 2006 4:14:36 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CoinSolve.cpp
r364 r367 491 491 double * solutionIn = NULL; 492 492 int * prioritiesIn = NULL; 493 int numberSOS = 0;494 int * sosStart = NULL;495 int * sosIndices = NULL;496 char * sosType = NULL;497 double * sosReference = NULL;498 int * sosPriority=NULL;499 493 #ifdef CBC_AMPL 500 494 ampl_info info; … … 1686 1680 double timeLeft = babModel->getMaximumSeconds(); 1687 1681 int numberOriginalColumns = babModel->solver()->getNumCols(); 1682 #ifdef CBC_AMPL 1683 if (usingAmpl&&info.numberSos&&doSOS) { 1684 // SOS 1685 assert (!preProcess); // do later 1686 int numberSOS = info.numberSos; 1687 int numberIntegers = babModel->numberIntegers(); 1688 int numberColumns = babModel->getNumCols(); 1689 /* model may not have created objects 1690 If none then create 1691 */ 1692 if (!numberIntegers||!babModel->numberObjects()) { 1693 int type = (pseudoUp) ? 1 : 0; 1694 babModel->findIntegers(true,type); 1695 numberIntegers = babModel->numberIntegers(); 1696 } 1697 // Do sets and priorities 1698 CbcObject ** objects = new CbcObject * [numberSOS]; 1699 const int * starts = info.sosStart; 1700 const int * which = info.sosIndices; 1701 const char * type = info.sosType; 1702 const double * weight = info.sosReference; 1703 // see if any priorities 1704 int i; 1705 bool gotPriorities=false; 1706 int * priorities=info.priorities; 1707 if (priorities) { 1708 for (i=0;i<numberColumns;i++) { 1709 if (priorities[i]) { 1710 gotPriorities=true; 1711 break; 1712 } 1713 } 1714 } 1715 priorities=info.sosPriority; 1716 if (priorities) { 1717 for (i=0;i<numberSOS;i++) { 1718 if (priorities[i]) { 1719 gotPriorities=true; 1720 break; 1721 } 1722 } 1723 } 1724 int iSOS; 1725 for (iSOS =0;iSOS<numberSOS;iSOS++) { 1726 int iStart = starts[iSOS]; 1727 int n=starts[iSOS+1]-iStart; 1728 objects[iSOS] = new CbcSOS(babModel,n,which+iStart,weight+iStart, 1729 iSOS,type[iSOS]); 1730 // higher for set 1731 objects[iSOS]->setPriority(10); 1732 if (gotPriorities&&info.sosPriority&&info.sosPriority[iSOS]) 1733 objects[iSOS]->setPriority(info.sosPriority[iSOS]); 1734 } 1735 babModel->addObjects(numberSOS,objects); 1736 for (iSOS=0;iSOS<numberSOS;iSOS++) 1737 delete objects[iSOS]; 1738 delete [] objects; 1739 } 1740 #endif 1688 1741 if (preProcess==6) { 1689 1742 // use strategy instead … … 1991 2044 solutionIn=info.primalSolution; 1992 2045 prioritiesIn = info.priorities; 1993 if (info.numberSos&&doSOS) {1994 // SOS1995 numberSOS = info.numberSos;1996 sosStart = info.sosStart;1997 sosIndices = info.sosIndices;1998 sosType = info.sosType;1999 sosReference = info.sosReference;2000 sosPriority = info.sosPriority;2001 }2002 2046 } 2003 2047 #endif … … 2090 2134 delete objects[iSOS]; 2091 2135 delete [] objects; 2092 } else if (priorities||branchDirection||pseudoDown||pseudoUp ||numberSOS) {2136 } else if (priorities||branchDirection||pseudoDown||pseudoUp) { 2093 2137 // do anyway for priorities etc 2094 2138 int numberIntegers = babModel->numberIntegers(); … … 2099 2143 int type = (pseudoUp) ? 1 : 0; 2100 2144 babModel->findIntegers(true,type); 2101 }2102 if (numberSOS) {2103 // Do sets and priorities2104 CbcObject ** objects = new CbcObject * [numberSOS];2105 int iSOS;2106 if (originalColumns) {2107 // redo sequence numbers2108 int numberColumns = babModel->getNumCols();2109 int nOld = originalColumns[numberColumns-1]+1;2110 int * back = new int[nOld];2111 int i;2112 for (i=0;i<nOld;i++)2113 back[i]=-1;2114 for (i=0;i<numberColumns;i++)2115 back[originalColumns[i]]=i;2116 // Really need better checks2117 int nMissing=0;2118 int n=sosStart[numberSOS];2119 for (i=0;i<n;i++) {2120 int iColumn = sosIndices[i];2121 int jColumn = back[iColumn];2122 if (jColumn>=0)2123 sosIndices[i] = jColumn;2124 else2125 nMissing++;2126 }2127 delete [] back;2128 if (nMissing)2129 printf("%d SOS variables vanished due to pre processing? - check validity?\n",nMissing);2130 }2131 for (iSOS =0;iSOS<numberSOS;iSOS++) {2132 int iStart = sosStart[iSOS];2133 int n=sosStart[iSOS+1]-iStart;2134 objects[iSOS] = new CbcSOS(babModel,n,sosIndices+iStart,sosReference+iStart,2135 iSOS,sosType[iSOS]);2136 if (sosPriority)2137 objects[iSOS]->setPriority(sosPriority[iSOS]);2138 else if (!prioritiesIn)2139 objects[iSOS]->setPriority(10); // rather than 10002140 }2141 babModel->addObjects(numberSOS,objects);2142 for (iSOS=0;iSOS<numberSOS;iSOS++)2143 delete objects[iSOS];2144 delete [] objects;2145 2145 } 2146 2146 CbcObject ** objects = babModel->objects(); … … 2190 2190 free(prioritiesIn); 2191 2191 prioritiesIn=NULL; 2192 free(sosStart);2193 sosStart=NULL;2194 free(sosIndices);2195 sosIndices=NULL;2196 free(sosType);2197 sosType=NULL;2198 free(sosReference);2199 sosReference=NULL;2200 free(sosPriority);2201 sosPriority=NULL;2202 2192 #ifdef CBC_AMPL 2203 2193 } … … 2398 2388 free(prioritiesIn); 2399 2389 prioritiesIn=NULL; 2400 free(sosStart);2401 sosStart=NULL;2402 free(sosIndices);2403 sosIndices=NULL;2404 free(sosType);2405 sosType=NULL;2406 free(sosReference);2407 sosReference=NULL;2408 free(sosPriority);2409 sosPriority=NULL;2410 2390 #ifdef CBC_AMPL 2411 2391 }
Note: See TracChangeset
for help on using the changeset viewer.