00001
00002
00003 #ifndef ClpHelperFunctions_H
00004 #define ClpHelperFunctions_H
00005
00014 double maximumAbsElement(const double * region, int size);
00015 void setElements(double * region, int size, double value);
00016 void multiplyAdd(const double * region1, int size, double multiplier1,
00017 double * region2, double multiplier2);
00018 double innerProduct(const double * region1, int size, const double * region2);
00019 void getNorms(const double * region, int size, double & norm1, double & norm2);
00020
00022 #ifdef ClpPdco_H
00023
00024
00025 inline double pdxxxmerit(int nlow, int nupp, int *low, int *upp, CoinDenseVector <double> &r1,
00026 CoinDenseVector <double> &r2, CoinDenseVector <double> &rL,
00027 CoinDenseVector <double> &rU, CoinDenseVector <double> &cL,
00028 CoinDenseVector <double> &cU ){
00029
00030
00031
00032 double sum1, sum2;
00033 CoinDenseVector <double> f(6);
00034 f[0] = r1.twoNorm();
00035 f[1] = r2.twoNorm();
00036 sum1 = sum2 = 0.0;
00037 for (int k=0; k<nlow; k++){
00038 sum1 += rL[low[k]]*rL[low[k]];
00039 sum2 += cL[low[k]]*cL[low[k]];
00040 }
00041 f[2] = sqrt(sum1);
00042 f[4] = sqrt(sum2);
00043 sum1 = sum2 = 0.0;
00044 for (int k=0; k<nupp; k++){
00045 sum1 += rL[upp[k]]*rL[upp[k]];
00046 sum2 += cL[upp[k]]*cL[upp[k]];
00047 }
00048 f[3] = sqrt(sum1);
00049 f[5] = sqrt(sum2);
00050
00051 return f.twoNorm();
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 inline void pdxxxresid1(ClpPdco *model, const int nlow, const int nupp, const int nfix,
00064 int *low, int *upp, int *fix,
00065 CoinDenseVector <double> &b, double *bl, double *bu, double d1, double d2,
00066 CoinDenseVector <double> &grad, CoinDenseVector <double> &rL,
00067 CoinDenseVector <double> &rU, CoinDenseVector <double> &x,
00068 CoinDenseVector <double> &x1, CoinDenseVector <double> &x2,
00069 CoinDenseVector <double> &y, CoinDenseVector <double> &z1,
00070 CoinDenseVector <double> &z2, CoinDenseVector <double> &r1,
00071 CoinDenseVector <double> &r2, double *Pinf, double *Dinf){
00072
00073
00074
00075
00076
00077
00078 double *x_elts = x.getElements();
00079 double *r2_elts = r2.getElements();
00080
00081 for (int k=0; k<nfix; k++)
00082 x_elts[fix[k]] = 0;
00083
00084 r1.clear();
00085 r2.clear();
00086 model->matVecMult( 1, r1, x );
00087 model->matVecMult( 2, r2, y );
00088 for (int k=0; k<nfix; k++)
00089 r2_elts[fix[k]] = 0;
00090
00091
00092 r1 = b - r1 - d2*d2*y;
00093 r2 = grad - r2 - z1;
00094 if(nupp > 0)
00095 r2 = r2 + z2;
00096
00097 for (int k=0; k<nlow; k++)
00098 rL[low[k]] = bl[low[k]] - x[low[k]] + x1[low[k]];
00099 for (int k=0; k<nupp; k++)
00100 rU[upp[k]] = - bu[upp[k]] + x[upp[k]] + x2[upp[k]];
00101
00102 double normL = 0.0;
00103 double normU = 0.0;
00104 for (int k=0; k<nlow; k++)
00105 if (rL[low[k]] > normL) normL = rL[low[k]];
00106 for (int k=0; k<nupp; k++)
00107 if (rU[upp[k]] > normU) normU = rU[upp[k]];
00108
00109 *Pinf = CoinMax(normL, normU);
00110 *Pinf = CoinMax( r1.infNorm() , *Pinf );
00111 *Dinf = r2.infNorm();
00112 *Pinf = CoinMax( *Pinf, 1e-99 );
00113 *Dinf = CoinMax( *Dinf, 1e-99 );
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 inline void pdxxxresid2(double mu, int nlow, int nupp, int *low, int *upp,
00125 CoinDenseVector <double> &cL, CoinDenseVector <double> &cU,
00126 CoinDenseVector <double> &x1, CoinDenseVector <double> &x2,
00127 CoinDenseVector <double> &z1, CoinDenseVector <double> &z2,
00128 double *center, double *Cinf, double *Cinf0){
00129
00130
00131
00132
00133
00134
00135
00136 double maxXz = -1e20;
00137 double minXz = 1e20;
00138
00139 double *x1_elts = x1.getElements();
00140 double *z1_elts = z1.getElements();
00141 double *cL_elts = cL.getElements();
00142 for (int k=0; k<nlow; k++){
00143 double x1z1 = x1_elts[low[k]] * z1_elts[low[k]];
00144 cL_elts[low[k]] = mu - x1z1;
00145 if(x1z1 > maxXz) maxXz = x1z1;
00146 if(x1z1 < minXz) minXz = x1z1;
00147 }
00148
00149 double *x2_elts = x2.getElements();
00150 double *z2_elts = z2.getElements();
00151 double *cU_elts = cU.getElements();
00152 for (int k=0; k<nupp; k++){
00153 double x2z2 = x2_elts[upp[k]] * z2_elts[upp[k]];
00154 cU_elts[upp[k]] = mu - x2z2;
00155 if(x2z2 > maxXz) maxXz = x2z2;
00156 if(x2z2 < minXz) minXz = x2z2;
00157 }
00158
00159 maxXz = CoinMax( maxXz, 1e-99 );
00160 minXz = CoinMax( minXz, 1e-99 );
00161 *center = maxXz / minXz;
00162
00163 double normL = 0.0;
00164 double normU = 0.0;
00165 for (int k=0; k<nlow; k++)
00166 if (cL_elts[low[k]] > normL) normL = cL_elts[low[k]];
00167 for (int k=0; k<nupp; k++)
00168 if (cU_elts[upp[k]] > normU) normU = cU_elts[upp[k]];
00169 *Cinf = CoinMax( normL, normU);
00170 *Cinf0 = maxXz;
00171 }
00172
00173
00174
00175
00176 inline double pdxxxstep( CoinDenseVector <double> &x, CoinDenseVector <double> &dx ){
00177
00178
00179
00180
00181 double step = 1e+20;
00182
00183 int n = x.size();
00184 double *x_elts = x.getElements();
00185 double *dx_elts = dx.getElements();
00186 for (int k=0; k<n; k++)
00187 if (dx_elts[k] < 0)
00188 if ((x_elts[k]/(-dx_elts[k])) < step)
00189 step = x_elts[k]/(-dx_elts[k]);
00190 return step;
00191 }
00192
00193
00194
00195
00196 inline double pdxxxstep(int nset, int *set, CoinDenseVector <double> &x, CoinDenseVector <double> &dx ){
00197
00198
00199
00200
00201 double step = 1e+20;
00202
00203 int n = x.size();
00204 double *x_elts = x.getElements();
00205 double *dx_elts = dx.getElements();
00206 for (int k=0; k<n; k++)
00207 if (dx_elts[k] < 0)
00208 if ((x_elts[k]/(-dx_elts[k])) < step)
00209 step = x_elts[k]/(-dx_elts[k]);
00210 return step;
00211 }
00212
00213
00214
00215 #endif
00216 #endif