- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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&);
39 BcpsSolution& operator=(const BcpsSolution&);
40
41 protected:
42
44 int size_;
45
47 BcpsObject_p *objects_;
48
50 double* values_;
51
53 double quality_;
54
55 public:
56
58 BcpsSolution()
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
146 AlpsReturnStatus decodeBcps(AlpsEncoded & encoded);
147
148 };
149
150 //#############################################################################
151 //#############################################################################
152
153 #endif
BcpsSolution::selectFractional
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
AlpsReturnStatus
Definition: Alps.h:118
BcpsSolution::print
virtual void print(std::ostream &os) const
Print out the solution.
Definition: BcpsSolution.h:130
BcpsObject
A class for describing the objects that comprise a BCPS subproblem.
Definition: BcpsObject.h:76
BcpsSolution::BcpsSolution
BcpsSolution()
Default constructor.
Definition: BcpsSolution.h:58
BcpsSolution::assignObjects
void assignObjects(BcpsObject_p *&obj)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:109
BcpsSolution::setSize
void setSize(int s)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:108
BcpsSolution::decodeBcps
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps part of solution from an encoded objects.
BcpsSolution::getQuality
double getQuality() const
Get the appropriate data member.
Definition: BcpsSolution.h:103
BcpsSolution
This class holds the solution objects.
Definition: BcpsSolution.h:34
BcpsSolution::getValues
const double * getValues() const
Get the appropriate data member.
Definition: BcpsSolution.h:102
AlpsEncoded
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
BcpsSolution::objects_
BcpsObject_p * objects_
List of objects associated with values.
Definition: BcpsSolution.h:47
BcpsSolution::quality_
double quality_
Quality/Objective value associated with this solution.
Definition: BcpsSolution.h:53
BcpsSolution::BcpsSolution
BcpsSolution(int size, BcpsObject_p *&objects, double *&values, double q)
Construct an object using the given arrays.
Definition: BcpsSolution.h:80
BcpsObject.h
BcpsSolution::selectNonzeros
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...
BcpsSolution::encodeBcps
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps part of solution into an encoded objects.
ALPS_OBJ_MAX
#define ALPS_OBJ_MAX
Definition: Alps.h:145
BcpsSolution::setQuality
void setQuality(double q)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:119
BcpsSolution::values_
double * values_
Solution values.
Definition: BcpsSolution.h:50
BcpsSolution::getSize
int getSize() const
Get the appropriate data member.
Definition: BcpsSolution.h:100
BcpsSolution::operator=
BcpsSolution & operator=(const BcpsSolution &)
BcpsSolution::getObjects
const BcpsObject_p * getObjects() const
Get the appropriate data member.
Definition: BcpsSolution.h:101
AlpsSolution
Definition: AlpsSolution.h:35
BcpsSolution::~BcpsSolution
virtual ~BcpsSolution()
Distructor.
Definition: BcpsSolution.h:88
BcpsSolution::setValues
void setValues(const double *vs, int s)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:113
AlpsSolution.h
BcpsSolution::BcpsSolution
BcpsSolution(int size, const double *values, double q)
Useful constructor.
Definition: BcpsSolution.h:64
BcpsSolution::size_
int size_
Size of values_.
Definition: BcpsSolution.h:44