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

ClpPrimalColumnDantzig.cpp

00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 
00004 #include "CoinPragma.hpp"
00005 
00006 #include <cstdio>
00007 
00008 #include "CoinIndexedVector.hpp"
00009 
00010 #include "ClpSimplex.hpp"
00011 #include "ClpPrimalColumnDantzig.hpp"
00012 #include "ClpFactorization.hpp"
00013 #include "ClpPackedMatrix.hpp"
00014 
00015 //#############################################################################
00016 // Constructors / Destructor / Assignment
00017 //#############################################################################
00018 
00019 //-------------------------------------------------------------------
00020 // Default Constructor 
00021 //-------------------------------------------------------------------
00022 ClpPrimalColumnDantzig::ClpPrimalColumnDantzig () 
00023 : ClpPrimalColumnPivot()
00024 {
00025   type_=1;
00026 }
00027 
00028 //-------------------------------------------------------------------
00029 // Copy constructor 
00030 //-------------------------------------------------------------------
00031 ClpPrimalColumnDantzig::ClpPrimalColumnDantzig (const ClpPrimalColumnDantzig & source) 
00032 : ClpPrimalColumnPivot(source)
00033 {  
00034 
00035 }
00036 
00037 //-------------------------------------------------------------------
00038 // Destructor 
00039 //-------------------------------------------------------------------
00040 ClpPrimalColumnDantzig::~ClpPrimalColumnDantzig ()
00041 {
00042 
00043 }
00044 
00045 //----------------------------------------------------------------
00046 // Assignment operator 
00047 //-------------------------------------------------------------------
00048 ClpPrimalColumnDantzig &
00049 ClpPrimalColumnDantzig::operator=(const ClpPrimalColumnDantzig& rhs)
00050 {
00051   if (this != &rhs) {
00052     ClpPrimalColumnPivot::operator=(rhs);
00053   }
00054   return *this;
00055 }
00056 
00057 // Returns pivot column, -1 if none
00058 int 
00059 ClpPrimalColumnDantzig::pivotColumn(CoinIndexedVector * updates,
00060                                     CoinIndexedVector * spareRow1,
00061                                     CoinIndexedVector * spareRow2,
00062                                     CoinIndexedVector * spareColumn1,
00063                                     CoinIndexedVector * spareColumn2)
00064 {
00065   assert(model_);
00066   int iSection,j;
00067   int number;
00068   int * index;
00069   double * updateBy;
00070   double * reducedCost;
00071 
00072   bool anyUpdates;
00073 
00074   if (updates->getNumElements()) {
00075     anyUpdates=true;
00076   } else {
00077     // sub flip - nothing to do
00078     anyUpdates=false;
00079   }
00080   if (anyUpdates) {
00081     model_->factorization()->updateColumnTranspose(spareRow2,updates);
00082     // put row of tableau in rowArray and columnArray
00083     model_->clpMatrix()->transposeTimes(model_,-1.0,
00084                                         updates,spareColumn2,spareColumn1);
00085     for (iSection=0;iSection<2;iSection++) {
00086       
00087       reducedCost=model_->djRegion(iSection);
00088       
00089       if (!iSection) {
00090         number = updates->getNumElements();
00091         index = updates->getIndices();
00092         updateBy = updates->denseVector();
00093       } else {
00094         number = spareColumn1->getNumElements();
00095         index = spareColumn1->getIndices();
00096         updateBy = spareColumn1->denseVector();
00097       }
00098       
00099       for (j=0;j<number;j++) {
00100         int iSequence = index[j];
00101         double value = reducedCost[iSequence];
00102         value -= updateBy[j];
00103         updateBy[j]=0.0;
00104         reducedCost[iSequence] = value;
00105       }
00106       
00107     }
00108     updates->setNumElements(0);
00109     spareColumn1->setNumElements(0);
00110   }
00111 
00112 
00113   // update of duals finished - now do pricing
00114 
00115   double largest=model_->currentPrimalTolerance();
00116   // we can't really trust infeasibilities if there is primal error
00117   if (model_->largestDualError()>1.0e-8)
00118     largest *= model_->largestDualError()/1.0e-8;
00119 
00120   
00121 
00122   double bestDj = model_->dualTolerance();
00123   int bestSequence=-1;
00124 
00125   double bestFreeDj = model_->dualTolerance();
00126   int bestFreeSequence=-1;
00127   
00128   number = model_->numberRows()+model_->numberColumns();
00129   int iSequence;
00130   reducedCost=model_->djRegion();
00131 
00132   for (iSequence=0;iSequence<number;iSequence++) {
00133     // check flagged variable
00134     if (!model_->flagged(iSequence)) {
00135       double value = reducedCost[iSequence];
00136       ClpSimplex::Status status = model_->getStatus(iSequence);
00137       
00138       switch(status) {
00139 
00140       case ClpSimplex::basic:
00141       case ClpSimplex::isFixed:
00142         break;
00143       case ClpSimplex::isFree:
00144       case ClpSimplex::superBasic:
00145         if (fabs(value)>bestFreeDj) { 
00146           bestFreeDj = fabs(value);
00147           bestFreeSequence = iSequence;
00148         }
00149         break;
00150       case ClpSimplex::atUpperBound:
00151         if (value>bestDj) {
00152           bestDj = value;
00153           bestSequence = iSequence;
00154         }
00155         break;
00156       case ClpSimplex::atLowerBound:
00157         if (value<-bestDj) {
00158           bestDj = -value;
00159           bestSequence = iSequence;
00160         }
00161       }
00162     }
00163   }
00164   // bias towards free
00165   if (bestFreeSequence>=0&&bestFreeDj > 0.1*bestDj) 
00166     bestSequence = bestFreeSequence;
00167   return bestSequence;
00168 }
00169   
00170 //-------------------------------------------------------------------
00171 // Clone
00172 //-------------------------------------------------------------------
00173 ClpPrimalColumnPivot * ClpPrimalColumnDantzig::clone(bool CopyData) const
00174 {
00175   if (CopyData) {
00176     return new ClpPrimalColumnDantzig(*this);
00177   } else {
00178     return new ClpPrimalColumnDantzig();
00179   }
00180 }
00181 

Generated on Wed Dec 3 14:37:30 2003 for CLP by doxygen 1.3.5