59 #include <ClpSimplex.hpp>
60 #include <ClpPrimalColumnSteepest.hpp>
61 #include <ClpDualRowSteepest.hpp>
62 #include <CoinIndexedVector.hpp>
63 #include <ClpConfig.h>
65 #include <config_clp.h>
66 #define CLP_VERSION VERSION
76 #include "scip/bitencode.h"
80 #if defined(_WIN32) || defined(_WIN64)
81 #define snprintf _snprintf
85 #ifdef LPI_CLP_DEBUG_WRITE_FILES
86 static int fileNr = 0;
90 #define SUMINFEASBOUND 1.0e-3
103 bool validFactorization;
105 bool setFactorizationFrequency;
116 #define COLS_PER_PACKET SCIP_DUALPACKETSIZE
118 #define ROWS_PER_PACKET SCIP_DUALPACKETSIZE
145 if( num > lpi->cstatsize )
149 newsize =
MAX(2*lpi->cstatsize, num);
150 SCIP_ALLOC( BMSreallocMemoryArray(&lpi->cstat, newsize) );
151 lpi->cstatsize = newsize;
153 assert(num <= lpi->cstatsize);
167 if( num > lpi->rstatsize )
171 newsize =
MAX(2*lpi->rstatsize, num);
172 SCIP_ALLOC( BMSreallocMemoryArray(&lpi->rstat, newsize) );
173 lpi->rstatsize = newsize;
175 assert(num <= lpi->rstatsize);
213 assert(lpistate != 0);
214 assert(lpistate->packcstat != 0);
215 assert(lpistate->packrstat != 0);
217 SCIPencodeDualBit(cstat, lpistate->packcstat, lpistate->ncols);
218 SCIPencodeDualBit(rstat, lpistate->packrstat, lpistate->nrows);
229 assert(lpistate != 0);
230 assert(lpistate->packcstat != 0);
231 assert(lpistate->packrstat != 0);
233 SCIPdecodeDualBit(lpistate->packcstat, cstat, lpistate->ncols);
234 SCIPdecodeDualBit(lpistate->packrstat, rstat, lpistate->nrows);
246 assert(lpistate != 0);
251 SCIP_ALLOC( BMSallocBlockMemory(blkmem, lpistate) );
252 SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packcstat, colpacketNum(ncols)) );
253 SCIP_ALLOC( BMSallocBlockMemoryArray(blkmem, &(*lpistate)->packrstat, rowpacketNum(nrows)) );
266 assert(lpistate != 0);
267 assert(*lpistate != 0);
269 BMSfreeBlockMemoryArray(blkmem, &(*lpistate)->packcstat, colpacketNum((*lpistate)->ncols));
270 BMSfreeBlockMemoryArray(blkmem, &(*lpistate)->packrstat, rowpacketNum((*lpistate)->nrows));
271 BMSfreeBlockMemory(blkmem, lpistate);
284 void invalidateSolution(
294 void setFactorizationFrequency(
299 if ( lpi->setFactorizationFrequency )
302 lpi->clp->defaultFactorizationFrequency();
303 lpi->setFactorizationFrequency =
true;
308 void setFastmipClpParameters(
324 lpi->clp->setPerturbation(50);
388 lpi->clp->setSpecialOptions(32|64|512|1024|32768);
390 lpi->clp->setSpecialOptions(32|64|128|512|1024|4096|32768);
394 lpi->clp->setMoreSpecialOptions(8192 | lpi->clp->moreSpecialOptions());
403 void unsetFastmipClpParameters(
407 lpi->fastmip =
FALSE;
410 lpi->clp->setPerturbation(100);
413 lpi->clp->setSpecialOptions(0);
416 lpi->clp->setPersistenceFlag(0);
446 return "COIN-OR Linear Programming Solver developed by J. Forrest et.al. (projects.coin-or.org/Clp)";
454 return (
void*) lpi->clp;
482 (*lpi)->clp =
new ClpSimplex();
485 (*lpi)->cstatsize = 0;
486 (*lpi)->rstatsize = 0;
487 (*lpi)->startscratch =
true;
489 (*lpi)->validFactorization =
false;
490 (*lpi)->setFactorizationFrequency =
false;
491 (*lpi)->fastmip =
FALSE;
492 invalidateSolution(*lpi);
506 ClpPrimalColumnSteepest primalSteepest;
507 (*lpi)->clp->setPrimalColumnPivotAlgorithm(primalSteepest);
515 ClpDualRowSteepest dualSteepest;
516 (*lpi)->clp->setDualRowPivotAlgorithm(dualSteepest);
519 (*lpi)->clp->setStrParam(ClpProbName, std::string(name) );
522 (*lpi)->clp->setOptimizationDirection(objsen);
525 (*lpi)->clp->setLogLevel(0);
528 (*lpi)->clp->scaling(0);
544 assert((*lpi)->clp != 0);
552 BMSfreeMemoryArrayNull(&(*lpi)->cstat);
553 BMSfreeMemoryArrayNull(&(*lpi)->rstat);
593 assert(lpi->clp != 0);
596 assert( nnonz > beg[ncols-1] );
598 invalidateSolution(lpi);
600 ClpSimplex* clp = lpi->clp;
604 SCIP_ALLOC( BMSallocMemoryArray(&mybeg, ncols + 1) );
605 BMScopyMemoryArray(mybeg, beg, ncols);
606 mybeg[ncols] = nnonz;
609 clp->loadProblem(ncols, nrows, mybeg, ind, val, lb, ub, obj, lhs, rhs);
610 BMSfreeMemoryArray( &mybeg );
613 clp->setOptimizationDirection(objsen);
616 if ( colnames || rownames )
618 std::vector<std::string> columnNames(ncols);
619 std::vector<std::string> rowNames(nrows);
622 for (
int j = 0; j < ncols; ++j)
623 columnNames[j].assign(colnames[j]);
627 for (
int i = 0; i < ncols; ++i)
628 rowNames[i].assign(rownames[i]);
630 clp->copyNames(rowNames, columnNames);
654 assert(lpi->clp != 0);
658 assert(nnonz == 0 || beg != 0);
659 assert(nnonz == 0 || ind != 0);
660 assert(nnonz == 0 || val != 0);
664 invalidateSolution(lpi);
667 int numCols = lpi->clp->getNumCols();
671 SCIP_ALLOC( BMSallocMemoryArray(&mybeg, ncols + 1) );
676 BMScopyMemoryArray(mybeg, beg, ncols);
677 mybeg[ncols] = nnonz;
680 lpi->clp->addColumns(ncols, lb, ub, obj, mybeg, ind, val);
684 for (
int j = 0; j <= ncols; ++j)
687 lpi->clp->addColumns(ncols, lb, ub, obj, mybeg, 0, 0);
689 BMSfreeMemoryArray(&mybeg);
694 std::vector<std::string> columnNames(ncols);
695 for (
int j = 0; j < ncols; ++j)
696 columnNames[j].assign(colnames[j]);
697 lpi->clp->copyColumnNames(columnNames, numCols, numCols + ncols);
714 assert(lpi->clp != 0);
715 assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
717 invalidateSolution(lpi);
720 int num = lastcol-firstcol+1;
722 SCIP_ALLOC( BMSallocMemoryArray( &which, num) );;
725 for (
int j = firstcol; j <= lastcol; ++j)
726 which[j - firstcol] = j;
728 lpi->clp->deleteColumns(num, which);
729 BMSfreeMemoryArray( &which );
746 assert(lpi->clp != 0);
749 invalidateSolution(lpi);
752 int ncols = lpi->clp->getNumCols();
754 SCIP_ALLOC( BMSallocMemoryArray( &which, ncols) );
756 for (
int j = 0; j < ncols; ++j)
761 lpi->clp->deleteColumns(cnt, which);
762 BMSfreeMemoryArray(&which);
766 for (
int j = 0; j < ncols; ++j)
797 assert(lpi->clp != 0);
800 assert(nnonz == 0 || beg != 0);
801 assert(nnonz == 0 || ind != 0);
802 assert(nnonz == 0 || val != 0);
804 invalidateSolution(lpi);
807 int numRows = lpi->clp->getNumRows();
810 SCIP_ALLOC( BMSallocMemoryArray( &mybeg, nrows + 1) );
815 BMScopyMemoryArray( mybeg, beg, nrows);
816 mybeg[nrows] = nnonz;
819 lpi->clp->addRows(nrows, lhs, rhs, mybeg, ind, val);
824 for (
int i = 0; i <= nrows; ++i)
826 lpi->clp->addRows(nrows, lhs, rhs, mybeg, 0, 0);
828 BMSfreeMemoryArray( &mybeg );
833 std::vector<std::string> rowNames(nrows);
834 for (
int j = 0; j < nrows; ++j)
835 rowNames[j].assign(rownames[j]);
836 lpi->clp->copyRowNames(rowNames, numRows, numRows + nrows);
850 SCIPdebugMessage(
"calling SCIPlpiDelRows() (number: %d)\n", lastrow-firstrow+1);
853 assert(lpi->clp != 0);
854 assert(0 <= firstrow && firstrow <= lastrow && lastrow < lpi->clp->numberRows());
856 invalidateSolution(lpi);
859 int num = lastrow-firstrow+1;
861 SCIP_ALLOC( BMSallocMemoryArray( &which, num) );
864 for (
int i = firstrow; i <= lastrow; ++i)
865 which[i - firstrow] = i;
867 lpi->clp->deleteRows(num, which);
869 BMSfreeMemoryArray( &which );
886 assert(lpi->clp != 0);
889 invalidateSolution(lpi);
892 int nrows = lpi->clp->getNumRows();
894 SCIP_ALLOC( BMSallocMemoryArray( &which, nrows) );
896 for (
int i = 0; i < nrows; ++i)
901 lpi->clp->deleteRows(cnt, which);
902 BMSfreeMemoryArray( &which );
906 for (
int i = 0; i < nrows; ++i)
929 assert(lpi->clp != 0);
931 invalidateSolution(lpi);
934 lpi->clp->resize(0,0);
952 assert(lpi->clp != 0);
957 invalidateSolution(lpi);
959 ClpSimplex* clp = lpi->clp;
963 double* sol = lpi->clp->primalColumnSolution();
964 const double* colLower = lpi->clp->getColLower();
965 const double* colUpper = lpi->clp->getColUpper();
967 for (
int j = 0; j < ncols; ++j)
969 clp->setColumnBounds(ind[j], lb[j], ub[j]);
972 if( clp->statusExists() )
974 assert( colLower != 0 );
975 assert( colUpper != 0 );
977 switch ( clp->getColumnStatus(k) )
979 case ClpSimplex::isFree:
980 case ClpSimplex::superBasic:
983 case ClpSimplex::atUpperBound:
984 sol[k] = colUpper[k];
985 assert( colUpper[k] == ub[j] );
987 case ClpSimplex::isFixed:
988 case ClpSimplex::atLowerBound:
989 sol[k] = colLower[k];
990 assert( colLower[k] == lb[j] );
1018 assert(lpi->clp != 0);
1023 invalidateSolution(lpi);
1025 ClpSimplex* clp = lpi->clp;
1027 for (
int i = 0; i < nrows; ++i)
1028 clp->setRowBounds(ind[i], lhs[i], rhs[i]);
1045 assert(lpi->clp != 0);
1046 assert(0 <= row && row < lpi->clp->numberRows());
1047 assert(0 <= col && col < lpi->clp->numberColumns());
1049 invalidateSolution(lpi);
1051 lpi->clp->matrix()->modifyCoefficient(row, col, newval);
1066 assert(lpi->clp != 0);
1068 invalidateSolution(lpi);
1071 lpi->clp->setOptimizationDirection(objsen);
1088 assert(lpi->clp != 0);
1092 invalidateSolution(lpi);
1094 ClpSimplex* clp = lpi->clp;
1097 for(
int j = 0; j < ncols; ++j )
1098 clp->setObjCoeff(ind[j], obj[j]);
1114 assert(lpi->clp != 0);
1115 assert(scaleval != 0.0);
1116 assert(0 <= row && row <= lpi->clp->numberRows() );
1118 invalidateSolution(lpi);
1124 ClpSimplex* clp = lpi->clp;
1127 double* lhs = clp->rowLower();
1128 double* rhs = clp->rowUpper();
1130 double lhsval = lhs[row];
1131 if( lhsval > -COIN_DBL_MAX )
1133 else if( scaleval < 0.0 )
1134 lhsval = COIN_DBL_MAX;
1135 double rhsval = rhs[row];
1136 if( rhsval < COIN_DBL_MAX)
1138 else if( scaleval < 0.0 )
1139 rhsval = -COIN_DBL_MAX;
1140 if( scaleval < 0.0 )
1154 CoinPackedMatrix* M = clp->matrix();
1155 assert( M->getNumCols() == clp->numberColumns() );
1157 const CoinBigIndex* beg = M->getVectorStarts();
1158 const int* length = M->getVectorLengths();
1159 const int* ind = M->getIndices();
1160 double* val = M->getMutableElements();
1162 for (
int j = 0; j < M->getNumCols(); ++j)
1164 for (CoinBigIndex k = beg[j]; k < beg[j] + length[j]; ++k)
1187 assert(lpi->clp != 0);
1188 assert(scaleval != 0.0);
1189 assert(0 <= col && col <= lpi->clp->numberColumns() );
1191 invalidateSolution(lpi);
1197 ClpSimplex* clp = lpi->clp;
1200 double* objvec = clp->objective();
1201 objvec[col] *= scaleval;
1204 double* lb = clp->columnLower();
1205 double* ub = clp->columnUpper();
1206 double lbval = lb[col];
1207 double ubval = ub[col];
1209 if( lbval > -COIN_DBL_MAX )
1211 else if( scaleval < 0.0 )
1212 lbval = COIN_DBL_MAX;
1213 if( ubval < COIN_DBL_MAX )
1215 else if( scaleval < 0.0 )
1216 ubval = -COIN_DBL_MAX;
1217 if( scaleval < 0.0 )
1228 CoinPackedMatrix* M = clp->matrix();
1229 assert( M->getNumCols() == clp->numberColumns() );
1231 const CoinBigIndex* beg = M->getVectorStarts();
1232 const int* length = M->getVectorLengths();
1233 double* val = M->getMutableElements();
1234 for (CoinBigIndex k = beg[col]; k < beg[col] + length[col]; ++k)
1263 assert(lpi->clp != 0);
1266 *nrows = lpi->clp->numberRows();
1281 assert(lpi->clp != 0);
1284 *ncols = lpi->clp->numberColumns();
1299 assert(lpi->clp != 0);
1302 *nnonz = lpi->clp->getNumElements();
1327 assert(lpi->clp != 0);
1328 assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
1330 ClpSimplex* clp = lpi->clp;
1333 assert( (lb != 0 && ub != 0) || (lb == 0 && ub == 0) );
1336 const double* colLower = clp->getColLower();
1337 const double* colUpper = clp->getColUpper();
1339 BMScopyMemoryArray( lb, colLower + firstcol, (lastcol - firstcol + 1));
1340 BMScopyMemoryArray( ub, colUpper + firstcol, (lastcol - firstcol + 1));
1343 assert( nnonz != 0 || beg == 0);
1344 assert( nnonz != 0 || ind == 0);
1345 assert( nnonz != 0 || val == 0);
1349 CoinPackedMatrix* M = clp->matrix();
1351 assert( M->getNumCols() == clp->numberColumns() );
1353 const CoinBigIndex* Mbeg = M->getVectorStarts();
1354 const int* Mlength = M->getVectorLengths();
1355 const int* Mind = M->getIndices();
1356 const double* Mval = M->getElements();
1360 for (
int j = firstcol; j <= lastcol; ++j)
1362 beg[j-firstcol] = *nnonz;
1364 BMScopyMemoryArray( (ind + (*nnonz)), Mind + Mbeg[j], Mlength[j]);
1365 BMScopyMemoryArray( (val + (*nnonz)), Mval + Mbeg[j], Mlength[j]);
1367 (*nnonz) += Mlength[j];
1394 assert(lpi->clp != 0);
1395 assert(0 <= firstrow && firstrow <= lastrow && lastrow < lpi->clp->numberRows());
1397 ClpSimplex* clp = lpi->clp;
1398 assert( (lhs != 0 && rhs != 0) || (lhs == 0 && rhs == 0) );
1401 const double* rowLower = clp->getRowLower();
1402 const double* rowUpper = clp->getRowUpper();
1404 BMScopyMemoryArray( lhs, rowLower + firstrow, (lastrow - firstrow + 1) );
1405 BMScopyMemoryArray( rhs, rowUpper + firstrow, (lastrow - firstrow + 1) );
1408 assert( nnonz != 0 || beg == 0);
1409 assert( nnonz != 0 || ind == 0);
1410 assert( nnonz != 0 || val == 0);
1414 ClpMatrixBase* M = clp->rowCopy();
1416 M = clp->clpMatrix()->reverseOrderedCopy();
1418 assert( M->getNumRows() == clp->numberRows() );
1420 const CoinBigIndex* Mbeg = M->getVectorStarts();
1421 const int* Mlength = M->getVectorLengths();
1422 const int* Mind = M->getIndices();
1423 const double* Mval = M->getElements();
1426 for(
int i = firstrow; i <= lastrow; ++i )
1428 beg[i-firstrow] = *nnonz;
1429 for( CoinBigIndex k = Mbeg[i]; k < Mbeg[i] + Mlength[i]; ++k )
1431 ind[*nnonz] = Mind[k];
1432 val[*nnonz] = Mval[k];
1449 int namestoragesize,
1465 int namestoragesize,
1482 assert(lpi !=
NULL);
1483 assert(lpi->clp !=
NULL);
1498 assert( lpi !=
NULL );
1499 assert( lpi->clp !=
NULL );
1500 assert( objsen !=
NULL );
1503 if ( lpi->clp->getObjSense() < 0 )
1523 assert(lpi->clp != 0);
1524 assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
1527 const double* obj = lpi->clp->getObjCoefficients();
1529 BMScopyMemoryArray( vals, obj + firstcol, (lastcol - firstcol + 1) );
1547 assert(lpi->clp != 0);
1548 assert(0 <= firstcol && firstcol <= lastcol && lastcol < lpi->clp->numberColumns());
1552 const double* colLower = lpi->clp->getColLower();
1553 BMScopyMemoryArray( lbs, colLower + firstcol, (lastcol - firstcol + 1) );
1558 const double* colUpper = lpi->clp->getColUpper();
1559 BMScopyMemoryArray( ubs, colUpper + firstcol, (lastcol - firstcol + 1) );
1578 assert(lpi->clp != 0);
1579 assert(0 <= firstrow && firstrow <= lastrow && lastrow < lpi->clp->numberRows());
1583 const double* rowLower = lpi->clp->getRowLower();
1584 BMScopyMemoryArray( lhss, rowLower + firstrow, (lastrow - firstrow + 1) );
1589 const double* rowUpper = lpi->clp->getRowUpper();
1590 BMScopyMemoryArray( rhss, rowUpper + firstrow, (lastrow - firstrow + 1) );
1608 assert(lpi->clp != 0);
1609 assert(0 <= col && col < lpi->clp->numberColumns());
1610 assert(0 <= row && row < lpi->clp->numberRows());
1613 *val = lpi->clp->matrix()->getCoefficient(row, col);
1637 assert(lpi->clp != 0);
1639 SCIPdebugMessage(
"calling Clp primal(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
1641 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1643 snprintf(filename, 255,
"debug_p_%d.mps", fileNr);
1644 fileNr = fileNr % 2;
1649 invalidateSolution(lpi);
1652 setFactorizationFrequency(lpi);
1655 if ( lpi->startscratch )
1657 lpi->clp->allSlackBasis(
true);
1658 lpi->validFactorization =
false;
1668 int startFinishOptions = 1;
1669 if ( lpi->validFactorization )
1670 startFinishOptions = startFinishOptions | 2;
1673 int status = lpi->clp->primal(0, startFinishOptions);
1675 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1676 char basisname[255];
1677 snprintf(basisname, 255,
"debug_p_%d.bas", fileNr);
1681 fileNr = fileNr % 2;
1684 lpi->validFactorization =
true;
1695 assert( status != -1 );
1696 assert( status != 5 );
1697 if ( status == 4 || status == 5 || status == -1 )
1710 assert(lpi->clp != 0);
1712 SCIPdebugMessage(
"calling Clp dual(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
1714 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1716 snprintf(filename, 255,
"debug_d_%d.mps", fileNr);
1719 snprintf(filename, 255,
"debug_d_%d.sav", fileNr);
1724 invalidateSolution(lpi);
1727 setFactorizationFrequency(lpi);
1730 if( lpi->startscratch )
1732 lpi->clp->allSlackBasis(
true);
1733 lpi->validFactorization =
false;
1743 int startFinishOptions = 1;
1744 if ( lpi->validFactorization )
1745 startFinishOptions = startFinishOptions | 2;
1748 int status = lpi->clp->dual(0, startFinishOptions);
1750 #ifdef LPI_CLP_DEBUG_WRITE_FILES
1751 char basisname[255];
1752 snprintf(basisname, 255,
"debug_d_%d.bas", fileNr);
1756 fileNr = fileNr % 2;
1759 lpi->validFactorization =
true;
1770 assert( status != -1 );
1771 assert( status != 5 );
1772 if ( status == 4 || status == 5 || status == -1 )
1786 assert(lpi->clp != 0);
1788 SCIPdebugMessage(
"calling Clp barrier(): %d cols, %d rows\n", lpi->clp->numberColumns(), lpi->clp->numberRows());
1790 invalidateSolution(lpi);
1799 int status = lpi->clp->barrier(crossover);
1812 assert( status != -1 );
1813 assert( status != 5 );
1814 if ( status == 4 || status == 5 || status == -1 )
1854 SCIPdebugMessage(
"calling SCIPlpiStrongbranch() on variable %d (%d iterations)\n", col, itlim);
1857 assert(lpi->clp != 0);
1860 assert(downvalid != 0);
1861 assert(upvalid != 0);
1863 ClpSimplex* clp = lpi->clp;
1866 int ncols = clp->numberColumns();
1867 assert( 0 <= col && col < ncols );
1868 double** outputSolution =
NULL;
1869 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution, 2) );
1870 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution[0], ncols) );
1871 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution[1], ncols) );
1873 int* outputStatus =
NULL;
1874 SCIP_ALLOC( BMSallocMemoryArray( &outputStatus, 2) );
1876 int* outputIterations =
NULL;
1877 SCIP_ALLOC( BMSallocMemoryArray( &outputIterations, 2) );
1880 int iterlimit = clp->maximumIterations();
1881 clp->setMaximumIterations(itlim);
1884 double objval = clp->objectiveValue();
1887 int specialoptions = clp->specialOptions();
1926 clp->setSpecialOptions(64|512|1024);
1928 clp->setSpecialOptions(64|128|512|1024|4096);
1939 int startFinishOptions = 1;
1940 if ( lpi->validFactorization )
1941 startFinishOptions = startFinishOptions | 2;
1944 *down =
EPSCEIL(psol - 1.0, 1e-06);
1963 int res = clp->strongBranching(1, &col, up, down, outputSolution, outputStatus, outputIterations,
false,
true, startFinishOptions);
1966 clp->setSpecialOptions(specialoptions);
1968 lpi->validFactorization =
true;
1979 *iter = outputIterations[0] + outputIterations[1];
1982 clp->setMaximumIterations(iterlimit);
1985 BMSfreeMemoryArray( &outputStatus );
1986 BMSfreeMemoryArray( &outputIterations );
1987 BMSfreeMemoryArray( &outputSolution[1] );
1988 BMSfreeMemoryArray( &outputSolution[0] );
1989 BMSfreeMemoryArray( &outputSolution );
2014 SCIPdebugMessage(
"calling SCIPlpiStrongbranches() on %d variables (%d iterations)\n", ncols, itlim);
2017 assert( lpi->clp != 0 );
2018 assert( cols != 0 );
2019 assert( psols != 0 );
2020 assert( down != 0 );
2022 assert( downvalid != 0 );
2023 assert( upvalid != 0 );
2025 ClpSimplex* clp = lpi->clp;
2028 int n = clp->numberColumns();
2029 assert( 0 < ncols && ncols <= n );
2030 double** outputSolution =
NULL;
2031 SCIP_ALLOC( BMSallocMemoryArray( &outputSolution, 2*ncols) );
2032 for (
int j = 0; j < 2*ncols; ++j)
2034 SCIP_ALLOC( BMSallocMemoryArray( &(outputSolution[j]), n) );
2037 int* outputStatus =
NULL;
2038 SCIP_ALLOC( BMSallocMemoryArray(&outputStatus, 2*ncols) );
2040 int* outputIterations =
NULL;
2041 SCIP_ALLOC( BMSallocMemoryArray(&outputIterations, 2*ncols) );
2044 int iterlimit = clp->maximumIterations();
2045 clp->setMaximumIterations(itlim);
2048 double objval = clp->objectiveValue();
2051 int specialoptions = clp->specialOptions();
2090 clp->setSpecialOptions(64|512|1024);
2092 clp->setSpecialOptions(64|128|512|1024|4096);
2103 int startFinishOptions = 1;
2104 if ( lpi->validFactorization )
2105 startFinishOptions = startFinishOptions | 2;
2108 for (
int j = 0; j < ncols; ++j)
2110 assert( 0 <= cols[j] && cols[j] < n );
2111 down[j] =
EPSCEIL(psols[j] - 1.0, 1e-06);
2112 up[j] =
EPSFLOOR(psols[j] + 1.0, 1e-06);
2115 downvalid[j] =
TRUE;
2134 int res = clp->strongBranching(ncols, cols, up, down, outputSolution, outputStatus, outputIterations,
false,
true, startFinishOptions);
2137 clp->setSpecialOptions(specialoptions);
2139 lpi->validFactorization =
true;
2141 for (
int j = 0; j < ncols; ++j)
2148 *iter += outputIterations[2*j] + outputIterations[2*j+1];
2150 BMSfreeMemoryArray(&outputSolution[2*j]);
2151 BMSfreeMemoryArray(&outputSolution[2*j+1]);
2155 clp->setMaximumIterations(iterlimit);
2158 BMSfreeMemoryArray( &outputStatus );
2159 BMSfreeMemoryArray( &outputIterations );
2160 BMSfreeMemoryArray( &outputSolution );
2184 SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
2209 SCIP_CALL( lpiStrongbranches(lpi, cols, ncols, psols, itlim, down, up, downvalid, upvalid, iter) );
2230 SCIP_CALL( lpiStrongbranch(lpi, col, psol, itlim, down, up, downvalid, upvalid, iter) );
2255 SCIP_CALL( lpiStrongbranches(lpi, cols, ncols, psols, itlim, down, up, downvalid, upvalid, iter) );
2275 assert(lpi !=
NULL);
2290 assert(lpi->clp != 0);
2291 assert(primalfeasible != 0);
2292 assert(dualfeasible != 0);
2294 if ( lpi->clp->primalFeasible() )
2295 *primalfeasible =
TRUE;
2297 *primalfeasible =
FALSE;
2299 if ( lpi->clp->dualFeasible() )
2300 *dualfeasible =
TRUE;
2302 *dualfeasible =
FALSE;
2305 if (lpi->clp->status()==0 && ( ! (*primalfeasible) || ! (*dualfeasible)) )
2307 if ( !(*primalfeasible) && lpi->clp->sumPrimalInfeasibilities() <
SUMINFEASBOUND )
2309 lpi->clp->setNumberPrimalInfeasibilities(0);
2310 *primalfeasible =
TRUE;
2312 if ( !(*dualfeasible) && lpi->clp->sumDualInfeasibilities() <
SUMINFEASBOUND)
2314 lpi->clp->setNumberDualInfeasibilities(0);
2315 *dualfeasible =
TRUE;
2333 assert(lpi->clp != 0);
2337 return ( lpi->clp->status() == 2 );
2351 assert(lpi->clp != 0);
2355 return ( lpi->clp->status() == 2 );
2367 assert(lpi->clp != 0);
2369 return ( lpi->clp->isProvenDualInfeasible() && lpi->clp->primalFeasible() );
2381 assert(lpi->clp != 0);
2388 return ( lpi->clp->status() == 1 && (lpi->clp->secondaryStatus() == 0 || lpi->clp->secondaryStatus() == 6) );
2400 assert(lpi->clp != 0);
2402 return ( lpi->clp->primalFeasible() );
2416 assert(lpi->clp != 0);
2420 return ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->algorithm() < 0 );
2434 assert(lpi->clp != 0);
2438 if ( lpi->clp->rayExists() )
2440 if ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->algorithm() < 0)
2444 if ( lpi->clp->status() != 2 || lpi->clp->algorithm() <= 0 )
2445 lpi->clp->deleteRay();
2462 assert(lpi->clp != 0);
2467 return ( lpi->clp->status() == 1 && lpi->clp->secondaryStatus() == 0 && lpi->clp->dualFeasible() );
2479 assert(lpi->clp != 0);
2481 return ( lpi->clp->isProvenDualInfeasible() );
2493 assert(lpi->clp != 0);
2495 return ( lpi->clp->dualFeasible() );
2507 assert(lpi->clp != 0);
2513 return( lpi->clp->isProvenOptimal() && (lpi->clp->secondaryStatus() == 0 || lpi->clp->secondaryStatus() == 6));
2525 assert(lpi->clp != 0);
2549 SCIPdebugMessage(
"status: %d secondary: %d\n", lpi->clp->status(), lpi->clp->secondaryStatus());
2550 assert( 0 <= lpi->clp->status() && lpi->clp->status() <= 5 );
2551 return( (lpi->clp->status() <= 3) && (lpi->clp->secondaryStatus() <= 1 || lpi->clp->secondaryStatus() == 6 || lpi->clp->secondaryStatus() == 9) );
2563 assert(lpi->clp != 0);
2566 if ( lpi->clp->status() == 1 )
2568 if ( lpi->clp->secondaryStatus() == 1 )
2574 return ( lpi->clp->isObjectiveLimitTestValid() && (lpi->clp->isPrimalObjectiveLimitReached() || lpi->clp->isDualObjectiveLimitReached()) );
2595 assert(lpi->clp != 0);
2599 return ( lpi->clp->status() == 3 && lpi->clp->secondaryStatus() != 9 );
2611 assert(lpi->clp != 0);
2615 return ( lpi->clp->status() == 3 && lpi->clp->secondaryStatus() == 9 );
2627 assert(lpi->clp != 0);
2629 return lpi->clp->status();
2642 assert(lpi->clp != 0);
2643 assert(objval != 0);
2645 *objval = lpi->clp->objectiveValue();
2664 assert(lpi->clp != 0);
2666 ClpSimplex* clp = lpi->clp;
2668 *objval = clp->objectiveValue();
2672 const double* sol = clp->getColSolution();
2673 BMScopyMemoryArray( primsol, sol, clp->numberColumns() );
2677 const double* dsol = clp->getRowPrice();
2678 BMScopyMemoryArray( dualsol, dsol, clp->numberRows() );
2682 const double* act = clp->getRowActivity();
2683 BMScopyMemoryArray( activity, act, clp->numberRows() );
2687 const double* red = clp->getReducedCost();
2688 BMScopyMemoryArray( redcost, red, clp->numberColumns() );
2704 assert(lpi->clp != 0);
2708 const double* clpray = lpi->clp->unboundedRay();
2713 BMScopyMemoryArray( ray, clpray, lpi->clp->numberColumns() );
2729 assert(lpi->clp != 0);
2730 assert(dualfarkas != 0);
2733 const double* dualray = lpi->clp->infeasibilityRay();
2738 BMScopyMemoryArray( dualfarkas, dualray, lpi->clp->numberRows() );
2759 assert(iterations != 0);
2761 *iterations = lpi->clp->numberIterations();
2777 assert(lpi !=
NULL);
2778 assert(quality !=
NULL);
2807 assert(lpi->clp != 0);
2809 ClpSimplex* clp = lpi->clp;
2814 for(
int i = 0; i < clp->numberRows(); ++i )
2816 switch ( clp->getRowStatus(i) )
2818 case ClpSimplex::isFree:
2821 case ClpSimplex::basic:
2824 case ClpSimplex::atUpperBound:
2827 case ClpSimplex::atLowerBound:
2830 case ClpSimplex::superBasic:
2833 case ClpSimplex::isFixed:
2834 if (clp->getRowPrice()[i] > 0.0)
2849 for(
int j = 0; j < clp->numberColumns(); ++j )
2851 switch ( clp->getColumnStatus(j) )
2853 case ClpSimplex::isFree:
2856 case ClpSimplex::basic:
2859 case ClpSimplex::atUpperBound:
2862 case ClpSimplex::atLowerBound:
2865 case ClpSimplex::superBasic:
2868 case ClpSimplex::isFixed:
2869 if (clp->getReducedCost()[j] > 0.0)
2895 assert(lpi->clp != 0);
2897 invalidateSolution(lpi);
2901 ClpSimplex* clp = lpi->clp;
2902 clp->createStatus();
2904 const double* lhs = clp->getRowLower();
2905 const double* rhs = clp->getRowUpper();
2907 assert( rstat != 0 || clp->numberRows() == 0 );
2908 for(
int i = 0; i < clp->numberRows(); ++i )
2910 int status = rstat[i];
2911 assert( 0 <= status && status <= 3 );
2918 if (lhs[i] <= -COIN_DBL_MAX && rhs[i] >= COIN_DBL_MAX)
2919 clp->setRowStatus(i, ClpSimplex::isFree);
2921 clp->setRowStatus(i, ClpSimplex::superBasic);
2924 clp->setRowStatus(i, ClpSimplex::basic);
2927 clp->setRowStatus(i, ClpSimplex::atUpperBound);
2930 if (
EPSEQ(rhs[i], lhs[i], 1e-6) )
2931 clp->setRowStatus(i, ClpSimplex::isFixed);
2933 clp->setRowStatus(i, ClpSimplex::atLowerBound);
2942 const double* lb = clp->getColLower();
2943 const double* ub = clp->getColUpper();
2945 assert( cstat != 0 || clp->numberColumns() == 0 );
2946 for(
int j = 0; j < clp->numberColumns(); ++j )
2948 int status = cstat[j];
2949 assert( 0 <= status && status <= 3 );
2956 if (lb[j] <= -COIN_DBL_MAX && ub[j] >= COIN_DBL_MAX)
2957 clp->setColumnStatus(j, ClpSimplex::isFree);
2959 clp->setColumnStatus(j, ClpSimplex::superBasic);
2962 clp->setColumnStatus(j, ClpSimplex::basic);
2965 clp->setColumnStatus(j, ClpSimplex::atUpperBound);
2968 if (
EPSEQ(ub[j], lb[j], 1e-6) )
2969 clp->setColumnStatus(j, ClpSimplex::isFixed);
2971 clp->setColumnStatus(j, ClpSimplex::atLowerBound);
2994 clp->setWhatsChanged(clp->whatsChanged() & (~512));
3010 assert(lpi->clp != 0);
3013 ClpSimplex* clp = lpi->clp;
3014 int nrows = clp->numberRows();
3015 int ncols = clp->numberColumns();
3018 SCIP_ALLOC( BMSallocMemoryArray(&idx, nrows) );
3023 if ( clp->secondaryStatus() == 6 )
3025 assert( clp->getNumElements() == 0 );
3026 for (
int i = 0; i < nrows; ++i)
3030 clp->getBasics(idx);
3032 for (
int i = 0; i < nrows; ++i)
3034 if ( idx[i] < ncols )
3037 bind[i] = -1 - (idx[i] - ncols);
3040 BMSfreeMemoryArray(&idx);
3056 assert( lpi->clp != 0 );
3057 assert( coef != 0 );
3058 assert( 0 <= r && r <= lpi->clp->numberRows() );
3060 ClpSimplex* clp = lpi->clp;
3061 clp->getBInvRow(r, coef);
3081 assert( lpi->clp != 0 );
3082 assert( coef != 0 );
3083 assert( 0 <= c && c <= lpi->clp->numberRows() );
3085 ClpSimplex* clp = lpi->clp;
3086 clp->getBInvCol(c, coef);
3103 assert( lpi->clp != 0 );
3104 assert( coef != 0 );
3105 assert( 0 <= r && r <= lpi->clp->numberRows() );
3107 ClpSimplex* clp = lpi->clp;
3108 clp->getBInvARow(r, coef, 0);
3124 assert( lpi->clp != 0 );
3125 assert( coef != 0 );
3126 assert( 0 <= c && c <= lpi->clp->numberColumns() );
3128 ClpSimplex* clp = lpi->clp;
3129 clp->getBInvACol(c, coef);
3156 assert(blkmem != 0);
3158 assert(lpi->clp != 0);
3159 assert(lpistate != 0);
3161 int ncols = lpi->clp->numberColumns();
3162 int nrows = lpi->clp->numberRows();
3167 SCIP_CALL( lpistateCreate(lpistate, blkmem, ncols, nrows) );
3170 SCIP_CALL( ensureCstatMem(lpi, ncols) );
3171 SCIP_CALL( ensureRstatMem(lpi, nrows) );
3177 (*lpistate)->ncols = ncols;
3178 (*lpistate)->nrows = nrows;
3179 lpistatePack(*lpistate, lpi->cstat, lpi->rstat);
3201 assert(lpi->clp != 0);
3202 assert(lpistate != 0);
3204 lpncols = lpi->clp->numberColumns();
3205 lpnrows = lpi->clp->numberRows();
3206 assert(lpistate->ncols <= lpncols);
3207 assert(lpistate->nrows <= lpnrows);
3210 SCIP_CALL( ensureCstatMem(lpi, lpncols) );
3211 SCIP_CALL( ensureRstatMem(lpi, lpnrows) );
3214 lpistateUnpack(lpistate, lpi->cstat, lpi->rstat);
3217 for( i = lpistate->ncols; i < lpncols; ++i )
3219 SCIP_Real bnd = (lpi->clp->getColLower())[i];
3223 bnd = (lpi->clp->getColUpper())[i];
3232 for( i = lpistate->nrows; i < lpnrows; ++i )
3249 assert(lpi->clp != 0);
3251 lpi->clp->allSlackBasis(
true);
3252 lpi->validFactorization =
false;
3267 assert(lpistate !=
NULL);
3269 if ( *lpistate !=
NULL )
3270 lpistateFree(lpistate, blkmem);
3281 return (lpistate !=
NULL);
3295 if ( lpi->clp->readBasis(fname) < 0 )
3318 if ( lpi->clp->writeBasis(fname,
false, 0) )
3345 assert(lpinorms !=
NULL);
3361 assert(lpinorms ==
NULL);
3374 assert(lpinorms ==
NULL);
3402 assert(lpi->clp != 0);
3408 *ival = lpi->startscratch;
3411 if( lpi->clp->scalingFlag() != 0 )
3417 *ival = (int)lpi->pricing;
3420 *ival = lpi->clp->logLevel() > 0 ?
TRUE :
FALSE;
3423 *ival = lpi->clp->maximumIterations();
3426 *ival = lpi->fastmip;
3446 assert(lpi->clp != 0);
3471 primalmode = 3; dualmode = 3;
break;
3473 primalmode = 0; dualmode = 1;
break;
3476 primalmode = 1; dualmode = 0;
break;
3478 primalmode = 1; dualmode = 2;
break;
3480 primalmode = 2; dualmode = 3;
break;
3486 ClpPrimalColumnSteepest primalpivot(primalmode);
3487 lpi->clp->setPrimalColumnPivotAlgorithm(primalpivot);
3488 ClpDualRowSteepest dualpivot(dualmode);
3489 lpi->clp->setDualRowPivotAlgorithm(dualpivot);
3496 lpi->startscratch = ival;
3499 lpi->clp->scaling(ival ==
TRUE ? 3 : 0);
3516 lpi->clp->setLogLevel(2);
3518 lpi->clp->setLogLevel(0);
3521 lpi->clp->setMaximumIterations(ival);
3526 setFastmipClpParameters(lpi);
3528 unsetFastmipClpParameters(lpi);
3548 assert(lpi->clp != 0);
3554 *dval = lpi->clp->primalTolerance();
3557 *dval = lpi->clp->dualTolerance();
3563 if ( lpi->clp->optimizationDirection() > 0 )
3564 *dval = lpi->clp->primalObjectiveLimit();
3566 *dval = lpi->clp->dualObjectiveLimit();
3569 if ( lpi->clp->optimizationDirection() > 0 )
3570 *dval = lpi->clp->dualObjectiveLimit();
3572 *dval = lpi->clp->primalObjectiveLimit();
3575 *dval = lpi->clp->maximumSeconds();
3594 assert(lpi->clp != 0);
3599 lpi->clp->setPrimalTolerance(dval);
3602 lpi->clp->setDualTolerance(dval);
3608 if ( lpi->clp->optimizationDirection() > 0 )
3609 lpi->clp->setPrimalObjectiveLimit(dval);
3611 lpi->clp->setDualObjectiveLimit(dval);
3614 if ( lpi->clp->optimizationDirection() > 0 )
3615 lpi->clp->setDualObjectiveLimit(dval);
3617 lpi->clp->setPrimalObjectiveLimit(dval);
3620 lpi->clp->setMaximumSeconds(dval);
3648 return COIN_DBL_MAX;
3660 return (val >= COIN_DBL_MAX);
3678 const char* filename
3683 f = fopen(filename,
"r");
3701 assert(lpi->clp != 0);
3705 if ( !fileExists(fname) )
3714 if ( lpi->clp->readMps(fname,
true,
false) )
3729 assert(lpi->clp != 0);
3738 if ( lpi->clp->writeMps(fname, 0, 2, lpi->clp->optimizationDirection()) )