TQpDataDens.cxx

Go to the documentation of this file.
00001 // @(#)root/quadp:$Id: TQpDataDens.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Eddy Offermann   May 2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 /*************************************************************************
00013  * Parts of this file are copied from the OOQP distribution and          *
00014  * are subject to the following license:                                 *
00015  *                                                                       *
00016  * COPYRIGHT 2001 UNIVERSITY OF CHICAGO                                  *
00017  *                                                                       *
00018  * The copyright holder hereby grants you royalty-free rights to use,    *
00019  * reproduce, prepare derivative works, and to redistribute this software*
00020  * to others, provided that any changes are clearly documented. This     *
00021  * software was authored by:                                             *
00022  *                                                                       *
00023  *   E. MICHAEL GERTZ      gertz@mcs.anl.gov                             *
00024  *   Mathematics and Computer Science Division                           *
00025  *   Argonne National Laboratory                                         *
00026  *   9700 S. Cass Avenue                                                 *
00027  *   Argonne, IL 60439-4844                                              *
00028  *                                                                       *
00029  *   STEPHEN J. WRIGHT     swright@cs.wisc.edu                           *
00030  *   Computer Sciences Department                                        *
00031  *   University of Wisconsin                                             *
00032  *   1210 West Dayton Street                                             *
00033  *   Madison, WI 53706   FAX: (608)262-9777                              *
00034  *                                                                       *
00035  * Any questions or comments may be directed to one of the authors.      *
00036  *                                                                       *
00037  * ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES OF   *
00038  * ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT, AND     *
00039  * OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A CONTRACT   *
00040  * WITH THE DEPARTMENT OF ENERGY.                                        *
00041  *************************************************************************/
00042 
00043 #include "Riostream.h"
00044 #include "TQpDataDens.h"
00045 
00046 //////////////////////////////////////////////////////////////////////////
00047 //                                                                      //
00048 // TQpDataDens                                                          //
00049 //                                                                      //
00050 // Data for the dense QP formulation                                    //
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 // Constructor
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 // Constructor
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 // Copy constructor
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 // calculate y = beta*y + alpha*(fQ*x)
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 // calculate y = beta*y + alpha*(fA*x)
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 // calculate y = beta*y + alpha*(fC*x)
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 // calculate y = beta*y + alpha*(fA^T*x)
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 // calculate y = beta*y + alpha*(fC^T*x)
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 // Return the largest component of several vectors in the data class
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 * /*opt*/) const
00218 {
00219 // Print all class members
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 // Insert the Hessian Q into the matrix M at index (row,col) for the fundamental
00246 // linear system
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 // Insert the constraint matrix A into the matrix M at index (row,col) for the fundamental
00256 // linear system
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 // Insert the constraint matrix C into the matrix M at index (row,col) for the fundamental
00266 // linear system
00267 
00268    m.SetSub(row,col,fC);
00269 }
00270 
00271 
00272 //______________________________________________________________________________
00273 void TQpDataDens::GetDiagonalOfQ(TVectorD &dq)
00274 {
00275 // Return in vector dq the diagonal of matrix fQ (Quadratic part of Objective function)
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 // Return value of the objective function
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 // Choose randomly a QP problem
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    // Now compute the real q = s-sprime
00322    const TVectorD q = s-sprime;
00323 
00324    // Adjust fCloBound and fCupBound appropriately
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 // Assignment operator
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 }

Generated on Tue Jul 5 14:37:58 2011 for ROOT_528-00b_version by  doxygen 1.5.1