6 #ifndef ClpHelperFunctions_H
7 #define ClpHelperFunctions_H
16 #error "don't have header file for math"
30 void setElements(
double *region,
int size,
double value);
31 void multiplyAdd(
const double *region1,
int size,
double multiplier1,
32 double *region2,
double multiplier2);
33 double innerProduct(
const double *region1,
int size,
const double *region2);
34 void getNorms(
const double *region,
int size,
double &norm1,
double &norm2);
38 void setElements(CoinWorkDouble *region,
int size, CoinWorkDouble value);
39 void multiplyAdd(
const CoinWorkDouble *region1,
int size, CoinWorkDouble multiplier1,
40 CoinWorkDouble *region2, CoinWorkDouble multiplier2);
41 CoinWorkDouble
innerProduct(
const CoinWorkDouble *region1,
int size,
const CoinWorkDouble *region2);
42 void getNorms(
const CoinWorkDouble *region,
int size, CoinWorkDouble &norm1, CoinWorkDouble &norm2);
44 CoinMemcpyN(
const double *from,
const int size, CoinWorkDouble *to)
46 for (
int i = 0; i < size; i++)
50 CoinMemcpyN(
const CoinWorkDouble *from,
const int size,
double *to)
52 for (
int i = 0; i < size; i++)
53 to[i] =
static_cast< double >(from[i]);
56 CoinMax(
const CoinWorkDouble x1,
const double x2)
58 return (x1 > x2) ? x1 : x2;
61 CoinMax(
double x1,
const CoinWorkDouble x2)
63 return (x1 > x2) ? x1 : x2;
66 CoinMin(
const CoinWorkDouble x1,
const double x2)
68 return (x1 < x2) ? x1 : x2;
71 CoinMin(
double x1,
const CoinWorkDouble x2)
73 return (x1 < x2) ? x1 : x2;
75 inline CoinWorkDouble
CoinSqrt(CoinWorkDouble x)
87 #define ClpTraceDebug(expression) \
91 void ClpTracePrint(std::string fileName, std::string message,
int line);
92 #define ClpTraceDebug(expression) \
94 if (!(expression)) { \
95 ClpTracePrint(__FILE__, __STRING(expression), __LINE__); \
102 inline double pdxxxmerit(
int nlow,
int nupp,
int *low,
int *upp, CoinDenseVector< double > &r1,
103 CoinDenseVector< double > &r2, CoinDenseVector< double > &rL,
104 CoinDenseVector< double > &rU, CoinDenseVector< double > &cL,
105 CoinDenseVector< double > &cU)
111 CoinDenseVector< double > f(6);
115 for (
int k = 0; k < nlow; k++) {
116 sum1 += rL[low[k]] * rL[low[k]];
117 sum2 += cL[low[k]] * cL[low[k]];
122 for (
int k = 0; k < nupp; k++) {
123 sum1 += rL[upp[k]] * rL[upp[k]];
124 sum2 += cL[upp[k]] * cL[upp[k]];
140 inline void pdxxxresid1(
ClpPdco *model,
const int nlow,
const int nupp,
const int nfix,
141 int *low,
int *upp,
int *fix,
142 CoinDenseVector< double > &b,
double *bl,
double *bu,
double d1,
double d2,
143 CoinDenseVector< double > &grad, CoinDenseVector< double > &rL,
144 CoinDenseVector< double > &rU, CoinDenseVector< double > &x,
145 CoinDenseVector< double > &x1, CoinDenseVector< double > &x2,
146 CoinDenseVector< double > &y, CoinDenseVector< double > &z1,
147 CoinDenseVector< double > &z2, CoinDenseVector< double > &r1,
148 CoinDenseVector< double > &r2,
double *Pinf,
double *Dinf)
156 double *x_elts = x.getElements();
157 double *r2_elts = r2.getElements();
159 for (
int k = 0; k < nfix; k++)
166 for (
int k = 0; k < nfix; k++)
169 r1 = b - r1 - d2 * d2 * y;
174 for (
int k = 0; k < nlow; k++)
175 rL[low[k]] = bl[low[k]] - x[low[k]] + x1[low[k]];
176 for (
int k = 0; k < nupp; k++)
177 rU[upp[k]] = -bu[upp[k]] + x[upp[k]] + x2[upp[k]];
181 for (
int k = 0; k < nlow; k++)
182 if (rL[low[k]] > normL)
184 for (
int k = 0; k < nupp; k++)
185 if (rU[upp[k]] > normU)
188 *Pinf = CoinMax(normL, normU);
189 *Pinf = CoinMax(r1.infNorm(), *Pinf);
190 *Dinf = r2.infNorm();
191 *Pinf = CoinMax(*Pinf, 1e-99);
192 *Dinf = CoinMax(*Dinf, 1e-99);
202 inline void pdxxxresid2(
double mu,
int nlow,
int nupp,
int *low,
int *upp,
203 CoinDenseVector< double > &cL, CoinDenseVector< double > &cU,
204 CoinDenseVector< double > &x1, CoinDenseVector< double > &x2,
205 CoinDenseVector< double > &z1, CoinDenseVector< double > &z2,
206 double *center,
double *Cinf,
double *Cinf0)
215 double maxXz = -1e20;
218 double *x1_elts = x1.getElements();
219 double *z1_elts = z1.getElements();
220 double *cL_elts = cL.getElements();
221 for (
int k = 0; k < nlow; k++) {
222 double x1z1 = x1_elts[low[k]] * z1_elts[low[k]];
223 cL_elts[low[k]] = mu - x1z1;
230 double *x2_elts = x2.getElements();
231 double *z2_elts = z2.getElements();
232 double *cU_elts = cU.getElements();
233 for (
int k = 0; k < nupp; k++) {
234 double x2z2 = x2_elts[upp[k]] * z2_elts[upp[k]];
235 cU_elts[upp[k]] = mu - x2z2;
242 maxXz = CoinMax(maxXz, 1e-99);
243 minXz = CoinMax(minXz, 1e-99);
244 *center = maxXz / minXz;
248 for (
int k = 0; k < nlow; k++)
249 if (cL_elts[low[k]] > normL)
250 normL = cL_elts[low[k]];
251 for (
int k = 0; k < nupp; k++)
252 if (cU_elts[upp[k]] > normU)
253 normU = cU_elts[upp[k]];
254 *Cinf = CoinMax(normL, normU);
261 inline double pdxxxstep(CoinDenseVector< double > &x, CoinDenseVector< double > &dx)
270 double *x_elts = x.getElements();
271 double *dx_elts = dx.getElements();
272 for (
int k = 0; k < n; k++)
274 if ((x_elts[k] / (-dx_elts[k])) < step)
275 step = x_elts[k] / (-dx_elts[k]);
282 inline double pdxxxstep(
int nset,
int *set, CoinDenseVector< double > &x, CoinDenseVector< double > &dx)
291 double *x_elts = x.getElements();
292 double *dx_elts = dx.getElements();
293 for (
int k = 0; k < n; k++)
295 if ((x_elts[k] / (-dx_elts[k])) < step)
296 step = x_elts[k] / (-dx_elts[k]);