6#ifndef ClpHelperFunctions_H
7#define ClpHelperFunctions_H
16#error "don't have header file for math"
30void multiplyAdd(
const double *region1,
int size,
double multiplier1,
31 double *region2,
double multiplier2);
32double innerProduct(
const double *region1,
int size,
const double *region2);
33void getNorms(
const double *region,
int size,
double &norm1,
double &norm2);
37void setElements(CoinWorkDouble *region,
int size, CoinWorkDouble value);
38void multiplyAdd(
const CoinWorkDouble *region1,
int size, CoinWorkDouble multiplier1,
39 CoinWorkDouble *region2, CoinWorkDouble multiplier2);
40CoinWorkDouble
innerProduct(
const CoinWorkDouble *region1,
int size,
const CoinWorkDouble *region2);
41void getNorms(
const CoinWorkDouble *region,
int size, CoinWorkDouble &norm1, CoinWorkDouble &norm2);
43CoinMemcpyN(
const double *from,
const int size, CoinWorkDouble *to)
45 for (
int i = 0; i < size; i++)
49CoinMemcpyN(
const CoinWorkDouble *from,
const int size,
double *to)
51 for (
int i = 0; i < size; i++)
52 to[i] =
static_cast< double >(from[i]);
55CoinMax(
const CoinWorkDouble x1,
const double x2)
57 return (x1 > x2) ? x1 : x2;
60CoinMax(
double x1,
const CoinWorkDouble x2)
62 return (x1 > x2) ? x1 : x2;
65CoinMin(
const CoinWorkDouble x1,
const double x2)
67 return (x1 < x2) ? x1 : x2;
70CoinMin(
double x1,
const CoinWorkDouble x2)
72 return (x1 < x2) ? x1 : x2;
74inline CoinWorkDouble
CoinSqrt(CoinWorkDouble x)
86#define ClpTraceDebug(expression) \
91#define ClpTraceDebug(expression) \
93 if (!(expression)) { \
94 ClpTracePrint(__FILE__, __STRING(expression), __LINE__); \
101inline double pdxxxmerit(
int nlow,
int nupp,
int *low,
int *upp, CoinDenseVector< double > &r1,
102 CoinDenseVector< double > &r2, CoinDenseVector< double > &rL,
103 CoinDenseVector< double > &rU, CoinDenseVector< double > &cL,
104 CoinDenseVector< double > &cU)
110 CoinDenseVector< double > f(6);
114 for (
int k = 0; k < nlow; k++) {
115 sum1 += rL[low[k]] * rL[low[k]];
116 sum2 += cL[low[k]] * cL[low[k]];
121 for (
int k = 0; k < nupp; k++) {
122 sum1 += rL[upp[k]] * rL[upp[k]];
123 sum2 += cL[upp[k]] * cL[upp[k]];
139inline void pdxxxresid1(
ClpPdco *model,
const int nlow,
const int nupp,
const int nfix,
140 int *low,
int *upp,
int *fix,
141 CoinDenseVector< double > &b,
double *bl,
double *bu,
double d1,
double d2,
142 CoinDenseVector< double > &grad, CoinDenseVector< double > &rL,
143 CoinDenseVector< double > &rU, CoinDenseVector< double > &x,
144 CoinDenseVector< double > &x1, CoinDenseVector< double > &x2,
145 CoinDenseVector< double > &y, CoinDenseVector< double > &z1,
146 CoinDenseVector< double > &z2, CoinDenseVector< double > &r1,
147 CoinDenseVector< double > &r2,
double *Pinf,
double *Dinf)
155 double *x_elts = x.getElements();
156 double *r2_elts = r2.getElements();
158 for (
int k = 0; k < nfix; k++)
165 for (
int k = 0; k < nfix; k++)
168 r1 = b - r1 - d2 * d2 * y;
173 for (
int k = 0; k < nlow; k++)
174 rL[low[k]] = bl[low[k]] - x[low[k]] + x1[low[k]];
175 for (
int k = 0; k < nupp; k++)
176 rU[upp[k]] = -bu[upp[k]] + x[upp[k]] + x2[upp[k]];
180 for (
int k = 0; k < nlow; k++)
181 if (rL[low[k]] > normL)
183 for (
int k = 0; k < nupp; k++)
184 if (rU[upp[k]] > normU)
187 *Pinf = CoinMax(normL, normU);
188 *Pinf = CoinMax(r1.infNorm(), *Pinf);
189 *Dinf = r2.infNorm();
190 *Pinf = CoinMax(*Pinf, 1e-99);
191 *Dinf = CoinMax(*Dinf, 1e-99);
201inline void pdxxxresid2(
double mu,
int nlow,
int nupp,
int *low,
int *upp,
202 CoinDenseVector< double > &cL, CoinDenseVector< double > &cU,
203 CoinDenseVector< double > &x1, CoinDenseVector< double > &x2,
204 CoinDenseVector< double > &z1, CoinDenseVector< double > &z2,
205 double *center,
double *Cinf,
double *Cinf0)
214 double maxXz = -1e20;
217 double *x1_elts = x1.getElements();
218 double *z1_elts = z1.getElements();
219 double *cL_elts = cL.getElements();
220 for (
int k = 0; k < nlow; k++) {
221 double x1z1 = x1_elts[low[k]] * z1_elts[low[k]];
222 cL_elts[low[k]] = mu - x1z1;
229 double *x2_elts = x2.getElements();
230 double *z2_elts = z2.getElements();
231 double *cU_elts = cU.getElements();
232 for (
int k = 0; k < nupp; k++) {
233 double x2z2 = x2_elts[upp[k]] * z2_elts[upp[k]];
234 cU_elts[upp[k]] = mu - x2z2;
241 maxXz = CoinMax(maxXz, 1e-99);
242 minXz = CoinMax(minXz, 1e-99);
243 *center = maxXz / minXz;
247 for (
int k = 0; k < nlow; k++)
248 if (cL_elts[low[k]] > normL)
249 normL = cL_elts[low[k]];
250 for (
int k = 0; k < nupp; k++)
251 if (cU_elts[upp[k]] > normU)
252 normU = cU_elts[upp[k]];
253 *Cinf = CoinMax(normL, normU);
260inline double pdxxxstep(CoinDenseVector< double > &x, CoinDenseVector< double > &dx)
269 double *x_elts = x.getElements();
270 double *dx_elts = dx.getElements();
271 for (
int k = 0; k < n; k++)
273 if ((x_elts[k] / (-dx_elts[k])) < step)
274 step = x_elts[k] / (-dx_elts[k]);
281inline double pdxxxstep(
int nset,
int *set, CoinDenseVector< double > &x, CoinDenseVector< double > &dx)
290 double *x_elts = x.getElements();
291 double *dx_elts = dx.getElements();
292 for (
int k = 0; k < n; k++)
294 if ((x_elts[k] / (-dx_elts[k])) < step)
295 step = x_elts[k] / (-dx_elts[k]);
double CoinSqrt(double x)
double innerProduct(const double *region1, int size, const double *region2)
double maximumAbsElement(const double *region, int size)
Note (JJF) I have added some operations on arrays even though they may duplicate CoinDenseVector.
void getNorms(const double *region, int size, double &norm1, double &norm2)
void ClpTracePrint(std::string fileName, std::string message, int line)
Trace.
void multiplyAdd(const double *region1, int size, double multiplier1, double *region2, double multiplier2)
void setElements(double *region, int size, double value)
This solves problems in Primal Dual Convex Optimization.
void matVecMult(int, double *, double *)