TQpDataBase.cxx

Go to the documentation of this file.
00001 // @(#)root/quadp:$Id: TQpDataBase.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 "TQpDataBase.h"
00044 
00045 //////////////////////////////////////////////////////////////////////////
00046 //                                                                      //
00047 // TQpDataBase                                                          //
00048 //                                                                      //
00049 // Data for the general QP formulation                                  //
00050 //                                                                      //
00051 // The Data class stores the data defining the problem and provides     //
00052 // methods for performing the operations with this data required by     //
00053 // the interior-point algorithms. These operations include assembling   //
00054 // the linear systems (5) or (7), performing matrix-vector operations   //
00055 // with the data, calculating norms of the data, reading input into the //
00056 // data structure from various sources, generating random problem       //
00057 // instances, and printing the data.                                    //
00058 //                                                                      //
00059 //////////////////////////////////////////////////////////////////////////
00060 
00061 ClassImp(TQpDataBase)
00062 
00063 //______________________________________________________________________________
00064 TQpDataBase::TQpDataBase()
00065 {
00066 // Default constructor
00067 
00068    fNx = 0;
00069    fMy = 0;
00070    fMz = 0;
00071 }
00072 
00073 
00074 //______________________________________________________________________________
00075 TQpDataBase::TQpDataBase(Int_t nx,Int_t my,Int_t mz)
00076 {
00077 // Constructor
00078 
00079    fNx = nx;
00080    fMy = my;
00081    fMz = mz;
00082 
00083    fG    .ResizeTo(fNx);
00084 
00085    fBa   .ResizeTo(fMy);
00086 
00087    fXupBound.ResizeTo(fNx);
00088    fXupIndex.ResizeTo(fNx);
00089    fXloBound.ResizeTo(fNx);
00090    fXloIndex.ResizeTo(fNx);
00091 
00092    fCupBound.ResizeTo(fMz);
00093    fCupIndex.ResizeTo(fMz);
00094    fCloBound.ResizeTo(fMz);
00095    fCloIndex.ResizeTo(fMz);
00096 }
00097 
00098 
00099 //______________________________________________________________________________
00100 TQpDataBase::TQpDataBase(const TQpDataBase &another) : TObject(another)
00101 {
00102 // Copy constructor
00103 
00104    *this = another;
00105 }
00106 
00107 
00108 //______________________________________________________________________________
00109 void TQpDataBase::RandomlyChooseBoundedVariables(
00110                            TVectorD &x,TVectorD &dualx,TVectorD &xlow,TVectorD &ixlow,
00111                            TVectorD &xupp,TVectorD &ixupp,Double_t &ix,Double_t percentLowerOnly,
00112                            Double_t percentUpperOnly,Double_t percentBound)
00113 {
00114 // Randomly choose  x and its boundaries 
00115 
00116    const Int_t n = x.GetNrows();
00117 
00118    // Initialize the upper and lower bounds on x
00119 
00120    Int_t i;
00121    for (i = 0; i < n; i++) {
00122       const Double_t r = Drand(ix);
00123 
00124       if (r < percentLowerOnly) {
00125          ixlow[i] = 1.0;
00126          xlow [i] = (Drand(ix)-0.5)*3.0;
00127          ixupp[i] = 0.0;
00128          xupp [i] = 0.0;
00129       }
00130       else if (r < percentLowerOnly+percentUpperOnly) {
00131          ixlow[i] = 0.0;
00132          xlow [i] = 0.0;
00133          ixupp[i] = 1.0;
00134          xupp [i] = (Drand(ix)-0.5)*3.0;
00135       }
00136       else if (r < percentLowerOnly+percentUpperOnly+percentBound) {
00137          ixlow[i] = 1.0;
00138          xlow [i] = (Drand(ix)-0.5)*3.0;
00139          ixupp[i] = 1.0;
00140          xupp [i] = xlow[i]+Drand(ix)*10.0;
00141       }
00142       else {
00143          // it is free
00144          ixlow[i] = 0.0;
00145          xlow [i] = 0.0;
00146          ixupp[i] = 0.0;
00147          xupp [i] = 0.0;
00148       }
00149    }
00150 
00151    for (i = 0; i < n; i++) {
00152       if (ixlow[i] == 0.0 && ixupp[i] == 0.0 ) {
00153          // x[i] not bounded
00154          x    [i] = 20.0*Drand(ix)-10.0;
00155          dualx[i] = 0.0;
00156       }
00157       else if (ixlow[i] != 0.0 && ixupp[i] != 0.0) {
00158          // x[i] is bounded above and below
00159          const Double_t r = Drand(ix);
00160          if (r < 0.33 ) {
00161             // x[i] is on its lower bound
00162             x    [i] = xlow[i];
00163             dualx[i] = 10.0*Drand(ix);
00164          }
00165          else if ( r > .66 ) {
00166             // x[i] is on its upper bound
00167             x    [i] =  xupp[i];
00168             dualx[i] = -10.0*Drand(ix);
00169          }
00170          else {
00171             // x[i] is somewhere in between
00172             const Double_t theta = .99*Drand(ix)+.005;
00173             x    [i] = (1-theta)*xlow[i]+theta*xupp[i];
00174             dualx[i] = 0.0;
00175          }
00176       }
00177       else if (ixlow[i] != 0.0) {
00178          // x[i] is only bounded below
00179          if (Drand(ix) < .33 ) {
00180             // x[i] is on its lower bound
00181             x    [i] = xlow[i];
00182             dualx[i] = 10.0*Drand(ix);
00183          }
00184          else {
00185             // x[i] is somewhere above its lower bound
00186             x    [i] = xlow[i]+0.005+10.0*Drand(ix);
00187             dualx[i] = 0.0;
00188          }
00189       }                          // x[i] only has an upper bound
00190       else {
00191          if (Drand(ix) > .66 ) {
00192             // x[i] is on its upper bound
00193             x    [i] = xupp[i];
00194             dualx[i] = -10.0*Drand(ix);
00195          }
00196          else {
00197             // x[i] is somewhere below its upper bound
00198             x    [i] = xupp[i]-0.005-10.0*Drand(ix);
00199             dualx[i] = 0.0;
00200          }
00201       }
00202    }
00203 }
00204 
00205 
00206 //______________________________________________________________________________
00207 TQpDataBase &TQpDataBase::operator=(const TQpDataBase &source)
00208 {
00209 // Assignment operator
00210 
00211    if (this != &source) {
00212       TObject::operator=(source);
00213       fNx = source.fNx;
00214       fMy = source.fMy;
00215       fMz = source.fMz;
00216 
00217       fG       .ResizeTo(source.fG)       ; fG        = source.fG       ;
00218       fBa      .ResizeTo(source.fBa)      ; fBa       = source.fBa      ;
00219       fXupBound.ResizeTo(source.fXupBound); fXupBound = source.fXupBound;
00220       fXupIndex.ResizeTo(source.fXupIndex); fXupIndex = source.fXupIndex;
00221       fXloBound.ResizeTo(source.fXloBound); fXloBound = source.fXloBound;
00222       fXloIndex.ResizeTo(source.fXloIndex); fXloIndex = source.fXloIndex;
00223       fCupBound.ResizeTo(source.fCupBound); fCupBound = source.fCupBound;
00224       fCupIndex.ResizeTo(source.fCupIndex); fCupIndex = source.fCupIndex;
00225       fCloBound.ResizeTo(source.fCloBound); fCloBound = source.fCloBound;
00226       fCloIndex.ResizeTo(source.fCloIndex); fCloIndex = source.fCloIndex;
00227    }
00228    return *this;
00229 }

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