- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Smi-0.93.1/FlopCpp/src/MP_data.hpp

Go to the documentation of this file.

    00001 // ******************** FlopCpp **********************************************
    00002 // File: MP_data.hpp
    00003 // $Id$
    00004 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
    00005 // Copyright (C) 2003 Tim Helge Hultberg
    00006 // All Rights Reserved.
    00007 // ****************************************************************************
    00008
    00009 #ifndef _MP_data_hpp_
    00010 #define _MP_data_hpp_
    00011
    00012 #include <vector>
    00013 #include <string>
    00014
    00015 #include "MP_index.hpp"
    00016 #include "MP_set.hpp"
    00017 #include "MP_constant.hpp"
    00018 #include "MP_boolean.hpp"
    00019
    00020 namespace flopc {
    00021
    00022     class MP_data;
    00023
    00029     class DataRef : public Constant_base, public Functor {
    00030     public:
    00031         DataRef(MP_data* d,
    00032                 const MP_index_exp& i1,
    00033                 const MP_index_exp& i2,
    00034                 const MP_index_exp& i3,
    00035                 const MP_index_exp& i4,
    00036                 const MP_index_exp& i5,
    00037                 int s = 0) :
    00038             D(d),I1(i1),I2(i2),I3(i3),I4(i4),I5(i5),C(0),stochastic(s) {}
    00039
    00040         ~DataRef() {}
    00041         DataRef& such_that(const MP_boolean& b);
    00042         double evaluate() const;
    00043         int getStage() const;
    00044         const DataRef& operator=(const DataRef& r);
    00045         const DataRef& operator=(const Constant& c);
    00046         void evaluate_lhs(double v) const;
    00047         void operator()() const;
    00048     private:
    00049         MP_data* D;
    00050         MP_index_exp I1,I2,I3,I4,I5;
    00051         Constant C;
    00052         int stochastic;
    00053         MP_boolean B;
    00054     };
    00055
    00071     class MP_data : public RowMajor, public Functor , public Named {
    00072         friend class MP_variable;
    00073         friend class DisplayData;
    00074         friend class DataRef;
    00075         friend class MP_model;
    00076     public:
    00077         void operator()() const;
    00079         void initialize(double d) {
    00080             for (int i=0; i<size(); i++) {
    00081                 v[i] = d;
    00082             }
    00083         }
    00087         MP_data(const MP_set_base &s1 = MP_set::getEmpty(),
    00088                 const MP_set_base &s2 = MP_set::getEmpty(),
    00089                 const MP_set_base &s3 = MP_set::getEmpty(),
    00090                 const MP_set_base &s4 = MP_set::getEmpty(),
    00091                 const MP_set_base &s5 = MP_set::getEmpty()) :
    00092             RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
    00093             S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
    00094             v(new double[size()]), manageData(true)
    00095             {
    00096                 initialize(0);
    00097             }
    00098
    00102         MP_data(double* value,
    00103                 const MP_set_base &s1 = MP_set::getEmpty(),
    00104                 const MP_set_base &s2 = MP_set::getEmpty(),
    00105                 const MP_set_base &s3 = MP_set::getEmpty(),
    00106                 const MP_set_base &s4 = MP_set::getEmpty(),
    00107                 const MP_set_base &s5 = MP_set::getEmpty()) :
    00108             RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
    00109             S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
    00110             v(value), manageData(false)
    00111             {
    00112             }
    00113
    00114         ~MP_data() {
    00115             if (manageData == true) delete[] v;
    00117 //          for (unsigned int i=0; i<myrefs.size(); i++) {
    00118 //              cout<<"# "<<i<<"   "<<myrefs[i]<<endl;
    00119 //              delete myrefs[i]; //Gives segmentation fault. I dont know why!
    00120 //          }
    00121         }
    00122
    00124         void value(const double* d) {
    00125             for (int i=0; i<size(); i++) {
    00126                 v[i] = d[i];
    00127             }
    00128         }
    00129
    00131         operator double() {
    00132             return operator()(0);
    00133         }
    00134
    00139         double& operator()(int lcli1, int lcli2=0, int lcli3=0, int lcli4=0, int lcli5=0) {
    00140             lcli1 = S1.check(lcli1);
    00141             lcli2 = S2.check(lcli2);
    00142             lcli3 = S3.check(lcli3);
    00143             lcli4 = S4.check(lcli4);
    00144             lcli5 = S5.check(lcli5);
    00145             int i = f(lcli1,lcli2,lcli3,lcli4,lcli5);
    00146             if (i == outOfBound) {
    00147                 outOfBoundData = 0;
    00148                 return outOfBoundData;
    00149             } else {
    00150                 return v[i];
    00151             }
    00152         }
    00153
    00158         DataRef& operator() (
    00159             const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
    00160             const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
    00161             const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
    00162             const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
    00163             const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
    00164             ) {
    00165             myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5));
    00166             return *myrefs.back();
    00167         }
    00168
    00169
    00171         void display(std::string s = "");
    00172     protected:
    00173         std::vector<DataRef*> myrefs;
    00174     private:
    00175         MP_data(const MP_data&); // Forbid copy constructor
    00176         MP_data& operator=(const MP_data&); // Forbid assignment
    00177
    00178         static double outOfBoundData;
    00179
    00180         MP_index i1,i2,i3,i4,i5;
    00181         const MP_set_base &S1,&S2,&S3,&S4,&S5;
    00182         double* v;
    00183         bool manageData;
    00184     };
    00185
    00186     class MP_stochastic_data : public MP_data {
    00187     public:
    00188         MP_stochastic_data(const MP_set_base &s1 = MP_set::getEmpty(),
    00189                            const MP_set_base &s2 = MP_set::getEmpty(),
    00190                            const MP_set_base &s3 = MP_set::getEmpty(),
    00191                            const MP_set_base &s4 = MP_set::getEmpty(),
    00192                            const MP_set_base &s5 = MP_set::getEmpty()) :
    00193             MP_data(s1,s2,s3,s4,s5) {}
    00194
    00195         using flopc::MP_data::operator();
    00196         DataRef& operator() (
    00197             const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
    00198             const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
    00199             const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
    00200             const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
    00201             const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
    00202             ) {
    00203             myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5, 1));
    00204             return *myrefs.back();
    00205         }
    00206     };
    00207
    00208 } // End of namespace flopc
    00209 #endif