Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TQpDataDens.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 "TQpDataDens.h"
44
45////////////////////////////////////////////////////////////////////////////////
46///
47/// \class TQpDataDens
48///
49/// Data for the dense QP formulation
50///
51////////////////////////////////////////////////////////////////////////////////
52
53
54////////////////////////////////////////////////////////////////////////////////
55/// Constructor
56
64
65
66////////////////////////////////////////////////////////////////////////////////
67/// Constructor
68
103
104
105////////////////////////////////////////////////////////////////////////////////
106/// Copy constructor
107
112
113
114////////////////////////////////////////////////////////////////////////////////
115/// calculate y = beta*y + alpha*(fQ*x)
116
118{
119 y *= beta;
120 if (fQ.GetNoElements() > 0)
121 y += alpha*(fQ*x);
122}
123
124
125////////////////////////////////////////////////////////////////////////////////
126/// calculate y = beta*y + alpha*(fA*x)
127
129{
130 y *= beta;
131 if (fA.GetNoElements() > 0)
132 y += alpha*(fA*x);
133}
134
135
136////////////////////////////////////////////////////////////////////////////////
137/// calculate y = beta*y + alpha*(fC*x)
138
140{
141 y *= beta;
142 if (fC.GetNoElements() > 0)
143 y += alpha*(fC*x);
144}
145
146
147////////////////////////////////////////////////////////////////////////////////
148/// calculate y = beta*y + alpha*(fA^T*x)
149
151{
152 y *= beta;
153 if (fA.GetNoElements() > 0)
154 y += alpha*(TMatrixD(TMatrixD::kTransposed,fA)*x);
155}
156
157
158////////////////////////////////////////////////////////////////////////////////
159/// calculate y = beta*y + alpha*(fC^T*x)
160
162{
163 y *= beta;
164 if (fC.GetNoElements() > 0)
165 y += alpha*(TMatrixD(TMatrixD::kTransposed,fC)*x);
166}
167
168
169////////////////////////////////////////////////////////////////////////////////
170/// Return the largest component of several vectors in the data class
171
212
213
214////////////////////////////////////////////////////////////////////////////////
215/// Print all class members
216
217void TQpDataDens::Print(Option_t * /*opt*/) const
218{
219 fQ.Print("Q");
220 fG.Print("c");
221
222 fXloBound.Print("xlow");
223 fXloIndex.Print("ixlow");
224
225 fXupBound.Print("xupp");
226 fXupIndex.Print("ixupp");
227
228 fA.Print("A");
229 fBa.Print("b");
230 fC.Print("C");
231
232 fCloBound.Print("clow");
233 fCloIndex.Print("iclow");
234
235 fCupBound.Print("cupp");
236 fCupIndex.Print("icupp");
237}
238
239
240////////////////////////////////////////////////////////////////////////////////
241/// Insert the Hessian Q into the matrix M at index (row,col) for the fundamental
242/// linear system
243
245{
246 m.SetSub(row,col,fQ);
247}
248
249
250////////////////////////////////////////////////////////////////////////////////
251/// Insert the constraint matrix A into the matrix M at index (row,col) for the fundamental
252/// linear system
253
255{
256 m.SetSub(row,col,fA);
257}
258
259
260////////////////////////////////////////////////////////////////////////////////
261/// Insert the constraint matrix C into the matrix M at index (row,col) for the fundamental
262/// linear system
263
265{
266 m.SetSub(row,col,fC);
267}
268
269
270////////////////////////////////////////////////////////////////////////////////
271/// Return in vector dq the diagonal of matrix fQ (Quadratic part of Objective function)
272
274{
275 const Int_t n = TMath::Min(fQ.GetNrows(),fQ.GetNcols());
276 dq.ResizeTo(n);
277 dq = TMatrixDDiag(fQ);
278}
279
280
281////////////////////////////////////////////////////////////////////////////////
282/// Return value of the objective function
283
285{
286 TVectorD tmp(fG);
287 this->Qmult(1.0,tmp,0.5,vars->fX);
288
289 return tmp*vars->fX;
290}
291
292
293////////////////////////////////////////////////////////////////////////////////
294/// Choose randomly a QP problem
295
297{
298 Double_t ix = 3074.20374;
299
304
305 fQ.RandomizePD(0.0,1.0,ix);
306 fA.Randomize(-10.0,10.0,ix);
307 fC.Randomize(-10.0,10.0,ix);
308 y .Randomize(-10.0,10.0,ix);
309
310 fG = xdual;
311 fG -= fQ*x;
312
315
316 fBa = fA*x;
317 s = fC*x;
318
319 // Now compute the real q = s-sprime
320 const TVectorD q = s-sprime;
321
322 // Adjust fCloBound and fCupBound appropriately
323 Add(fCloBound,1.0,q);
324 Add(fCupBound,1.0,q);
325
328}
329
330
331////////////////////////////////////////////////////////////////////////////////
332/// Assignment operator
333
335{
336 if (this != &source) {
338 fQ.ResizeTo(source.fQ); fQ = source.fQ;
339 fA.ResizeTo(source.fA); fA = source.fA;
340 fC.ResizeTo(source.fC); fC = source.fC;
341 }
342 return *this;
343}
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
float * q
TMatrixTDiag< Double_t > TMatrixDDiag
TMatrixT< Double_t > TMatrixD
Definition TMatrixDfwd.h:23
virtual TMatrixTBase< Element > & Randomize(Element alpha, Element beta, Double_t &seed)
Randomize matrix element values.
Int_t GetNrows() const
void Print(Option_t *name="") const override
Print the matrix as a table of elements.
Int_t GetNoElements() const
Int_t GetNcols() const
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
virtual TMatrixTSym< Element > & RandomizePD(Element alpha, Element beta, Double_t &seed)
randomize matrix element values but keep matrix symmetric positive definite
TMatrixTSym< Element > & Use(Int_t row_lwb, Int_t row_upb, Element *data)
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])
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
Data for the general QP formulation.
Definition TQpDataBase.h:61
TQpDataBase & operator=(const TQpDataBase &source)
Assignment operator.
TVectorD fXupIndex
Definition TQpDataBase.h:80
TVectorD fXloBound
Definition TQpDataBase.h:81
TVectorD fCloIndex
Definition TQpDataBase.h:86
TVectorD fCupIndex
Definition TQpDataBase.h:84
TVectorD fG
Definition TQpDataBase.h:77
TVectorD fXupBound
Definition TQpDataBase.h:79
TVectorD fXloIndex
Definition TQpDataBase.h:82
TVectorD fCupBound
Definition TQpDataBase.h:83
TVectorD fCloBound
Definition TQpDataBase.h:85
TVectorD fBa
Definition TQpDataBase.h:78
static void RandomlyChooseBoundedVariables(TVectorD &x, TVectorD &dualx, TVectorD &blx, TVectorD &ixlow, TVectorD &bux, TVectorD &ixupp, Double_t &ix, Double_t percentLowerOnly, Double_t percentUpperOnly, Double_t percentBound)
Randomly choose x and its boundaries.
Data for the dense QP formulation.
Definition TQpDataDens.h:63
Double_t DataNorm() override
Return the largest component of several vectors in the data class.
void Qmult(Double_t beta, TVectorD &y, Double_t alpha, const TVectorD &x) override
calculate y = beta*y + alpha*(fQ*x)
void Cmult(Double_t beta, TVectorD &y, Double_t alpha, const TVectorD &x) override
calculate y = beta*y + alpha*(fC*x)
void GetDiagonalOfQ(TVectorD &dQ) override
Return in vector dq the diagonal of matrix fQ (Quadratic part of Objective function)
void DataRandom(TVectorD &x, TVectorD &y, TVectorD &z, TVectorD &s) override
Choose randomly a QP problem.
TMatrixD fC
Definition TQpDataDens.h:70
void Amult(Double_t beta, TVectorD &y, Double_t alpha, const TVectorD &x) override
calculate y = beta*y + alpha*(fA*x)
TMatrixDSym fQ
Definition TQpDataDens.h:68
Double_t ObjectiveValue(TQpVar *vars) override
Return value of the objective function.
TMatrixD fA
Definition TQpDataDens.h:69
void PutCIntoAt(TMatrixDBase &M, Int_t row, Int_t col) override
Insert the constraint matrix C into the matrix M at index (row,col) for the fundamental linear system...
void Print(Option_t *opt="") const override
Print all class members.
void PutQIntoAt(TMatrixDBase &M, Int_t row, Int_t col) override
Insert the Hessian Q into the matrix M at index (row,col) for the fundamental linear system.
void PutAIntoAt(TMatrixDBase &M, Int_t row, Int_t col) override
Insert the constraint matrix A into the matrix M at index (row,col) for the fundamental linear system...
void ATransmult(Double_t beta, TVectorD &y, Double_t alpha, const TVectorD &x) override
calculate y = beta*y + alpha*(fA^T*x)
TQpDataDens & operator=(const TQpDataDens &source)
Assignment operator.
void CTransmult(Double_t beta, TVectorD &y, Double_t alpha, const TVectorD &x) override
calculate y = beta*y + alpha*(fC^T*x)
Class containing the variables for the general QP formulation.
Definition TQpVar.h:60
TVectorD fX
Definition TQpVar.h:91
Element NormInf() const
Compute the infinity-norm of the vector MAX{ |v[i]| }.
Definition TVectorT.cxx:602
Bool_t MatchesNonZeroPattern(const TVectorT< Element > &select)
Check if vector elements as selected through array select are non-zero.
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
Definition TVectorT.cxx:293
Int_t GetNrows() const
Definition TVectorT.h:75
TVectorT< Element > & SelectNonZeros(const TVectorT< Element > &select)
Keep only element as selected through array select non-zero.
Definition TVectorT.cxx:543
void Print(Option_t *option="") const override
Print the vector as a list of elements.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:199
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
TMarker m
Definition textangle.C:8