Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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/// \class TQpProbSparse
50///
51/// dense matrix problem formulation
52///
53////////////////////////////////////////////////////////////////////////////////
54
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 Int_t nnzQ,Int_t *irowQ,Int_t *icolQ,Double_t *Q,
81 Double_t *xlo,Bool_t *ixlo,
82 Double_t *xup,Bool_t *ixup,
83 Int_t nnzA,Int_t *irowA,Int_t *icolA,Double_t *A,
84 Double_t *bA,
85 Int_t nnzC,Int_t *irowC,Int_t *icolC,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 TMatrixDSparse mQ ; mQ .Use(fNx,fNx,nnzQ,irowQ,icolQ,Q);
91 TVectorD vxlo; vxlo.Use(fNx,xlo);
92 TVectorD vxup; vxup.Use(fNx,xup);
94 TVectorD vbA ;
95 if (fMy > 0) {
96 mA .Use(fMy,fNx,nnzA,irowA,icolA,A);
97 vbA .Use(fMy,bA);
98 }
100 TVectorD vclo;
101 TVectorD vcup;
102 if (fMz > 0) {
103 mC .Use(fMz,fNx,nnzC,irowC,icolC,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 TQpDataSparse *data = new TQpDataSparse(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 TMatrixDSparse &mQ = (TMatrixDSparse &) Q_in;
142 TMatrixDSparse &mA = (TMatrixDSparse &) A_in;
143 TMatrixDSparse &mC = (TMatrixDSparse &) 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 TQpDataSparse *data = new TQpDataSparse(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 TQpDataSparse *data = (TQpDataSparse *) 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 TQpDataSparse *data = (TQpDataSparse *) 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 TQpDataSparse *data = (TQpDataSparse *) data_in;
196 return new TQpLinSolverSparse(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
207void TQpProbSparse::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
234{
235 data = new TQpDataSparse(fNx,fMy,fMz);
236 soln = this->MakeVariables(data);
237 data->SetNonZeros(nnzQ,nnzA,nnzC);
238 data->DataRandom(soln->fX,soln->fY,soln->fZ,soln->fS);
239}
240
241
242////////////////////////////////////////////////////////////////////////////////
243/// Assignment operator
244
246{
247 if (this != &source) {
249 }
250 return *this;
251}
#define c(i)
Definition RSha256.hxx:101
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
TMatrixTBase< Double_t > TMatrixDBase
TMatrixTSparse< Double_t > TMatrixDSparse
TVectorT< Double_t > TVectorD
Definition TVectorDfwd.h:23
Int_t GetNrows() const
Int_t GetNcols() const
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)
Data for the general QP formulation.
Definition TQpDataBase.h:61
Data for the sparse QP formulation.
Implementation of main solver for linear systems.
Implements the aspects of the solvers for dense general QP formulation that are specific to the dense...
TQpProbBase()
Default constructor.
TQpProbBase & operator=(const TQpProbBase &source)
Assignment operator.
void JoinRHS(TVectorD &rhs_in, TVectorD &rhs1_in, TVectorD &rhs2_in, TVectorD &rhs3_in) override
Assembles a single vector object from three given vectors .
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.
TQpProbSparse & operator=(const TQpProbSparse &source)
Assignment operator.
TQpVar * MakeVariables(const TQpDataBase *data) override
Setup the variables.
void MakeRandomData(TQpDataSparse *&data, TQpVar *&soln, Int_t nnzQ, Int_t nnzA, Int_t nnzC)
Create a random QP problem.
TQpResidual * MakeResiduals(const TQpDataBase *data) override
Setup the residuals.
void SeparateVars(TVectorD &x_in, TVectorD &y_in, TVectorD &z_in, TVectorD &vars_in) override
Extracts three component vectors from a given aggregated vector.
TQpLinSolverBase * MakeLinSys(const TQpDataBase *data) override
Setup the linear solver.
The Residuals class calculates and stores the quantities that appear on the right-hand side of the li...
Definition TQpResidual.h:62
Class containing the variables for the general QP formulation.
Definition TQpVar.h:60
TVectorD fX
Definition TQpVar.h:91
TVectorD fS
Definition TQpVar.h:92
TVectorD fY
Definition TQpVar.h:93
TVectorD fZ
Definition TQpVar.h:94
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:373
Int_t GetNrows() const
Definition TVectorT.h:75
TVectorT< Element > & SetSub(Int_t row_lwb, const TVectorT< Element > &source)
Insert vector source starting at [row_lwb], thereby overwriting the part [row_lwb....
Definition TVectorT.cxx:422
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
Definition TVectorT.cxx:349