00001
00002
00003 #include <stdio.h>
00004 #include <math.h>
00005 #include "CoinPresolveMatrix.hpp"
00006 #include "CoinPresolveUseless.hpp"
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 const CoinPresolveAction *useless_constraint_action::presolve(CoinPresolveMatrix * prob,
00017 const int *useless_rows,
00018 int nuseless_rows,
00019 const CoinPresolveAction *next)
00020 {
00021
00022 double *colels = prob->colels_;
00023
00024
00025 int *hrow = prob->hrow_;
00026
00027 const CoinBigIndex *mcstrt = prob->mcstrt_;
00028
00029
00030 int *hincol = prob->hincol_;
00031
00032
00033
00034
00035 const double *rowels = prob->rowels_;
00036 const int *hcol = prob->hcol_;
00037 const CoinBigIndex *mrstrt = prob->mrstrt_;
00038
00039
00040 int *hinrow = prob->hinrow_;
00041
00042
00043 double *rlo = prob->rlo_;
00044 double *rup = prob->rup_;
00045
00046 action *actions = new action [nuseless_rows];
00047
00048 #if PRESOLVE_SUMMARY
00049 printf("NUSELESS ROWS: %d\n", nuseless_rows);
00050 #endif
00051
00052 for (int i=0; i<nuseless_rows; ++i) {
00053 int irow = useless_rows[i];
00054 CoinBigIndex krs = mrstrt[irow];
00055 CoinBigIndex kre = krs + hinrow[irow];
00056
00057 action *f = &actions[i];
00058
00059 f->row = irow;
00060 f->ninrow = hinrow[irow];
00061 f->rlo = rlo[irow];
00062 f->rup = rup[irow];
00063 f->rowcols = copyOfArray(&hcol[krs], hinrow[irow]);
00064 f->rowels = copyOfArray(&rowels[krs], hinrow[irow]);
00065
00066 for (CoinBigIndex k=krs; k<kre; k++)
00067 presolve_delete_from_row(hcol[k], irow, mcstrt, hincol, hrow, colels);
00068 hinrow[irow] = 0;
00069
00070
00071 rlo[irow] = 0.0;
00072 rup[irow] = 0.0;
00073 }
00074
00075
00076 next = new useless_constraint_action(nuseless_rows, actions, next);
00077
00078 return (next);
00079 }
00080
00081 const char *useless_constraint_action::name() const
00082 {
00083 return ("useless_constraint_action");
00084 }
00085
00086 void useless_constraint_action::postsolve(CoinPostsolveMatrix *prob) const
00087 {
00088 const action *const actions = actions_;
00089 const int nactions = nactions_;
00090
00091 double *colels = prob->colels_;
00092 int *hrow = prob->hrow_;
00093 CoinBigIndex *mcstrt = prob->mcstrt_;
00094 int *link = prob->link_;
00095 int *hincol = prob->hincol_;
00096
00097
00098 double *rowacts = prob->acts_;
00099 const double *sol = prob->sol_;
00100
00101
00102 CoinBigIndex free_list = prob->free_list_;
00103
00104 double *rlo = prob->rlo_;
00105 double *rup = prob->rup_;
00106
00107 for (const action *f = &actions[nactions-1]; actions<=f; f--) {
00108
00109 int irow = f->row;
00110 int ninrow = f->ninrow;
00111 const int *rowcols = f->rowcols;
00112 const double *rowels = f->rowels;
00113 double rowact = 0.0;
00114
00115 rup[irow] = f->rup;
00116 rlo[irow] = f->rlo;
00117
00118 for (CoinBigIndex k=0; k<ninrow; k++) {
00119 int jcol = rowcols[k];
00120
00121
00122
00123 {
00124 CoinBigIndex kk = free_list;
00125 free_list = link[free_list];
00126
00127 check_free_list(free_list);
00128
00129 hrow[kk] = irow;
00130 colels[kk] = rowels[k];
00131 link[kk] = mcstrt[jcol];
00132 mcstrt[jcol] = kk;
00133 }
00134
00135 rowact += rowels[k] * sol[jcol];
00136 hincol[jcol]++;
00137 }
00138
00139
00140 PRESOLVEASSERT(prob->getRowStatus(irow)==CoinPrePostsolveMatrix::basic);
00141
00142
00143 rowacts[irow] = rowact;
00144 }
00145 prob->free_list_ = free_list;
00146 }
00147
00148