Logo ROOT   6.10/09
Reference Guide
TQpProbSparse.cxx
Go to the documentation of this file.
1 // @(#)root/quadp:$Id$
2 // Author: Eddy Offermann May 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 "TQpProbSparse.h"
44 #include "TMatrixD.h"
45 #include "TQpLinSolverSparse.h"
46 
47 //////////////////////////////////////////////////////////////////////////
48 // //
49 // TQpProbSparse //
50 // //
51 // dense matrix problem formulation //
52 // //
53 //////////////////////////////////////////////////////////////////////////
54 
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Constructor
59 
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  Int_t nnzQ,Int_t *irowQ,Int_t *icolQ,Double_t *Q,
82  Double_t *xlo,Bool_t *ixlo,
83  Double_t *xup,Bool_t *ixup,
84  Int_t nnzA,Int_t *irowA,Int_t *icolA,Double_t *A,
85  Double_t *bA,
86  Int_t nnzC,Int_t *irowC,Int_t *icolC,Double_t *C,
87  Double_t *clo,Bool_t *iclo,
88  Double_t *cup,Bool_t *icup)
89 {
90  TVectorD vc ; vc .Use(fNx,c);
91  TMatrixDSparse mQ ; mQ .Use(fNx,fNx,nnzQ,irowQ,icolQ,Q);
92  TVectorD vxlo; vxlo.Use(fNx,xlo);
93  TVectorD vxup; vxup.Use(fNx,xup);
94  TMatrixDSparse mA ;
95  TVectorD vbA ;
96  if (fMy > 0) {
97  mA .Use(fMy,fNx,nnzA,irowA,icolA,A);
98  vbA .Use(fMy,bA);
99  }
100  TMatrixDSparse mC ;
101  TVectorD vclo;
102  TVectorD vcup;
103  if (fMz > 0) {
104  mC .Use(fMz,fNx,nnzC,irowC,icolC,C);
105  vclo.Use(fMz,clo);
106  vcup.Use(fMz,cup);
107  }
108 
109  TVectorD vixlo(fNx);
110  TVectorD vixup(fNx);
111  for (Int_t ix = 0; ix < fNx; ix++) {
112  vixlo[ix] = (ixlo[ix]) ? 1.0 : 0.0;
113  vixup[ix] = (ixup[ix]) ? 1.0 : 0.0;
114  }
115 
116  TVectorD viclo(fMz);
117  TVectorD vicup(fMz);
118  for (Int_t ic = 0; ic < fMz; ic++) {
119  viclo[ic] = (iclo[ic]) ? 1.0 : 0.0;
120  vicup[ic] = (icup[ic]) ? 1.0 : 0.0;
121  }
122 
123  TQpDataSparse *data = new TQpDataSparse(vc,mQ,vxlo,vixlo,vxup,vixup,mA,vbA,mC,vclo,
124  viclo,vcup,vicup);
125 
126  return data;
127 }
128 
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Setup the data
132 
134  TMatrixDBase &Q_in,
135  TVectorD &xlo, TVectorD &ixlo,
136  TVectorD &xup, TVectorD &ixup,
137  TMatrixDBase &A_in,TVectorD &bA,
138  TMatrixDBase &C_in,
139  TVectorD &clo, TVectorD &iclo,
140  TVectorD &cup, TVectorD &icup)
141 {
142  TMatrixDSparse &mQ = (TMatrixDSparse &) Q_in;
143  TMatrixDSparse &mA = (TMatrixDSparse &) A_in;
144  TMatrixDSparse &mC = (TMatrixDSparse &) C_in;
145 
146  R__ASSERT(mQ.GetNrows() == fNx && mQ.GetNcols() == fNx);
147  if (fMy > 0) R__ASSERT(mA.GetNrows() == fMy && mA.GetNcols() == fNx);
148  else R__ASSERT(mA.GetNrows() == fMy);
149  if (fMz > 0) R__ASSERT(mC.GetNrows() == fMz && mC.GetNcols() == fNx);
150  else R__ASSERT(mC.GetNrows() == fMz);
151 
152  R__ASSERT(c.GetNrows() == fNx);
153  R__ASSERT(xlo.GetNrows() == fNx);
154  R__ASSERT(ixlo.GetNrows() == fNx);
155  R__ASSERT(xup.GetNrows() == fNx);
156  R__ASSERT(ixup.GetNrows() == fNx);
157 
158  R__ASSERT(bA.GetNrows() == fMy);
159  R__ASSERT(clo.GetNrows() == fMz);
160  R__ASSERT(iclo.GetNrows() == fMz);
161  R__ASSERT(cup.GetNrows() == fMz);
162  R__ASSERT(icup.GetNrows() == fMz);
163 
164  TQpDataSparse *data = new TQpDataSparse(c,mQ,xlo,ixlo,xup,ixup,mA,bA,mC,clo,iclo,cup,icup);
165 
166  return data;
167 }
168 
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Setup the residuals
172 
174 {
175  TQpDataSparse *data = (TQpDataSparse *) data_in;
176  return new TQpResidual(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
177 }
178 
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Setup the variables
182 
184 {
185  TQpDataSparse *data = (TQpDataSparse *) data_in;
186 
187  return new TQpVar(fNx,fMy,fMz,data->fXloIndex,data->fXupIndex,data->fCloIndex,data->fCupIndex);
188 }
189 
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Setup the linear solver
193 
195 {
196  TQpDataSparse *data = (TQpDataSparse *) data_in;
197  return new TQpLinSolverSparse(this,data);
198 }
199 
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// Assembles a single vector object from three given vectors .
203 /// rhs_out (output) final joined vector
204 /// rhs1_in (input) first part of rhs
205 /// rhs2_in (input) middle part of rhs
206 /// rhs3_in (input) last part of rhs .
207 
208 void TQpProbSparse::JoinRHS(TVectorD &rhs,TVectorD &rhs1_in,TVectorD &rhs2_in,TVectorD &rhs3_in)
209 {
210  rhs.SetSub(0,rhs1_in);
211  if (fMy > 0) rhs.SetSub(fNx, rhs2_in);
212  if (fMz > 0) rhs.SetSub(fNx+fMy,rhs3_in);
213 }
214 
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Extracts three component vectors from a given aggregated vector.
218 /// vars_in (input) aggregated vector
219 /// x_in (output) first part of vars
220 /// y_in (output) middle part of vars
221 /// z_in (output) last part of vars
222 
224 {
225  x_in = vars_in.GetSub(0,fNx-1);
226  if (fMy > 0) y_in = vars_in.GetSub(fNx, fNx+fMy-1);
227  if (fMz > 0) z_in = vars_in.GetSub(fNx+fMy,fNx+fMy+fMz-1);
228 }
229 
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Create a random QP problem
233 
235 {
236  data = new TQpDataSparse(fNx,fMy,fMz);
237  soln = this->MakeVariables(data);
238  data->SetNonZeros(nnzQ,nnzA,nnzC);
239  data->DataRandom(soln->fX,soln->fY,soln->fZ,soln->fS);
240 }
241 
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 /// Assignment operator
245 
247 {
248  if (this != &source) {
249  TQpProbBase::operator=(source);
250  }
251  return *this;
252 }
const int nx
Definition: kalman.C:16
virtual TQpVar * MakeVariables(const TQpDataBase *data)
Setup the variables.
TVectorD fXloIndex
Definition: TQpDataBase.h:82
Int_t GetNcols() const
Definition: TMatrixTBase.h:125
#define R__ASSERT(e)
Definition: TError.h:96
Int_t GetNrows() const
Definition: TVectorT.h:75
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
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
virtual void SeparateVars(TVectorD &x_in, TVectorD &y_in, TVectorD &z_in, TVectorD &vars_in)
Extracts three component vectors from a given aggregated vector.
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.
void MakeRandomData(TQpDataSparse *&data, TQpVar *&soln, Int_t nnzQ, Int_t nnzA, Int_t nnzC)
Create a random QP problem.
void SetNonZeros(Int_t nnzQ, Int_t nnzA, Int_t nnzC)
Allocate space for the appropriate number of non-zeros in the matrices.
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
virtual TQpLinSolverBase * MakeLinSys(const TQpDataBase *data)
Setup the linear solver.
static double C[]
virtual TQpResidual * MakeResiduals(const TQpDataBase *data)
Setup the residuals.
TVectorD fXupIndex
Definition: TQpDataBase.h:80
Linear Algebra Package.
Int_t GetNrows() const
Definition: TMatrixTBase.h:122
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
TMatrixTSparse< Element > & Use(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb, Int_t nr_nonzeros, Int_t *pRowIndex, Int_t *pColIndex, Element *pData)
TVectorD fY
Definition: TQpVar.h:93
TQpProbSparse & operator=(const TQpProbSparse &source)
Assignment operator.
virtual TQpDataBase * MakeData(Double_t *c, Int_t nnzQ, Int_t *irowQ, Int_t *icolQ, Double_t *Q, Double_t *xlo, Bool_t *ixlo, Double_t *xup, Bool_t *ixup, Int_t nnzA, Int_t *irowA, Int_t *icolA, Double_t *A, Double_t *bA, Int_t nnzC, Int_t *irowC, Int_t *icolC, Double_t *C, Double_t *clo, Bool_t *iclo, Double_t *cup, Bool_t *icup)
Setup the data.
Definition: TQpVar.h:59
TVectorD fS
Definition: TQpVar.h:92
TVectorD fCloIndex
Definition: TQpDataBase.h:86
virtual void JoinRHS(TVectorD &rhs_in, TVectorD &rhs1_in, TVectorD &rhs2_in, TVectorD &rhs3_in)
Assembles a single vector object from three given vectors .
TQpProbBase & operator=(const TQpProbBase &source)
Assignment operator.
Definition: TQpProbBase.cxx:94
static double Q[]
TVectorD fZ
Definition: TQpVar.h:94