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