00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "Riostream.h"
00044 #include "TQpDataDens.h"
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 ClassImp(TQpDataDens)
00055
00056
00057 TQpDataDens::TQpDataDens(Int_t nx,Int_t my,Int_t mz)
00058 : TQpDataBase(nx,my,mz)
00059 {
00060
00061
00062 fQ.ResizeTo(fNx,fNx);
00063 fA.ResizeTo(fMy,fNx);
00064 fC.ResizeTo(fMz,fNx);
00065 }
00066
00067
00068
00069 TQpDataDens::TQpDataDens(TVectorD &c_in, TMatrixDSym &Q_in,
00070 TVectorD &xlow_in,TVectorD &ixlow_in,
00071 TVectorD &xupp_in,TVectorD &ixupp_in,
00072 TMatrixD &A_in, TVectorD &bA_in,
00073 TMatrixD &C_in,
00074 TVectorD &clow_in,TVectorD &iclow_in,
00075 TVectorD &cupp_in,TVectorD &icupp_in)
00076 {
00077
00078
00079 fG .ResizeTo(c_in) ; fG = c_in;
00080 fBa .ResizeTo(bA_in) ; fBa = bA_in;
00081 fXloBound.ResizeTo(xlow_in) ; fXloBound = xlow_in;
00082 fXloIndex.ResizeTo(ixlow_in); fXloIndex = ixlow_in;
00083 fXupBound.ResizeTo(xupp_in) ; fXupBound = xupp_in;
00084 fXupIndex.ResizeTo(ixupp_in); fXupIndex = ixupp_in;
00085 fCloBound.ResizeTo(clow_in) ; fCloBound = clow_in;
00086 fCloIndex.ResizeTo(iclow_in); fCloIndex = iclow_in;
00087 fCupBound.ResizeTo(cupp_in) ; fCupBound = cupp_in;
00088 fCupIndex.ResizeTo(icupp_in); fCupIndex = icupp_in;
00089
00090 fNx = fG.GetNrows();
00091 fQ.Use(Q_in);
00092
00093 if (A_in.GetNrows() > 0) {
00094 fA.Use(A_in);
00095 fMy = fA.GetNrows();
00096 } else
00097 fMy = 0;
00098
00099 if (C_in.GetNrows() > 0) {
00100 fC.Use(C_in);
00101 fMz = fC.GetNrows();
00102 } else
00103 fMz = 0;
00104 }
00105
00106
00107
00108 TQpDataDens::TQpDataDens(const TQpDataDens &another) : TQpDataBase(another)
00109 {
00110
00111
00112 *this = another;
00113 }
00114
00115
00116
00117 void TQpDataDens::Qmult(Double_t beta,TVectorD &y,Double_t alpha,const TVectorD &x )
00118 {
00119
00120
00121 y *= beta;
00122 if (fQ.GetNoElements() > 0)
00123 y += alpha*(fQ*x);
00124 }
00125
00126
00127
00128 void TQpDataDens::Amult(Double_t beta,TVectorD &y,Double_t alpha,const TVectorD &x)
00129 {
00130
00131
00132 y *= beta;
00133 if (fA.GetNoElements() > 0)
00134 y += alpha*(fA*x);
00135 }
00136
00137
00138
00139 void TQpDataDens::Cmult(Double_t beta,TVectorD &y,Double_t alpha,const TVectorD &x)
00140 {
00141
00142
00143 y *= beta;
00144 if (fC.GetNoElements() > 0)
00145 y += alpha*(fC*x);
00146 }
00147
00148
00149
00150 void TQpDataDens::ATransmult(Double_t beta,TVectorD &y,Double_t alpha,const TVectorD &x)
00151 {
00152
00153
00154 y *= beta;
00155 if (fA.GetNoElements() > 0)
00156 y += alpha*(TMatrixD(TMatrixD::kTransposed,fA)*x);
00157 }
00158
00159
00160
00161 void TQpDataDens::CTransmult(Double_t beta,TVectorD &y,Double_t alpha,const TVectorD &x)
00162 {
00163
00164
00165 y *= beta;
00166 if (fC.GetNoElements() > 0)
00167 y += alpha*(TMatrixD(TMatrixD::kTransposed,fC)*x);
00168 }
00169
00170
00171
00172 Double_t TQpDataDens::DataNorm()
00173 {
00174
00175
00176 Double_t norm = 0.0;
00177
00178 Double_t componentNorm = fG.NormInf();
00179 if (componentNorm > norm) norm = componentNorm;
00180
00181 TMatrixDSym fQ_abs(fQ);
00182 componentNorm = (fQ_abs.Abs()).Max();
00183 if (componentNorm > norm) norm = componentNorm;
00184
00185 componentNorm = fBa.NormInf();
00186 if (componentNorm > norm) norm = componentNorm;
00187
00188 TMatrixD fA_abs(fQ);
00189 componentNorm = (fA_abs.Abs()).Max();
00190 if (componentNorm > norm) norm = componentNorm;
00191
00192 TMatrixD fC_abs(fQ);
00193 componentNorm = (fC_abs.Abs()).Max();
00194 if (componentNorm > norm) norm = componentNorm;
00195
00196 R__ASSERT(fXloBound.MatchesNonZeroPattern(fXloIndex));
00197 componentNorm = fXloBound.NormInf();
00198 if (componentNorm > norm) norm = componentNorm;
00199
00200 R__ASSERT(fXupBound.MatchesNonZeroPattern(fXupIndex));
00201 componentNorm = fXupBound.NormInf();
00202 if (componentNorm > norm) norm = componentNorm;
00203
00204 R__ASSERT(fCloBound.MatchesNonZeroPattern(fCloIndex));
00205 componentNorm = fCloBound.NormInf();
00206 if (componentNorm > norm) norm = componentNorm;
00207
00208 R__ASSERT(fCupBound.MatchesNonZeroPattern(fCupIndex));
00209 componentNorm = fCupBound.NormInf();
00210 if (componentNorm > norm) norm = componentNorm;
00211
00212 return norm;
00213 }
00214
00215
00216
00217 void TQpDataDens::Print(Option_t * ) const
00218 {
00219
00220
00221 fQ.Print("Q");
00222 fG.Print("c");
00223
00224 fXloBound.Print("xlow");
00225 fXloIndex.Print("ixlow");
00226
00227 fXupBound.Print("xupp");
00228 fXupIndex.Print("ixupp");
00229
00230 fA.Print("A");
00231 fBa.Print("b");
00232 fC.Print("C");
00233
00234 fCloBound.Print("clow");
00235 fCloIndex.Print("iclow");
00236
00237 fCupBound.Print("cupp");
00238 fCupIndex.Print("icupp");
00239 }
00240
00241
00242
00243 void TQpDataDens::PutQIntoAt(TMatrixDBase &m,Int_t row,Int_t col)
00244 {
00245
00246
00247
00248 m.SetSub(row,col,fQ);
00249 }
00250
00251
00252
00253 void TQpDataDens::PutAIntoAt(TMatrixDBase &m,Int_t row,Int_t col)
00254 {
00255
00256
00257
00258 m.SetSub(row,col,fA);
00259 }
00260
00261
00262
00263 void TQpDataDens::PutCIntoAt(TMatrixDBase &m,Int_t row,Int_t col)
00264 {
00265
00266
00267
00268 m.SetSub(row,col,fC);
00269 }
00270
00271
00272
00273 void TQpDataDens::GetDiagonalOfQ(TVectorD &dq)
00274 {
00275
00276
00277 const Int_t n = TMath::Min(fQ.GetNrows(),fQ.GetNcols());
00278 dq.ResizeTo(n);
00279 dq = TMatrixDDiag(fQ);
00280 }
00281
00282
00283
00284 Double_t TQpDataDens::ObjectiveValue(TQpVar *vars)
00285 {
00286
00287
00288 TVectorD tmp(fG);
00289 this->Qmult(1.0,tmp,0.5,vars->fX);
00290
00291 return tmp*vars->fX;
00292 }
00293
00294
00295
00296 void TQpDataDens::DataRandom(TVectorD &x,TVectorD &y,TVectorD &z,TVectorD &s)
00297 {
00298
00299
00300 Double_t ix = 3074.20374;
00301
00302 TVectorD xdual(fNx);
00303 this->RandomlyChooseBoundedVariables(x,xdual,fXloBound,fXloIndex,fXupBound,fXupIndex,ix,.25,.25,.25);
00304 TVectorD sprime(fMz);
00305 this->RandomlyChooseBoundedVariables(sprime,z,fCloBound,fCloIndex,fCupBound,fCupIndex,ix,.25,.25,.5);
00306
00307 fQ.RandomizePD(0.0,1.0,ix);
00308 fA.Randomize(-10.0,10.0,ix);
00309 fC.Randomize(-10.0,10.0,ix);
00310 y .Randomize(-10.0,10.0,ix);
00311
00312 fG = xdual;
00313 fG -= fQ*x;
00314
00315 fG += TMatrixD(TMatrixD::kTransposed,fA)*y;
00316 fG += TMatrixD(TMatrixD::kTransposed,fC)*z;
00317
00318 fBa = fA*x;
00319 s = fC*x;
00320
00321
00322 const TVectorD q = s-sprime;
00323
00324
00325 Add(fCloBound,1.0,q);
00326 Add(fCupBound,1.0,q);
00327
00328 fCloBound.SelectNonZeros(fCloIndex);
00329 fCupBound.SelectNonZeros(fCupIndex);
00330 }
00331
00332
00333
00334 TQpDataDens &TQpDataDens::operator=(const TQpDataDens &source)
00335 {
00336
00337
00338 if (this != &source) {
00339 TQpDataBase::operator=(source);
00340 fQ.ResizeTo(source.fQ); fQ = source.fQ;
00341 fA.ResizeTo(source.fA); fA = source.fA;
00342 fC.ResizeTo(source.fC); fC = source.fC;
00343 }
00344 return *this;
00345 }