Bcps 0.95.1
Loading...
Searching...
No Matches
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-2023, 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 "BcpsConfig.h"
28#include "BcpsObject.h"
29
30//#############################################################################
33//#############################################################################
34
35class BCPSLIB_EXPORT BcpsSolution : public AlpsSolution {
36
37 private:
38
40 BcpsSolution& operator=(const BcpsSolution&);
41
42 protected:
43
45 int size_;
46
49
51 double* values_;
52
54 double quality_;
55
56 public:
57
60 :
61 size_(0), objects_(NULL), values_(NULL), quality_(ALPS_OBJ_MAX)
62 {}
63
65 BcpsSolution(int size, const double *values, double q)
66 :
67 size_(size), objects_(NULL), values_(NULL), quality_(q) {
68
69 if (size > 0) {
70 values_ = new double [size];
71 memcpy(values_, values, sizeof(double) * size);
72 }
73 else {
74 std::cout << "ERROR: Solution size = " << size << std::endl;
75 assert(size > 0);
76 }
77 }
78
81 BcpsSolution(int size, BcpsObject_p*& objects, double*& values, double q)
82 :
83 size_(size), objects_(objects), values_(values), quality_(q) {
84 objects = NULL;
85 values = NULL;
86 }
87
89 virtual ~BcpsSolution() {
90 if (objects_) {
91 for (int i = 0; i < size_; ++i) {
92 delete objects_[i];
93 }
94 delete[] objects_;
95 }
96 delete[] values_;
97 }
98
101 inline int getSize() const { return size_; }
102 inline const BcpsObject_p* getObjects() const { return objects_; }
103 inline const double* getValues() const { return values_; }
104 inline double getQuality() const { return quality_; }
109 inline void setSize(int s) { size_ = s; }
110 inline void assignObjects(BcpsObject_p *& obj){
111 objects_ = obj;
112 obj = NULL;
113 }
114 inline void setValues(const double *vs, int s) {
115 if (!values_) delete [] values_;
116 values_ = new double [s];
117 size_ = s;
118 memcpy(values_, vs, s * sizeof(double));
119 }
120 inline void setQuality(double q) { quality_ = q; }
126 virtual BcpsSolution* selectNonzeros(const double etol = 1e-5) const;
127 virtual BcpsSolution* selectFractional(const double etol = 1e-5) const;
131 virtual void print(std::ostream& os) const {
132 for (int j = 0; j < size_; ++j) {
133 if (values_[j] > 1.0e-15 || values_[j] < -1.0e-15) {
134 os << "x[" << j << "] = " << values_[j] << std::endl;
135 }
136 }
137 }
138
139 //------------------------------------------------------
140 // Parallel.
141 //------------------------------------------------------
142
144 AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const;
145
147 AlpsReturnStatus decodeBcps(AlpsEncoded & encoded);
148
149};
150
151//#############################################################################
152//#############################################################################
153
154#endif
A class for describing the objects that comprise a BCPS subproblem.
Definition BcpsObject.h:77
This class holds the solution objects.
void setQuality(double q)
const BcpsObject_p * getObjects() const
BcpsSolution(int size, BcpsObject_p *&objects, double *&values, double q)
Construct an object using the given arrays.
double getQuality() const
int size_
Size of values_.
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 decodeBcps(AlpsEncoded &encoded)
Unpack Bcps part of solution from an encoded objects.
double * values_
Solution values.
void assignObjects(BcpsObject_p *&obj)
BcpsObject_p * objects_
List of objects associated with values.
BcpsSolution()
Default constructor.
int getSize() const
Get the appropriate data member.
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps part of solution into an encoded objects.
virtual BcpsSolution * selectFractional(const double etol=1e-5) const
double quality_
Quality/Objective value associated with this solution.
void setValues(const double *vs, int s)
BcpsSolution(int size, const double *values, double q)
Useful constructor.
void setSize(int s)
Set/assign the appropriate data member.
virtual ~BcpsSolution()
Distructor.
virtual void print(std::ostream &os) const
Print out the solution.
const double * getValues() const
#define BCPSLIB_EXPORT
Definition config.h:5