loplugin:useuniqueptr in CoinMPSolver

Change-Id: Ibe0dfdfabf6f56498564406441a9c505e93dd9a6
Reviewed-on: https://gerrit.libreoffice.org/60112
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2018-09-06 11:25:47 +02:00
parent 7c7e2fe9ad
commit 2bfc7d4809
2 changed files with 29 additions and 30 deletions

View File

@@ -143,7 +143,7 @@ void SAL_CALL CoinMPSolver::solve()
// set objective function
const std::vector<double>& rObjCoeff = aCellsHash[maObjective];
double* pObjectCoeffs = new double[nVariables];
std::unique_ptr<double[]> pObjectCoeffs(new double[nVariables]);
for (nVar=0; nVar<nVariables; nVar++)
pObjectCoeffs[nVar] = rObjCoeff[nVar+1];
double nObjectConst = rObjCoeff[0]; // constant term of objective
@@ -152,12 +152,12 @@ void SAL_CALL CoinMPSolver::solve()
size_t nRows = maConstraints.getLength();
size_t nCompSize = nVariables * nRows;
double* pCompMatrix = new double[nCompSize]; // first collect all coefficients, row-wise
std::unique_ptr<double[]> pCompMatrix(new double[nCompSize]); // first collect all coefficients, row-wise
for (size_t i=0; i<nCompSize; i++)
pCompMatrix[i] = 0.0;
double* pRHS = new double[nRows];
char* pRowType = new char[nRows];
std::unique_ptr<double[]> pRHS(new double[nRows]);
std::unique_ptr<char[]> pRowType(new char[nRows]);
for (size_t i=0; i<nRows; i++)
{
pRHS[i] = 0.0;
@@ -217,10 +217,10 @@ void SAL_CALL CoinMPSolver::solve()
// Find non-zero coefficients, column-wise
int* pMatrixBegin = new int[nVariables+1];
int* pMatrixCount = new int[nVariables];
double* pMatrix = new double[nCompSize]; // not always completely used
int* pMatrixIndex = new int[nCompSize];
std::unique_ptr<int[]> pMatrixBegin(new int[nVariables+1]);
std::unique_ptr<int[]> pMatrixCount(new int[nVariables]);
std::unique_ptr<double[]> pMatrix(new double[nCompSize]); // not always completely used
std::unique_ptr<int[]> pMatrixIndex(new int[nCompSize]);
int nMatrixPos = 0;
for (nVar=0; nVar<nVariables; nVar++)
{
@@ -239,13 +239,12 @@ void SAL_CALL CoinMPSolver::solve()
pMatrixCount[nVar] = nMatrixPos - nBegin;
}
pMatrixBegin[nVariables] = nMatrixPos;
delete[] pCompMatrix;
pCompMatrix = nullptr;
pCompMatrix.reset();
// apply settings to all variables
double* pLowerBounds = new double[nVariables];
double* pUpperBounds = new double[nVariables];
std::unique_ptr<double[]> pLowerBounds(new double[nVariables]);
std::unique_ptr<double[]> pUpperBounds(new double[nVariables]);
for (nVar=0; nVar<nVariables; nVar++)
{
pLowerBounds[nVar] = mbNonNegative ? 0.0 : -DBL_MAX;
@@ -254,7 +253,7 @@ void SAL_CALL CoinMPSolver::solve()
// bounds could possibly be further restricted from single-cell constraints
}
char* pColType = new char[nVariables];
std::unique_ptr<char[]> pColType(new char[nVariables]);
for (nVar=0; nVar<nVariables; nVar++)
pColType[nVar] = mbInteger ? 'I' : 'C';
@@ -287,25 +286,25 @@ void SAL_CALL CoinMPSolver::solve()
HPROB hProb = CoinCreateProblem("");
int nResult = CoinLoadProblem( hProb, nVariables, nRows, nMatrixPos, 0,
nObjectSense, nObjectConst, pObjectCoeffs,
pLowerBounds, pUpperBounds, pRowType, pRHS, nullptr,
pMatrixBegin, pMatrixCount, pMatrixIndex, pMatrix,
nObjectSense, nObjectConst, pObjectCoeffs.get(),
pLowerBounds.get(), pUpperBounds.get(), pRowType.get(), pRHS.get(), nullptr,
pMatrixBegin.get(), pMatrixCount.get(), pMatrixIndex.get(), pMatrix.get(),
nullptr, nullptr, nullptr );
if (nResult == SOLV_CALL_SUCCESS)
{
nResult = CoinLoadInteger( hProb, pColType );
nResult = CoinLoadInteger( hProb, pColType.get() );
}
delete[] pColType;
delete[] pMatrixIndex;
delete[] pMatrix;
delete[] pMatrixCount;
delete[] pMatrixBegin;
delete[] pUpperBounds;
delete[] pLowerBounds;
delete[] pRowType;
delete[] pRHS;
delete[] pObjectCoeffs;
pColType.reset();
pMatrixIndex.reset();
pMatrix.reset();
pMatrixCount.reset();
pMatrixBegin.reset();
pUpperBounds.reset();
pLowerBounds.reset();
pRowType.reset();
pRHS.reset();
pObjectCoeffs.reset();
CoinSetRealOption( hProb, COIN_REAL_MAXSECONDS, mnTimeout );
CoinSetRealOption( hProb, COIN_REAL_MIPMAXSEC, mnTimeout );

View File

@@ -186,12 +186,12 @@ void SAL_CALL LpsolveSolver::solve()
// set objective function
const std::vector<double>& rObjCoeff = aCellsHash[maObjective];
REAL* pObjVal = new REAL[nVariables+1];
std::unique_ptr<REAL[]> pObjVal(new REAL[nVariables+1]);
pObjVal[0] = 0.0; // ignored
for (nVar=0; nVar<nVariables; nVar++)
pObjVal[nVar+1] = rObjCoeff[nVar+1];
set_obj_fn( lp, pObjVal );
delete[] pObjVal;
set_obj_fn( lp, pObjVal.get() );
pObjVal.reset();
set_rh( lp, 0, rObjCoeff[0] ); // constant term of objective
// add rows