Dip  0.92.4
DecompVar.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, Lehigh University //
8 // //
9 // Copyright (C) 2002-2007, Lehigh University, Matthew Galati, and Ted Ralphs//
10 // All Rights Reserved. //
11 //===========================================================================//
12 
13 //this is a lambda_s variable
14 //assumption throughout is lambda is {0,1}
15 
16 #ifndef DECOMP_VAR_INCLUDED
17 #define DECOMP_VAR_INCLUDED
18 
19 #include "DecompPortable.h"
20 #include "UtilHash.h"
21 
22 #include <iostream>
23 using namespace std;
24 
25 class DecompApp;
26 
27 // --------------------------------------------------------------------- //
28 class DecompVar {
29 private:
30  DecompVar(const DecompVar&);
31  DecompVar& operator=(const DecompVar&);
32 
33 public:
34  //THINK: or user overriden way to store it (like a tree)
35  //and a function which says expandVarToCol - just as in cuts
36  CoinPackedVector m_s;//this is the var in terms of x-space
37 
38 private:
39  //TODO: lb, ub, "type"?
40  double m_origCost;
41  double m_redCost; //(c - uA'')s - alpha
42  int m_effCnt; //effectiveness counter
43  string m_strHash;
44 
45 public:
46  inline double getOriginalCost() const {
47  return m_origCost;
48  }
49  inline double getReducedCost() const {
50  return m_redCost;
51  }
52  inline double getEffectiveness() const {
53  return m_effCnt;
54  }
55  inline double getLowerBound() const {
56  return 0.0; //TODO
57  }
58  inline double getUpperBound() const {
59  return DecompInf; //TODO
60  }
61  inline string getStrHash() const {
62  return m_strHash;
63  }
64 
65  inline void setReducedCost(const double redCost) {
66  m_redCost = redCost;
67  }
68  bool isEquivalent(const DecompVar& dvar) {
69  return m_s.isEquivalent(dvar.m_s);
70  }
71 
72  void fillDenseArr(int len,
73  double* arr);
74 
75 public:
76  virtual void print(ostream* os = &cout,
77  DecompApp* app = 0) const;
78 
79 public:
80  DecompVar(const vector<int> & ind,
81  const vector<double> & els,
82  const double redCost,
83  const double origCost) :
84  m_s (),
85  m_origCost(origCost),
86  m_redCost (redCost),
87  m_effCnt (0),
88  m_strHash () {
89  if (ind.size() > 0) {
90  m_s.setVector(static_cast<int>(ind.size()),
91  &ind[0], &els[0], DECOMP_TEST_DUPINDEX);
92  m_strHash = UtilCreateStringHash(static_cast<int>(ind.size()),
93  &ind[0], &els[0]);
94  }
95  }
96 
97  DecompVar(const int len,
98  const int* ind,
99  const double* els,
100  const double redCost,
101  const double origCost) :
102  m_s (),
103  m_origCost(origCost),
104  m_redCost (redCost),
105  m_effCnt (0),
106  m_strHash () {
107  if (len > 0) {
108  m_s.setVector(len, ind, els, DECOMP_TEST_DUPINDEX);
109  m_strHash = UtilCreateStringHash(len, ind, els);
110  }
111  }
112 
113  DecompVar(const int denseLen,
114  const double* denseArray,
115  const double redCost,
116  const double origCost) :
117  m_s (DECOMP_TEST_DUPINDEX),
118  m_origCost(origCost),
119  m_redCost (redCost),
120  m_effCnt (0),
121  m_strHash () {
122  UtilPackedVectorFromDense(denseLen, denseArray, DecompEpsilon, m_s);
123 
124  if (m_s.getNumElements() > 0) {
125  m_strHash = UtilCreateStringHash(denseLen, denseArray);
126  }
127  }
128 
129  virtual ~DecompVar() {};
130 };
131 
132 #endif
#define DECOMP_TEST_DUPINDEX
Definition: Decomp.h:339
CoinPackedVector * UtilPackedVectorFromDense(const int len, const double *dense, const double etol)
double getReducedCost() const
Definition: DecompVar.h:49
double getOriginalCost() const
Definition: DecompVar.h:46
DecompVar(const vector< int > &ind, const vector< double > &els, const double redCost, const double origCost)
Definition: DecompVar.h:80
CoinPackedVector m_s
Definition: DecompVar.h:33
double getEffectiveness() const
Definition: DecompVar.h:52
virtual ~DecompVar()
Definition: DecompVar.h:129
void setReducedCost(const double redCost)
Definition: DecompVar.h:65
const double DecompEpsilon
Definition: Decomp.h:100
double getUpperBound() const
Definition: DecompVar.h:58
string getStrHash() const
Definition: DecompVar.h:61
DecompVar(const int len, const int *ind, const double *els, const double redCost, const double origCost)
Definition: DecompVar.h:97
bool isEquivalent(const DecompVar &dvar)
Definition: DecompVar.h:68
Sparse Vector.
double getLowerBound() const
Definition: DecompVar.h:55
DecompVar(const int denseLen, const double *denseArray, const double redCost, const double origCost)
Definition: DecompVar.h:113
string m_strHash
Definition: DecompVar.h:43
The main application class.
Definition: DecompApp.h:48
string UtilCreateStringHash(const int len, const double *els, const int precision=6)