// Copyright (C) 2002, International Business Machines // Corporation and others. All Rights Reserved. #include #include #include "CoinHelperFunctions.hpp" #include "CoinPresolveMatrix.hpp" #include "CoinPresolveZeros.hpp" #if PRESOLVE_DEBUG || PRESOLVE_CONSISTENCY #include "CoinPresolvePsdebug.hpp" #endif namespace { // begin unnamed file-local namespace // Sees how many zeros there are static int count_col_zeros (int ncheckcols, const int * checkcols, const CoinBigIndex *mcstrt, double *colels, int *hrow, int *hincol) { int nactions = 0; int i; for (i=0; icolels_; int *hrow = prob->hrow_; CoinBigIndex *mcstrt = prob->mcstrt_; int *hincol = prob->hincol_; presolvehlink *clink = prob->clink_ ; presolvehlink *rlink = prob->rlink_ ; // int i; int nzeros = count_col_zeros(ncheckcols,checkcols, mcstrt,colels,hrow,hincol); if (nzeros == 0) { return (next); } else { dropped_zero * zeros = new dropped_zero[nzeros]; nzeros=drop_col_zeros(ncheckcols,checkcols, mcstrt,colels,hrow,hincol,clink, zeros); double *rowels = prob->rowels_; int *hcol = prob->hcol_; CoinBigIndex *mrstrt = prob->mrstrt_; int *hinrow = prob->hinrow_; // int nrows = prob->nrows_; # if PRESOLVE_SUMMARY printf("NZEROS: %d\n", nzeros); # endif // make the row rep consistent drop_row_zeros(nzeros,zeros,mrstrt,rowels,hcol,hinrow,rlink) ; dropped_zero *zeros1 = new dropped_zero[nzeros]; CoinMemcpyN(zeros, nzeros, zeros1); delete [] zeros; return (new drop_zero_coefficients_action(nzeros, zeros1, next)); } } const CoinPresolveAction *drop_zero_coefficients(CoinPresolveMatrix *prob, const CoinPresolveAction *next) { int ncheck = prob->ncols_; int *checkcols = new int[ncheck]; if (!prob->anyProhibited()) { for (int i=0; incols_; i++) if (!prob->colProhibited(i)) checkcols[ncheck++] = i; } const CoinPresolveAction *retval = drop_zero_coefficients_action::presolve(prob, checkcols, ncheck, next); delete[]checkcols; return (retval); } void drop_zero_coefficients_action::postsolve(CoinPostsolveMatrix *prob) const { const int nzeros = nzeros_; const dropped_zero *const zeros = zeros_; double *colels = prob->colels_; int *hrow = prob->hrow_; CoinBigIndex *mcstrt = prob->mcstrt_; int *hincol = prob->hincol_; int *link = prob->link_; CoinBigIndex &free_list = prob->free_list_; for (const dropped_zero *z = &zeros[nzeros-1]; zeros<=z; z--) { int irow = z->row; int jcol = z->col; { CoinBigIndex k = free_list; assert(k >= 0 && k < prob->bulk0_) ; free_list = link[free_list]; hrow[k] = irow; colels[k] = 0.0; link[k] = mcstrt[jcol]; mcstrt[jcol] = k; } hincol[jcol]++; } # if PRESOLVE_CONSISTENCY presolve_check_free_list(prob) ; # endif }