CouenneRecordBestSol.hpp

Go to the documentation of this file.
00001 // (C) Copyright Francois Margot and Carnegie Mellon University 2011
00002 // All Rights Reserved.
00003 // This code is published under the Eclipse Public License (EPL).
00004 //
00005 // Authors :
00006 // Francois Margot, Tepper School of Business, Carnegie Mellon University,
00007 //
00008 // Date : 3/31/2011
00009 
00010 #ifndef RECBESTSOL_H
00011 #define RECBESTSOL_H
00012 
00013 #include "CouenneTypes.hpp"
00014 
00015 
00016 namespace Couenne {
00017 
00018 class CouenneProblem;
00019 
00020 // class to record best found feasible solution
00021 class CouenneRecordBestSol {
00022 
00023 public:
00024 
00025   // size of initial domain
00026   int cardInitDom;
00027   // vector of length cardInitDom indicating if a variable is integer or not;
00028   bool *initIsInt;
00029   // vector of indices of integer variables
00030   std::vector<int> listInt;
00031   // copy of initial domain lower bounds
00032   CouNumber *initDomLb;
00033   // copy of initial domain upper bounds
00034   CouNumber *initDomUb;
00035 
00036   // true if a solution value has been recorded, false otherwise
00037   bool hasSol;
00038   // size of vector sol
00039   int cardSol;
00040   // if not NULL, recorded solution
00041   double *sol;
00042   // recorded value
00043   double val;
00044   // recorded maximum violation of a bound, integrality or constraint
00045   double maxViol;
00046 
00047   // used by checkNLP2 and for update
00048   int cardModSol;
00049   double *modSol; 
00050   double modSolVal; 
00051   double modSolMaxViol; 
00052 
00053 public:
00055   CouenneRecordBestSol();
00056 
00058   CouenneRecordBestSol(const CouenneRecordBestSol &other);
00059 
00061   ~CouenneRecordBestSol();
00062 
00063   inline int getCardInitDom() const {return cardInitDom;};
00064   inline bool *getInitIsInt() const {return initIsInt;};
00065   inline std::vector<int> getListInt() const {return listInt;};
00066   // set both initIsInt and listInt from the given vector givenIsInt
00067   void setInitIsInt(const bool *givenIsInt, const int givenCard);
00068   inline CouNumber *getInitDomLb() const {return initDomLb;};
00069   void setInitDomLb(const CouNumber *givenLb, const int givenCard);
00070   inline CouNumber *getInitDomUb() const {return initDomUb;};
00071   void setInitDomUb(const CouNumber *givenUb, const int givenCard);
00072 
00073   void setHasSol(const bool givenHasSol);
00074   inline bool getHasSol() const {return hasSol;};
00075   void setSol(const double *givenSol, const int givenCard, 
00076               const double givenMaxViol);
00077   inline int getCardSol() const {return cardSol;};
00078   void setCardSol(const int givenCard);
00079   inline double *getSol() const {return sol;};
00080   inline double getMaxViol() const {return maxViol;};
00081   void setVal(const double givenVal);
00082   inline double getVal() {return val;};
00083 
00084   // record givenSol as best solution if givenVal is smaller
00085   // than val (or if no solution was recorded previously)
00086   void update(const double *givenSol, const int givenCard, 
00087               const double givenVal, const double givenMaxViol);
00088 
00089   // use modSol, modSolVal, modSolMaxViol for updating only if
00090   // modSolVal is smaller than val (or if no solution was recorded previously)
00091   void update();
00092 
00093   // compare given two solutions and set sol, solVal, and maxViol to
00094   // the best of the two with finite value (< 1e49); return -1 if both have
00095   // infinite value, return 0 if solA is saved, return 1 if solB is saved  
00096   int compareAndSave(const double *solA, const double solAVal,
00097                      const double solAMaxViol, 
00098                      const bool solAIsFeas,
00099                      const double *solB, const double solBVal,
00100                      const double solBMaxViol, 
00101                      const bool solBIsFeas,
00102                      const int cardSol,
00103                      const double precision);
00104 
00105   inline int getCardModSol() const {return cardModSol;};
00106   double *getModSol(const int expectedCard);
00107   inline double getModSolVal() const {return modSolVal;};
00108   inline double getModSolMaxViol() const {return modSolMaxViol;};
00109 
00110   // set modSol, modSolVal, and modSolMaxViol to given values; if
00111   // givenModSol == NULL, only the other two are set
00112   void setModSol(const double *givenModSol, const int givenModCard, 
00113                  const double givenModVal, const double givenModMaxViol);
00114 
00115   // print sol, solVal, and maxViol
00116   void printSol(FILE *fsol) const;
00117 };
00118 
00119 }
00120 
00121 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 2 Aug 2012 for Couenne by  doxygen 1.6.1