Changeset 2280
- Timestamp:
- Jun 14, 2016 10:39:54 AM (5 years ago)
- Location:
- trunk/Cbc/src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cbc/src/CbcHeuristic.cpp
r2161 r2280 1251 1251 OsiSolverInterface * solver3 = solver2->clone(); 1252 1252 for (int i = 0; i < numberColumns; i++) { 1253 if ( solver3->isInteger(i)) {1253 if (isHeuristicInteger(solver3,i)) { 1254 1254 int k = which[i]; 1255 1255 double value = inputSolution_[k]; … … 1267 1267 OsiSolverInterface * solver4 = solver2->clone(); 1268 1268 for (int i = 0; i < numberColumns; i++) { 1269 if ( solver4->isInteger(i)) {1269 if (isHeuristicInteger(solver4,i)) { 1270 1270 int k = which[i]; 1271 1271 double value = floor(inputSolution_[k] + 0.5); … … 1283 1283 const double * solution = solver4->getColSolution(); 1284 1284 for (int i = 0; i < numberColumns; i++) { 1285 if ( solver4->isInteger(i)) {1285 if (isHeuristicInteger(solver4,i)) { 1286 1286 double value = floor(solution[i] + 0.5); 1287 1287 if (fabs(value - solution[i]) > 1.0e-6) … … 1494 1494 bool good = true; 1495 1495 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 1496 if ( solverC->isInteger(iColumn)) {1496 if (isHeuristicInteger(solverC,iColumn)) { 1497 1497 if (lower[iColumn] > lowerC[iColumn] && 1498 1498 upper[iColumn] < upperC[iColumn]) { … … 1509 1509 int n = 0; 1510 1510 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 1511 if ( solverC->isInteger(iColumn)) {1511 if (isHeuristicInteger(solverC,iColumn)) { 1512 1512 if (lower[iColumn] == upperC[iColumn]) { 1513 1513 rhs += lower[iColumn]; … … 2075 2075 2076 2076 double penalty = 0.0; 2077 const char * integerType = model_->integerType();2078 2077 // see if feasible - just using singletons 2079 2078 for (i = 0; i < numberRows; i++) { … … 2110 2109 double distance = absInfeasibility / absElement; 2111 2110 double thisCost = -direction * objective[iColumn] * distance; 2112 if (i ntegerType[iColumn]) {2111 if (isHeuristicInteger(solver,iColumn)) { 2113 2112 distance = ceil(distance - useTolerance); 2114 2113 if (currentValue - distance >= lowerValue - useTolerance) { … … 2135 2134 double distance = absInfeasibility / absElement; 2136 2135 double thisCost = direction * objective[iColumn] * distance; 2137 if (i ntegerType[iColumn]) {2136 if (isHeuristicInteger(solver,iColumn)) { 2138 2137 distance = ceil(distance - 1.0e-7); 2139 2138 assert (currentValue - distance <= upperValue + useTolerance); … … 2171 2170 int iColumn; 2172 2171 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 2173 if (i ntegerType[iColumn])2172 if (isHeuristicInteger(solver,iColumn)) 2174 2173 continue; 2175 2174 double currentValue = newSolution[iColumn]; … … 2320 2319 numberPasses++; 2321 2320 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 2322 bool isInteger = (integerType[iColumn] != 0);2321 bool isInteger = isHeuristicInteger(solver,iColumn); 2323 2322 double currentValue = newSolution[iColumn]; 2324 2323 double lowerValue = lower[iColumn]; … … 2652 2651 int nCandidate = 0; 2653 2652 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 2654 bool isInteger = (integerType[iColumn] != 0);2653 bool isInteger = isHeuristicInteger(solver,iColumn); 2655 2654 if (isInteger) { 2656 2655 double currentValue = newSolution[iColumn]; -
trunk/Cbc/src/CbcHeuristic.hpp
r2094 r2280 17 17 18 18 class CbcModel; 19 19 #ifdef COIN_HAS_CLP 20 #include "OsiClpSolverInterface.hpp" 21 #endif 20 22 //############################################################################# 21 23 … … 302 304 return numCouldRun_; 303 305 } 306 /// Is it integer for heuristics? 307 #ifdef COIN_HAS_CLP 308 inline bool isHeuristicInteger(const OsiSolverInterface * solver, int iColumn) const 309 { 310 const OsiClpSolverInterface * clpSolver 311 = dynamic_cast<const OsiClpSolverInterface *> (solver); 312 if (clpSolver) 313 return clpSolver->isHeuristicInteger(iColumn); 314 else 315 return solver->isInteger(iColumn); 316 } 317 #else 318 inline bool isHeuristicInteger(const OsiSolverInterface * solver, int iColumn) 319 { return solver->isInteger(iColumn);} 320 #endif 304 321 /*! \brief Clone, but ... 305 322 -
trunk/Cbc/src/CbcHeuristicDive.cpp
r2184 r2280 9 9 #endif 10 10 11 #include "CbcHeuristicDive.hpp"12 11 #include "CbcStrategy.hpp" 13 12 #include "CbcModel.hpp" … … 20 19 #include "OsiClpSolverInterface.hpp" 21 20 #endif 21 #include "CbcHeuristicDive.hpp" 22 22 23 23 //#define DIVE_FIX_BINARY_VARIABLES … … 389 389 random[i] = randomNumberGenerator_.randomDouble() + 0.3; 390 390 int iColumn = integerVariable[i]; 391 if (!isHeuristicInteger(solver,iColumn)) 392 continue; 391 393 back[iColumn]=i; 392 394 double value = newSolution[iColumn]; … … 433 435 for (int i = 0; i < numberIntegers; i++) { 434 436 int iColumn = integerVariable[i]; 437 if (!isHeuristicInteger(solver,iColumn)) 438 continue; 435 439 double value = newSolution[iColumn]; 436 440 if (fabs(floor(value + 0.5) - value) > integerTolerance) { … … 456 460 for (int i = 0; i < numberIntegers; i++) { 457 461 int iColumn = integerVariable[i]; 462 if (!isHeuristicInteger(solver,iColumn)) 463 continue; 458 464 double value = newSolution[iColumn]; 459 465 if (fabs(floor(value + 0.5) - value) > integerTolerance) { … … 476 482 for (i = 0; i < numberIntegers; i++) { 477 483 int iColumn = integerVariable[i]; 484 if (!isHeuristicInteger(solver,iColumn)) 485 continue; 478 486 double value = newSolution[bestColumn]; 479 487 if (fabs(floor(value + 0.5) - value) > integerTolerance) { … … 620 628 for (int i = 0; i < numberIntegers; i++) { 621 629 int iColumn = integerVariable[i]; 630 if (!isHeuristicInteger(solver,iColumn)) 631 continue; 622 632 if (upper[iColumn] > lower[iColumn]) { 623 633 numberFree++; … … 659 669 for (int i = 0; i < numberIntegers; i++) { 660 670 int iColumn = integerVariable[i]; 671 if (!isHeuristicInteger(solver,iColumn)) 672 continue; 661 673 if (upper[iColumn] > lower[iColumn]) { 662 674 if (priority_) { … … 787 799 for (int i = 0; i < numberIntegers; i++) { 788 800 int iColumn = integerVariable[i]; 801 if (!isHeuristicInteger(solver,iColumn)) 802 continue; 789 803 double value = newSolution[iColumn]; 790 804 double away = fabs(floor(value + 0.5) - value); … … 931 945 for (int i = 0; i < numberIntegers; i++) { 932 946 int iColumn = integerVariable[i]; 947 if (!isHeuristicInteger(solver,iColumn)) 948 continue; 933 949 double value = newSolution[iColumn]; 934 950 double away = fabs(floor(value + 0.5) - value); … … 1066 1082 for (int i = 0; i < numberIntegers; i++) { 1067 1083 int iColumn = integerVariable[i]; 1084 if (!isHeuristicInteger(solver,iColumn)) 1085 continue; 1068 1086 double value = newSolution[iColumn]; 1069 1087 if (fabs(floor(value + 0.5) - value) > integerTolerance) { … … 1279 1297 const int * row = matrix_.getIndices(); 1280 1298 const CoinBigIndex * columnStart = matrix_.getVectorStarts(); 1299 OsiSolverInterface * solver = model_->solver(); 1281 1300 const int * columnLength = matrix_.getVectorLengths(); 1282 const double * rowLower = model_->solver()->getRowLower();1283 const double * rowUpper = model_->solver()->getRowUpper();1301 const double * rowLower = solver->getRowLower(); 1302 const double * rowUpper = solver->getRowUpper(); 1284 1303 for (int i = 0; i < numberIntegers; i++) { 1285 1304 int iColumn = integerVariable[i]; 1305 if (!isHeuristicInteger(solver,iColumn)) 1306 continue; 1286 1307 int down = 0; 1287 1308 int up = 0; … … 1329 1350 const int numberRows = matrixByRow_.getNumRows(); 1330 1351 const int numberCols = matrixByRow_.getNumCols(); 1331 1332 const double * lower = model_->solver()->getColLower(); 1333 const double * upper = model_->solver()->getColUpper(); 1334 const double * rowLower = model_->solver()->getRowLower(); 1335 const double * rowUpper = model_->solver()->getRowUpper(); 1352 1353 OsiSolverInterface * solver = model_->solver(); 1354 const double * lower = solver->getColLower(); 1355 const double * upper = solver->getColUpper(); 1356 const double * rowLower = solver->getRowLower(); 1357 const double * rowUpper = solver->getRowUpper(); 1336 1358 1337 1359 // const char * integerType = model_->integerType(); … … 1340 1362 // const int numberIntegers = model_->numberIntegers(); 1341 1363 // const int * integerVariable = model_->integerVariable(); 1342 const double * objective = model_->solver()->getObjCoefficients();1364 const double * objective = solver->getObjCoefficients(); 1343 1365 1344 1366 // vector to store the row number of variable bound rows … … 1353 1375 for (int k = rowStart[i]; k < rowStart[i] + rowLength[i]; k++) { 1354 1376 int iColumn = column[k]; 1355 if ( model_->solver()->isInteger(iColumn) &&1377 if (isHeuristicInteger(solver,iColumn) && 1356 1378 lower[iColumn] == 0.0 && upper[iColumn] == 1.0 && 1357 1379 objective[iColumn] == 0.0 && … … 1359 1381 positiveBinary < 0) 1360 1382 positiveBinary = iColumn; 1361 else if ( model_->solver()->isInteger(iColumn) &&1383 else if (isHeuristicInteger(solver,iColumn) && 1362 1384 lower[iColumn] == 0.0 && upper[iColumn] == 1.0 && 1363 1385 objective[iColumn] == 0.0 && … … 1464 1486 for (int i = 0 ; i < numberIntegers ; i++) { 1465 1487 int iColumn = integerVariable[i] ; 1488 if (!isHeuristicInteger(solver,iColumn)) 1489 continue; 1466 1490 double djValue = direction * reducedCost[iColumn] ; 1467 1491 if (upper[iColumn] - lower[iColumn] > integerTolerance) { … … 1547 1571 for (int i = 0; i < numberIntegers; i++) { 1548 1572 int iColumn = integerVariable[i]; 1573 if (!isHeuristicInteger(solver,iColumn)) 1574 continue; 1549 1575 if (upper[iColumn] > lower[iColumn]) { 1550 1576 numberFree++; -
trunk/Cbc/src/CbcHeuristicDiveCoefficient.cpp
r2094 r2280 86 86 for (int i = 0; i < numberIntegers; i++) { 87 87 int iColumn = integerVariable[i]; 88 if (!isHeuristicInteger(solver,iColumn)) 89 continue; 88 90 double value = newSolution[iColumn]; 89 91 double fraction = value - floor(value); -
trunk/Cbc/src/CbcHeuristicDiveFractional.cpp
r2093 r2280 81 81 for (int i = 0; i < numberIntegers; i++) { 82 82 int iColumn = integerVariable[i]; 83 if (!isHeuristicInteger(solver,iColumn)) 84 continue; 83 85 double value = newSolution[iColumn]; 84 86 double fraction = value - floor(value); -
trunk/Cbc/src/CbcHeuristicDiveGuided.cpp
r2093 r2280 93 93 for (int i = 0; i < numberIntegers; i++) { 94 94 int iColumn = integerVariable[i]; 95 if (!isHeuristicInteger(solver,iColumn)) 96 continue; 95 97 double value = newSolution[iColumn]; 96 98 double fraction = value - floor(value); -
trunk/Cbc/src/CbcHeuristicDiveLineSearch.cpp
r2093 r2280 84 84 for (int i = 0; i < numberIntegers; i++) { 85 85 int iColumn = integerVariable[i]; 86 if (!isHeuristicInteger(solver,iColumn)) 87 continue; 86 88 double rootValue = rootNodeLPSol[iColumn]; 87 89 double value = newSolution[iColumn]; -
trunk/Cbc/src/CbcHeuristicDivePseudoCost.cpp
r2093 r2280 89 89 for (int i = 0; i < numberIntegers; i++) { 90 90 int iColumn = integerVariable[i]; 91 if (!isHeuristicInteger(solver,iColumn)) 92 continue; 91 93 double rootValue = rootNodeLPSol[iColumn]; 92 94 double value = newSolution[iColumn]; … … 218 220 for (int i = 0; i < numberIntegers; i++) { 219 221 int iColumn = integerVariable[i]; 222 if (!isHeuristicInteger(solver,iColumn)) 223 continue; 220 224 if (upper[iColumn] > lower[iColumn]) { 221 225 numberFree++; -
trunk/Cbc/src/CbcHeuristicDiveVectorLength.cpp
r2093 r2280 85 85 for (int i = 0; i < numberIntegers; i++) { 86 86 int iColumn = integerVariable[i]; 87 if (!isHeuristicInteger(solver,iColumn)) 88 continue; 87 89 double value = newSolution[iColumn]; 88 90 double fraction = value - floor(value); -
trunk/Cbc/src/CbcHeuristicFPump.cpp
r2146 r2280 216 216 // Returns 1 if solution, 0 if not 217 217 int 218 CbcHeuristicFPump::solution (double & solutionValue,218 CbcHeuristicFPump::solutionInternal(double & solutionValue, 219 219 double * betterSolution) 220 220 { … … 286 286 double cutoff; 287 287 model_->solver()->getDblParam(OsiDualObjectiveLimit, cutoff); 288 double realCutoff=cutoff; 289 bool secondMajorPass=false; 288 290 double direction = model_->solver()->getObjSense(); 289 291 cutoff *= direction; … … 336 338 assert(integerObject || integerObject2); 337 339 #endif 340 #ifdef COIN_HAS_CLP 341 if (!isHeuristicInteger(model_->solver(),iColumn)) 342 continue; 343 #endif 338 344 double value = initialSolution[iColumn]; 339 345 double nearest = floor(value + 0.5); … … 370 376 for (i = 0; i < numberIntegers; i++) { 371 377 int iColumn = integerVariableOrig[i]; 378 #ifdef COIN_HAS_CLP 379 if (!isHeuristicInteger(model_->solver(),iColumn)) 380 continue; 381 #endif 372 382 if (upper[iColumn] - lower[iColumn] < 1.000001) 373 383 integerVariable[j++] = iColumn; … … 476 486 double artificialFactor = 0.00001; 477 487 // also try rounding! 478 double * roundingSolution = new double[ numberColumns];479 double roundingObjective = solutionValue;488 double * roundingSolution = new double[2*numberColumns]; 489 double roundingObjective = realCutoff; 480 490 CbcRounding roundingHeuristic(*model_); 481 491 int dualPass = 0; … … 807 817 randomNumberGenerator_.setSeed(987654321); 808 818 } 819 #ifdef COIN_HAS_CLP 820 { 821 OsiClpSolverInterface * clpSolver 822 = dynamic_cast<OsiClpSolverInterface *> (clonedSolver); 823 //printf("real cutoff %g fake %g - second pass %c\n",realCutoff,cutoff, 824 // secondMajorPass ? 'Y' : 'N'); 825 if (clpSolver && (((accumulate_&16) != 0) || 826 ((accumulate_&8)!=0 && secondMajorPass))) { 827 // try rounding heuristic 828 OsiSolverInterface * saveSolver = model_->swapSolver(clonedSolver); 829 ClpSimplex * simplex = clpSolver->getModelPtr(); 830 double * solverSolution = simplex->primalColumnSolution(); 831 memcpy(solverSolution,solution,numberColumns*sizeof(double)); 832 // Compute using dot product 833 double newSolutionValue = -saveOffset; 834 for ( i = 0 ; i < numberColumns ; i++ ) 835 newSolutionValue += saveObjective[i] * solution[i]; 836 simplex->setObjectiveValue(newSolutionValue); 837 clpSolver->setObjective(saveObjective); 838 CbcRounding heuristic1(*model_); 839 heuristic1.setHeuristicName("rounding in feaspump!"); 840 heuristic1.setWhen(1); 841 newSolutionValue=realCutoff; 842 int ifSolR = heuristic1.solution(newSolutionValue, 843 roundingSolution+numberColumns); 844 model_->swapSolver(saveSolver); 845 if (ifSolR&&newSolutionValue<roundingObjective) { 846 roundingObjective=newSolutionValue; 847 //printf("rounding obj of %g?\n", roundingObjective); 848 memcpy(roundingSolution,roundingSolution+numberColumns, 849 numberColumns*sizeof(double)); 850 } 851 } 852 } 853 #endif 809 854 returnCode = rounds(solver, newSolution,/*saveObjective,*/ 810 855 numberIntegers, integerVariable, … … 817 862 } 818 863 numberPasses++; 864 if (roundingObjective<realCutoff) { 865 if (returnCode) { 866 newSolutionValue = -saveOffset; 867 for ( i = 0 ; i < numberColumns ; i++ ) 868 newSolutionValue += saveObjective[i] * newSolution[i]; 869 } else { 870 newSolutionValue = COIN_DBL_MAX; 871 } 872 if (roundingObjective<newSolutionValue&&false) { 873 returnCode=1; 874 memcpy(newSolution,roundingSolution, 875 numberColumns*sizeof(double)); 876 } 877 } 819 878 if (returnCode) { 820 879 // SOLUTION IS INTEGER … … 841 900 for (i = 0; i < numberIntegersOrig; i++) { 842 901 int iColumn = integerVariableOrig[i]; 902 #ifdef COIN_HAS_CLP 903 if (!isHeuristicInteger(solver,iColumn)) 904 continue; 905 #endif 843 906 double value = floor(newSolution[iColumn] + 0.5); 844 907 if (solver->isBinary(iColumn)) { … … 932 995 } 933 996 newSolutionValue += objective[iColumn] * newSolution[iColumn]; 934 if ( solver->isInteger(iColumn)) {997 if (isHeuristicInteger(solver,iColumn)) { 935 998 double intValue = floor(value+0.5); 936 999 if (fabs(value-intValue)>largestAway) { … … 993 1056 model_->setBestSolution(saveOldSolution, numberColumns, saveObjectiveValue); 994 1057 delete [] saveOldSolution; 1058 realCutoff = model_->getMinimizationObjValue(); 995 1059 } 996 1060 if (action == 0 || model_->maximumSecondsReached()) { … … 1156 1220 continue; 1157 1221 // deal with fixed variables (i.e., upper=lower) 1158 if (fabs(lower[iColumn] - upper[iColumn]) < primalTolerance || ! solver->isInteger(iColumn)) {1222 if (fabs(lower[iColumn] - upper[iColumn]) < primalTolerance || !isHeuristicInteger(solver,iColumn)) { 1159 1223 //if (lower[iColumn] > 1. - primalTolerance) solver->setObjCoeff(iColumn,-costValue); 1160 1224 //else solver->setObjCoeff(iColumn,costValue); … … 1318 1382 for (i = 0; i < numberIntegersOrig; i++) { 1319 1383 int iColumn = integerVariableOrig[i]; 1384 #ifdef COIN_HAS_CLP 1385 if (!isHeuristicInteger(solver,iColumn)) 1386 continue; 1387 #endif 1320 1388 #ifdef RAND_RAND 1321 1389 if (nChanged > numberChanged) … … 1341 1409 for (i = 0; i < numberIntegersOrig; i++) { 1342 1410 int iColumn = integerVariableOrig[i]; 1411 #ifdef COIN_HAS_CLP 1412 if (!isHeuristicInteger(solver,iColumn)) 1413 continue; 1414 #endif 1343 1415 if (objective[iColumn] > 0.0) { 1344 1416 if (basis->getStructStatus(iColumn) == … … 1395 1467 const double * newSolution = solver->getColSolution(); 1396 1468 for (int iColumn = 0 ; iColumn < numberColumns ; iColumn++ ) { 1397 if ( solver->isInteger(iColumn)) {1469 if (isHeuristicInteger(solver,iColumn)) { 1398 1470 double value = newSolution[iColumn]; 1399 1471 double nearest = floor(value + 0.5); … … 1459 1531 for ( i = 0 ; i < numberColumns ; i++ ) { 1460 1532 double value = newSolution[i]; 1461 if ( solver->isInteger(i)) {1533 if (isHeuristicInteger(solver,i)) { 1462 1534 double nearest = floor(value + 0.5); 1463 1535 if (fabs(value - nearest) > 1.0e-6) { … … 1672 1744 const double * newSolution = solver->getColSolution(); 1673 1745 for ( i = 0 ; i < numberColumns ; i++ ) { 1674 if ( solver->isInteger(i)) {1746 if (isHeuristicInteger(solver,i)) { 1675 1747 double value = newSolution[i]; 1676 1748 double nearest = floor(value + 0.5); … … 1740 1812 for (i = 0; i < numberIntegersOrig; i++) { 1741 1813 int iColumn = integerVariableOrig[i]; 1814 #ifdef COIN_HAS_CLP 1815 if (!isHeuristicInteger(solver,iColumn)) 1816 continue; 1817 #endif 1742 1818 if (objective[iColumn] > 0.0) 1743 1819 closestSolution[i] = 0; … … 1857 1933 solutionValue = roundingObjective; 1858 1934 newSolutionValue = solutionValue; 1935 realCutoff=solutionValue-1.0e-5; 1859 1936 memcpy(betterSolution, roundingSolution, numberColumns*sizeof(double)); 1860 1937 solutionFound = true; … … 1903 1980 for (i = 0; i < numberIntegersOrig; i++) { 1904 1981 int iColumn = integerVariableOrig[i]; 1982 #ifdef COIN_HAS_CLP 1983 if (!isHeuristicInteger(newSolver,iColumn)) 1984 continue; 1985 #endif 1905 1986 //const OsiObject * object = model_->object(i); 1906 1987 //double originalLower; … … 1934 2015 if (fixContinuous) { 1935 2016 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 1936 if (! newSolver->isInteger(iColumn) && usedColumn[iColumn] <= allowedPass) {2017 if (!isHeuristicInteger(newSolver,iColumn) && usedColumn[iColumn] <= allowedPass) { 1937 2018 double value = lastSolution[iColumn]; 1938 2019 if (value < colLower[iColumn] + 1.0e-8) { … … 2042 2123 const double * obj = newSolver->getObjCoefficients(); 2043 2124 for (int i = 0 ; i < numberColumns ; i++ ) { 2044 if ( newSolver->isInteger(i)) {2125 if (isHeuristicInteger(newSolver,i)) { 2045 2126 double value = newSolution[i]; 2046 2127 double nearest = floor(value + 0.5); … … 2067 2148 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 2068 2149 double value = newSolution[iColumn]; 2069 if ( newSolver->isInteger(iColumn)) {2150 if (isHeuristicInteger(newSolver,iColumn)) { 2070 2151 value = floor(newSolution[iColumn] + 0.5); 2071 2152 newSolver->setColLower(iColumn, value); … … 2150 2231 const double * solution = newSolver->getColSolution(); 2151 2232 for (int i = 0 ; i < numberColumns ; i++ ) { 2152 if ( newSolver->isInteger(i)) {2233 if (isHeuristicInteger(newSolver,i)) { 2153 2234 double value = solution[i]; 2154 2235 double nearest = floor(value + 0.5); … … 2192 2273 const double * upper = model_->solver()->getColUpper(); 2193 2274 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 2194 if ( newSolver->isInteger(iColumn)) {2275 if (isHeuristicInteger(newSolver,iColumn)) { 2195 2276 double value = floor(newSolution[iColumn] + 0.5); 2196 2277 newSolver->setColLower(iColumn, value); … … 2253 2334 if (solutionFound) finalReturnCode = 1; 2254 2335 cutoff = CoinMin(cutoff, solutionValue - model_->getCutoffIncrement()); 2336 realCutoff = cutoff; 2255 2337 if (numberTries >= maximumRetries_ || !solutionFound || exitAll || cutoff < continuousObjectiveValue + 1.0e-7) { 2256 2338 break; … … 2272 2354 break; 2273 2355 sprintf(pumpPrint, "Round again with cutoff of %g", cutoff); 2356 secondMajorPass=true; 2274 2357 model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) 2275 2358 << pumpPrint … … 2301 2384 for (i = 0; i < numberIntegersOrig; i++) { 2302 2385 int iColumn = integerVariableOrig[i]; 2386 #ifdef COIN_HAS_CLP 2387 if (!isHeuristicInteger(newSolver,iColumn)) 2388 continue; 2389 #endif 2303 2390 int direction = closestSolution[i]; 2304 2391 closestSolution[i] = iColumn; … … 2383 2470 2384 2471 /**************************END MAIN PROCEDURE ***********************************/ 2472 /* If general integers then adds variables to turn into binaries round 2473 solution 2474 */ 2475 int 2476 CbcHeuristicFPump::solution(double & objectiveValue, double * newSolution) 2477 { 2478 double * newSolution2=NULL; 2479 double objective2=COIN_DBL_MAX; 2480 int returnCode2=0; 2481 int oddGeneral = (accumulate_&(32|64|128))>>5; 2482 if (oddGeneral) { 2483 int maxAround=2; 2484 bool fixSatisfied=false; 2485 // clone solver and modify 2486 OsiSolverInterface * solver = cloneBut(2); // wasmodel_->solver()->clone(); 2487 double cutoff; 2488 model_->solver()->getDblParam(OsiDualObjectiveLimit, cutoff); 2489 int numberColumns = model_->getNumCols(); 2490 int numberIntegers = model_->numberIntegers(); 2491 const int * integerVariableOrig = model_->integerVariable(); 2492 int general = 0; 2493 int nAdd=0; 2494 const double * lower = solver->getColLower(); 2495 const double * upper = solver->getColUpper(); 2496 const double * initialSolution = solver->getColSolution(); 2497 // we may be being clever so make sure solver lines up wuth model 2498 for (int i = 0; i < numberColumns; i++) 2499 solver->setContinuous(i); 2500 for (int i = 0; i < numberIntegers; i++) { 2501 int iColumn = integerVariableOrig[i]; 2502 #ifdef COIN_HAS_CLP 2503 if (!isHeuristicInteger(solver,iColumn)) 2504 continue; 2505 #endif 2506 double value = initialSolution[iColumn]; 2507 double nearest = floor(value + 0.5); 2508 if (upper[iColumn] - lower[iColumn] > 1.000001) { 2509 if (fabs(value-nearest)<1.0e-6&&fixSatisfied) { 2510 solver->setColLower(iColumn,nearest); 2511 solver->setColUpper(iColumn,nearest); 2512 } else { 2513 general++; 2514 int up=static_cast<int>(upper[iColumn]); 2515 int lo=static_cast<int>(lower[iColumn]); 2516 int near=static_cast<int>(nearest); 2517 up = CoinMin(up,near+maxAround); 2518 lo = CoinMax(lo,near-maxAround); 2519 solver->setColLower(iColumn,lo); 2520 solver->setColUpper(iColumn,up); 2521 int n=up-lo; 2522 // 1 - 1, 2,3 - 2, 4567 - 3 2523 while (n) { 2524 nAdd++; 2525 n = n>>1; 2526 } 2527 } 2528 } else { 2529 solver->setInteger(iColumn); 2530 } 2531 } 2532 if (!general) { 2533 delete solver; 2534 } 2535 if (general) { 2536 CbcModel * saveModel = model_; 2537 int * addStart = new int[nAdd+1]; 2538 memset(addStart,0,(nAdd+1)*sizeof(int)); 2539 int * addIndex = new int[general+nAdd]; 2540 double * addElement = new double[general+nAdd]; 2541 double * addLower = new double[nAdd]; 2542 double * addUpper = new double[nAdd]; 2543 for (int i=0;i<nAdd;i++) { 2544 addLower[i]=0.0; 2545 addUpper[i]=1.0; 2546 } 2547 solver->addCols(nAdd, addStart, NULL, NULL, addLower, addUpper, NULL); 2548 lower = solver->getColLower(); 2549 upper = solver->getColUpper(); 2550 // now rows 2551 nAdd = 0; 2552 int nEl = 0; 2553 int nAddRow = 0; 2554 for (int i = 0; i < numberIntegers; i++) { 2555 int iColumn = integerVariableOrig[i]; 2556 #ifdef COIN_HAS_CLP 2557 if (!isHeuristicInteger(solver,iColumn)) 2558 continue; 2559 #endif 2560 if (upper[iColumn] - lower[iColumn] > 1.000001) { 2561 int up=static_cast<int>(upper[iColumn]); 2562 int lo=static_cast<int>(lower[iColumn]); 2563 addLower[nAddRow] = lo; 2564 addUpper[nAddRow] = lo; 2565 addIndex[nEl] = iColumn; 2566 addElement[nEl++] = 1.0; 2567 int n=up-lo; 2568 // 1 - 1, 2,3 - 2, 4567 - 3 2569 int el=1; 2570 while (n) { 2571 addIndex[nEl] = numberColumns+nAdd; 2572 addElement[nEl++] = -el; 2573 nAdd++; 2574 n = n>>1; 2575 el = el<<1; 2576 } 2577 nAddRow++; 2578 addStart[nAddRow]=nEl; 2579 } 2580 } 2581 for (int i=0;i<nAdd;i++) 2582 solver->setInteger(i+numberColumns); 2583 solver->addRows(nAddRow, addStart, addIndex, addElement, addLower, addUpper); 2584 delete [] addStart; 2585 delete [] addIndex; 2586 delete [] addElement; 2587 delete [] addLower; 2588 delete [] addUpper; 2589 solver->resolve(); 2590 solver->writeMps("test"); 2591 // new CbcModel 2592 model_=new CbcModel(*solver); 2593 model_->findIntegers(true); 2594 // set cutoff 2595 solver->setDblParam(OsiDualObjectiveLimit, cutoff); 2596 model_->setCutoff(cutoff); 2597 newSolution2 = new double [numberColumns+nAdd]; 2598 objective2=objectiveValue; 2599 returnCode2=solutionInternal(objective2,newSolution2); 2600 delete solver; 2601 delete model_; 2602 model_=saveModel; 2603 } 2604 } 2605 int returnCode=solutionInternal(objectiveValue,newSolution); 2606 if (returnCode2&&false) { 2607 int numberColumns=model_->getNumCols(); 2608 memcpy(newSolution,newSolution2,numberColumns*sizeof(double)); 2609 } 2610 delete [] newSolution2; 2611 return returnCode; 2612 } 2385 2613 2386 2614 // update model … … 2433 2661 for (CoinBigIndex k = rowStart[i]; k < rowStart[i] + rowLength[i]; k++) { 2434 2662 int iColumn = column[k]; 2435 if (elementByRow[k] != 1.0 || ! solver->isInteger(iColumn)) {2663 if (elementByRow[k] != 1.0 || !isHeuristicInteger(solver,iColumn)) { 2436 2664 cover = false; 2437 2665 break; … … 2479 2707 for (CoinBigIndex k = rowStart[i]; k < rowStart[i] + rowLength[i]; k++) { 2480 2708 int iColumn = column[k]; 2481 if (elementByRow[k] != 1.0 || ! solver->isInteger(iColumn)) {2709 if (elementByRow[k] != 1.0 || !isHeuristicInteger(solver,iColumn)) { 2482 2710 cover = false; 2483 2711 break; … … 2700 2928 // First improve by moving continuous ones 2701 2929 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 2702 if (! solver->isInteger(iColumn)) {2930 if (!isHeuristicInteger(solver,iColumn)) { 2703 2931 double solValue = solution[iColumn]; 2704 2932 double thetaUp = columnUpper[iColumn] - solValue; -
trunk/Cbc/src/CbcHeuristicFPump.hpp
r1573 r2280 65 65 virtual int solution(double & objectiveValue, 66 66 double * newSolution); 67 67 /** If general integers then adds variables to turn into binaries round 68 solution 69 */ 70 int solutionGeneral(double & objectiveValue, double * newSolution, 71 int maxAround=1,bool fixSatisfied=false); 68 72 /// Set maximum Time (default off) - also sets starttime to current 69 73 void setMaximumTime(double value); … … 249 253 reuse - refers to initial solve after adding in new "cut" 250 254 If we add 8 then can run after initial cuts (if no solution) 255 16 - extra rounding 256 32,64,128 - create binaries for general 251 257 */ 252 258 int accumulate_; … … 271 277 /*bool roundExpensive=false,*/ 272 278 double downValue = 0.5, int *flip = 0); 279 /// Does real work 280 int solutionInternal(double & objectiveValue, double * newSolution); 273 281 /* note for eagle eyed readers. 274 282 when_ can now be exotic - -
trunk/Cbc/src/CbcHeuristicGreedy.cpp
r2216 r2280 172 172 CoinBigIndex j; 173 173 double value = solution[iColumn]; 174 if ( solver->isInteger(iColumn)) {174 if (isHeuristicInteger(solver,iColumn)) { 175 175 // Round down integer 176 176 if (fabs(floor(value + 0.5) - value) < integerTolerance) { … … 201 201 CoinBigIndex j; 202 202 double value = solution[iColumn]; 203 if ( solver->isInteger(iColumn)) {203 if (isHeuristicInteger(solver,iColumn)) { 204 204 // but round up if no activity 205 205 if (roundup && value >= 0.499999 && !newSolution[iColumn]) { … … 246 246 double value = newSolution[iColumn]; 247 247 double cost = direction * objective[iColumn]; 248 if ( solver->isInteger(iColumn)) {248 if (isHeuristicInteger(solver,iColumn)) { 249 249 // use current upper or original upper 250 250 if (value + 0.99 < originalUpper[iColumn]) { … … 593 593 CoinBigIndex j; 594 594 double value = solution[iColumn]; 595 if ( solver->isInteger(iColumn)) {595 if (isHeuristicInteger(solver,iColumn)) { 596 596 // Round down integer 597 597 if (fabs(floor(value + 0.5) - value) < integerTolerance) { … … 623 623 CoinBigIndex j; 624 624 double value = solution[iColumn]; 625 if ( solver->isInteger(iColumn)) {625 if (isHeuristicInteger(solver,iColumn)) { 626 626 // but round up if no activity 627 627 if (roundup && value >= 0.6 && !newSolution[iColumn]) { … … 669 669 double value = newSolution[iColumn]; 670 670 double cost = direction * objective[iColumn]; 671 if ( solver->isInteger(iColumn)) {671 if (isHeuristicInteger(solver,iColumn)) { 672 672 // use current upper or original upper 673 673 if (value + 0.9999 < originalUpper[iColumn]) { … … 750 750 OsiSolverInterface * newSolver = model_->continuousSolver()->clone(); 751 751 for (iColumn = 0; iColumn < numberColumns; iColumn++) { 752 if ( newSolver->isInteger(iColumn))752 if (isHeuristicInteger(newSolver,iColumn)) 753 753 newSolver->setColLower(iColumn, newSolution[iColumn]); 754 754 } … … 1036 1036 int nSOS=0; 1037 1037 int iSOS=-1; 1038 if (! solver->isInteger(iColumn))1038 if (!isHeuristicInteger(solver,iColumn)) 1039 1039 good = false; 1040 1040 for (j = columnStart[iColumn]; … … 1862 1862 CoinBigIndex j; 1863 1863 int nSOS=0; 1864 if (! solver->isInteger(iColumn))1864 if (!isHeuristicInteger(solver,iColumn)) 1865 1865 good = false; 1866 1866 for (j = columnStart[iColumn]; -
trunk/Cbc/src/CbcHeuristicLocal.cpp
r2105 r2280 182 182 for (i = 0; i < numberIntegers; i++) { 183 183 int iColumn = integerVariable[i]; 184 if (!isHeuristicInteger(newSolver,iColumn)) 185 continue; 184 186 const OsiObject * object = model_->object(i); 185 187 // get original bounds … … 212 214 for (i = 0; i < numberIntegers; i++) { 213 215 int iColumn = integerVariable[i]; 216 if (!isHeuristicInteger(newSolver,iColumn)) 217 continue; 214 218 if (used_[iColumn]) { 215 219 which[n] = iColumn; … … 224 228 for (i = 0; i < n; i++) { 225 229 int iColumn = integerVariable[i]; 230 if (!isHeuristicInteger(newSolver,iColumn)) 231 continue; 226 232 if (used_[iColumn] <= allow) { 227 233 newSolver->setColUpper(iColumn, colLower[iColumn]); … … 260 266 double direction = newSolver->getObjSense(); 261 267 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 262 if (! newSolver->isInteger(iColumn)) {268 if (!isHeuristicInteger(newSolver,iColumn)) { 263 269 if (!used_[iColumn]) { 264 270 //double djValue = dj[iColumn]*direction; … … 275 281 int nFix2 = 0; 276 282 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 277 if (! newSolver->isInteger(iColumn)) {283 if (!isHeuristicInteger(newSolver,iColumn)) { 278 284 if (!used_[iColumn]) { 279 285 double djValue = dj[iColumn] * direction; … … 437 443 const double * columnLower = solver->getColLower(); 438 444 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 439 if (! solver->isInteger(iColumn)) {445 if (!isHeuristicInteger(solver,iColumn)) { 440 446 if (solution[iColumn] > columnLower[iColumn] + 1.0e-8) 441 447 used_[iColumn] = numberSolutions_; … … 473 479 for (i = 0; i < numberIntegers; i++) { 474 480 int iColumn = integerVariable[i]; 481 if (!isHeuristicInteger(solver,iColumn)) 482 continue; 475 483 const OsiObject * object = model_->object(i); 476 484 // get original bounds … … 571 579 int * integerVariable = 572 580 CoinCopyOfArray(model_->integerVariable(),numberIntegers); 581 #ifdef COIN_HAS_CLP 582 OsiClpSolverInterface * clpSolver 583 = dynamic_cast<OsiClpSolverInterface *> (model_->solver()); 584 if (clpSolver ) { 585 // take out some integers 586 int nn=numberIntegers; 587 numberIntegers=0; 588 for (int i=0;i<nn;i++) { 589 int iColumn=integerVariable[i]; 590 if (clpSolver->isHeuristicInteger(iColumn)) 591 integerVariable[numberIntegers++]=iColumn; 592 } 593 } 594 #endif 573 595 if (swap>9 && numberIntegers>500) { 574 596 int type=swap/10; … … 1147 1169 for (int i = 0; i < numberIntegers; i++) { 1148 1170 int iColumn = integerVariable[i]; 1171 if (!isHeuristicInteger(newSolver,iColumn)) 1172 continue; 1149 1173 if (fabs(solutionIn[iColumn])<1.0e-5) 1150 1174 obj[iColumn]=1.0; … … 1201 1225 if ((returnCode&1) != 0) { 1202 1226 // redo objective 1203 const double * obj = model_->continuousSolver()->getObjCoefficients(); 1227 OsiSolverInterface * solver = model_->continuousSolver(); 1228 const double * obj = solver->getObjCoefficients(); 1204 1229 solutionValue = - offset; 1205 1230 int sumIncrease=0.0; … … 1209 1234 for (int i=0;i<numberColumns;i++) { 1210 1235 solutionValue += obj[i]*betterSolution[i]; 1211 if ( model_->isInteger(i)) {1236 if (isHeuristicInteger(solver,i)) { 1212 1237 int change=static_cast<int>(floor(solutionIn[i]-betterSolution[i]+0.5)); 1213 1238 if (change>0) { … … 1360 1385 for (i = 0; i < numberIntegers; i++) { 1361 1386 int iColumn = integerVariable[i]; 1387 if (!isHeuristicInteger(newSolver,iColumn)) 1388 continue; 1362 1389 double lower = colLower[iColumn]; 1363 1390 double upper = colUpper[iColumn]; … … 1389 1416 for (i = 0; i < numberIntegers; i++) { 1390 1417 int iColumn = integerVariable[i]; 1418 if (!isHeuristicInteger(newSolver,iColumn)) 1419 continue; 1391 1420 double lower = colLower[iColumn]; 1392 1421 double upper = colUpper[iColumn]; … … 1451 1480 double newLower; 1452 1481 double newUpper; 1453 if ( newSolver->isInteger(iColumn)) {1482 if (isHeuristicInteger(newSolver,iColumn)) { 1454 1483 newLower = CoinMax(lower, floor(value) - 2.0); 1455 1484 newUpper = CoinMin(upper, ceil(value) + 2.0); … … 1474 1503 double newLower = lower; 1475 1504 double newUpper = upper; 1476 if ( newSolver->isInteger(iColumn)) {1505 if (isHeuristicInteger(newSolver,iColumn)) { 1477 1506 if (value < lower + 1.0e-6) { 1478 1507 nFix++; … … 1640 1669 const double * solution = model_->savedSolution(k); 1641 1670 for (int j = 0; j < numberColumns; j++) { 1642 if ( solver->isInteger(j)) {1671 if (isHeuristicInteger(solver,j)) { 1643 1672 if (fixed[j] == -COIN_DBL_MAX) 1644 1673 fixed[j] = floor(solution[j] + 0.5); … … 1650 1679 const double * colLower = solver->getColLower(); 1651 1680 for (int i = 0; i < numberColumns; i++) { 1652 if ( solver->isInteger(i)) {1681 if (isHeuristicInteger(solver,i)) { 1653 1682 double value = fixed[i]; 1654 1683 if (value != COIN_DBL_MAX) { -
trunk/Cbc/src/CbcHeuristicRINS.cpp
r2094 r2280 166 166 numberSolutions_ = model_->getSolutionCount(); 167 167 168 OsiSolverInterface * solver = model_->solver(); 168 169 int numberIntegers = model_->numberIntegers(); 169 170 const int * integerVariable = model_->integerVariable(); … … 172 173 for (i = 0; i < numberIntegers; i++) { 173 174 int iColumn = integerVariable[i]; 175 if (!isHeuristicInteger(solver,iColumn)) 176 continue; 174 177 const OsiObject * object = model_->object(i); 175 178 // get original bounds … … 223 226 for (i = 0; i < numberIntegers; i++) { 224 227 int iColumn = integerVariable[i]; 228 if (!isHeuristicInteger(solver,iColumn)) 229 continue; 225 230 const OsiObject * object = model_->object(i); 226 231 // get original bounds … … 282 287 double direction = newSolver->getObjSense(); 283 288 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 284 if (! newSolver->isInteger(iColumn)) {289 if (!isHeuristicInteger(newSolver,iColumn)) { 285 290 double value = bestSolution[iColumn]; 286 291 if (value < colLower[iColumn] + 1.0e-8) { … … 298 303 int nFix2 = 0; 299 304 for (int iColumn = 0; iColumn < numberColumns; iColumn++) { 300 if (! newSolver->isInteger(iColumn)) {305 if (!isHeuristicInteger(newSolver,iColumn)) { 301 306 double value = bestSolution[iColumn]; 302 307 if (value < colLower[iColumn] + 1.0e-8) { -
trunk/Cbc/src/CbcSolver.cpp
r2279 r2280 4362 4362 threshold -= 10000*highPriority; 4363 4363 } 4364 // If 1000 set then don't put obj on ne variables 4365 bool moveObjective=true; 4366 if (threshold>1000) { 4367 moveObjective=false; 4368 threshold -= 1000; 4369 } 4364 4370 const double * columnLower = solver2->getColLower(); 4365 4371 const double * columnUpper = solver2->getColUpper(); … … 4492 4498 for (int kColumn=iLast;kColumn<jColumn;kColumn++) { 4493 4499 iColumn=which[kColumn]; 4494 solver2->setObjCoeff(iColumn,0.0); 4500 if (moveObjective) 4501 solver2->setObjCoeff(iColumn,0.0); 4495 4502 double lowerValue=columnLower[iColumn]; 4496 4503 double upperValue=columnUpper[iColumn]; … … 4501 4508 elementValue=1.0; 4502 4509 } 4510 if (!moveObjective) 4511 objectiveNew[numberDifferentObj]=0.0; 4503 4512 columnAdd[numberElements]=iColumn; 4504 4513 elementAdd[numberElements++]=elementValue; … … 4546 4555 lowerNew, upperNew,objectiveNew); 4547 4556 // add constraints and make integer if all integer in group 4557 #ifdef COIN_HAS_CLP 4558 OsiClpSolverInterface * clpSolver2 4559 = dynamic_cast<OsiClpSolverInterface *> (solver2); 4560 #endif 4548 4561 for (int iObj=0; iObj < numberDifferentObj; iObj++) { 4549 4562 lowerNew[iObj]=0.0; 4550 4563 upperNew[iObj]=0.0; 4551 4564 solver2->setInteger(numberColumns+iObj); 4565 #ifdef COIN_HAS_CLP 4566 if (clpSolver2) 4567 clpSolver2->setOptionalInteger(numberColumns+iObj); 4568 #endif 4552 4569 } 4553 4570 solver2->addRows(numberDifferentObj, -
trunk/Cbc/src/CbcSolverHeuristics.cpp
r2105 r2280 1215 1215 int accumulate = r / 1000; 1216 1216 r -= 1000 * accumulate; 1217 if (accumulate >= 10 ) {1218 int which = accumulate / 10 ;1219 accumulate -= 10 * which;1217 if (accumulate >= 100) { 1218 int which = accumulate / 100; 1219 accumulate -= 100 * which; 1220 1220 which--; 1221 1221 // weights and factors -
trunk/Cbc/src/CbcSymmetry.hpp
r2207 r2280 222 222 { return GSparse_ != NULL;} 223 223 inline int errorStatus() const 224 #ifndef NTY_TRACES 224 225 { return stats_->errstatus;} 226 #else 227 { return 0;} 228 #endif 225 229 /** 226 230 * Methods to classify orbits. Not horribly efficient, but gets the job done
Note: See TracChangeset
for help on using the changeset viewer.