BlisVariable.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Bcps Linear 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  if (size_ > 0) {
76  delete [] indices_; indices_ = NULL;
77  delete [] values_; values_ = NULL;
78  }
79  }
80 
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  }
103  protected:
104 
108 
109  encoded->writeRep(objCoef_);
110  encoded->writeRep(indices_, size_);
111  encoded->writeRep(values_, size_);
112 
113  return status;
114  }
115 
119 
120  encoded.readRep(objCoef_);
121  encoded.readRep(indices_, size_);
122  encoded.readRep(values_, size_);
123 
124  return status;
125  }
126 
127  public:
128 
131  AlpsReturnStatus status;
132 
133  status = encodeBcpsObject(encoded);
134  status = encodeBlis(encoded);
135 
136  return status;
137  }
138 
140  virtual AlpsKnowledge* decode(AlpsEncoded &encoded) const {
142  BlisVariable * var = new BlisVariable();
143 
144  // Unpack Bcps part.
145  status = var->decodeBcpsObject(encoded);
146  if (status) {
147  throw CoinError("Failed to decode Bcps part of var",
148  "decode",
149  "BlisObject");
150  }
151 
152  // Unpack Blis part.
153  status = var->decodeBlis(encoded);
154  if (status) {
155  throw CoinError("Failed to decode Blis part of var",
156  "decode",
157  "BlisObject");
158  }
159  return var;
160  }
161 
162 };
163 
164 //#############################################################################
165 
166 #endif /* End of file */
167 
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:117
double * getValues()
Return data.
Definition: BlisVariable.h:85
int * getIndices() const
Return data.
Definition: BlisVariable.h:84
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
int * indices_
Definition: BlisVariable.h:37
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
Decode a variable from an encoded object.
Definition: BlisVariable.h:140
BlisVariable(double lbh, double ubh, double lbs, double ubs)
Definition: BlisVariable.h:54
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:90
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:130
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
int getSize() const
Return data.
Definition: BlisVariable.h:83