Dip  0.92.4
DecompCutOsi.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_CUTOSI_HPP
17 #define DECOMP_CUTOSI_HPP
18 
19 
20 #include "UtilHash.h"
21 #include "DecompCut.h"
22 #include "OsiRowCut.hpp"
23 
24 //THINK:
25 //why?? if we really want to be able to let the user use OsiRowCut's
26 //then just make this public OsiRowCut or something... then need multiple
27 //inheritance? how does ABC do?
28 
29 //really want a generic cut implementation here...
30 //or just use osi?
31 
32 
33 class DecompCutOsi : public DecompCut {
34 private:
35  DecompCutOsi(const DecompVar&);
37 
38 private:
40  /* THINK: seems a waste to have to copy construct the OsiRowCut, a pointer
41  should be enough - but error on pure virtual */
42  /* at least make it a pointer to OsiRowCut? */
43 public:
44  //is this an expensive operation?
45  //temp fix
46  char sense(double infinity) const {
47  double lb_ = m_osiCut.lb();
48  double ub_ = m_osiCut.ub();
49 
50  if ( lb_ == ub_ ) {
51  return 'E';
52  } else if ( lb_ == -infinity && ub_ == infinity ) {
53  return 'N';
54  } else if ( lb_ == -infinity ) {
55  return 'L';
56  } else if ( ub_ == infinity ) {
57  return 'G';
58  } else {
59  return 'R';
60  }
61  }
62 
63  double rhs(double infinity) const {
64  double lb_ = m_osiCut.lb();
65  double ub_ = m_osiCut.ub();
66 
67  if ( lb_ == ub_ ) {
68  return ub_;
69  } else if ( lb_ == -infinity && ub_ == infinity ) {
70  return 0.0;
71  } else if ( lb_ == -infinity ) {
72  return ub_;
73  } else if ( ub_ == infinity ) {
74  return lb_;
75  } else {
76  return ub_;
77  }
78  }
79 
80  void setStringHash(double infinity) {
81  //we cannot trust osi row cuts sense, since cpx and clp have different infinities...
85  //m_osiCut.sense(),
86  sense(infinity),
87  //m_osiCut.rhs()
88  rhs(infinity),
89  infinity
90  );
91  //ranges?
92  }
93  void setStringHash(CoinPackedVector* row, double infinity) {
95  row->getIndices(),
96  row->getElements(),
97  //m_osiCut.sense(),
98  sense(infinity),
99  //m_osiCut.rhs()
100  rhs(infinity),
101  infinity
102  );
103  //ranges?
104  }
105 
106  void setBounds() {
109  }
110 
111  //think about when is this used?
114  m_osiCut.row().getIndices(),
117  /* TODO: tests for dups by default - shut this off for production */
118  }
119 
120 public:
121  void print(std::ostream* os = &std::cout) const {
122  (*os).precision(2);
123  (*os) << std::endl;
124  const int* ind = m_osiCut.row().getIndices();
125  const double* els = m_osiCut.row().getElements();
126 
127  for (int i = 0; i < m_osiCut.row().getNumElements(); i++) {
128  (*os) << " + " << els[i] << " x[" << ind[i] << "]";
129  }
130 
131  if (getLowerBound() < -1.0e10 / 2) { //INF?
132  (*os) << " lb: -INF";
133  } else {
134  (*os) << " lb: " << getLowerBound();
135  }
136 
137  if (getUpperBound() > 1.0e10 / 2) { //INF?
138  (*os) << " ub: INF";
139  } else {
140  (*os) << " ub: " << getUpperBound();
141  }
142 
143  (*os) << " vio: " << getViolation() << "\n";
144  }
145 
146 public:
148  : DecompCut(), m_osiCut(osiCut) {
149  setBounds();
150  };
151  virtual ~DecompCutOsi() {}
152 
153 };
154 
155 #endif
#define DECOMP_TEST_DUPINDEX
Definition: Decomp.h:339
OsiRowCut m_osiCut
Definition: DecompCutOsi.h:39
Row Cut Class.
Definition: OsiRowCut.hpp:29
double getUpperBound() const
Definition: DecompCut.h:50
virtual const int * getIndices() const
Get indices of elements.
void setBounds()
Definition: DecompCutOsi.h:106
virtual const double * getElements() const
Get element values.
void setVector(int size, const int *inds, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set vector size, indices, and elements.
DecompCutOsi(const DecompVar &)
std::string m_strHash
Definition: DecompCut.h:43
OsiRowCut_inline double lb() const
Get lower bound.
virtual int getNumElements() const
Get the size.
OsiRowCut_inline const CoinPackedVector & row() const
Get row elements.
DecompCutOsi(OsiRowCut &osiCut)
Definition: DecompCutOsi.h:147
OsiRowCut_inline double ub() const
Get upper bound.
void print(std::ostream *os=&std::cout) const
Definition: DecompCutOsi.h:121
void setUpperBound(const double ub)
Definition: DecompCut.h:67
void setStringHash(double infinity)
Definition: DecompCutOsi.h:80
char sense(double infinity) const
Definition: DecompCutOsi.h:46
virtual ~DecompCutOsi()
Definition: DecompCutOsi.h:151
void expandCutToRow(CoinPackedVector *row)
Definition: DecompCutOsi.h:112
double getLowerBound() const
Definition: DecompCut.h:47
DecompCutOsi & operator=(const DecompVar &)
char sense() const
Definition: DecompCutOsi.h:44
void setStringHash(CoinPackedVector *row, double infinity)
Definition: DecompCutOsi.h:93
Sparse Vector.
double rhs(double infinity) const
Definition: DecompCutOsi.h:63
void setLowerBound(const double lb)
Definition: DecompCut.h:64
double rhs() const
Definition: DecompCutOsi.h:61
string UtilCreateStringHash(const int len, const double *els, const int precision=6)
double getViolation() const
Definition: DecompCut.h:53