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