00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ACDCTraits_H
00010 #define ACDCTraits_H
00011
00012 namespace ACDCGenerator {
00013
00018 struct ACDCTraitsType {};
00019
00027 template <typename FncPtr>
00028 struct ACDCFncTraits: public ACDCTraitsType {
00029
00034 static inline double value(const FncPtr & f, const DVector & x) {
00035 return (*f)(x);
00036 }
00037
00038 };
00039
00046 template <typename Rnd>
00047 struct ACDCRandomTraits: public ACDCTraitsType {
00048
00052 static inline double rnd(Rnd * r) { return r->flat(); }
00053
00057 static inline double rnd(Rnd * r, double xl, double xu) {
00058 return xl + (xu - xl)*rnd(r);
00059 }
00060
00072 template <typename InputIterator, typename OutputIterator>
00073 static inline void rnd(Rnd * r, InputIterator l, InputIterator lend,
00074 InputIterator u, OutputIterator res) {
00075 for ( ; l != lend; ++l ) *res++ = *l + (*u++ - *l)*rnd(r);
00076 }
00077
00082 template <typename OutputIterator>
00083 static inline void rnd(Rnd * r, int D, OutputIterator res) {
00084 for ( int d = 0; d < D; ++d ) *res++ = rnd(r);
00085 }
00086
00090 static inline bool rndBool(Rnd * r, double x) { return rnd(r) < x; }
00091
00095 static inline bool rndBool(Rnd * r, double x, double y) {
00096 return rndBool(r, x/(x + y)); }
00097
00101 static inline long rndInt(Rnd * r, long x) {
00102 return long(rnd(r, 0.0, double(x)));
00103 }
00104
00105 };
00106
00107 }
00108
00109 #endif