Dip  0.92.4
DecompCut.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the DIP Solver Framework. //
3 // //
4 // DIP is distributed under the Eclipse Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Authors: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // Ted Ralphs, Lehigh University (ted@lehigh.edu) //
9 // Jiadong Wang, Lehigh University (jiw408@lehigh.edu) //
10 // //
11 // Copyright (C) 2002-2019, Lehigh University, Matthew Galati, Ted Ralphs //
12 // All Rights Reserved. //
13 //===========================================================================//
14 
15 
16 #ifndef DECOMP_CUT_INCLUDED
17 #define DECOMP_CUT_INCLUDED
18 
19 //a cut in terms of the original x variables
20 
21 //by default it could look for OSI-CGL cuts? for CP procedures
22 //or the user can provide its own cut generator - force them to return
23 //a common cut structure?
24 
25 //the user might have some compact way to store its cut, for example
26 //with TSP cuts, they just want to store the customer set, and then
27 //they override a function called expandCutToRow which tells this base
28 //class how to expand into the LP
29 
30 #include "Decomp.h"
31 #include "UtilHash.h"
32 #include "UtilMacros.h"
33 
34 class DecompCut {
35 private:
36  double m_lb; //row lower bound
37  double m_ub; //row upper bound
38  //THINK, or they can stick in as sense/rhs
39  double m_violation; //current violation
40  int m_effCnt; //effectiveness counter
41 
42 protected:
43  std::string m_strHash;
44  //TODO - use distance instead of violation? see SAS
45 
46 public:
47  inline double getLowerBound() const {
48  return m_lb;
49  }
50  inline double getUpperBound() const {
51  return m_ub;
52  }
53  inline double getViolation() const {
54  return m_violation;
55  }
56  inline int getEffCnt() const {
57  return m_effCnt;
58  }
59  inline std::string getStrHash() const {
60  return m_strHash;
61  }
62 
63 public:
64  inline void setLowerBound(const double lb) {
65  m_lb = lb;
66  }
67  inline void setUpperBound(const double ub) {
68  m_ub = ub;
69  }
70  inline void setViolation(const double violation) {
71  m_violation = violation;
72  }
73 
74  bool calcViolation(const CoinPackedVector* row,
75  const double* x);
76 
77 public:
78  //but these should be optional to user! after they show us how to
79  //expandCutToRow... then we should be able to handle the hashing and
80  //checking isSame, etc... the user can override it, if they can do it
81  //faster - but we should not force them
82 
83  //now it is essentially a DecompCutOsi
84  virtual void setStringHash(CoinPackedVector* row, double infinity) {
85  //the user can override this if they can do it faster... also
86  //should link up with isSame
87  char sense;
88  double rhs, range;
90  getUpperBound(), infinity,
91  sense, rhs, range);
93  row->getIndices(),
94  row->getElements(),
95  sense, rhs, infinity);
96  //need backup for user
97  //throw CoinError("Method was invoked but not overridden.",
98  // "setStringHash", "DecompCut");1
99  }
100 
101  virtual void expandCutToRow(CoinPackedVector* row) {
102  throw CoinError("Method was invoked but not overridden.",
103  "expandCutToRow", "DecompCut");
104  }
105 
106  virtual void setBounds() {
107  throw CoinError("Method was invoked but not overridden.",
108  "setBounds", "DecompCut");
109  }
110 
111  virtual bool isSame(const DecompCut* cut) const {
112  return false;
113  }
114 
115  virtual void print(std::ostream* os = &std::cout) const;
116 
117 public:
118  inline void resetEffCnt() {
119  m_effCnt = 0;
120  }
121 
124  inline void increaseEffCnt() {
125  m_effCnt = m_effCnt <= 0 ? 1 : m_effCnt + 1;
126  }
127 
130  inline void decreaseEffCnt() {
131  m_effCnt = m_effCnt >= 0 ? -1 : m_effCnt - 1;
132  }
133 
134 public:
136  m_lb (0.0),
137  m_ub (0.0),
138  m_violation(0.0),
139  m_effCnt (0),
140  m_strHash () {
141  };
142  virtual ~DecompCut() {};
143 
144 };
145 
146 #endif
void setViolation(const double violation)
Definition: DecompCut.h:70
double m_violation
Definition: DecompCut.h:39
virtual ~DecompCut()
Definition: DecompCut.h:142
virtual void setStringHash(CoinPackedVector *row, double infinity)
Definition: DecompCut.h:84
double m_ub
Definition: DecompCut.h:37
void increaseEffCnt()
Increase the effectiveness count by 1 (or to 1 if it was negative).
Definition: DecompCut.h:124
double getUpperBound() const
Definition: DecompCut.h:50
virtual const int * getIndices() const
Get indices of elements.
std::string getStrHash() const
Definition: DecompCut.h:59
virtual const double * getElements() const
Get element values.
double m_lb
Definition: DecompCut.h:36
void UtilBoundToSense(const double lb, const double ub, const double inf, char &sense, double &rhs, double &range)
Definition: UtilMacros.h:405
virtual void print(std::ostream *os=&std::cout) const
void resetEffCnt()
Definition: DecompCut.h:118
std::string m_strHash
Definition: DecompCut.h:43
virtual int getNumElements() const
Get the size.
virtual void expandCutToRow(CoinPackedVector *row)
Definition: DecompCut.h:101
void setUpperBound(const double ub)
Definition: DecompCut.h:67
virtual void setBounds()
Definition: DecompCut.h:106
double getLowerBound() const
Definition: DecompCut.h:47
int getEffCnt() const
Definition: DecompCut.h:56
void decreaseEffCnt()
Decrease the effectiveness count by 1 (or to -1 if it was positive).
Definition: DecompCut.h:130
int m_effCnt
Definition: DecompCut.h:40
Error Class thrown by an exception.
Definition: CoinError.hpp:42
Sparse Vector.
void setLowerBound(const double lb)
Definition: DecompCut.h:64
virtual bool isSame(const DecompCut *cut) const
Definition: DecompCut.h:111
bool calcViolation(const CoinPackedVector *row, const double *x)
string UtilCreateStringHash(const int len, const double *els, const int precision=6)
double getViolation() const
Definition: DecompCut.h:53