#ifndef __INDICES_H__ #define __INDICES_H__ #include #define INFINI (std::numeric_limits::infinity()) #include #include #include /** types d'indices utilisés * * utiliser ces types permet d'être prévenu à la compilation * lorsqu'on se trompe dans l'ordre des indices pour accéder * à des tableaux multidimensionnels */ struct week_t; struct wlen_t; struct monEntier { int v ; operator int() const {return v;} explicit monEntier(int i) {v=i;} monEntier() {v=0;} }; struct constraint_t : monEntier { explicit constraint_t(int i) {v=i;} constraint_t & operator ++() { ++v; return (*this); } }; #define C13 ((constraint_t)13) #define C14 ((constraint_t)14) #define C15 ((constraint_t)15) #define C16 ((constraint_t)16) #define C17 ((constraint_t)17) #define C18 ((constraint_t)18) #define C19 ((constraint_t)19) #define C20 ((constraint_t)20) #define C21 ((constraint_t)21) struct heure : monEntier { explicit heure(int i) {v=i;} heure() {v=0;} }; struct tlen_t : monEntier { explicit tlen_t(int i) {v=i;} tlen_t() {v=0;} inline heure operator *(heure o) const; }; struct timestep_t : monEntier { explicit timestep_t(int i) {v=i;} timestep_t() {v=0;} inline tlen_t operator/(week_t h) const ; inline timestep_t operator-(tlen_t h) const ; inline timestep_t operator+(tlen_t h) const ; timestep_t & operator ++() { ++v; return (*this); } timestep_t & operator --() { --v; return (*this); } }; struct week_t : monEntier { explicit week_t(int i) {v=i;} week_t() {v=0;} // timestep_t operator*(timestep_t t) {return (timestep_t) (v*(int)t);} timestep_t operator*(tlen_t l) const {return (timestep_t)(v*l.v);} bool operator<(week_t other) const { return v(week_t other) const { return v>other.v; } week_t & operator ++() { ++v; return (*this); } inline week_t operator -(wlen_t l) const; inline week_t operator +(wlen_t l) const; inline wlen_t operator -(week_t other) const; }; struct wlen_t : monEntier { explicit wlen_t(int i) {v=i;} wlen_t() {v=0;} }; struct scenario_t : monEntier { explicit scenario_t(int i) {v=i;} scenario_t() {v=0;} scenario_t & operator ++() { ++v; return (*this); } }; struct powerplants1_t : monEntier { explicit powerplants1_t(int i) {v=i;} powerplants1_t() {v=0;} powerplants1_t & operator ++() { ++v; return (*this); } }; struct powerplants2_t : monEntier { explicit powerplants2_t(int i) {v=i;} powerplants2_t() {v=0;} powerplants2_t & operator ++() { ++v; return (*this); } }; struct campaign_t : monEntier { #define K_Tp1 ((campaign_t)-2) explicit campaign_t(int i) {v=i;} campaign_t() {v=0;} campaign_t & operator ++() { ++v; return (*this); } }; struct points_t : monEntier { explicit points_t(int i) {v=i;} points_t() {v=0;} }; tlen_t timestep_t::operator/(week_t h) const {return (tlen_t) (v/(int)h);} timestep_t timestep_t::operator-(tlen_t h) const {return timestep_t(v-(int)h);} timestep_t timestep_t::operator+(tlen_t h) const {return timestep_t(v+(int)h);} week_t week_t::operator -(wlen_t l) const { return week_t(v-l.v); } week_t week_t::operator +(wlen_t l) const { return week_t(v+l.v); } wlen_t week_t::operator -(week_t other) const { return wlen_t(v-other.v); } heure tlen_t::operator *(heure o) const { return heure(v*o.v); } /** * * unités de puissance, d'énergie et de coût * */ struct kWh; struct monDouble { double v ; explicit monDouble(double d) {v=d;} monDouble() {v=0;} }; template inline Type sup(const Type & d) { return (Type) (d.v * (1+std::numeric_limits::epsilon())); } template inline Type inf(const Type & d) { return (Type) (d.v * (1-std::numeric_limits::epsilon())); } struct coeff_t : monDouble { explicit coeff_t(double d) {v=d;} coeff_t(){v=0;} coeff_t operator-(const coeff_t & o) const {return coeff_t(v-o.v);} coeff_t operator+(const coeff_t & o) const {return coeff_t(v+o.v);} coeff_t operator*(const coeff_t & o) const {return coeff_t(v*o.v);} coeff_t operator/(const coeff_t & o) const {return coeff_t(v/o.v);} coeff_t & operator*=(const coeff_t & o) {v *= o.v; return *this;} bool operator!=(const coeff_t & o) const { return v!=o.v;} bool operator< (const coeff_t & o) const { return v< o.v;} }; struct kW : monDouble { explicit kW(double d) {v=d;} kW() {v=0;} inline kWh operator*(heure t) const ; kW & operator+=(const kW & o) {v += o.v; return *this;} kW & operator/=(const coeff_t & o) {v /= o.v; return *this;} bool operator< (const kW & o) const { return v< o.v;} bool operator>=(const kW & o) const { return v>=o.v;} }; struct kWh_carre; struct kWh : monDouble { explicit kWh(double d) {v=d;} kWh(){v=0;} kWh operator*(const coeff_t & c) const {return kWh(v*c.v);} kWh operator/(const coeff_t & c) const {return kWh(v/c.v);} kWh operator-(const kWh & o) const {return kWh(v-o.v);} kWh operator+(const kWh & o) const {return kWh(v+o.v);} kWh & operator+=(const kWh & o) {v += o.v; return *this;} kWh & operator-=(const kWh & o) {v -= o.v; return *this;} kWh & operator/=(const coeff_t & o) {v /= o.v; return *this;} kWh & operator/=(const scenario_t & s) { v /= s.v; return *this;} kWh & operator*=(const coeff_t & o) {v *= o.v; return *this;} coeff_t operator/(const kWh & o) const {return coeff_t(v/o.v);} kW operator/(const heure & duree) {return kW(v/duree.v);} bool operator>=(const kWh & o) const { return v>=o.v;} bool operator<=(const kWh & o) const { return v<=o.v;} bool operator< (const kWh & o) const { return v< o.v;} bool operator> (const kWh & o) const { return v> o.v;} bool operator!=(const kWh & o) const { return v!=o.v;} bool operator==(const kWh & o) const { return v==o.v;} inline kWh_carre operator*(const kWh & o) const; }; struct kWh_carre : monDouble { explicit kWh_carre(double d) {v=d;} kWh_carre(){v=0;} kWh operator/(const kWh & o) const {return kWh(v/o.v);} bool operator> (const kWh_carre & o) const { return v> o.v;} kWh_carre & operator+=(const kWh_carre & o) {v=v+o.v; return (*this);} }; struct euros_par_kWh; struct euros_par_semaine; struct euros : monDouble { explicit euros(double d) {v=d;} euros(){v=0;} bool operator> (const euros & o) const { return v> o.v;} bool operator< (const euros & o) const { return v< o.v;} bool operator<=(const euros & o) const { return v<=o.v;} euros operator-(const euros & o) const {return euros(v-o.v);} euros operator+(const euros & o) const {return euros(v+o.v);} euros & operator-=(const euros & o) { v -= o.v; return *this;} euros & operator+=(const euros & o) { v += o.v; return *this;} euros & operator/=(const scenario_t & s) { v /= s.v; return *this;} inline euros_par_kWh operator/(const kWh & prod) const; inline euros_par_semaine operator/(const wlen_t & w) const; // inline euros operator/(const coeff_t & c) const {return euros(v/c);}; inline euros operator*(const coeff_t & c) const {return euros(v*c.v);}; }; struct euros_par_kWh : monDouble { explicit euros_par_kWh(double d) {v=d;} euros_par_kWh() {v=0;} euros operator *(kWh fuel) const { return euros(v * fuel.v); } euros_par_kWh operator *(coeff_t c) const { return euros_par_kWh(v * c.v); } bool operator< (const euros_par_kWh & o) const { return v< o.v;} bool operator>=(const euros_par_kWh & o) const { return v>=o.v;} euros_par_kWh operator+(const euros_par_kWh & o) const {return euros_par_kWh(v+o.v);} euros_par_kWh operator-(const euros_par_kWh & o) const {return euros_par_kWh(v-o.v);} euros_par_kWh & operator+=(const euros_par_kWh & o) { v += o.v; return *this;} euros_par_kWh & operator-=(const euros_par_kWh & o) { v -= o.v; return *this;} euros_par_kWh & operator/=(const tlen_t & s) { v /= s.v; return *this; } euros_par_kWh & operator/=(const scenario_t & s) { v /= s.v; return *this;} }; struct euros_par_semaine : monDouble { explicit euros_par_semaine(double d) {v=d;} euros_par_semaine() {v=0;} euros operator *(wlen_t w) const { return euros(v * w.v); } euros_par_semaine operator *(coeff_t c) const { return euros_par_semaine(v * c.v); } bool operator< (const euros_par_semaine & o) const { return v< o.v;} bool operator>=(const euros_par_semaine & o) const { return v>=o.v;} euros_par_semaine operator+(const euros_par_semaine & o) const {return euros_par_semaine(v+o.v);} euros_par_semaine operator-(const euros_par_semaine & o) const {return euros_par_semaine(v-o.v);} euros_par_semaine & operator+=(const euros_par_semaine & o) { v += o.v; return *this;} euros_par_semaine & operator-=(const euros_par_semaine & o) { v -= o.v; return *this;} }; /* conversions */ kWh kW::operator*(heure t) const { return kWh( v * t ) ; } inline euros_par_kWh euros::operator/(const kWh & prod) const { return euros_par_kWh( v / prod.v ); } inline euros_par_semaine euros::operator/(const wlen_t & w) const { return euros_par_semaine( v / w.v ); } inline kWh_carre kWh::operator*(const kWh & o) const { return kWh_carre(v*o.v); } inline std::ifstream & operator>>(std::ifstream & is, campaign_t & o) { is >> o.v ; return is; } inline std::ifstream & operator>>(std::ifstream & is, wlen_t & o) { is >> o.v ; return is; } inline std::ifstream & operator>>(std::ifstream & is, coeff_t & o) { is >> o.v ; return is; } inline std::ifstream & operator>>(std::ifstream & is, heure & o) { is >> o.v ; return is; } inline std::ifstream & operator>>(std::ifstream & is, kW & o) { is >> o.v ; return is; } inline std::ifstream & operator>>(std::ifstream & is, kWh & o) { is >> o.v ; return is; } inline std::ifstream & operator>>(std::ifstream & is, euros_par_kWh & o) { is >> o.v ; return is; } inline std::ifstream & operator>>(std::ifstream & is, euros_par_semaine & o) { is >> o.v ; return is; } inline std::ostream & operator<<(std::ostream & os, monDouble o) { os << o.v ; return os; } /** * * foncteurs et fonctions utilitaires * */ // Foncteur servant à libérer un pointeur - applicable à n'importe quel type struct Delete { template void operator ()(T*& p) const { delete p; p = (T*) 0; } }; // Foncteur servant à vider un vecteur - applicable à n'importe quel type de vecteur #include struct Vide { template void operator ()(std::vector& p) const { p.resize(0); } }; // Foncteur servant à créer un vecteur - applicable à n'importe quel type de pointeur sur un vecteur template struct New { size_t m_s; T m_v; New(size_t size, T val) {m_s = size;} void operator ()(std::vector*& p) const { p = new std::vector( m_s, m_v); } }; inline std::string operator+ (const std::string & prefix, int n) { std::ostringstream out; out << n ; return prefix + out.str(); } #endif