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