Dip  0.92.4
AlpsDecompSolution.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 #ifndef AlpsDecompSolution_h
16 #define AlpsDecompSolution_h
17 
18 //===========================================================================//
19 #include "AlpsSolution.h"
20 #include "AlpsDecompModel.h"
21 
22 //===========================================================================//
24 protected:
26  int m_size;
27 
29  double* m_values;
30 
32  double m_quality;
33 
35  const DecompApp* m_app;
36 
37 public:
41  inline const int getSize() const {
42  return m_size;
43  }
44 
46  inline const double* getValues() const {
47  return m_values;
48  }
49 
51  inline const double getQuality() const {
52  return m_quality;
53  }
54 
55 public:
57  AlpsSolution(),
58  m_size (0),
59  m_values (0),
60  m_quality (1e75),
61  m_app (0) {}
62 
63  AlpsDecompSolution(const int size,
64  const double* values,
65  const double quality,
66  const DecompApp* app = NULL,
67  const int depth = -1,
68  const AlpsNodeIndex_t index = -1) :
69  AlpsSolution(index, depth),
70  m_size (size),
71  m_values (0),
72  m_quality (quality),
73  m_app (app) {
74  CoinAssert(m_size > 0);
75  m_values = new double[m_size];
76  CoinAssertHint(m_values, "Error: Out of Memory");
77  memcpy(m_values, values, sizeof(double) * m_size);
78  }
79 
80  virtual ~AlpsDecompSolution() {
82  };
83 
85  virtual void print(std::ostream& os) const {
86  if (m_app) {
87  DecompAlgo* decompAlgo = m_app->getDecompAlgo();
88  DecompConstraintSet* modelCore
89  = decompAlgo->getModelCore().getModel();
91  modelCore->getColNames(),
92  m_values);
93  }
94 
95  /*int i;
96  os << setiosflags(ios::fixed|ios::showpoint)
97  << setw(14);
98 
99  os << "-------------------------" << endl;
100  os << "Quality = " << getQuality() << endl;
101  for (i = 0; i < m_size; i++) {
102  if (!UtilIsZero(m_values[i])){
103  os << setw(6) << i << " " << m_values[i] << endl;
104  }
105  }
106  os << "-------------------------" << endl;
107  os << resetiosflags(ios::fixed|ios::showpoint|ios::scientific); */
108  }
109 };
110 
111 #endif
const int getSize() const
Get length of solution.
virtual void print(std::ostream &os) const
Print out the solution.
virtual ~AlpsDecompSolution()
Get length of solution.
DecompConstraintSet * getModel() const
Definition: DecompModel.h:35
const DecompApp * m_app
Pointer to DecompApp for the print function.
AlpsDecompSolution(const int size, const double *values, const double quality, const DecompApp *app=NULL, const int depth=-1, const AlpsNodeIndex_t index=-1)
Get length of solution.
#define UTIL_DELARR(x)
Definition: UtilMacros.h:29
#define CoinAssertHint(expression, hint)
Definition: CoinError.hpp:184
double * m_values
Solution values.
double m_quality
Quality of solution (bound wrt to objective).
const DecompSubModel & getModelCore() const
Get a ptr to the current solution (in x-space).
Definition: DecompAlgo.h:684
DecompAlgo * getDecompAlgo() const
Get a pointer to the base algorithm class.
Definition: DecompApp.h:256
int AlpsNodeIndex_t
Definition: AlpsTreeNode.h:37
int m_size
Length of solution (number of columns).
const std::vector< std::string > & getColNames() const
const double * getValues() const
Get solution values.
virtual void printOriginalSolution(const int n_cols, const std::vector< std::string > &colNames, const double *solution, std::ostream *os=&std::cout) const
Initialize the dual vector for PhaseII of PC.
#define CoinAssert(expression)
Definition: CoinError.hpp:183
Base class for DECOMP algorithms.
Definition: DecompAlgo.h:62
The main application class.
Definition: DecompApp.h:48
AlpsDecompSolution()
Get length of solution.
const double getQuality() const
Get quality of solution.