ROOT  6.06/09
Reference Guide
TQpDataBase.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 "TQpDataBase.h"
44 
45 //////////////////////////////////////////////////////////////////////////
46 // //
47 // TQpDataBase //
48 // //
49 // Data for the general QP formulation //
50 // //
51 // The Data class stores the data defining the problem and provides //
52 // methods for performing the operations with this data required by //
53 // the interior-point algorithms. These operations include assembling //
54 // the linear systems (5) or (7), performing matrix-vector operations //
55 // with the data, calculating norms of the data, reading input into the //
56 // data structure from various sources, generating random problem //
57 // instances, and printing the data. //
58 // //
59 //////////////////////////////////////////////////////////////////////////
60 
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Default constructor
65 
67 {
68  fNx = 0;
69  fMy = 0;
70  fMz = 0;
71 }
72 
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Constructor
76 
78 {
79  fNx = nx;
80  fMy = my;
81  fMz = mz;
82 
83  fG .ResizeTo(fNx);
84 
85  fBa .ResizeTo(fMy);
86 
91 
96 }
97 
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Copy constructor
101 
102 TQpDataBase::TQpDataBase(const TQpDataBase &another) : TObject(another)
103 {
104  *this = another;
105 }
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Randomly choose x and its boundaries
110 
112  TVectorD &x,TVectorD &dualx,TVectorD &xlow,TVectorD &ixlow,
113  TVectorD &xupp,TVectorD &ixupp,Double_t &ix,Double_t percentLowerOnly,
114  Double_t percentUpperOnly,Double_t percentBound)
115 {
116  const Int_t n = x.GetNrows();
117 
118  // Initialize the upper and lower bounds on x
119 
120  Int_t i;
121  for (i = 0; i < n; i++) {
122  const Double_t r = Drand(ix);
123 
124  if (r < percentLowerOnly) {
125  ixlow[i] = 1.0;
126  xlow [i] = (Drand(ix)-0.5)*3.0;
127  ixupp[i] = 0.0;
128  xupp [i] = 0.0;
129  }
130  else if (r < percentLowerOnly+percentUpperOnly) {
131  ixlow[i] = 0.0;
132  xlow [i] = 0.0;
133  ixupp[i] = 1.0;
134  xupp [i] = (Drand(ix)-0.5)*3.0;
135  }
136  else if (r < percentLowerOnly+percentUpperOnly+percentBound) {
137  ixlow[i] = 1.0;
138  xlow [i] = (Drand(ix)-0.5)*3.0;
139  ixupp[i] = 1.0;
140  xupp [i] = xlow[i]+Drand(ix)*10.0;
141  }
142  else {
143  // it is free
144  ixlow[i] = 0.0;
145  xlow [i] = 0.0;
146  ixupp[i] = 0.0;
147  xupp [i] = 0.0;
148  }
149  }
150 
151  for (i = 0; i < n; i++) {
152  if (ixlow[i] == 0.0 && ixupp[i] == 0.0 ) {
153  // x[i] not bounded
154  x [i] = 20.0*Drand(ix)-10.0;
155  dualx[i] = 0.0;
156  }
157  else if (ixlow[i] != 0.0 && ixupp[i] != 0.0) {
158  // x[i] is bounded above and below
159  const Double_t r = Drand(ix);
160  if (r < 0.33 ) {
161  // x[i] is on its lower bound
162  x [i] = xlow[i];
163  dualx[i] = 10.0*Drand(ix);
164  }
165  else if ( r > .66 ) {
166  // x[i] is on its upper bound
167  x [i] = xupp[i];
168  dualx[i] = -10.0*Drand(ix);
169  }
170  else {
171  // x[i] is somewhere in between
172  const Double_t theta = .99*Drand(ix)+.005;
173  x [i] = (1-theta)*xlow[i]+theta*xupp[i];
174  dualx[i] = 0.0;
175  }
176  }
177  else if (ixlow[i] != 0.0) {
178  // x[i] is only bounded below
179  if (Drand(ix) < .33 ) {
180  // x[i] is on its lower bound
181  x [i] = xlow[i];
182  dualx[i] = 10.0*Drand(ix);
183  }
184  else {
185  // x[i] is somewhere above its lower bound
186  x [i] = xlow[i]+0.005+10.0*Drand(ix);
187  dualx[i] = 0.0;
188  }
189  } // x[i] only has an upper bound
190  else {
191  if (Drand(ix) > .66 ) {
192  // x[i] is on its upper bound
193  x [i] = xupp[i];
194  dualx[i] = -10.0*Drand(ix);
195  }
196  else {
197  // x[i] is somewhere below its upper bound
198  x [i] = xupp[i]-0.005-10.0*Drand(ix);
199  dualx[i] = 0.0;
200  }
201  }
202  }
203 }
204 
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Assignment operator
208 
210 {
211  if (this != &source) {
212  TObject::operator=(source);
213  fNx = source.fNx;
214  fMy = source.fMy;
215  fMz = source.fMz;
216 
217  fG .ResizeTo(source.fG) ; fG = source.fG ;
218  fBa .ResizeTo(source.fBa) ; fBa = source.fBa ;
219  fXupBound.ResizeTo(source.fXupBound); fXupBound = source.fXupBound;
220  fXupIndex.ResizeTo(source.fXupIndex); fXupIndex = source.fXupIndex;
221  fXloBound.ResizeTo(source.fXloBound); fXloBound = source.fXloBound;
222  fXloIndex.ResizeTo(source.fXloIndex); fXloIndex = source.fXloIndex;
223  fCupBound.ResizeTo(source.fCupBound); fCupBound = source.fCupBound;
224  fCupIndex.ResizeTo(source.fCupIndex); fCupIndex = source.fCupIndex;
225  fCloBound.ResizeTo(source.fCloBound); fCloBound = source.fCloBound;
226  fCloIndex.ResizeTo(source.fCloIndex); fCloIndex = source.fCloIndex;
227  }
228  return *this;
229 }
const int nx
Definition: kalman.C:16
TVectorD fXupBound
Definition: TQpDataBase.h:85
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
Definition: TVectorT.cxx:291
TQpDataBase & operator=(const TQpDataBase &source)
Assignment operator.
TVectorD fXloIndex
Definition: TQpDataBase.h:88
TVectorD fG
Definition: TQpDataBase.h:83
Int_t GetNrows() const
Definition: TVectorT.h:81
int Int_t
Definition: RtypesCore.h:41
TVectorD fCupIndex
Definition: TQpDataBase.h:90
Double_t x[n]
Definition: legend1.C:17
TVectorD fCloBound
Definition: TQpDataBase.h:91
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:102
ClassImp(TQpDataBase) TQpDataBase
Default constructor.
Definition: TQpDataBase.cxx:61
ROOT::R::TRInterface & r
Definition: Object.C:4
TVectorD fXloBound
Definition: TQpDataBase.h:87
TVectorD fXupIndex
Definition: TQpDataBase.h:86
double Double_t
Definition: RtypesCore.h:55
TVectorD fBa
Definition: TQpDataBase.h:84
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.
Mother of all ROOT objects.
Definition: TObject.h:58
TVectorD fCupBound
Definition: TQpDataBase.h:89
TVectorD fCloIndex
Definition: TQpDataBase.h:92
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
const Int_t n
Definition: legend1.C:16