Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

CoinPresolveUseless.cpp

00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #include <stdio.h>
00004 #include <math.h>
00005 #include "CoinPresolveMatrix.hpp"
00006 #include "CoinPresolveUseless.hpp"
00007 
00008 
00009 // WHAT HAPPENS IF COLS ARE DROPPED AS A RESULT??
00010 // should be like do_tighten.
00011 // not really - one could fix costed variables to appropriate bound.
00012 // ok, don't bother about it.  If it is costed, it will be checked
00013 // when it is eliminated as an empty col; if it is costed in the
00014 // wrong direction, the problem is unbounded, otherwise it is pegged
00015 // at its bound.  no special action need be taken here.
00016 const CoinPresolveAction *useless_constraint_action::presolve(CoinPresolveMatrix * prob,
00017                                                                   const int *useless_rows,
00018                                                                   int nuseless_rows,
00019                                        const CoinPresolveAction *next)
00020 {
00021   // may be modified by useless constraint
00022   double *colels        = prob->colels_;
00023 
00024   // may be modified by useless constraint
00025         int *hrow       = prob->hrow_;
00026 
00027   const CoinBigIndex *mcstrt    = prob->mcstrt_;
00028 
00029   // may be modified by useless constraint
00030         int *hincol     = prob->hincol_;
00031 
00032         //  double *clo = prob->clo_;
00033         //  double *cup = prob->cup_;
00034 
00035   const double *rowels  = prob->rowels_;
00036   const int *hcol       = prob->hcol_;
00037   const CoinBigIndex *mrstrt    = prob->mrstrt_;
00038 
00039   // may be written by useless constraint
00040         int *hinrow     = prob->hinrow_;
00041         //  const int nrows     = prob->nrows_;
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     // just to make things squeeky
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   //  double *rowduals  = prob->rowduals_;
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       //      CoinBigIndex kk = mcstrt[jcol];
00121 
00122       // append deleted row element to each col
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     // I don't know if this is always true
00140     PRESOLVEASSERT(prob->getRowStatus(irow)==CoinPrePostsolveMatrix::basic);
00141     // rcosts are unaffected since rowdual is 0
00142 
00143     rowacts[irow] = rowact;
00144   }
00145   prob->free_list_ = free_list;
00146 }
00147 
00148 

Generated on Wed Dec 3 14:34:23 2003 for Coin by doxygen 1.3.5