#include #include #include #include #include #include using namespace std; class desc { public: desc() { randomise(); } void randomise() { for (unsigned int i=0; i<13; ++i) { m_data[i]=rand()%1000/1000.0f; } } float m_data[13]; }; class test { public: test(int brain_size) { for (int i=0; i m_brain; float dist(const desc &a, const desc &b) { float ret = 0; for(unsigned int i=0; i<13; ++i) { ret += abs(a.m_data[i]-b.m_data[i]); } } int find_closest(const desc &a) { float closest = 999999999999; unsigned int closest_index = 0; unsigned int index = 0; for (vector::iterator i=m_brain.begin(); i!=m_brain.end(); ++i) { float d = dist(a,**i); if (dios &operator||(ios &s, T &v) { ofstream *pos=dynamic_cast(&s); if (pos!=NULL) { ofstream &os = *pos; return os.write((char*)(&v),sizeof(T)); } else { ifstream *pis=dynamic_cast(&s); assert(pis); ifstream &is = *pis; return is.read((char *)(&v),sizeof(T)); } } templateios &stream_array(ios &s, T *v, size_t &len) { ofstream *pos=dynamic_cast(&s); if (pos!=NULL) { ofstream &os = *pos; os||len; return os.write((char*)v,sizeof(T)*len); } else { ifstream *pis=dynamic_cast(&s); assert(pis); ifstream &is = *pis; is||len; return is.read((char *)v,sizeof(T)*len); } } class sertest { public: sertest() { size = 100; buf = new float[size]; } void build() { for (unsigned int n=0; n