inline T * ClpCopyOfArray(const T *array, const CoinBigIndex size, T value) { T *arrayNew = new T[size]; if (array) ClpDisjointCopyN(array, size, arrayNew); else ClpFillN(arrayNew, size, value); return arrayNew; }
/// This returns a non const array filled with input from scalar or actual array template <class T> inline T* ClpCopyOfArray( const T * array, const int size, T value) { T * arrayNew = new T[size]; if (array) ClpDisjointCopyN(array, size, arrayNew); else ClpFillN ( arrayNew, size, value); return arrayNew; }
/* Returns reduced gradient.Returns an offset (to be added to current one). */ double ClpLinearObjective::reducedGradient(ClpSimplex * model, double * region, bool /*useFeasibleCosts*/) { int numberRows = model->numberRows(); //work space CoinIndexedVector * workSpace = model->rowArray(0); CoinIndexedVector arrayVector; arrayVector.reserve(numberRows + 1); int iRow; #ifdef CLP_DEBUG workSpace->checkClear(); #endif double * array = arrayVector.denseVector(); int * index = arrayVector.getIndices(); int number = 0; const double * cost = model->costRegion(); //assert (!useFeasibleCosts); const int * pivotVariable = model->pivotVariable(); for (iRow = 0; iRow < numberRows; iRow++) { int iPivot = pivotVariable[iRow]; double value = cost[iPivot]; if (value) { array[iRow] = value; index[number++] = iRow; } } arrayVector.setNumElements(number); int numberColumns = model->numberColumns(); // Btran basic costs double * work = workSpace->denseVector(); model->factorization()->updateColumnTranspose(workSpace, &arrayVector); ClpFillN(work, numberRows, 0.0); // now look at dual solution double * rowReducedCost = region + numberColumns; double * dual = rowReducedCost; double * rowCost = model->costRegion(0); for (iRow = 0; iRow < numberRows; iRow++) { dual[iRow] = array[iRow]; } double * dj = region; ClpDisjointCopyN(model->costRegion(1), numberColumns, dj); model->transposeTimes(-1.0, dual, dj); for (iRow = 0; iRow < numberRows; iRow++) { // slack double value = dual[iRow]; value += rowCost[iRow]; rowReducedCost[iRow] = value; } return 0.0; }