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-2013, 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 
31 class 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 
133  using AlpsKnowledge::encode ;
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 
double objCoef_
Definition: BlisVariable.h:35
BlisVariable(double lbh, double ubh, double lbs, double ubs, double obj, int s, const int *ind, const double *val)
Definition: BlisVariable.h:61
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
virtual ~BlisVariable()
Definition: BlisVariable.h:74
AlpsReturnStatus
Definition: Alps.h:118
AlpsReturnStatus decodeBlis(AlpsEncoded &encoded)
Unpack Blis part from a encode object.
Definition: BlisVariable.h:119
double * getValues()
Return data.
Definition: BlisVariable.h:84
int * getIndices() const
Return data.
Definition: BlisVariable.h:83
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
int * indices_
Definition: BlisVariable.h:37
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
BlisVariable(double lbh, double ubh, double lbs, double ubs)
Definition: BlisVariable.h:54
void setObjCoef(double coef)
Set data.
Definition: BlisVariable.h:100
AlpsReturnStatus encodeBlis(AlpsEncoded *encoded)
Pack Blis part into an encoded object.
Definition: BlisVariable.h:106
AlpsReturnStatus encodeBcpsObject(AlpsEncoded *encoded) const
Pack Bcps part to a encode object.
Definition: BcpsObject.h:294
void setData(int s, const int *ind, const double *val)
Set data.
Definition: BlisVariable.h:89
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
double * values_
Definition: BlisVariable.h:38
Error Class thrown by an exception.
Definition: CoinError.hpp:42
virtual AlpsReturnStatus encode(AlpsEncoded *encoded)
Pack to a encode object.
Definition: BlisVariable.h:135
AlpsReturnStatus decodeBcpsObject(AlpsEncoded &encoded)
Unpack Bcps part from a encode object.
Definition: BcpsObject.h:310
BlisVariable(double obj, int s, const int *ind, const double *val)
Definition: BlisVariable.h:44
virtual AlpsEncoded * encode() const
This method should encode the content of the object and return a pointer to the encoded form...
int getSize() const
Return data.
Definition: BlisVariable.h:82