Bcps 0.94.5
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-2017, 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
34class BcpsSolution : public AlpsSolution {
35
36 private:
37
39 BcpsSolution& operator=(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
144
147
148};
149
150//#############################################################################
151//#############################################################################
152
153#endif
AlpsReturnStatus
#define ALPS_OBJ_MAX
A class for describing the objects that comprise a BCPS subproblem.
Definition: BcpsObject.h:76
This class holds the solution objects.
Definition: BcpsSolution.h:34
void setQuality(double q)
Definition: BcpsSolution.h:119
const BcpsObject_p * getObjects() const
Definition: BcpsSolution.h:101
BcpsSolution(int size, BcpsObject_p *&objects, double *&values, double q)
Construct an object using the given arrays.
Definition: BcpsSolution.h:80
double getQuality() const
Definition: BcpsSolution.h:103
int size_
Size of values_.
Definition: BcpsSolution.h:44
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.
Definition: BcpsSolution.h:50
void assignObjects(BcpsObject_p *&obj)
Definition: BcpsSolution.h:109
BcpsObject_p * objects_
List of objects associated with values.
Definition: BcpsSolution.h:47
BcpsSolution()
Default constructor.
Definition: BcpsSolution.h:58
int getSize() const
Get the appropriate data member.
Definition: BcpsSolution.h:100
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.
Definition: BcpsSolution.h:53
void setValues(const double *vs, int s)
Definition: BcpsSolution.h:113
BcpsSolution(int size, const double *values, double q)
Useful constructor.
Definition: BcpsSolution.h:64
void setSize(int s)
Set/assign the appropriate data member.
Definition: BcpsSolution.h:108
virtual ~BcpsSolution()
Distructor.
Definition: BcpsSolution.h:88
virtual void print(std::ostream &os) const
Print out the solution.
Definition: BcpsSolution.h:130
const double * getValues() const
Definition: BcpsSolution.h:102