00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "MP_index.hpp"
00010 #include "MP_domain.hpp"
00011 #include "MP_set.hpp"
00012 #include "MP_model.hpp"
00013
00014 namespace flopc {
00015
00016 MP_index& MP_index::Empty = *new MP_index();
00017 MP_index& MP_index::Any_index = *new MP_index();
00018 MP_index_exp MP_index_exp::Empty = *new MP_index_exp(Constant(0.0));
00019
00020 MP_index &MP_index::getEmpty() {
00021 return Empty;
00022 }
00023 MP_index &MP_index::Any() {
00024 return Any_index;
00025 }
00026 const MP_index_exp &MP_index_exp::getEmpty() {
00027 return Empty;
00028 }
00029
00030 class MP_index_constant : public MP_index_base {
00031 friend class MP_index_exp;
00032 public:
00033 private:
00034 MP_index_constant(const Constant& c) : C(c) {}
00035 int evaluate() const {
00036 return int(C->evaluate());
00037 }
00038 MP_index* getIndex() const {
00039 return 0;
00040 }
00041 virtual MP_domain getDomain(MP_set* s) const{
00042 return MP_domain::getEmpty();
00043 }
00044 Constant C;
00045 };
00046
00047 class MP_index_subsetRef : public MP_index_base {
00048 friend class MP_index_exp;
00049 private:
00050 MP_index_subsetRef(const SUBSETREF& s) : S(&s) {}
00051 int evaluate() const {
00052 cout<<"eval subsetref "<<S->evaluate()<<endl;
00053 return int(S->evaluate());
00054 }
00055 MP_index* getIndex() const {
00056 return S->getIndex();
00057 }
00058 virtual MP_domain getDomain(MP_set* s) const{
00059 return MP_domain(S->getDomain(s));
00060 }
00061 const SUBSETREF* S;
00062 };
00063
00064 MP_index_exp operator+(MP_index& i,const Constant& j) {
00065 return new MP_index_sum(i,j);
00066 }
00067
00068 MP_index_exp operator+(MP_index& i,const int& j) {
00069 return new MP_index_sum(i,Constant(j));
00070 }
00071
00072 MP_index_exp operator-(MP_index& i,const Constant& j) {
00073 return new MP_index_dif(i,j);
00074 }
00075
00076 MP_index_exp operator-(MP_index& i,const int& j) {
00077 return new MP_index_dif(i,Constant(j));
00078 }
00079
00080 MP_index_exp operator*(MP_index& i,const Constant& j) {
00081 return new MP_index_mult(i,j);
00082 }
00083
00084
00085 }
00086
00087 using namespace flopc;
00088
00089
00090 MP_domain MP_index::getDomain(MP_set* s) const{
00091 return new MP_domain_set(s,const_cast<MP_index*>(this)) ;
00092 }
00093
00094 MP_domain MP_index_mult::getDomain(MP_set* s) const{
00095 return left->getDomain(s);
00096 }
00097
00098 MP_domain MP_index_sum::getDomain(MP_set* s) const{
00099 return left->getDomain(s);
00100 }
00101
00102 MP_domain MP_index_dif::getDomain(MP_set* s) const{
00103 return left->getDomain(s);
00104 }
00105
00106 MP_index_exp::MP_index_exp(int i) :
00107 Handle<MP_index_base*>(new MP_index_constant(Constant(i))) {}
00108
00109 MP_index_exp::MP_index_exp(const SUBSETREF& s) :
00110 Handle<MP_index_base*>(new MP_index_subsetRef(s)) {}
00111
00112 MP_index_exp::MP_index_exp(const Constant& c) :
00113 Handle<MP_index_base*>(new MP_index_constant(c)) {}
00114
00115 MP_index_exp::MP_index_exp(MP_index& i) :
00116 Handle<MP_index_base*>(&i) { operator->()->count++; }
00117
00118 MP_index_exp::MP_index_exp(const MP_index_exp &other):
00119 Handle<MP_index_base*>((const Handle<MP_index_base*> &)other) {}
00120