# 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 to record best found feasible solution
    00019 class CouenneRecordBestSol {
    00020
    00021 public:
    00022
    00023   // size of initial domain
    00024   int cardInitDom;
    00025   // vector of length cardInitDom indicating if a variable is integer or not;
    00026   bool *initIsInt;
    00027   // vector of indices of integer variables
    00028   std::vector<int> listInt;
    00029   // copy of initial domain lower bounds
    00030   CouNumber *initDomLb;
    00031   // copy of initial domain upper bounds
    00032   CouNumber *initDomUb;
    00033
    00034   // true if a solution value has been recorded, false otherwise
    00035   bool hasSol;
    00036   // size of vector sol
    00037   int cardSol;
    00038   // if not NULL, recorded solution
    00039   double *sol;
    00040   // recorded value
    00041   double val;
    00042   // recorded maximum violation of a bound, integrality or constraint
    00043   double maxViol;
    00044
    00045   // used by checkNLP2 and for update
    00046   int cardModSol;
    00047   double *modSol;
    00048   double modSolVal;
    00049   double modSolMaxViol;
    00050
    00051 public:
    00053   CouenneRecordBestSol();
    00054
    00056   CouenneRecordBestSol(const CouenneRecordBestSol &other);
    00057
    00059   ~CouenneRecordBestSol();
    00060
    00061   inline int getCardInitDom() const {return cardInitDom;};
    00062   inline bool *getInitIsInt() const {return initIsInt;};
    00063   inline std::vector<int> getListInt() const {return listInt;};
    00064   // set both initIsInt and listInt from the given vector givenIsInt
    00065   void setInitIsInt(const bool *givenIsInt, const int givenCard);
    00066   inline CouNumber *getInitDomLb() const {return initDomLb;};
    00067   void setInitDomLb(const CouNumber *givenLb, const int givenCard);
    00068   inline CouNumber *getInitDomUb() const {return initDomUb;};
    00069   void setInitDomUb(const CouNumber *givenUb, const int givenCard);
    00070
    00071   void setHasSol(const bool givenHasSol);
    00072   inline bool getHasSol() const {return hasSol;};
    00073   void setSol(const double *givenSol, const int givenCard,
    00074               const double givenMaxViol);
    00075   inline int getCardSol() const {return cardSol;};
    00076   void setCardSol(const int givenCard);
    00077   inline double *getSol() const {return sol;};
    00078   inline double getMaxViol() const {return maxViol;};
    00079   void setVal(const double givenVal);
    00080   inline double getVal() {return val;};
    00081
    00082   // record givenSol as best solution if givenVal is smaller
    00083   // than val (or if no solution was recorded previously)
    00084   void update(const double *givenSol, const int givenCard,
    00085               const double givenVal, const double givenMaxViol);
    00086
    00087   // use modSol, modSolVal, modSolMaxViol for updating only if
    00088   // modSolVal is smaller than val (or if no solution was recorded previously)
    00089   void update();
    00090
    00091   // compare given two solutions and set sol, solVal, and maxViol to
    00092   // the best of the two with finite value (< 1e49); return -1 if both have
    00093   // infinite value, return 0 if solA is saved, return 1 if solB is saved
    00094   int compareAndSave(const double *solA, const double solAVal,
    00095                      const double solAMaxViol,
    00096                      const bool solAIsFeas,
    00097                      const double *solB, const double solBVal,
    00098                      const double solBMaxViol,
    00099                      const bool solBIsFeas,
    00100                      const int cardSol,
    00101                      const double precision);
    00102
    00103   inline int getCardModSol() const {return cardModSol;}
    00104   double *getModSol(const int expectedCard);
    00105   inline double getModSolVal() const {return modSolVal;}
    00106   inline double getModSolMaxViol() const {return modSolMaxViol;}
    00107
    00108   // set modSol, modSolVal, and modSolMaxViol to given values; if
    00109   // givenModSol == NULL, only the other two are set
    00110   void setModSol(const double *givenModSol, const int givenModCard,
    00111                  const double givenModVal, const double givenModMaxViol);
    00112
    00113   // print sol, solVal, and maxViol
    00114   void printSol(FILE *fsol) const;
    00115 };
    00116
    00117 }
    00118
    00119 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines