00001
00020 #ifndef MATHUTIL_H
00021 #define MATHUTIL_H
00022
00023 #include "OSParameters.h"
00024 #include "OSdtoa.h"
00025 #include "OSErrorClass.h"
00026 #include "OSGeneral.h"
00027
00028
00029 #include <string>
00030
00031 #ifdef __cplusplus
00032 extern std::string os_dtoa_format(double x);
00033 #endif
00034
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038
00039 double os_strtod_wrap(const char *str, char **strEnd);
00040
00041 #ifdef __cplusplus
00042 }
00043 #endif
00044
00057 class MathUtil
00058 {
00059 public:
00060
00062 MathUtil();
00063
00065 ~MathUtil();
00066
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00095
00096
00097
00098
00099
00116 static SparseMatrix* convertLinearConstraintCoefficientMatrixToTheOtherMajor(
00117 bool isColumnMajor, int startSize, int valueSize, int* start, int* index,
00118 double* value, int dimension);
00119
00125 std::string format_os_dtoa( double x);
00126
00127
00136
00137
00146
00147
00148
00149
00150 };
00151
00152
00168 inline void getMultIncr(int* i, int *mult, int *incr, int size, int defaultIncr)
00169 {
00170 int k;
00171
00172 *mult = 1;
00173 *incr = defaultIncr;
00174
00175 if (size == 1) return;
00176
00177 for (k=1; (k < size) && (i[k] - i[k-1] == defaultIncr); k++)
00178 {
00179 (*mult)++;
00180 }
00181 if (*mult > 1 || size == 2) return;
00182
00183 *incr = i[1] - i[0];
00184 if (i[2] - i[1] != *incr) return;
00185
00186 *mult = 3;
00187 for (k=3; (k < size) && (i[k] - i[k-1] == *incr); k++)
00188 {
00189 (*mult)++;
00190 }
00191 return;
00192 }
00193
00194
00206 inline void getMultIncr(double* a, int *mult, double *incr, int size)
00207 {
00208 double mark;
00209 int k;
00210
00211 *mult = 1;
00212 *incr = 0;
00213
00214 if (size == 1) return;
00215
00216 mark = a[0];
00217 for (k=1; (k < size) && (a[k] == mark); k++)
00218 {
00219 (*mult)++;
00220 }
00221 if (*mult > 1 || size == 2) return;
00222
00223 *incr = a[1] - a[0];
00224 if (a[2] - a[1] != *incr) return;
00225
00226 *mult = 3;
00227 for (k=3; (k < size) && (a[k] - a[k-1] == *incr); k++)
00228 {
00229 (*mult)++;
00230 }
00231 return;
00232 }
00233
00234
00235
00246 inline int getMult(int* i, int size)
00247 {
00248 int mark;
00249
00250 int mult = 1;
00251
00252 if (size == 1) return mult;
00253
00254 mark = i[0];
00255 for (int k=1; (k < size) && (i[k] == mark); k++)
00256 {
00257 mult++;
00258 }
00259 return mult;
00260 }
00261
00262
00263
00274 inline int getMult(double* a, int size)
00275 {
00276 double mark;
00277
00278 int mult = 1;
00279
00280 if (size == 1) return mult;
00281
00282 mark = a[0];
00283 for (int k=1; (k < size) && (a[k] == mark); k++)
00284 {
00285 mult++;
00286 }
00287 return mult;
00288 }
00289
00290
00298 double OSRand();
00299
00300
00308 double OSiRand(int iMin, int iMax);
00309
00310 #endif