Blis 0.95.0
Loading...
Searching...
No Matches
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-2023, 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#include "BlisConfig.h"
29
30//#############################################################################
31
32class BLISLIB_EXPORT BlisVariable : public BcpsVariable {
33
34 private:
35
36 double objCoef_;
37 int size_;
38 int *indices_;
39 double *values_;
40
41 public:
42
43 BlisVariable() : objCoef_(0.0), size_(0), indices_(NULL), values_(NULL) {}
44
45 BlisVariable(double obj, int s, const int *ind, const double *val)
46 {
47 objCoef_ = obj;
48 size_ = s;
49 indices_ = new int [s];
50 values_ = new double [s];
51 memcpy(indices_, ind, s * sizeof(int));
52 memcpy(values_, val, s * sizeof(double));
53 }
54
55 BlisVariable(double lbh, double ubh, double lbs, double ubs)
56 :
57 BcpsVariable(lbh, ubh, lbs, ubs),
58 objCoef_(0.0),
59 size_(0), indices_(NULL), values_(NULL)
60 {}
61
62 BlisVariable(double lbh, double ubh, double lbs, double ubs,
63 double obj, int s, const int *ind, const double *val)
64 :
65 BcpsVariable(lbh, ubh, lbs, ubs)
66 {
67 objCoef_ = obj;
68 size_ = s;
69 indices_ = new int [s];
70 values_ = new double [s];
71 memcpy(indices_, ind, s * sizeof(int));
72 memcpy(values_, val, s * sizeof(double));
73 }
74
75 virtual ~BlisVariable(){
76 delete [] indices_; indices_ = NULL;
77 delete [] values_; values_ = NULL;
78 }
79
82 double getObjCoef() { return objCoef_; }
83 int getSize() const { return size_; }
84 int* getIndices() const { return indices_; }
85 double* getValues() { return values_; }
90 void setData(int s, const int *ind, const double *val) {
91 if (size_ < s) {
92 delete [] indices_; indices_ = NULL;
93 delete [] values_; values_ = NULL;
94 indices_ = new int [s];
95 values_ = new double [s];
96 }
97 size_ = s;
98 memcpy(indices_, ind, sizeof(int) * s);
99 memcpy(values_, val, sizeof(double) * s);
100 }
101 void setObjCoef(double coef) { objCoef_ = coef; }
104 protected:
105
107 AlpsReturnStatus encodeBlis(AlpsEncoded *encoded) {
108 AlpsReturnStatus status = AlpsReturnStatusOk;
109
110 //std::cout << "****** encodeBlis var: size_ = " << size_ << std::endl;
111
112 encoded->writeRep(objCoef_);
113 encoded->writeRep(indices_, size_);
114 encoded->writeRep(values_, size_);
115
116 return status;
117 }
118
120 AlpsReturnStatus decodeBlis(AlpsEncoded &encoded) {
121 AlpsReturnStatus status = AlpsReturnStatusOk;
122
123 encoded.readRep(objCoef_);
124 encoded.readRep(indices_, size_);
125 encoded.readRep(values_, size_);
126
127 //std::cout << "****** decodeBlis var: size_ = " << size_ << std::endl;
128
129 return status;
130 }
131
132 public:
133
134 using AlpsKnowledge::encode ;
136 virtual AlpsReturnStatus encode(AlpsEncoded *encoded){
137 AlpsReturnStatus status;
138
139 status = encodeBcpsObject(encoded);
140 status = encodeBlis(encoded);
141
142 return status;
143 }
144
146 virtual AlpsKnowledge* decode(AlpsEncoded &encoded) const {
147 AlpsReturnStatus status = AlpsReturnStatusOk;
148 BlisVariable * var = new BlisVariable();
149
150 // Unpack Bcps part.
151 status = var->decodeBcpsObject(encoded);
152 if (status) {
153 throw CoinError("Failed to decode Bcps part of var",
154 "decode",
155 "BlisObject");
156 }
157
158 // Unpack Blis part.
159 status = var->decodeBlis(encoded);
160 if (status) {
161 throw CoinError("Failed to decode Blis part of var",
162 "decode",
163 "BlisObject");
164 }
165 return var;
166 }
167
168};
169
170//#############################################################################
171
172#endif /* End of file */
173
int * getIndices() const
int getSize() const
BlisVariable(double obj, int s, const int *ind, const double *val)
double getObjCoef()
Return data
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
Decode a variable from an encoded object.
double * getValues()
BlisVariable(double lbh, double ubh, double lbs, double ubs)
BlisVariable(double lbh, double ubh, double lbs, double ubs, double obj, int s, const int *ind, const double *val)
virtual ~BlisVariable()
AlpsReturnStatus decodeBlis(AlpsEncoded &encoded)
Unpack Blis part from a encode object.
void setData(int s, const int *ind, const double *val)
Set data
virtual AlpsReturnStatus encode(AlpsEncoded *encoded)
Pack to a encode object.
void setObjCoef(double coef)
AlpsReturnStatus encodeBlis(AlpsEncoded *encoded)
Pack Blis part into an encoded object.
#define BLISLIB_EXPORT
Definition config.h:5