Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneRecordBestSol.hpp
Go to the documentation of this file.
1 // (C) Copyright Francois Margot and Carnegie Mellon University 2011
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License (EPL).
4 //
5 // Authors :
6 // Francois Margot, Tepper School of Business, Carnegie Mellon University,
7 //
8 // Date : 3/31/2011
9 
10 #ifndef RECBESTSOL_H
11 #define RECBESTSOL_H
12 
13 #include "CouenneTypes.hpp"
14 
15 
16 namespace Couenne {
17 
18 // class to record best found feasible solution
20 
21 public:
22 
23  // size of initial domain
25  // vector of length cardInitDom indicating if a variable is integer or not;
26  bool *initIsInt;
27  // vector of indices of integer variables
28  std::vector<int> listInt;
29  // copy of initial domain lower bounds
31  // copy of initial domain upper bounds
33 
34  // true if a solution value has been recorded, false otherwise
35  bool hasSol;
36  // size of vector sol
37  int cardSol;
38  // if not NULL, recorded solution
39  double *sol;
40  // recorded value
41  double val;
42  // recorded maximum violation of a bound, integrality or constraint
43  double maxViol;
44 
45  // used by checkNLP2 and for update
47  double *modSol;
48  double modSolVal;
49  double modSolMaxViol;
50 
51 public:
54 
57 
60 
61  inline int getCardInitDom() const {return cardInitDom;};
62  inline bool *getInitIsInt() const {return initIsInt;};
63  inline std::vector<int> getListInt() const {return listInt;};
64  // set both initIsInt and listInt from the given vector givenIsInt
65  void setInitIsInt(const bool *givenIsInt, const int givenCard);
66  inline CouNumber *getInitDomLb() const {return initDomLb;};
67  void setInitDomLb(const CouNumber *givenLb, const int givenCard);
68  inline CouNumber *getInitDomUb() const {return initDomUb;};
69  void setInitDomUb(const CouNumber *givenUb, const int givenCard);
70 
71  void setHasSol(const bool givenHasSol);
72  inline bool getHasSol() const {return hasSol;};
73  void setSol(const double *givenSol, const int givenCard,
74  const double givenMaxViol);
75  inline int getCardSol() const {return cardSol;};
76  void setCardSol(const int givenCard);
77  inline double *getSol() const {return sol;};
78  inline double getMaxViol() const {return maxViol;};
79  void setVal(const double givenVal);
80  inline double getVal() {return val;};
81 
82  // record givenSol as best solution if givenVal is smaller
83  // than val (or if no solution was recorded previously)
84  void update(const double *givenSol, const int givenCard,
85  const double givenVal, const double givenMaxViol);
86 
87  // use modSol, modSolVal, modSolMaxViol for updating only if
88  // modSolVal is smaller than val (or if no solution was recorded previously)
89  void update();
90 
91  // compare given two solutions and set sol, solVal, and maxViol to
92  // the best of the two with finite value (< 1e49); return -1 if both have
93  // infinite value, return 0 if solA is saved, return 1 if solB is saved
94  int compareAndSave(const double *solA, const double solAVal,
95  const double solAMaxViol,
96  const bool solAIsFeas,
97  const double *solB, const double solBVal,
98  const double solBMaxViol,
99  const bool solBIsFeas,
100  const int cardSol,
101  const double precision);
102 
103  inline int getCardModSol() const {return cardModSol;}
104  double *getModSol(const int expectedCard);
105  inline double getModSolVal() const {return modSolVal;}
106  inline double getModSolMaxViol() const {return modSolMaxViol;}
107 
108  // set modSol, modSolVal, and modSolMaxViol to given values; if
109  // givenModSol == NULL, only the other two are set
110  void setModSol(const double *givenModSol, const int givenModCard,
111  const double givenModVal, const double givenModMaxViol);
112 
113  // print sol, solVal, and maxViol
114  void printSol(FILE *fsol) const;
115 };
116 
117 }
118 
119 #endif
void setHasSol(const bool givenHasSol)
void printSol(FILE *fsol) const
void setSol(const double *givenSol, const int givenCard, const double givenMaxViol)
std::vector< int > getListInt() const
void setInitIsInt(const bool *givenIsInt, const int givenCard)
void setVal(const double givenVal)
void setInitDomLb(const CouNumber *givenLb, const int givenCard)
void setInitDomUb(const CouNumber *givenUb, const int givenCard)
double CouNumber
main number type in Couenne
int compareAndSave(const double *solA, const double solAVal, const double solAMaxViol, const bool solAIsFeas, const double *solB, const double solBVal, const double solBMaxViol, const bool solBIsFeas, const int cardSol, const double precision)
void setModSol(const double *givenModSol, const int givenModCard, const double givenModVal, const double givenModMaxViol)
double * getModSol(const int expectedCard)
void setCardSol(const int givenCard)
~CouenneRecordBestSol()
Destructor.
CouenneRecordBestSol()
Constructor.