Blis 0.94
BlisVariable.h
Go to the documentation of this file.
1/*===========================================================================*
2 * This file is part of the BiCePS Linear Integer Solver (BLIS). *
3 * *
4 * BLIS 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 * *
20 * Copyright (C) 2001-2019, Lehigh University, Yan Xu, and Ted Ralphs. *
21 * All Rights Reserved. *
22 *===========================================================================*/
23
24#ifndef BlisVariable_h_
25#define BlisVariable_h_
26
27#include "BcpsObject.h"
28
29//#############################################################################
30
31class BlisVariable : public BcpsVariable {
32
33 private:
34
35 double objCoef_;
36 int size_;
37 int *indices_;
38 double *values_;
39
40 public:
41
42 BlisVariable() : objCoef_(0.0), size_(0), indices_(NULL), values_(NULL) {}
43
44 BlisVariable(double obj, int s, const int *ind, const double *val)
45 {
46 objCoef_ = obj;
47 size_ = s;
48 indices_ = new int [s];
49 values_ = new double [s];
50 memcpy(indices_, ind, s * sizeof(int));
51 memcpy(values_, val, s * sizeof(double));
52 }
53
54 BlisVariable(double lbh, double ubh, double lbs, double ubs)
55 :
56 BcpsVariable(lbh, ubh, lbs, ubs),
57 objCoef_(0.0),
58 size_(0), indices_(NULL), values_(NULL)
59 {}
60
61 BlisVariable(double lbh, double ubh, double lbs, double ubs,
62 double obj, int s, const int *ind, const double *val)
63 :
64 BcpsVariable(lbh, ubh, lbs, ubs)
65 {
66 objCoef_ = obj;
67 size_ = s;
68 indices_ = new int [s];
69 values_ = new double [s];
70 memcpy(indices_, ind, s * sizeof(int));
71 memcpy(values_, val, s * sizeof(double));
72 }
73
74 virtual ~BlisVariable(){
75 delete [] indices_; indices_ = NULL;
76 delete [] values_; values_ = NULL;
77 }
78
81 double getObjCoef() { return objCoef_; }
82 int getSize() const { return size_; }
83 int* getIndices() const { return indices_; }
84 double* getValues() { return values_; }
89 void setData(int s, const int *ind, const double *val) {
90 if (size_ < s) {
91 delete [] indices_; indices_ = NULL;
92 delete [] values_; values_ = NULL;
93 indices_ = new int [s];
94 values_ = new double [s];
95 }
96 size_ = s;
97 memcpy(indices_, ind, sizeof(int) * s);
98 memcpy(values_, val, sizeof(double) * s);
99 }
100 void setObjCoef(double coef) { objCoef_ = coef; }
103 protected:
104
108
109 //std::cout << "****** encodeBlis var: size_ = " << size_ << std::endl;
110
111 encoded->writeRep(objCoef_);
112 encoded->writeRep(indices_, size_);
113 encoded->writeRep(values_, size_);
114
115 return status;
116 }
117
121
122 encoded.readRep(objCoef_);
123 encoded.readRep(indices_, size_);
124 encoded.readRep(values_, size_);
125
126 //std::cout << "****** decodeBlis var: size_ = " << size_ << std::endl;
127
128 return status;
129 }
130
131 public:
132
136 AlpsReturnStatus status;
137
138 status = encodeBcpsObject(encoded);
139 status = encodeBlis(encoded);
140
141 return status;
142 }
143
145 virtual AlpsKnowledge* decode(AlpsEncoded &encoded) const {
147 BlisVariable * var = new BlisVariable();
148
149 // Unpack Bcps part.
150 status = var->decodeBcpsObject(encoded);
151 if (status) {
152 throw CoinError("Failed to decode Bcps part of var",
153 "decode",
154 "BlisObject");
155 }
156
157 // Unpack Blis part.
158 status = var->decodeBlis(encoded);
159 if (status) {
160 throw CoinError("Failed to decode Blis part of var",
161 "decode",
162 "BlisObject");
163 }
164 return var;
165 }
166
167};
168
169//#############################################################################
170
171#endif /* End of file */
172
AlpsReturnStatus
AlpsReturnStatusOk
AlpsEncoded & readRep(T &value)
AlpsEncoded & writeRep(const T &value)
virtual AlpsEncoded * encode() const
AlpsReturnStatus encodeBcpsObject(AlpsEncoded *encoded) const
AlpsReturnStatus decodeBcpsObject(AlpsEncoded &encoded)
int * getIndices() const
Definition: BlisVariable.h:83
int getSize() const
Definition: BlisVariable.h:82
BlisVariable(double obj, int s, const int *ind, const double *val)
Definition: BlisVariable.h:44
double getObjCoef()
Return data
Definition: BlisVariable.h:81
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
Decode a variable from an encoded object.
Definition: BlisVariable.h:145
double * getValues()
Definition: BlisVariable.h:84
BlisVariable(double lbh, double ubh, double lbs, double ubs)
Definition: BlisVariable.h:54
BlisVariable(double lbh, double ubh, double lbs, double ubs, double obj, int s, const int *ind, const double *val)
Definition: BlisVariable.h:61
virtual ~BlisVariable()
Definition: BlisVariable.h:74
AlpsReturnStatus decodeBlis(AlpsEncoded &encoded)
Unpack Blis part from a encode object.
Definition: BlisVariable.h:119
void setData(int s, const int *ind, const double *val)
Set data
Definition: BlisVariable.h:89
virtual AlpsReturnStatus encode(AlpsEncoded *encoded)
Pack to a encode object.
Definition: BlisVariable.h:135
void setObjCoef(double coef)
Definition: BlisVariable.h:100
AlpsReturnStatus encodeBlis(AlpsEncoded *encoded)
Pack Blis part into an encoded object.
Definition: BlisVariable.h:106