// Copyright (C) 2003, International Business Machines // Corporation and others. All Rights Reserved. #ifndef ClpHelperFunctions_H #define ClpHelperFunctions_H /** Note (JJF) I have added some operations on arrays even though they may duplicate CoinDenseVector. I think the use of templates was a mistake as I don't think inline generic code can take as much advantage of parallelism or machine architectures or memory hierarchies. */ double maximumAbsElement(const double * region, int size); void setElements(double * region, int size, double value); void multiplyAdd(const double * region1, int size, double multiplier1, double * region2, double multiplier2); double innerProduct(const double * region1, int size, const double * region2); void getNorms(const double * region, int size, double & norm1, double & norm2); /// Following only included if ClpPdco defined #ifdef ClpPdco_H inline double pdxxxmerit(int nlow, int nupp, int *low, int *upp, CoinDenseVector &r1, CoinDenseVector &r2, CoinDenseVector &rL, CoinDenseVector &rU, CoinDenseVector &cL, CoinDenseVector &cU ){ // Evaluate the merit function for Newton's method. // It is the 2-norm of the three sets of residuals. double sum1, sum2; CoinDenseVector f(6); f[0] = r1.twoNorm(); f[1] = r2.twoNorm(); sum1 = sum2 = 0.0; for (int k=0; k &b, double *bl, double *bu, double d1, double d2, CoinDenseVector &grad, CoinDenseVector &rL, CoinDenseVector &rU, CoinDenseVector &x, CoinDenseVector &x1, CoinDenseVector &x2, CoinDenseVector &y, CoinDenseVector &z1, CoinDenseVector &z2, CoinDenseVector &r1, CoinDenseVector &r2, double *Pinf, double *Dinf){ // Form residuals for the primal and dual equations. // rL, rU are output, but we input them as full vectors // initialized (permanently) with any relevant zeros. // Get some element pointers for efficiency double *x_elts = x.getElements(); double *r2_elts = r2.getElements(); for (int k=0; kmatVecMult( 1, r1, x ); model->matVecMult( 2, r2, y ); for (int k=0; k 0) r2 = r2 + z2; for (int k=0; k normL) normL = rL[low[k]]; for (int k=0; k normU) normU = rU[upp[k]]; *Pinf = CoinMax(normL, normU); *Pinf = CoinMax( r1.infNorm() , *Pinf ); *Dinf = r2.infNorm(); *Pinf = CoinMax( *Pinf, 1e-99 ); *Dinf = CoinMax( *Dinf, 1e-99 ); } //----------------------------------------------------------------------- // End private function pdxxxresid1 //----------------------------------------------------------------------- //function [cL,cU,center,Cinf,Cinf0] = ... // pdxxxresid2( mu,low,upp,cL,cU,x1,x2,z1,z2 ) inline void pdxxxresid2(double mu, int nlow, int nupp, int *low, int *upp, CoinDenseVector &cL, CoinDenseVector &cU, CoinDenseVector &x1, CoinDenseVector &x2, CoinDenseVector &z1, CoinDenseVector &z2, double *center, double *Cinf, double *Cinf0){ // Form residuals for the complementarity equations. // cL, cU are output, but we input them as full vectors // initialized (permanently) with any relevant zeros. // Cinf is the complementarity residual for X1 z1 = mu e, etc. // Cinf0 is the same for mu=0 (i.e., for the original problem). double maxXz = -1e20; double minXz = 1e20; double *x1_elts = x1.getElements(); double *z1_elts = z1.getElements(); double *cL_elts = cL.getElements(); for (int k=0; k maxXz) maxXz = x1z1; if(x1z1 < minXz) minXz = x1z1; } double *x2_elts = x2.getElements(); double *z2_elts = z2.getElements(); double *cU_elts = cU.getElements(); for (int k=0; k maxXz) maxXz = x2z2; if(x2z2 < minXz) minXz = x2z2; } maxXz = CoinMax( maxXz, 1e-99 ); minXz = CoinMax( minXz, 1e-99 ); *center = maxXz / minXz; double normL = 0.0; double normU = 0.0; for (int k=0; k normL) normL = cL_elts[low[k]]; for (int k=0; k normU) normU = cU_elts[upp[k]]; *Cinf = CoinMax( normL, normU); *Cinf0 = maxXz; } //----------------------------------------------------------------------- // End private function pdxxxresid2 //----------------------------------------------------------------------- inline double pdxxxstep( CoinDenseVector &x, CoinDenseVector &dx ){ // Assumes x > 0. // Finds the maximum step such that x + step*dx >= 0. double step = 1e+20; int n = x.size(); double *x_elts = x.getElements(); double *dx_elts = dx.getElements(); for (int k=0; k &x, CoinDenseVector &dx ){ // Assumes x > 0. // Finds the maximum step such that x + step*dx >= 0. double step = 1e+20; int n = x.size(); double *x_elts = x.getElements(); double *dx_elts = dx.getElements(); for (int k=0; k