Loading [MathJax]/extensions/tex2jax.js
ROOT  6.06/09
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
46 //////////////////////////////////////////////////////////////////////////
47 // //
48 // TQpProbDens //
49 // //
50 // dense matrix problem formulation //
51 // //
52 //////////////////////////////////////////////////////////////////////////
53 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Constructor
58 
60  TQpProbBase(nx,my,mz)
61 {
62  // We do not want more constrains than variables
63  R__ASSERT(nx-my-mz > 0);
64 }
65 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Copy constructor
69 
71 {
72  *this = another;
73 }
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Setup the data
78 
80  Double_t *Q,
81  Double_t *xlo,Bool_t *ixlo,
82  Double_t *xup,Bool_t *ixup,
83  Double_t *A, Double_t *bA,
84  Double_t *C,
85  Double_t *clo,Bool_t *iclo,
86  Double_t *cup,Bool_t *icup)
87 {
88  TVectorD vc ; vc .Use(fNx,c);
89  TMatrixDSym mQ ; mQ .Use(fNx,Q);
90  TVectorD vxlo; vxlo.Use(fNx,xlo);
91  TVectorD vxup; vxup.Use(fNx,xup);
92  TMatrixD mA ;
93  TVectorD vbA ;
94  if (fMy > 0) {
95  mA .Use(fMy,fNx,A);
96  vbA .Use(fMy,bA);
97  }
98  TMatrixD mC ;
99  TVectorD vclo;
100  TVectorD vcup;
101  if (fMz > 0) {
102  mC .Use(fMz,fNx,C);
103  vclo.Use(fMz,clo);
104  vcup.Use(fMz,cup);
105  }
106 
107  TVectorD vixlo(fNx);
108  TVectorD vixup(fNx);
109  for (Int_t ix = 0; ix < fNx; ix++) {
110  vixlo[ix] = (ixlo[ix]) ? 1.0 : 0.0;
111  vixup[ix] = (ixup[ix]) ? 1.0 : 0.0;
112  }
113 
114  TVectorD viclo(fMz);
115  TVectorD vicup(fMz);
116  for (Int_t ic = 0; ic < fMz; ic++) {
117  viclo[ic] = (iclo[ic]) ? 1.0 : 0.0;
118  vicup[ic] = (icup[ic]) ? 1.0 : 0.0;
119  }
120 
121  TQpDataDens *data = new TQpDataDens(vc,mQ,vxlo,vixlo,vxup,vixup,mA,vbA,mC,vclo,
122  viclo,vcup,vicup);
123 
124  return data;
125 }
126 
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Setup the data
130 
132  TMatrixDBase &Q_in,
133  TVectorD &xlo, TVectorD &ixlo,
134  TVectorD &xup, TVectorD &ixup,
135  TMatrixDBase &A_in,TVectorD &bA,
136  TMatrixDBase &C_in,
137  TVectorD &clo, TVectorD &iclo,
138  TVectorD &cup, TVectorD &icup)
139 {
140  TMatrixDSym &mQ = (TMatrixDSym &) Q_in;
141  TMatrixD &mA = (TMatrixD &) A_in;
142  TMatrixD &mC = (TMatrixD &) C_in;
143 
144  R__ASSERT(mQ.GetNrows() == fNx && mQ.GetNcols() == fNx);
145  if (fMy > 0) R__ASSERT(mA.GetNrows() == fMy && mA.GetNcols() == fNx);
146  else R__ASSERT(mA.GetNrows() == fMy);
147  if (fMz > 0) R__ASSERT(mC.GetNrows() == fMz && mC.GetNcols() == fNx);
148  else R__ASSERT(mC.GetNrows() == fMz);
149 
150  R__ASSERT(c.GetNrows() == fNx);
151  R__ASSERT(xlo.GetNrows() == fNx);
152  R__ASSERT(ixlo.GetNrows() == fNx);
153  R__ASSERT(xup.GetNrows() == fNx);
154  R__ASSERT(ixup.GetNrows() == fNx);
155 
156  R__ASSERT(bA.GetNrows() == fMy);
157  R__ASSERT(clo.GetNrows() == fMz);
158  R__ASSERT(iclo.GetNrows() == fMz);
159  R__ASSERT(cup.GetNrows() == fMz);
160  R__ASSERT(icup.GetNrows() == fMz);
161 
162  TQpDataDens *data = new TQpDataDens(c,mQ,xlo,ixlo,xup,ixup,mA,bA,mC,clo,iclo,cup,icup);
163 
164  return data;
165 }
166 
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Setup the residuals
170 
172 {
173  TQpDataDens *data = (TQpDataDens *) data_in;
174  return new TQpResidual(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
175 }
176 
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Setup the variables
180 
182 {
183  TQpDataDens *data = (TQpDataDens *) data_in;
184 
185  return new TQpVar(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
186 }
187 
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// Setup the linear solver
191 
193 {
194  TQpDataDens *data = (TQpDataDens *) data_in;
195  return new TQpLinSolverDens(this,data);
196 }
197 
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 /// Assembles a single vector object from three given vectors .
201 /// rhs_out (output) final joined vector
202 /// rhs1_in (input) first part of rhs
203 /// rhs2_in (input) middle part of rhs
204 /// rhs3_in (input) last part of rhs .
205 
206 void TQpProbDens::JoinRHS(TVectorD &rhs,TVectorD &rhs1_in,TVectorD &rhs2_in,TVectorD &rhs3_in)
207 {
208  rhs.SetSub(0,rhs1_in);
209  if (fMy > 0) rhs.SetSub(fNx, rhs2_in);
210  if (fMz > 0) rhs.SetSub(fNx+fMy,rhs3_in);
211 }
212 
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// Extracts three component vectors from a given aggregated vector.
216 /// vars_in (input) aggregated vector
217 /// x_in (output) first part of vars
218 /// y_in (output) middle part of vars
219 /// z_in (output) last part of vars
220 
222 {
223  x_in = vars_in.GetSub(0,fNx-1);
224  if (fMy > 0) y_in = vars_in.GetSub(fNx, fNx+fMy-1);
225  if (fMz > 0) z_in = vars_in.GetSub(fNx+fMy,fNx+fMy+fMz-1);
226 }
227 
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Create a random QP problem
231 
232 void TQpProbDens::MakeRandomData(TQpDataDens *&data,TQpVar *&soln,Int_t /*nnzQ*/,Int_t /*nnzA*/,Int_t /*nnzC*/)
233 {
234  data = new TQpDataDens(fNx,fMy,fMz);
235  soln = this->MakeVariables(data);
236  data->DataRandom(soln->fX,soln->fY,soln->fZ,soln->fS);
237 }
238 
239 
240 ////////////////////////////////////////////////////////////////////////////////
241 /// Assignment operator
242 
244 {
245  if (this != &source) {
246  TQpProbBase::operator=(source);
247  }
248  return *this;
249 }
const int nx
Definition: kalman.C:16
TVectorD fXloIndex
Definition: TQpDataBase.h:88
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 GetNrows() const
Definition: TVectorT.h:81
#define R__ASSERT(e)
Definition: TError.h:98
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:370
virtual TQpResidual * MakeResiduals(const TQpDataBase *data)
Setup the residuals.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TQpProbDens & operator=(const TQpProbDens &source)
Assignment operator.
TVectorD fX
Definition: TQpVar.h:97
static double A[]
TVectorD fCupIndex
Definition: TQpDataBase.h:90
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
Definition: TVectorT.cxx:346
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:419
virtual void DataRandom(TVectorD &x, TVectorD &y, TVectorD &z, TVectorD &s)
Choose randomly a QP problem.
Int_t GetNrows() const
Definition: TMatrixTBase.h:134
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:86
virtual TQpLinSolverBase * MakeLinSys(const TQpDataBase *data)
Setup the linear solver.
double Double_t
Definition: RtypesCore.h:55
TVectorD fY
Definition: TQpVar.h:99
Int_t GetNcols() const
Definition: TMatrixTBase.h:137
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:1044
Definition: TQpVar.h:65
TVectorD fS
Definition: TQpVar.h:98
TVectorD fCloIndex
Definition: TQpDataBase.h:92
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:79
ClassImp(TQpProbDens) TQpProbDens
Constructor.
Definition: TQpProbDens.cxx:54
TQpProbBase & operator=(const TQpProbBase &source)
Assignment operator.
Definition: TQpProbBase.cxx:94
static double Q[]
TVectorD fZ
Definition: TQpVar.h:100
virtual TQpVar * MakeVariables(const TQpDataBase *data)
Setup the variables.