Couenne  0.5.8
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
Couenne::CouenneRecordBestSol::setVal
void setVal(const double givenVal)
Couenne::CouenneRecordBestSol::sol
double * sol
Definition: CouenneRecordBestSol.hpp:39
Couenne::CouenneRecordBestSol::initDomLb
CouNumber * initDomLb
Definition: CouenneRecordBestSol.hpp:30
Couenne::CouenneRecordBestSol::listInt
std::vector< int > listInt
Definition: CouenneRecordBestSol.hpp:28
Couenne::CouenneRecordBestSol::getHasSol
bool getHasSol() const
Definition: CouenneRecordBestSol.hpp:72
Couenne::CouenneRecordBestSol::val
double val
Definition: CouenneRecordBestSol.hpp:41
Couenne::CouenneRecordBestSol::modSolMaxViol
double modSolMaxViol
Definition: CouenneRecordBestSol.hpp:49
Couenne::CouenneRecordBestSol::getVal
double getVal()
Definition: CouenneRecordBestSol.hpp:80
Couenne::CouenneRecordBestSol::getInitIsInt
bool * getInitIsInt() const
Definition: CouenneRecordBestSol.hpp:62
Couenne::CouenneRecordBestSol::maxViol
double maxViol
Definition: CouenneRecordBestSol.hpp:43
Couenne::CouenneRecordBestSol::getInitDomUb
CouNumber * getInitDomUb() const
Definition: CouenneRecordBestSol.hpp:68
Couenne::CouenneRecordBestSol::getCardModSol
int getCardModSol() const
Definition: CouenneRecordBestSol.hpp:103
Couenne
general include file for different compilers
Definition: CouenneAggrProbing.hpp:24
Couenne::CouenneRecordBestSol::cardSol
int cardSol
Definition: CouenneRecordBestSol.hpp:37
Couenne::CouenneRecordBestSol::compareAndSave
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)
Couenne::CouenneRecordBestSol::getMaxViol
double getMaxViol() const
Definition: CouenneRecordBestSol.hpp:78
Couenne::CouenneRecordBestSol
Definition: CouenneRecordBestSol.hpp:19
Couenne::CouenneRecordBestSol::setSol
void setSol(const double *givenSol, const int givenCard, const double givenMaxViol)
Couenne::CouenneRecordBestSol::setModSol
void setModSol(const double *givenModSol, const int givenModCard, const double givenModVal, const double givenModMaxViol)
Couenne::CouenneRecordBestSol::getCardSol
int getCardSol() const
Definition: CouenneRecordBestSol.hpp:75
Couenne::CouNumber
double CouNumber
main number type in Couenne
Definition: CouenneTypes.hpp:100
Couenne::CouenneRecordBestSol::modSol
double * modSol
Definition: CouenneRecordBestSol.hpp:47
Couenne::CouenneRecordBestSol::setInitDomLb
void setInitDomLb(const CouNumber *givenLb, const int givenCard)
Couenne::CouenneRecordBestSol::printSol
void printSol(FILE *fsol) const
Couenne::CouenneRecordBestSol::initDomUb
CouNumber * initDomUb
Definition: CouenneRecordBestSol.hpp:32
Couenne::CouenneRecordBestSol::setCardSol
void setCardSol(const int givenCard)
Couenne::CouenneRecordBestSol::getModSol
double * getModSol(const int expectedCard)
Couenne::CouenneRecordBestSol::getInitDomLb
CouNumber * getInitDomLb() const
Definition: CouenneRecordBestSol.hpp:66
Couenne::CouenneRecordBestSol::hasSol
bool hasSol
Definition: CouenneRecordBestSol.hpp:35
CouenneTypes.hpp
Couenne::CouenneRecordBestSol::setInitDomUb
void setInitDomUb(const CouNumber *givenUb, const int givenCard)
Couenne::CouenneRecordBestSol::getSol
double * getSol() const
Definition: CouenneRecordBestSol.hpp:77
Couenne::CouenneRecordBestSol::setInitIsInt
void setInitIsInt(const bool *givenIsInt, const int givenCard)
Couenne::CouenneRecordBestSol::cardModSol
int cardModSol
Definition: CouenneRecordBestSol.hpp:46
Couenne::CouenneRecordBestSol::~CouenneRecordBestSol
~CouenneRecordBestSol()
Destructor.
Couenne::CouenneRecordBestSol::cardInitDom
int cardInitDom
Definition: CouenneRecordBestSol.hpp:24
Couenne::CouenneRecordBestSol::getModSolMaxViol
double getModSolMaxViol() const
Definition: CouenneRecordBestSol.hpp:106
Couenne::CouenneRecordBestSol::getModSolVal
double getModSolVal() const
Definition: CouenneRecordBestSol.hpp:105
Couenne::CouenneRecordBestSol::modSolVal
double modSolVal
Definition: CouenneRecordBestSol.hpp:48
Couenne::CouenneRecordBestSol::getListInt
std::vector< int > getListInt() const
Definition: CouenneRecordBestSol.hpp:63
Couenne::CouenneRecordBestSol::update
void update()
Couenne::CouenneRecordBestSol::CouenneRecordBestSol
CouenneRecordBestSol()
Constructor.
Couenne::CouenneRecordBestSol::setHasSol
void setHasSol(const bool givenHasSol)
Couenne::CouenneRecordBestSol::getCardInitDom
int getCardInitDom() const
Definition: CouenneRecordBestSol.hpp:61
Couenne::CouenneRecordBestSol::CouenneRecordBestSol
CouenneRecordBestSol(const CouenneRecordBestSol &other)
Copy constructor.
Couenne::CouenneRecordBestSol::update
void update(const double *givenSol, const int givenCard, const double givenVal, const double givenMaxViol)
Couenne::CouenneRecordBestSol::initIsInt
bool * initIsInt
Definition: CouenneRecordBestSol.hpp:26