# AbcNonLinearCost.hpp

Go to the documentation of this file.

    00001 /* $Id: AbcNonLinearCost.hpp 1910 2013-01-27 02:00:13Z stefan $ */
    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 inline int originalStatus(unsigned char status)
    00044 {
    00045   return (status & 15);
    00046 }
    00047 inline int currentStatus(unsigned char status)
    00048 {
    00049   return (status >> 4);
    00050 }
    00051 inline void setOriginalStatus(unsigned char & status, int value)
    00052 {
    00053   status = static_cast<unsigned char>(status & ~15);
    00054   status = static_cast<unsigned char>(status | value);
    00055 }
    00056 inline void setCurrentStatus(unsigned char &status, int value)
    00057 {
    00058   status = static_cast<unsigned char>(status & ~(15 << 4));
    00059   status = static_cast<unsigned char>(status | (value << 4));
    00060 }
    00061 inline void setInitialStatus(unsigned char &status)
    00062 {
    00063   status = static_cast<unsigned char>(CLP_FEASIBLE | (CLP_SAME << 4));
    00064 }
    00065 inline void setSameStatus(unsigned char &status)
    00066 {
    00067   status = static_cast<unsigned char>(status & ~(15 << 4));
    00068   status = static_cast<unsigned char>(status | (CLP_SAME << 4));
    00069 }
    00070 class AbcNonLinearCost  {
    00071
    00072 public:
    00073
    00076
    00077   AbcNonLinearCost();
    00082   AbcNonLinearCost(AbcSimplex * model);
    00084   ~AbcNonLinearCost();
    00085   // Copy
    00086   AbcNonLinearCost(const AbcNonLinearCost&);
    00087   // Assignment
    00088   AbcNonLinearCost& operator=(const AbcNonLinearCost&);
    00090
    00091
    00098   void checkInfeasibilities(double oldTolerance = 0.0);
    00102   void checkInfeasibilities(int numberInArray, const int * index);
    00109   void checkChanged(int numberInArray, CoinIndexedVector * update);
    00116   void goThru(int numberInArray, double multiplier,
    00117               const int * index, const double * work,
    00118               double * rhs);
    00121   void goBack(int numberInArray, const int * index,
    00122               double * rhs);
    00128   void goBackAll(const CoinIndexedVector * update);
    00130   void zapCosts();
    00132   void refreshCosts(const double * columnCosts);
    00134   void feasibleBounds();
    00136   void refresh();
    00138   void refreshFromPerturbed(double tolerance);
    00142   double setOne(int sequence, double solutionValue);
    00146   double setOneBasic(int iRow, double solutionValue);
    00150   int setOneOutgoing(int sequence, double &solutionValue);
    00152   double nearest(int iRow, double solutionValue);
    00156   inline double changeInCost(int /*sequence*/, double alpha) const {
    00157     return (alpha > 0.0) ? infeasibilityWeight_ : -infeasibilityWeight_;
    00158   }
    00159   inline double changeUpInCost(int /*sequence*/) const {
    00160     return -infeasibilityWeight_;
    00161   }
    00162   inline double changeDownInCost(int /*sequence*/) const {
    00163     return infeasibilityWeight_;
    00164   }
    00166   inline double changeInCost(int iRow, double alpha, double &rhs) {
    00167     int sequence=model_->pivotVariable()[iRow];
    00168     double returnValue = 0.0;
    00169     unsigned char iStatus = status_[sequence];
    00170     int iWhere = currentStatus(iStatus);
    00171     if (iWhere == CLP_SAME)
    00172       iWhere = originalStatus(iStatus);
    00173     // rhs always increases
    00174     if (iWhere == CLP_FEASIBLE) {
    00175       if (alpha > 0.0) {
    00176         // going below
    00177         iWhere = CLP_BELOW_LOWER;
    00178         rhs = COIN_DBL_MAX;
    00179       } else {
    00180         // going above
    00181         iWhere = CLP_ABOVE_UPPER;
    00182         rhs = COIN_DBL_MAX;
    00183       }
    00184     } else if (iWhere == CLP_BELOW_LOWER) {
    00185       assert (alpha < 0);
    00186       // going feasible
    00187       iWhere = CLP_FEASIBLE;
    00188       rhs += bound_[sequence] - model_->upperRegion()[sequence];
    00189     } else {
    00190       assert (iWhere == CLP_ABOVE_UPPER);
    00191       // going feasible
    00192       iWhere = CLP_FEASIBLE;
    00193       rhs += model_->lowerRegion()[sequence] - bound_[sequence];
    00194     }
    00195     setCurrentStatus(status_[sequence], iWhere);
    00196     returnValue = fabs(alpha) * infeasibilityWeight_;
    00197     return returnValue;
    00198   }
    00200
    00201
    00204
    00205   inline int numberInfeasibilities() const {
    00206     return numberInfeasibilities_;
    00207   }
    00209   inline double changeInCost() const {
    00210     return changeCost_;
    00211   }
    00213   inline double feasibleCost() const {
    00214     return feasibleCost_;
    00215   }
    00217   double feasibleReportCost() const;
    00219   inline double sumInfeasibilities() const {
    00220     return sumInfeasibilities_;
    00221   }
    00223   inline double largestInfeasibility() const {
    00224     return largestInfeasibility_;
    00225   }
    00227   inline double averageTheta() const {
    00228     return averageTheta_;
    00229   }
    00230   inline void setAverageTheta(double value) {
    00231     averageTheta_ = value;
    00232   }
    00233   inline void setChangeInCost(double value) {
    00234     changeCost_ = value;
    00235   }
    00237
    00238   inline unsigned char * statusArray() const {
    00239     return status_;
    00240   }
    00241   inline int getCurrentStatus(int sequence)
    00242   {return (status_[sequence] >> 4);}
    00244   void validate();
    00246
    00247 private:
    00250
    00251   double changeCost_;
    00253   double feasibleCost_;
    00255   double infeasibilityWeight_;
    00257   double largestInfeasibility_;
    00259   double sumInfeasibilities_;
    00261   double averageTheta_;
    00263   int numberRows_;
    00265   int numberColumns_;
    00267   AbcSimplex * model_;
    00269   int numberInfeasibilities_;
    00270   // new stuff
    00272   unsigned char * status_;
    00274   double * bound_;
    00276   double * cost_;
    00278 };
    00279
    00280 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines