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

CoinPresolveIsolated.cpp

00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #include <stdio.h>
00004 #include <math.h>
00005 
00006 #include "CoinPresolveMatrix.hpp"
00007 #include "CoinPresolveIsolated.hpp"
00008 
00009 
00010 // Rarely, there may a constraint whose variables only
00011 // occur in that constraint.
00012 // In this case it is a completely independent problem.
00013 // We should be able to solve it right now.
00014 // Since that is actually not trivial, I'm just going to ignore
00015 // them and stick them back in at postsolve.
00016 const CoinPresolveAction *isolated_constraint_action::presolve(CoinPresolveMatrix *prob,
00017                                                             int irow,
00018                                                             const CoinPresolveAction *next)
00019 {
00020   int *hincol   = prob->hincol_;
00021   const CoinBigIndex *mcstrt    = prob->mcstrt_;
00022   int *hrow     = prob->hrow_;
00023   double *colels        = prob->colels_;
00024 
00025   double *clo   = prob->clo_;
00026   double *cup   = prob->cup_;
00027 
00028   const double *rowels  = prob->rowels_;
00029   const int *hcol       = prob->hcol_;
00030   const CoinBigIndex *mrstrt    = prob->mrstrt_;
00031 
00032   // may be written by useless constraint
00033   int *hinrow   = prob->hinrow_;
00034 
00035   double *rlo   = prob->rlo_;
00036   double *rup   = prob->rup_;
00037 
00038   CoinBigIndex krs = mrstrt[irow];
00039   CoinBigIndex kre = krs + hinrow[irow];
00040   
00041   double *dcost = prob->cost_;
00042 
00043 #if     DEBUG_PRESOLVE
00044   printf("ISOLATED:  %d - ", irow);
00045   for (CoinBigIndex k = krs; k<kre; ++k)
00046     printf("%d ", hcol[k]);
00047   printf("\n");
00048 #endif
00049 
00050   if (rlo[irow] != 0.0 || rup[irow] != 0.0) {
00051 #if     DEBUG_PRESOLVE
00052     printf("can't handle non-trivial isolated constraints for now\n");
00053 #endif
00054     return NULL;
00055   }
00056   CoinBigIndex k;
00057   for ( k = krs; k<kre; ++k) {
00058     int jcol = hcol[k];
00059     if (clo[jcol] != 0.0 && cup[jcol] != 0.0) {
00060 #if     DEBUG_PRESOLVE
00061       printf("can't handle non-trivial isolated constraints for now\n");
00062 #endif
00063     return NULL;
00064     }
00065   }
00066 
00067   int nc = hinrow[irow];
00068 
00069 #if 0
00070   double tableau = new double[nc];
00071   double sol = new double[nc];
00072   double clo = new double[nc];
00073   double cup = new double[nc];
00074 
00075 
00076   for (int i=0; i<nc; ++i) {
00077     int col = hcol[krs+1];
00078     tableau[i] = rowels[krs+i];
00079     clo[i] = prob->clo[krs+i];
00080     cup[i] = prob->cup[krs+i];
00081 
00082     sol[i] = clo[i];
00083   }
00084 #endif
00085 
00086   // HACK - set costs to 0.0 so empty.cpp doesn't complain
00087   double *costs = new double[nc];
00088   for (k = krs; k<kre; ++k) {
00089     costs[k-krs] = dcost[hcol[k]];
00090     dcost[hcol[k]] = 0.0;
00091   }
00092   
00093   next = new isolated_constraint_action(rlo[irow], rup[irow],
00094                                         irow, nc,
00095                                         copyOfArray(&hcol[krs], nc*sizeof(int)),
00096                                         copyOfArray(&rowels[krs], nc*sizeof(double)),
00097                                         costs,
00098                                         next);
00099 
00100   for ( k=krs; k<kre; k++)
00101     presolve_delete_from_row(hcol[k], irow, mcstrt, hincol, hrow, colels);
00102   hinrow[irow] = 0;
00103 
00104   // just to make things squeeky
00105   rlo[irow] = 0.0;
00106   rup[irow] = 0.0;
00107 
00108   return (next);
00109 }
00110 
00111 const char *isolated_constraint_action::name() const
00112 {
00113   return ("isolated_constraint_action");
00114 }
00115 
00116 void isolated_constraint_action::postsolve(CoinPostsolveMatrix *prob) const
00117 {
00118   double *colels        = prob->colels_;
00119   int *hrow             = prob->hrow_;
00120   CoinBigIndex *mcstrt          = prob->mcstrt_;
00121   int *link             = prob->link_;
00122   int *hincol           = prob->hincol_;
00123   
00124   double *rowduals      = prob->rowduals_;
00125   double *rowacts       = prob->acts_;
00126   double *sol           = prob->sol_;
00127 
00128   CoinBigIndex free_list                = prob->free_list_;
00129 
00130 
00131   // hides fields
00132   double *rlo   = prob->rlo_;
00133   double *rup   = prob->rup_;
00134 
00135   double rowact = 0.0;
00136 
00137   int irow  = this->row_;
00138 
00139   rup[irow] = this->rup_;
00140   rlo[irow] = this->rlo_;
00141   int k;
00142 
00143   for (k=0; k<this->ninrow_; k++) {
00144     int jcol = this->rowcols_[k];
00145 
00146     sol[jcol] = 0.0;    // ONLY ACCEPTED SUCH CONSTRAINTS
00147 
00148     CoinBigIndex kk = free_list;
00149     free_list = link[free_list];
00150 
00151     check_free_list(free_list);
00152 
00153     mcstrt[jcol] = kk;
00154 
00155     //rowact += rowels[k] * sol[jcol];
00156 
00157     colels[kk] = this->rowels_[k];
00158     hrow[kk]   = irow;
00159 
00160     hincol[jcol] = 1;
00161   }
00162 
00163   // ???
00164   prob->setRowStatus(irow,CoinPrePostsolveMatrix::basic);
00165     rowduals[irow] = 0.0;
00166 
00167   rowacts[irow] = rowact;
00168 
00169   prob->free_list_ = free_list;
00170 }
00171 

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