6 #ifndef ClpHelperFunctions_H
7 #define ClpHelperFunctions_H
16 # error "don't have header file for math"
29 void setElements(
double * region,
int size,
double value);
30 void multiplyAdd(
const double * region1,
int size,
double multiplier1,
31 double * region2,
double multiplier2);
32 double innerProduct(
const double * region1,
int size,
const double * region2);
33 void getNorms(
const double * region,
int size,
double & norm1,
double & norm2);
37 void setElements(CoinWorkDouble * region,
int size, CoinWorkDouble value);
38 void multiplyAdd(
const CoinWorkDouble * region1,
int size, CoinWorkDouble multiplier1,
39 CoinWorkDouble * region2, CoinWorkDouble multiplier2);
40 CoinWorkDouble
innerProduct(
const CoinWorkDouble * region1,
int size,
const CoinWorkDouble * region2);
41 void getNorms(
const CoinWorkDouble * region,
int size, CoinWorkDouble & norm1, CoinWorkDouble & norm2);
43 CoinMemcpyN(
const double * from,
const int size, CoinWorkDouble * to)
45 for (
int i = 0; i < size; i++)
49 CoinMemcpyN(
const CoinWorkDouble * from,
const int size,
double * to)
51 for (
int i = 0; i < size; i++)
52 to[i] = static_cast<double>(from[i]);
55 CoinMax(
const CoinWorkDouble x1,
const double x2)
57 return (x1 > x2) ? x1 : x2;
60 CoinMax(
double x1,
const CoinWorkDouble x2)
62 return (x1 > x2) ? x1 : x2;
65 CoinMin(
const CoinWorkDouble x1,
const double x2)
67 return (x1 < x2) ? x1 : x2;
70 CoinMin(
double x1,
const CoinWorkDouble x2)
72 return (x1 < x2) ? x1 : x2;
74 inline CoinWorkDouble
CoinSqrt(CoinWorkDouble x)
86 # define ClpTraceDebug(expression) {}
88 void ClpTracePrint(std::string fileName, std::string message,
int line);
89 # define ClpTraceDebug(expression) { \
90 if (!(expression)) { ClpTracePrint(__FILE__,__STRING(expression),__LINE__); } \
97 inline double pdxxxmerit(
int nlow,
int nupp,
int *low,
int *upp, CoinDenseVector <double> &r1,
98 CoinDenseVector <double> &r2, CoinDenseVector <double> &rL,
99 CoinDenseVector <double> &rU, CoinDenseVector <double> &cL,
100 CoinDenseVector <double> &cU )
106 CoinDenseVector <double> f(6);
110 for (
int k = 0; k < nlow; k++) {
111 sum1 += rL[low[k]] * rL[low[k]];
112 sum2 += cL[low[k]] * cL[low[k]];
117 for (
int k = 0; k < nupp; k++) {
118 sum1 += rL[upp[k]] * rL[upp[k]];
119 sum2 += cL[upp[k]] * cL[upp[k]];
136 inline void pdxxxresid1(
ClpPdco *model,
const int nlow,
const int nupp,
const int nfix,
137 int *low,
int *upp,
int *fix,
138 CoinDenseVector <double> &b,
double *bl,
double *bu,
double d1,
double d2,
139 CoinDenseVector <double> &grad, CoinDenseVector <double> &rL,
140 CoinDenseVector <double> &rU, CoinDenseVector <double> &x,
141 CoinDenseVector <double> &x1, CoinDenseVector <double> &x2,
142 CoinDenseVector <double> &y, CoinDenseVector <double> &z1,
143 CoinDenseVector <double> &z2, CoinDenseVector <double> &r1,
144 CoinDenseVector <double> &r2,
double *Pinf,
double *Dinf)
152 double *x_elts = x.getElements();
153 double *r2_elts = r2.getElements();
155 for (
int k = 0; k < nfix; k++)
162 for (
int k = 0; k < nfix; k++)
166 r1 = b - r1 - d2 * d2 * y;
171 for (
int k = 0; k < nlow; k++)
172 rL[low[k]] = bl[low[k]] - x[low[k]] + x1[low[k]];
173 for (
int k = 0; k < nupp; k++)
174 rU[upp[k]] = - bu[upp[k]] + x[upp[k]] + x2[upp[k]];
178 for (
int k = 0; k < nlow; k++)
179 if (rL[low[k]] > normL) normL = rL[low[k]];
180 for (
int k = 0; k < nupp; k++)
181 if (rU[upp[k]] > normU) normU = rU[upp[k]];
183 *Pinf = CoinMax(normL, normU);
184 *Pinf = CoinMax( r1.infNorm() , *Pinf );
185 *Dinf = r2.infNorm();
186 *Pinf = CoinMax( *Pinf, 1e-99 );
187 *Dinf = CoinMax( *Dinf, 1e-99 );
198 inline void pdxxxresid2(
double mu,
int nlow,
int nupp,
int *low,
int *upp,
199 CoinDenseVector <double> &cL, CoinDenseVector <double> &cU,
200 CoinDenseVector <double> &x1, CoinDenseVector <double> &x2,
201 CoinDenseVector <double> &z1, CoinDenseVector <double> &z2,
202 double *center,
double *Cinf,
double *Cinf0)
211 double maxXz = -1e20;
214 double *x1_elts = x1.getElements();
215 double *z1_elts = z1.getElements();
216 double *cL_elts = cL.getElements();
217 for (
int k = 0; k < nlow; k++) {
218 double x1z1 = x1_elts[low[k]] * z1_elts[low[k]];
219 cL_elts[low[k]] = mu - x1z1;
220 if (x1z1 > maxXz) maxXz = x1z1;
221 if (x1z1 < minXz) minXz = x1z1;
224 double *x2_elts = x2.getElements();
225 double *z2_elts = z2.getElements();
226 double *cU_elts = cU.getElements();
227 for (
int k = 0; k < nupp; k++) {
228 double x2z2 = x2_elts[upp[k]] * z2_elts[upp[k]];
229 cU_elts[upp[k]] = mu - x2z2;
230 if (x2z2 > maxXz) maxXz = x2z2;
231 if (x2z2 < minXz) minXz = x2z2;
234 maxXz = CoinMax( maxXz, 1e-99 );
235 minXz = CoinMax( minXz, 1e-99 );
236 *center = maxXz / minXz;
240 for (
int k = 0; k < nlow; k++)
241 if (cL_elts[low[k]] > normL) normL = cL_elts[low[k]];
242 for (
int k = 0; k < nupp; k++)
243 if (cU_elts[upp[k]] > normU) normU = cU_elts[upp[k]];
244 *Cinf = CoinMax( normL, normU);
251 inline double pdxxxstep( 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]);
272 inline double pdxxxstep(
int nset,
int *set, CoinDenseVector <double> &x, CoinDenseVector <double> &dx )
281 double *x_elts = x.getElements();
282 double *dx_elts = dx.getElements();
283 for (
int k = 0; k < n; k++)
285 if ((x_elts[k] / (-dx_elts[k])) < step)
286 step = x_elts[k] / (-dx_elts[k]);
This solves problems in Primal Dual Convex Optimization.
void multiplyAdd(const double *region1, int size, double multiplier1, double *region2, double multiplier2)
void getNorms(const double *region, int size, double &norm1, double &norm2)
double CoinSqrt(double x)
void setElements(double *region, int size, double value)
void ClpTracePrint(std::string fileName, std::string message, int line)
Trace.
double maximumAbsElement(const double *region, int size)
Note (JJF) I have added some operations on arrays even though they may duplicate CoinDenseVector.
void matVecMult(int, double *, double *)
double innerProduct(const double *region1, int size, const double *region2)