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
00113 static SparseMatrix* convertLinearConstraintCoefficientMatrixToTheOtherMajor(
00114 bool isColumnMajor, int startSize, int valueSize, int* start, int* index,
00115 double* value, int dimension);
00116
00122 std::string format_os_dtoa( double x);
00123
00124
00133
00134
00143
00144
00145
00146
00147 };
00148
00149
00165 inline void getMultIncr(int* i, int *mult, int *incr, int size, int defaultIncr)
00166 {
00167 int k;
00168
00169 *mult = 1;
00170 *incr = defaultIncr;
00171
00172 if (size == 1) return;
00173
00174 for (k=1; (k < size) && (i[k] - i[k-1] == defaultIncr); k++)
00175 {
00176 (*mult)++;
00177 }
00178 if (*mult > 1 || size == 2) return;
00179
00180 *incr = i[1] - i[0];
00181 if (i[2] - i[1] != *incr) return;
00182
00183 *mult = 3;
00184 for (k=3; (k < size) && (i[k] - i[k-1] == *incr); k++)
00185 {
00186 (*mult)++;
00187 }
00188 return;
00189 }
00190
00191
00203 inline void getMultIncr(double* a, int *mult, double *incr, int size)
00204 {
00205 double mark;
00206 int k;
00207
00208 *mult = 1;
00209 *incr = 0;
00210
00211 if (size == 1) return;
00212
00213 mark = a[0];
00214 for (k=1; (k < size) && (a[k] == mark); k++)
00215 {
00216 (*mult)++;
00217 }
00218 if (*mult > 1 || size == 2) return;
00219
00220 *incr = a[1] - a[0];
00221 if (a[2] - a[1] != *incr) return;
00222
00223 *mult = 3;
00224 for (k=3; (k < size) && (a[k] - a[k-1] == *incr); k++)
00225 {
00226 (*mult)++;
00227 }
00228 return;
00229 }
00230
00231
00232
00243 inline int getMult(int* i, int size)
00244 {
00245 int mark;
00246
00247 int mult = 1;
00248
00249 if (size == 1) return mult;
00250
00251 mark = i[0];
00252 for (int k=1; (k < size) && (i[k] == mark); k++)
00253 {
00254 mult++;
00255 }
00256 return mult;
00257 }
00258
00259
00260
00271 inline int getMult(double* a, int size)
00272 {
00273 double mark;
00274
00275 int mult = 1;
00276
00277 if (size == 1) return mult;
00278
00279 mark = a[0];
00280 for (int k=1; (k < size) && (a[k] == mark); k++)
00281 {
00282 mult++;
00283 }
00284 return mult;
00285 }
00286
00287
00295 double OSRand();
00296
00297
00305 double OSiRand(int iMin, int iMax);
00306
00307
00308 #endif