AbcNonLinearCost.hpp

Go to the documentation of this file.
00001 /* $Id: AbcNonLinearCost.hpp 2024 2014-03-07 17:18:15Z forrest $ */
00002 // Copyright (C) 2002, International Business Machines
00003 // Corporation and others, Copyright (C) 2012, FasterCoin.  All Rights Reserved.
00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
00005 
00006 #ifndef AbcNonLinearCost_H
00007 #define AbcNonLinearCost_H
00008 
00009 
00010 #include "CoinPragma.hpp"
00011 #include "AbcCommon.hpp"
00012 
00013 class AbcSimplex;
00014 class CoinIndexedVector;
00015 
00033 /* status has original status and current status
00034    0 - below lower so stored is upper
00035    1 - in range
00036    2 - above upper so stored is lower
00037    4 - (for current) - same as original
00038 */
00039 #define CLP_BELOW_LOWER 0
00040 #define CLP_FEASIBLE 1
00041 #define CLP_ABOVE_UPPER 2
00042 #define CLP_SAME 4
00043 #ifndef ClpNonLinearCost_H
00044 inline int originalStatus(unsigned char status)
00045 {
00046   return (status & 15);
00047 }
00048 inline int currentStatus(unsigned char status)
00049 {
00050   return (status >> 4);
00051 }
00052 inline void setOriginalStatus(unsigned char & status, int value)
00053 {
00054   status = static_cast<unsigned char>(status & ~15);
00055   status = static_cast<unsigned char>(status | value);
00056 }
00057 inline void setCurrentStatus(unsigned char &status, int value)
00058 {
00059   status = static_cast<unsigned char>(status & ~(15 << 4));
00060   status = static_cast<unsigned char>(status | (value << 4));
00061 }
00062 inline void setInitialStatus(unsigned char &status)
00063 {
00064   status = static_cast<unsigned char>(CLP_FEASIBLE | (CLP_SAME << 4));
00065 }
00066 inline void setSameStatus(unsigned char &status)
00067 {
00068   status = static_cast<unsigned char>(status & ~(15 << 4));
00069   status = static_cast<unsigned char>(status | (CLP_SAME << 4));
00070 }
00071 #endif
00072 class AbcNonLinearCost  {
00073   
00074 public:
00075   
00078 
00079   AbcNonLinearCost();
00084   AbcNonLinearCost(AbcSimplex * model);
00086   ~AbcNonLinearCost();
00087   // Copy
00088   AbcNonLinearCost(const AbcNonLinearCost&);
00089   // Assignment
00090   AbcNonLinearCost& operator=(const AbcNonLinearCost&);
00092   
00093   
00100   void checkInfeasibilities(double oldTolerance = 0.0);
00104   void checkInfeasibilities(int numberInArray, const int * index);
00111   void checkChanged(int numberInArray, CoinIndexedVector * update);
00118   void goThru(int numberInArray, double multiplier,
00119               const int * index, const double * work,
00120               double * rhs);
00123   void goBack(int numberInArray, const int * index,
00124               double * rhs);
00130   void goBackAll(const CoinIndexedVector * update);
00132   void zapCosts();
00134   void refreshCosts(const double * columnCosts);
00136   void feasibleBounds();
00138   void refresh();
00140   void refreshFromPerturbed(double tolerance);
00144   double setOne(int sequence, double solutionValue);
00148   double setOneBasic(int iRow, double solutionValue);
00152   int setOneOutgoing(int sequence, double &solutionValue);
00154   double nearest(int iRow, double solutionValue);
00158   inline double changeInCost(int /*sequence*/, double alpha) const {
00159     return (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
00160   }
00161   inline double changeUpInCost(int /*sequence*/) const {
00162     return -infeasibilityWeight_;
00163   }
00164   inline double changeDownInCost(int /*sequence*/) const {
00165     return infeasibilityWeight_;
00166   }
00168   inline double changeInCost(int iRow, double alpha, double &rhs) {
00169     int sequence=model_->pivotVariable()[iRow];
00170     double returnValue = 0.0;
00171     unsigned char iStatus = status_[sequence];
00172     int iWhere = currentStatus(iStatus);
00173     if (iWhere == CLP_SAME)
00174       iWhere = originalStatus(iStatus);
00175     // rhs always increases
00176     if (iWhere == CLP_FEASIBLE) {
00177       if (alpha > 0.0) {
00178         // going below
00179         iWhere = CLP_BELOW_LOWER;
00180         rhs = COIN_DBL_MAX;
00181       } else {
00182         // going above
00183         iWhere = CLP_ABOVE_UPPER;
00184         rhs = COIN_DBL_MAX;
00185       }
00186     } else if (iWhere == CLP_BELOW_LOWER) {
00187       assert (alpha < 0);
00188       // going feasible
00189       iWhere = CLP_FEASIBLE;
00190       rhs += bound_[sequence] - model_->upperRegion()[sequence];
00191     } else {
00192       assert (iWhere == CLP_ABOVE_UPPER);
00193       // going feasible
00194       iWhere = CLP_FEASIBLE;
00195       rhs += model_->lowerRegion()[sequence] - bound_[sequence];
00196     }
00197     setCurrentStatus(status_[sequence], iWhere);
00198     returnValue = fabs(alpha) * infeasibilityWeight_;
00199     return returnValue;
00200   }
00202   
00203   
00206 
00207   inline int numberInfeasibilities() const {
00208     return numberInfeasibilities_;
00209   }
00211   inline double changeInCost() const {
00212     return changeCost_;
00213   }
00215   inline double feasibleCost() const {
00216     return feasibleCost_;
00217   }
00219   double feasibleReportCost() const;
00221   inline double sumInfeasibilities() const {
00222     return sumInfeasibilities_;
00223   }
00225   inline double largestInfeasibility() const {
00226     return largestInfeasibility_;
00227   }
00229   inline double averageTheta() const {
00230     return averageTheta_;
00231   }
00232   inline void setAverageTheta(double value) {
00233     averageTheta_ = value;
00234   }
00235   inline void setChangeInCost(double value) {
00236     changeCost_ = value;
00237   }
00239 
00240   inline unsigned char * statusArray() const {
00241     return status_;
00242   }
00243   inline int getCurrentStatus(int sequence)
00244   {return (status_[sequence] >> 4);}
00246   void validate();
00248   
00249 private:
00252 
00253   double changeCost_;
00255   double feasibleCost_;
00257   double infeasibilityWeight_;
00259   double largestInfeasibility_;
00261   double sumInfeasibilities_;
00263   double averageTheta_;
00265   int numberRows_;
00267   int numberColumns_;
00269   AbcSimplex * model_;
00271   int numberInfeasibilities_;
00272   // new stuff
00274   unsigned char * status_;
00276   double * bound_;
00278   double * cost_;
00280 };
00281 
00282 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 3 Jun 2015 for Cgl by  doxygen 1.6.1