Go to the documentation of this file.00001 #include "global.h"
00002
00003 base_generator_type randGenerator(42u);
00004 boost::uniform_real<> uniDistReal(0, 1);
00005 boost::variate_generator<base_generator_type&, boost::uniform_real<> > uniReal(randGenerator, uniDistReal);
00006 boost::uniform_int<> uniDistInt(0, INT_MAX);
00007 boost::variate_generator<base_generator_type&, boost::uniform_int<> > uniInt(randGenerator, uniDistInt);
00008 boost::normal_distribution<> normDist(0, 1);
00009 boost::variate_generator<base_generator_type&, boost::normal_distribution<> > normReal(randGenerator, normDist);
00010 boost::math::normal_distribution<> normDistMath(0, 1);
00011
00012
00013 void randPerm(vector<int>& A, int n)
00014 {
00015 for (int i = 0; i < n; i++)
00016 A[i] = i+1;
00017
00018 int r, temp;
00019 for (int i = n-1; i >= 0; i--)
00020 {
00021 r = uniInt() % (i + 1);
00022
00023 temp = A[i];
00024 A[i] = A[r];
00025 A[r] = temp;
00026 }
00027 }
00028
00029 string itos(int number)
00030 {
00031 ostringstream buffer;
00032
00033 buffer << number;
00034
00035 return buffer.str();
00036 }
00037
00038 void skipLinesUntil(ifstream& infile, string text)
00039 {
00040 char line[LEN];
00041 string temp;
00042
00043 do
00044 {
00045 infile.getline(line, LEN);
00046 temp = line;
00047 } while (temp.find(text) == string::npos);
00048 }
00049
00050 char* getValue(ifstream& infile)
00051 {
00052 char line[LEN], * first;
00053
00054
00055 do
00056 {
00057 infile.getline(line, LEN);
00058 } while (line[0] == COMMENT);
00059
00060 first = strtok(line, DELIMS);
00061
00062
00063 if (line[0] == REPEAT)
00064 return first;
00065
00066
00067 return strtok(NULL, DELIMS);
00068 }
00069
00070 string getStringValue(ifstream& infile)
00071 {
00072 char line[LEN];
00073
00074
00075 do
00076 {
00077 infile.getline(line, LEN);
00078 } while (line[0] == COMMENT);
00079
00080
00081 strtok(line, DELIMS);
00082 string value = strtok(NULL, DELIMS);
00083 return value;
00084 }
00085
00086 void getBound(ifstream& infile, vector<double>* bound_r, vector<int>* bound_d_z, int n)
00087 {
00088 char* value;
00089 bool repeat = false;
00090
00091 if (bound_r != NULL)
00092 {
00093 for (int i = 0; i < n; i++)
00094 {
00095 if (!repeat)
00096 {
00097 value = getValue(infile);
00098
00099 if (value[0] != REPEAT)
00100 bound_r->push_back(strtod(value, NULL));
00101 else
00102 {
00103 repeat = true;
00104 i--;
00105 }
00106 }
00107 else
00108 bound_r->push_back(bound_r->at(i-1));
00109 }
00110 }
00111
00112 if (bound_d_z != NULL)
00113 {
00114 for (int i = 0; i < n; i++)
00115 {
00116 if (!repeat)
00117 {
00118 value = getValue(infile);
00119
00120 if (value[0] != REPEAT)
00121 bound_d_z->push_back(atoi(value));
00122 else
00123 {
00124 repeat = true;
00125 i--;
00126 }
00127 }
00128 else
00129 bound_d_z->push_back(bound_d_z->at(i-1));
00130 }
00131 }
00132 }
00133
00134 void findAndReplace(string& text, const char* find, const char* replace)
00135 {
00136 if (strlen(find) != strlen(replace))
00137 {
00138 cerr << "findAndReplace(): find and replace must be of equal length!" << endl;
00139 return;
00140 }
00141
00142 unsigned pos = text.find(find);
00143
00144 while (pos != string::npos)
00145 {
00146 text.replace(pos, strlen(find), replace);
00147 pos = text.find(find);
00148 }
00149 }