Dip 0.95.0
Loading...
Searching...
No Matches
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
34class DecompCut {
35private:
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
42protected:
43 std::string m_strHash;
44 //TODO - use distance instead of violation? see SAS
45
46public:
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
63public:
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
75 const double* x);
76
77public:
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
117public:
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
134public:
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
std::string UtilCreateStringHash(const int len, const double *els, const int precision=6)
void UtilBoundToSense(const double lb, const double ub, const double inf, char &sense, double &rhs, double &range)
Definition: UtilMacros.h:785
virtual const double * getElements() const
virtual int getNumElements() const
virtual const int * getIndices() const
bool calcViolation(const CoinPackedVector *row, const double *x)
virtual void print(std::ostream *os=&std::cout) const
virtual void setBounds()
Definition: DecompCut.h:106
virtual void setStringHash(CoinPackedVector *row, double infinity)
Definition: DecompCut.h:84
std::string getStrHash() const
Definition: DecompCut.h:59
int getEffCnt() const
Definition: DecompCut.h:56
double getLowerBound() const
Definition: DecompCut.h:47
std::string m_strHash
Definition: DecompCut.h:43
virtual ~DecompCut()
Definition: DecompCut.h:142
virtual bool isSame(const DecompCut *cut) const
Definition: DecompCut.h:111
void resetEffCnt()
Definition: DecompCut.h:118
void decreaseEffCnt()
Decrease the effectiveness count by 1 (or to -1 if it was positive).
Definition: DecompCut.h:130
double getUpperBound() const
Definition: DecompCut.h:50
void setUpperBound(const double ub)
Definition: DecompCut.h:67
virtual void expandCutToRow(CoinPackedVector *row)
Definition: DecompCut.h:101
void setLowerBound(const double lb)
Definition: DecompCut.h:64
void setViolation(const double violation)
Definition: DecompCut.h:70
void increaseEffCnt()
Increase the effectiveness count by 1 (or to 1 if it was negative).
Definition: DecompCut.h:124
double getViolation() const
Definition: DecompCut.h:53