FLOPC++
MP_data.hpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_data.hpp
3 // $Id$
4 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 // Copyright (C) 2003 Tim Helge Hultberg
6 // All Rights Reserved.
7 // ****************************************************************************
8 
9 #ifndef _MP_data_hpp_
10 #define _MP_data_hpp_
11 
12 #include <vector>
13 #include "MP_index.hpp"
14 #include "MP_set.hpp"
15 #include "MP_constant.hpp"
16 #include "MP_boolean.hpp"
17 
18 namespace flopc {
19 
20  class MP_data;
21 
27  class DataRef : public Constant_base, public Functor {
28  public:
30  const MP_index_exp& i1,
31  const MP_index_exp& i2,
32  const MP_index_exp& i3,
33  const MP_index_exp& i4,
34  const MP_index_exp& i5,
35  int s = 0) :
36  D(d),I1(i1),I2(i2),I3(i3),I4(i4),I5(i5),C(0),stochastic(s) {}
37 
38  ~DataRef() {}
39  DataRef& such_that(const MP_boolean& b);
40  double evaluate() const;
41  int getStage() const;
42  const DataRef& operator=(const DataRef& r);
43  const DataRef& operator=(const Constant& c);
44  void evaluate_lhs(double v) const;
45  void operator()() const;
46  DataRef& probability(double p) { return *this; }
47  private:
53  };
54 
71  class MP_data : public RowMajor, public Functor , public Named {
72  friend class MP_variable;
73  friend class DisplayData;
74  friend class DataRef;
75  friend class MP_model;
76  public:
77  void operator()() const;
79  void initialize(double d) {
80  for (int i=0; i<size(); i++) {
81  v[i] = d;
82  }
83  }
88  const MP_set_base &s2 = MP_set::getEmpty(),
89  const MP_set_base &s3 = MP_set::getEmpty(),
90  const MP_set_base &s4 = MP_set::getEmpty(),
91  const MP_set_base &s5 = MP_set::getEmpty()) :
92  RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
93  S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
94  v(new double[size()]), manageData(true)
95  {
96  initialize(0);
97  }
98 
102  MP_data(double* value,
103  const MP_set_base &s1 = MP_set::getEmpty(),
104  const MP_set_base &s2 = MP_set::getEmpty(),
105  const MP_set_base &s3 = MP_set::getEmpty(),
106  const MP_set_base &s4 = MP_set::getEmpty(),
107  const MP_set_base &s5 = MP_set::getEmpty()) :
108  RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
109  S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
110  v(value), manageData(false)
111  { }
112 
114  if (manageData == true) delete[] v;
115  }
116 
118  void value(const double* d) {
119  for (int i=0; i<size(); i++) {
120  v[i] = d[i];
121  }
122  }
123 
125  operator double() {
126  return operator()(0);
127  }
128 
133  double& operator()(int lcli1, int lcli2=0, int lcli3=0, int lcli4=0, int lcli5=0) {
134  lcli1 = S1.check(lcli1);
135  lcli2 = S2.check(lcli2);
136  lcli3 = S3.check(lcli3);
137  lcli4 = S4.check(lcli4);
138  lcli5 = S5.check(lcli5);
139  int i = f(lcli1,lcli2,lcli3,lcli4,lcli5);
140  if (i == outOfBound) {
141  outOfBoundData = 0;
142  return outOfBoundData;
143  } else {
144  return v[i];
145  }
146  }
147 
153  const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
154  const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
155  const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
156  const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
157  const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
158  ) {
159  myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5));
160  return *myrefs.back();
161  }
162 
163 
165  void display(string s = "");
166  protected:
167  vector<DataRef*> myrefs;
168  private:
169  MP_data(const MP_data&); // Forbid copy constructor
170  MP_data& operator=(const MP_data&); // Forbid assignment
171 
172  static double outOfBoundData;
173 
175  const MP_set_base &S1,&S2,&S3,&S4,&S5;
176  double* v;
178  };
179 
180  class MP_stochastic_data : public MP_data {
181  public:
183  const MP_set_base &s2 = MP_set::getEmpty(),
184  const MP_set_base &s3 = MP_set::getEmpty(),
185  const MP_set_base &s4 = MP_set::getEmpty(),
186  const MP_set_base &s5 = MP_set::getEmpty()) :
187  MP_data(s1,s2,s3,s4,s5) {}
188 
189  using flopc::MP_data::operator(); // From bugsquashing party. Some compiler needs this?
190 
192  const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
193  const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
194  const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
195  const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
196  const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
197  ) {
198  myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5, 1));
199  return *myrefs.back();
200  }
201  };
202 
203 } // End of namespace flopc
204 #endif
MP_index_exp I2
Definition: MP_data.hpp:49
void evaluate_lhs(double v) const
Definition: MP_data.cpp:79
int getStage() const
Definition: MP_data.cpp:60
static MP_set & getEmpty()
gets the distinct 'empty' MP_set.
Definition: MP_set.cpp:17
void value(const double *d)
Used to bind and deep copy data into the MP_data data structure.
Definition: MP_data.hpp:118
const DataRef & operator=(const DataRef &r)
Definition: MP_data.cpp:29
const MP_set_base & S3
Definition: MP_data.hpp:175
MP_data(const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
Definition: MP_data.hpp:87
DataRef & probability(double p)
Definition: MP_data.hpp:46
MP_index i1
Definition: MP_data.hpp:174
Representation of an index.This is one of the main public interface classes. It is used to iterate th...
Definition: MP_index.hpp:53
double * v
Definition: MP_data.hpp:176
MP_data & operator=(const MP_data &)
MP_index i2
Definition: MP_data.hpp:174
void initialize(double d)
similar to value() but copies the same value to all entries.
Definition: MP_data.hpp:79
MP_index_exp I4
Definition: MP_data.hpp:49
MP_boolean B
Definition: MP_data.hpp:52
static double outOfBoundData
Definition: MP_data.hpp:172
Utility interface class for adding a string name onto a structure.
MP_index i5
Definition: MP_data.hpp:174
Representation of an expression involving an index.This is one of the main public interface classes...
Definition: MP_index.hpp:141
int f(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
Base class for all "constant" types of data.
Definition: MP_constant.hpp:20
double evaluate() const
Definition: MP_data.cpp:43
MP_stochastic_data(const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
Definition: MP_data.hpp:182
int size() const
DataRef(MP_data *d, const MP_index_exp &i1, const MP_index_exp &i2, const MP_index_exp &i3, const MP_index_exp &i4, const MP_index_exp &i5, int s=0)
Definition: MP_data.hpp:29
static const MP_index_exp & getEmpty()
Return the unique empty expression.
Definition: MP_index.cpp:26
int check(int i) const
Definition: MP_set.hpp:38
MP_index_exp I3
Definition: MP_data.hpp:49
const int outOfBound
Distinct return value on conditions where an index goes out of bounds.
Reference to a set of data.
Definition: MP_data.hpp:27
This is the anchor point for all constructs in a FlopC++ model.The constructors take an OsiSolverInte...
Definition: MP_model.hpp:90
MP_index i4
Definition: MP_data.hpp:174
All flopc++ code is contained within the flopc namespace.
Definition: flopc.cpp:11
Constant C
Definition: MP_data.hpp:50
Reference counted class for all "boolean" types of data.This contains counters to ConstantBase pointe...
Definition: MP_boolean.hpp:40
friend class DisplayData
Definition: MP_data.hpp:73
DataRef & such_that(const MP_boolean &b)
Definition: MP_data.cpp:37
MP_index_exp I1
Definition: MP_data.hpp:49
MP_data * D
Definition: MP_data.hpp:48
friend class DataRef
Definition: MP_data.hpp:74
Symantic representation of a variable.This is one of the main public interface classes. It should be directly declared by clients of the FlopC++. The parametersof construction are MP_set s which specify the indexes over which the variable is defined.
Definition: MP_variable.hpp:35
Function object. Often used.
const MP_set_base & S5
Definition: MP_data.hpp:175
Reference counted class for all "constant" types of data.
Definition: MP_constant.hpp:49
Input data set.This is one of the main public interface classes. It is normally directly constructed ...
Definition: MP_data.hpp:71
double & operator()(int lcli1, int lcli2=0, int lcli3=0, int lcli4=0, int lcli5=0)
Definition: MP_data.hpp:133
void display(string s="")
For displaying data in a human readable format.
Definition: MP_data.cpp:102
const MP_set_base & S4
Definition: MP_data.hpp:175
MP_index i3
Definition: MP_data.hpp:174
Internal representation of a "set".
Definition: MP_set.hpp:30
vector< DataRef * > myrefs
Definition: MP_data.hpp:167
MP_index_exp I5
Definition: MP_data.hpp:49
const MP_set_base & S2
Definition: MP_data.hpp:175
MP_data(double *value, const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
Definition: MP_data.hpp:102
void operator()() const
Definition: MP_data.cpp:33
const MP_set_base & S1
Definition: MP_data.hpp:175
void operator()() const
Definition: MP_data.cpp:92