BcpsSolution.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Branch, Constrain and Price Software (BiCePS) *
3  * *
4  * BiCePS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Ted Ralphs, Lehigh University *
11  * *
12  * Conceptual Design: *
13  * *
14  * Yan Xu, Lehigh University *
15  * Ted Ralphs, Lehigh University *
16  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17  * Matthew Saltzman, Clemson University *
18  * *
19  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
20  * All Rights Reserved. *
21  *===========================================================================*/
22 
23 #ifndef BcpsSolution_h_
24 #define BcpsSolution_h_
25 
26 #include "AlpsSolution.h"
27 #include "BcpsObject.h"
28 
29 //#############################################################################
32 //#############################################################################
33 
34 class BcpsSolution : public AlpsSolution {
35 
36  private:
37 
38  BcpsSolution(const BcpsSolution&);
40 
41  protected:
42 
44  int size_;
45 
48 
50  double* values_;
51 
53  double quality_;
54 
55  public:
56 
59  :
60  size_(0), objects_(NULL), values_(NULL), quality_(ALPS_OBJ_MAX)
61  {}
62 
64  BcpsSolution(int size, const double *values, double q)
65  :
66  size_(size), objects_(NULL), values_(NULL), quality_(q) {
67 
68  if (size > 0) {
69  values_ = new double [size];
70  memcpy(values_, values, sizeof(double) * size);
71  }
72  else {
73  std::cout << "ERROR: Solution size = " << size << std::endl;
74  assert(size > 0);
75  }
76  }
77 
80  BcpsSolution(int size, BcpsObject_p*& objects, double*& values, double q)
81  :
82  size_(size), objects_(objects), values_(values), quality_(q) {
83  objects = NULL;
84  values = NULL;
85  }
86 
88  virtual ~BcpsSolution() {
89  if (objects_) {
90  for (int i = 0; i < size_; ++i) {
91  delete objects_[i];
92  }
93  delete[] objects_;
94  }
95  delete[] values_;
96  }
97 
100  inline int getSize() const { return size_; }
101  inline const BcpsObject_p* getObjects() const { return objects_; }
102  inline const double* getValues() const { return values_; }
103  inline double getQuality() const { return quality_; }
108  inline void setSize(int s) { size_ = s; }
109  inline void assignObjects(BcpsObject_p *& obj){
110  objects_ = obj;
111  obj = NULL;
112  }
113  inline void setValues(const double *vs, int s) {
114  if (!values_) delete [] values_;
115  values_ = new double [s];
116  size_ = s;
117  memcpy(values_, vs, s * sizeof(double));
118  }
119  inline void setQuality(double q) { quality_ = q; }
125  virtual BcpsSolution* selectNonzeros(const double etol = 1e-5) const;
126  virtual BcpsSolution* selectFractional(const double etol = 1e-5) const;
130  virtual void print(std::ostream& os) const {
131  for (int j = 0; j < size_; ++j) {
132  if (values_[j] > 1.0e-15 || values_[j] < -1.0e-15) {
133  os << "x[" << j << "] = " << values_[j] << std::endl;
134  }
135  }
136  }
137 
138  //------------------------------------------------------
139  // Parallel.
140  //------------------------------------------------------
141 
143  AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const;
144 
147 
148 };
149 
150 //#############################################################################
151 //#############################################################################
152 
153 #endif
virtual BcpsSolution * selectFractional(const double etol=1e-5) const
Select the fractional/nonzero elements from the solution array and return a new object in compacted f...
AlpsReturnStatus
Definition: Alps.h:118
virtual void print(std::ostream &os) const
Print out the solution.
Definition: BcpsSolution.h:130
A class for describing the objects that comprise a BCPS subproblem.
Definition: BcpsObject.h:76
BcpsSolution()
Default constructor.
Definition: BcpsSolution.h:58
void assignObjects(BcpsObject_p *&obj)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:109
void setSize(int s)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:108
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps part of solution from an encoded objects.
double getQuality() const
Get the appropriate data member.
Definition: BcpsSolution.h:103
This class holds the solution objects.
Definition: BcpsSolution.h:34
const double * getValues() const
Get the appropriate data member.
Definition: BcpsSolution.h:102
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
BcpsObject_p * objects_
List of objects associated with values.
Definition: BcpsSolution.h:47
double quality_
Quality/Objective value associated with this solution.
Definition: BcpsSolution.h:53
BcpsSolution(int size, BcpsObject_p *&objects, double *&values, double q)
Construct an object using the given arrays.
Definition: BcpsSolution.h:80
virtual BcpsSolution * selectNonzeros(const double etol=1e-5) const
Select the fractional/nonzero elements from the solution array and return a new object in compacted f...
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps part of solution into an encoded objects.
#define ALPS_OBJ_MAX
Definition: Alps.h:145
void setQuality(double q)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:119
double * values_
Solution values.
Definition: BcpsSolution.h:50
int getSize() const
Get the appropriate data member.
Definition: BcpsSolution.h:100
BcpsSolution & operator=(const BcpsSolution &)
const BcpsObject_p * getObjects() const
Get the appropriate data member.
Definition: BcpsSolution.h:101
virtual ~BcpsSolution()
Distructor.
Definition: BcpsSolution.h:88
void setValues(const double *vs, int s)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:113
BcpsSolution(int size, const double *values, double q)
Useful constructor.
Definition: BcpsSolution.h:64
int size_
Size of values_.
Definition: BcpsSolution.h:44