4 #ifndef ClpHelperFunctions_H
5 #define ClpHelperFunctions_H
16 void setElements(
double * region,
int size,
double value);
17 void multiplyAdd(
const double * region1,
int size,
double multiplier1,
18 double * region2,
double multiplier2);
19 double innerProduct(
const double * region1,
int size,
const double * region2);
20 void getNorms(
const double * region,
int size,
double & norm1,
double & norm2);
24 void setElements(CoinWorkDouble * region,
int size, CoinWorkDouble value);
25 void multiplyAdd(
const CoinWorkDouble * region1,
int size, CoinWorkDouble multiplier1,
26 CoinWorkDouble * region2, CoinWorkDouble multiplier2);
27 CoinWorkDouble
innerProduct(
const CoinWorkDouble * region1,
int size,
const CoinWorkDouble * region2);
28 void getNorms(
const CoinWorkDouble * region,
int size, CoinWorkDouble & norm1, CoinWorkDouble & norm2);
30 CoinMemcpyN(
const double * from,
const int size, CoinWorkDouble * to)
32 for (
int i = 0; i < size; i++)
36 CoinMemcpyN(
const CoinWorkDouble * from,
const int size,
double * to)
38 for (
int i = 0; i < size; i++)
39 to[i] = static_cast<double>(from[i]);
42 CoinMax(
const CoinWorkDouble x1,
const double x2)
44 return (x1 > x2) ? x1 : x2;
47 CoinMax(
double x1,
const CoinWorkDouble x2)
49 return (x1 > x2) ? x1 : x2;
52 CoinMin(
const CoinWorkDouble x1,
const double x2)
54 return (x1 < x2) ? x1 : x2;
57 CoinMin(
double x1,
const CoinWorkDouble x2)
59 return (x1 < x2) ? x1 : x2;
61 inline CoinWorkDouble
CoinSqrt(CoinWorkDouble x)
76 inline double pdxxxmerit(
int nlow,
int nupp,
int *low,
int *upp, CoinDenseVector <double> &r1,
77 CoinDenseVector <double> &r2, CoinDenseVector <double> &rL,
78 CoinDenseVector <double> &rU, CoinDenseVector <double> &cL,
79 CoinDenseVector <double> &cU )
85 CoinDenseVector <double> f(6);
89 for (
int k = 0; k < nlow; k++) {
90 sum1 += rL[low[k]] * rL[low[k]];
91 sum2 += cL[low[k]] * cL[low[k]];
96 for (
int k = 0; k < nupp; k++) {
97 sum1 += rL[upp[k]] * rL[upp[k]];
98 sum2 += cL[upp[k]] * cL[upp[k]];
115 inline void pdxxxresid1(
ClpPdco *model,
const int nlow,
const int nupp,
const int nfix,
116 int *low,
int *upp,
int *fix,
117 CoinDenseVector <double> &b,
double *bl,
double *bu,
double d1,
double d2,
118 CoinDenseVector <double> &grad, CoinDenseVector <double> &rL,
119 CoinDenseVector <double> &rU, CoinDenseVector <double> &x,
120 CoinDenseVector <double> &x1, CoinDenseVector <double> &x2,
121 CoinDenseVector <double> &y, CoinDenseVector <double> &z1,
122 CoinDenseVector <double> &z2, CoinDenseVector <double> &r1,
123 CoinDenseVector <double> &r2,
double *Pinf,
double *Dinf)
131 double *x_elts = x.getElements();
132 double *r2_elts = r2.getElements();
134 for (
int k = 0; k < nfix; k++)
141 for (
int k = 0; k < nfix; k++)
145 r1 = b - r1 - d2 * d2 * y;
150 for (
int k = 0; k < nlow; k++)
151 rL[low[k]] = bl[low[k]] - x[low[k]] + x1[low[k]];
152 for (
int k = 0; k < nupp; k++)
153 rU[upp[k]] = - bu[upp[k]] + x[upp[k]] + x2[upp[k]];
157 for (
int k = 0; k < nlow; k++)
158 if (rL[low[k]] > normL) normL = rL[low[k]];
159 for (
int k = 0; k < nupp; k++)
160 if (rU[upp[k]] > normU) normU = rU[upp[k]];
162 *Pinf = CoinMax(normL, normU);
163 *Pinf = CoinMax( r1.infNorm() , *Pinf );
164 *Dinf = r2.infNorm();
165 *Pinf = CoinMax( *Pinf, 1e-99 );
166 *Dinf = CoinMax( *Dinf, 1e-99 );
177 inline void pdxxxresid2(
double mu,
int nlow,
int nupp,
int *low,
int *upp,
178 CoinDenseVector <double> &cL, CoinDenseVector <double> &cU,
179 CoinDenseVector <double> &x1, CoinDenseVector <double> &x2,
180 CoinDenseVector <double> &z1, CoinDenseVector <double> &z2,
181 double *center,
double *Cinf,
double *Cinf0)
190 double maxXz = -1e20;
193 double *x1_elts = x1.getElements();
194 double *z1_elts = z1.getElements();
195 double *cL_elts = cL.getElements();
196 for (
int k = 0; k < nlow; k++) {
197 double x1z1 = x1_elts[low[k]] * z1_elts[low[k]];
198 cL_elts[low[k]] = mu - x1z1;
199 if (x1z1 > maxXz) maxXz = x1z1;
200 if (x1z1 < minXz) minXz = x1z1;
203 double *x2_elts = x2.getElements();
204 double *z2_elts = z2.getElements();
205 double *cU_elts = cU.getElements();
206 for (
int k = 0; k < nupp; k++) {
207 double x2z2 = x2_elts[upp[k]] * z2_elts[upp[k]];
208 cU_elts[upp[k]] = mu - x2z2;
209 if (x2z2 > maxXz) maxXz = x2z2;
210 if (x2z2 < minXz) minXz = x2z2;
213 maxXz = CoinMax( maxXz, 1e-99 );
214 minXz = CoinMax( minXz, 1e-99 );
215 *center = maxXz / minXz;
219 for (
int k = 0; k < nlow; k++)
220 if (cL_elts[low[k]] > normL) normL = cL_elts[low[k]];
221 for (
int k = 0; k < nupp; k++)
222 if (cU_elts[upp[k]] > normU) normU = cU_elts[upp[k]];
223 *Cinf = CoinMax( normL, normU);
230 inline double pdxxxstep( CoinDenseVector <double> &x, CoinDenseVector <double> &dx )
239 double *x_elts = x.getElements();
240 double *dx_elts = dx.getElements();
241 for (
int k = 0; k < n; k++)
243 if ((x_elts[k] / (-dx_elts[k])) < step)
244 step = x_elts[k] / (-dx_elts[k]);
251 inline double pdxxxstep(
int nset,
int *set, CoinDenseVector <double> &x, CoinDenseVector <double> &dx )
260 double *x_elts = x.getElements();
261 double *dx_elts = dx.getElements();
262 for (
int k = 0; k < n; k++)
264 if ((x_elts[k] / (-dx_elts[k])) < step)
265 step = x_elts[k] / (-dx_elts[k]);
void matVecMult(int, double *, double *)
LSQR.
void getNorms(const double *region, int size, double &norm1, double &norm2)
void setElements(double *region, int size, double value)
double maximumAbsElement(const double *region, int size)
Note (JJF) I have added some operations on arrays even though they may duplicate CoinDenseVector.
double innerProduct(const double *region1, int size, const double *region2)
This solves problems in Primal Dual Convex Optimization.
double CoinSqrt(double x)
void multiplyAdd(const double *region1, int size, double multiplier1, double *region2, double multiplier2)