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