Dip  0.92.4
DecompSolution.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 #ifndef DECOMP_SOLUTION_INCLUDED
14 #define DECOMP_SOLUTION_INCLUDED
15 
16 class DecompSolution {
17 protected:
19  int m_size;
20 
22  double* m_values;
23 
25  double m_quality;
26 
27 public:
31  inline const int getSize() const {
32  return m_size;
33  }
34 
36  inline const double* getValues() const {
37  return m_values;
38  }
39 
41  inline const double getQuality() const {
42  return m_quality;
43  }
44 
45 public:
46  virtual void print(ostream& os = cout) const {
47  int i;
48  os << setiosflags(ios::fixed | ios::showpoint)
49  << setw(14);
50  os << "-------------------------" << endl;
51 
52  for (i = 0; i < m_size; i++) {
53  if (!UtilIsZero(m_values[i])) {
54  os << setw(6) << i << " " << m_values[i] << endl;
55  }
56  }
57 
58  os << "-------------------------" << endl;
59  os << resetiosflags(ios::fixed | ios::showpoint | ios::scientific);
60  }
61 
62 public:
64  DecompSolution(const DecompSolution& source) :
65  m_size(source.m_size),
66  m_values(0),
67  m_quality(source.m_quality) {
68  m_values = new double[m_size];
69  CoinAssertHint(m_values, "Error: Out of Memory");
70  memcpy(m_values, source.m_values, m_size * sizeof(double));
71  }
73  if (this != &rhs) {
74  m_size = rhs.m_size;
75  m_quality = rhs.m_quality;
76  m_values = new double[m_size];
77  CoinAssertHint(m_values, "Error: Out of Memory");
78  memcpy(m_values, rhs.m_values, m_size * sizeof(double));
79  }
80 
81  return *this;
82  }
83 
84 public:
89  m_size(0),
90  m_values(0),
91  m_quality(DecompInf) {
92  }
93 
95  DecompSolution(const int size,
96  const double* values,
97  const double quality) :
98  m_size(size),
99  m_values(0),
100  m_quality(quality) {
101  CoinAssert(m_size > 0);
102  m_values = new double[m_size];
103  CoinAssertHint(m_values, "Error: Out of Memory");
104  memcpy(m_values, values, m_size * sizeof(double));
105  }
106 
107  virtual ~DecompSolution() {
109  };
110 };
111 
112 #endif
const double * getValues() const
Get solution values.
double * m_values
Solution values.
bool UtilIsZero(const double x, const double etol=1.0e-8)
Definition: UtilMacros.h:272
virtual ~DecompSolution()
Default constructor.
int m_size
Length of solution (number of columns).
const int getSize() const
Get length of solution.
double m_quality
Quality of solution (bound wrt to objective).
virtual void print(ostream &os=cout) const
Get length of solution.
#define UTIL_DELARR(x)
Definition: UtilMacros.h:29
DecompSolution(const int size, const double *values, const double quality)
Constructor.
#define CoinAssertHint(expression, hint)
Definition: CoinError.hpp:184
DecompSolution & operator=(const DecompSolution &rhs)
const double getQuality() const
Get quality of solution.
DecompSolution(const DecompSolution &source)
#define CoinAssert(expression)
Definition: CoinError.hpp:183
DecompSolution()
Default constructor.