Logo ROOT   6.13/01
Reference Guide
TQpProbDens.cxx
Go to the documentation of this file.
1 // @(#)root/matrix:$Id$
2 // Authors: Fons Rademakers, Eddy Offermann Mar 2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /*************************************************************************
13  * Parts of this file are copied from the OOQP distribution and *
14  * are subject to the following license: *
15  * *
16  * COPYRIGHT 2001 UNIVERSITY OF CHICAGO *
17  * *
18  * The copyright holder hereby grants you royalty-free rights to use, *
19  * reproduce, prepare derivative works, and to redistribute this software*
20  * to others, provided that any changes are clearly documented. This *
21  * software was authored by: *
22  * *
23  * E. MICHAEL GERTZ gertz@mcs.anl.gov *
24  * Mathematics and Computer Science Division *
25  * Argonne National Laboratory *
26  * 9700 S. Cass Avenue *
27  * Argonne, IL 60439-4844 *
28  * *
29  * STEPHEN J. WRIGHT swright@cs.wisc.edu *
30  * Computer Sciences Department *
31  * University of Wisconsin *
32  * 1210 West Dayton Street *
33  * Madison, WI 53706 FAX: (608)262-9777 *
34  * *
35  * Any questions or comments may be directed to one of the authors. *
36  * *
37  * ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES OF *
38  * ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT, AND *
39  * OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A CONTRACT *
40  * WITH THE DEPARTMENT OF ENERGY. *
41  *************************************************************************/
42 
43 #include "TQpProbDens.h"
44 #include "TMatrixD.h"
45 #include "TQpLinSolverDens.h"
46 
47 //////////////////////////////////////////////////////////////////////////
48 // //
49 // TQpProbDens //
50 // //
51 // dense matrix problem formulation //
52 // //
53 //////////////////////////////////////////////////////////////////////////
54 
55 ClassImp(TQpProbDens);
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Constructor
59 
60 TQpProbDens::TQpProbDens(Int_t nx,Int_t my,Int_t mz) :
61  TQpProbBase(nx,my,mz)
62 {
63  // We do not want more constrains than variables
64  R__ASSERT(nx-my-mz > 0);
65 }
66 
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Copy constructor
70 
72 {
73  *this = another;
74 }
75 
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Setup the data
79 
81  Double_t *Q,
82  Double_t *xlo,Bool_t *ixlo,
83  Double_t *xup,Bool_t *ixup,
84  Double_t *A, Double_t *bA,
85  Double_t *C,
86  Double_t *clo,Bool_t *iclo,
87  Double_t *cup,Bool_t *icup)
88 {
89  TVectorD vc ; vc .Use(fNx,c);
90  TMatrixDSym mQ ; mQ .Use(fNx,Q);
91  TVectorD vxlo; vxlo.Use(fNx,xlo);
92  TVectorD vxup; vxup.Use(fNx,xup);
93  TMatrixD mA ;
94  TVectorD vbA ;
95  if (fMy > 0) {
96  mA .Use(fMy,fNx,A);
97  vbA .Use(fMy,bA);
98  }
99  TMatrixD mC ;
100  TVectorD vclo;
101  TVectorD vcup;
102  if (fMz > 0) {
103  mC .Use(fMz,fNx,C);
104  vclo.Use(fMz,clo);
105  vcup.Use(fMz,cup);
106  }
107 
108  TVectorD vixlo(fNx);
109  TVectorD vixup(fNx);
110  for (Int_t ix = 0; ix < fNx; ix++) {
111  vixlo[ix] = (ixlo[ix]) ? 1.0 : 0.0;
112  vixup[ix] = (ixup[ix]) ? 1.0 : 0.0;
113  }
114 
115  TVectorD viclo(fMz);
116  TVectorD vicup(fMz);
117  for (Int_t ic = 0; ic < fMz; ic++) {
118  viclo[ic] = (iclo[ic]) ? 1.0 : 0.0;
119  vicup[ic] = (icup[ic]) ? 1.0 : 0.0;
120  }
121 
122  TQpDataDens *data = new TQpDataDens(vc,mQ,vxlo,vixlo,vxup,vixup,mA,vbA,mC,vclo,
123  viclo,vcup,vicup);
124 
125  return data;
126 }
127 
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Setup the data
131 
133  TMatrixDBase &Q_in,
134  TVectorD &xlo, TVectorD &ixlo,
135  TVectorD &xup, TVectorD &ixup,
136  TMatrixDBase &A_in,TVectorD &bA,
137  TMatrixDBase &C_in,
138  TVectorD &clo, TVectorD &iclo,
139  TVectorD &cup, TVectorD &icup)
140 {
141  TMatrixDSym &mQ = (TMatrixDSym &) Q_in;
142  TMatrixD &mA = (TMatrixD &) A_in;
143  TMatrixD &mC = (TMatrixD &) C_in;
144 
145  R__ASSERT(mQ.GetNrows() == fNx && mQ.GetNcols() == fNx);
146  if (fMy > 0) R__ASSERT(mA.GetNrows() == fMy && mA.GetNcols() == fNx);
147  else R__ASSERT(mA.GetNrows() == fMy);
148  if (fMz > 0) R__ASSERT(mC.GetNrows() == fMz && mC.GetNcols() == fNx);
149  else R__ASSERT(mC.GetNrows() == fMz);
150 
151  R__ASSERT(c.GetNrows() == fNx);
152  R__ASSERT(xlo.GetNrows() == fNx);
153  R__ASSERT(ixlo.GetNrows() == fNx);
154  R__ASSERT(xup.GetNrows() == fNx);
155  R__ASSERT(ixup.GetNrows() == fNx);
156 
157  R__ASSERT(bA.GetNrows() == fMy);
158  R__ASSERT(clo.GetNrows() == fMz);
159  R__ASSERT(iclo.GetNrows() == fMz);
160  R__ASSERT(cup.GetNrows() == fMz);
161  R__ASSERT(icup.GetNrows() == fMz);
162 
163  TQpDataDens *data = new TQpDataDens(c,mQ,xlo,ixlo,xup,ixup,mA,bA,mC,clo,iclo,cup,icup);
164 
165  return data;
166 }
167 
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// Setup the residuals
171 
173 {
174  TQpDataDens *data = (TQpDataDens *) data_in;
175  return new TQpResidual(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
176 }
177 
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Setup the variables
181 
183 {
184  TQpDataDens *data = (TQpDataDens *) data_in;
185 
186  return new TQpVar(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
187 }
188 
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Setup the linear solver
192 
194 {
195  TQpDataDens *data = (TQpDataDens *) data_in;
196  return new TQpLinSolverDens(this,data);
197 }
198 
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// Assembles a single vector object from three given vectors .
202 /// rhs_out (output) final joined vector
203 /// rhs1_in (input) first part of rhs
204 /// rhs2_in (input) middle part of rhs
205 /// rhs3_in (input) last part of rhs .
206 
207 void TQpProbDens::JoinRHS(TVectorD &rhs,TVectorD &rhs1_in,TVectorD &rhs2_in,TVectorD &rhs3_in)
208 {
209  rhs.SetSub(0,rhs1_in);
210  if (fMy > 0) rhs.SetSub(fNx, rhs2_in);
211  if (fMz > 0) rhs.SetSub(fNx+fMy,rhs3_in);
212 }
213 
214 
215 ////////////////////////////////////////////////////////////////////////////////
216 /// Extracts three component vectors from a given aggregated vector.
217 /// vars_in (input) aggregated vector
218 /// x_in (output) first part of vars
219 /// y_in (output) middle part of vars
220 /// z_in (output) last part of vars
221 
223 {
224  x_in = vars_in.GetSub(0,fNx-1);
225  if (fMy > 0) y_in = vars_in.GetSub(fNx, fNx+fMy-1);
226  if (fMz > 0) z_in = vars_in.GetSub(fNx+fMy,fNx+fMy+fMz-1);
227 }
228 
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Create a random QP problem
232 
233 void TQpProbDens::MakeRandomData(TQpDataDens *&data,TQpVar *&soln,Int_t /*nnzQ*/,Int_t /*nnzA*/,Int_t /*nnzC*/)
234 {
235  data = new TQpDataDens(fNx,fMy,fMz);
236  soln = this->MakeVariables(data);
237  data->DataRandom(soln->fX,soln->fY,soln->fZ,soln->fS);
238 }
239 
240 
241 ////////////////////////////////////////////////////////////////////////////////
242 /// Assignment operator
243 
245 {
246  if (this != &source) {
247  TQpProbBase::operator=(source);
248  }
249  return *this;
250 }
TVectorD fXloIndex
Definition: TQpDataBase.h:82
TMatrixTSym< Element > & Use(Int_t row_lwb, Int_t row_upb, Element *data)
void MakeRandomData(TQpDataDens *&data, TQpVar *&soln, Int_t nnzQ, Int_t nnzA, Int_t nnzC)
Create a random QP problem.
virtual void SeparateVars(TVectorD &x_in, TVectorD &y_in, TVectorD &z_in, TVectorD &vars_in)
Extracts three component vectors from a given aggregated vector.
Int_t GetNcols() const
Definition: TMatrixTBase.h:125
Int_t GetNrows() const
Definition: TVectorT.h:75
virtual TQpResidual * MakeResiduals(const TQpDataBase *data)
Setup the residuals.
TQpProbDens & operator=(const TQpProbDens &source)
Assignment operator.
TVectorD fX
Definition: TQpVar.h:91
static double A[]
TVectorD fCupIndex
Definition: TQpDataBase.h:84
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
Definition: TVectorT.cxx:347
TVectorT< Element > & SetSub(Int_t row_lwb, const TVectorT< Element > &source)
Insert vector source starting at [row_lwb], thereby overwriting the part [row_lwb..row_lwb+nrows_source];.
Definition: TVectorT.cxx:420
virtual void DataRandom(TVectorD &x, TVectorD &y, TVectorD &z, TVectorD &s)
Choose randomly a QP problem.
TVectorT< Element > & GetSub(Int_t row_lwb, Int_t row_upb, TVectorT< Element > &target, Option_t *option="S") const
Get subvector [row_lwb..row_upb]; The indexing range of the returned vector depends on the argument o...
Definition: TVectorT.cxx:371
static double C[]
virtual void JoinRHS(TVectorD &rhs_in, TVectorD &rhs1_in, TVectorD &rhs2_in, TVectorD &rhs3_in)
Assembles a single vector object from three given vectors .
TVectorD fXupIndex
Definition: TQpDataBase.h:80
virtual TQpLinSolverBase * MakeLinSys(const TQpDataBase *data)
Setup the linear solver.
Linear Algebra Package.
Int_t GetNrows() const
Definition: TMatrixTBase.h:122
TVectorD fY
Definition: TQpVar.h:93
TMatrixT< Element > & Use(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb, Element *data)
Use the array data to fill the matrix ([row_lwb..row_upb] x [col_lwb..col_upb])
Definition: TMatrixT.cxx:1053
Definition: TQpVar.h:59
TVectorD fS
Definition: TQpVar.h:92
TVectorD fCloIndex
Definition: TQpDataBase.h:86
virtual TQpDataBase * MakeData(Double_t *c, Double_t *Q, Double_t *xlo, Bool_t *ixlo, Double_t *xup, Bool_t *ixup, Double_t *A, Double_t *bA, Double_t *C, Double_t *clo, Bool_t *iclo, Double_t *cup, Bool_t *icup)
Setup the data.
Definition: TQpProbDens.cxx:80
TQpProbBase & operator=(const TQpProbBase &source)
Assignment operator.
Definition: TQpProbBase.cxx:94
static double Q[]
TVectorD fZ
Definition: TQpVar.h:94
virtual TQpVar * MakeVariables(const TQpDataBase *data)
Setup the variables.