Minotaur 0.4.1
Docs for developers
Eigen.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2008 - 2025 The Minotaur Team.
5//
6
15#ifndef MINOTAUREIGEN_H
16#define MINOTAUREIGEN_H
17
18#include "LinearFunction.h"
19#include "QuadraticFunction.h"
20
21namespace Minotaur {
22
23 class QuadraticFunction;
24 typedef QuadraticFunction *QuadraticFunctionPtr;
25 typedef const QuadraticFunction *ConstQuadraticFunctionPtr;
26 //class EigenVector;
27 //typedef LinearFunction EigenVector;
28 //typedef LinearFunctionPtr EigenVectorPtr;
29 typedef std::pair<double, LinearFunctionPtr> EigenPair;
30 typedef std::vector<EigenPair>::const_iterator EigenPairConstIterator;
31
32 class Eigen;
33 typedef Eigen *EigenPtr;
34
35 // /**
36 // In Minotaur, EigenVectors are used only in the context of quadratic
37 // functions. Thus an Eigen Vector is just a linear function.
38 // */
39 // class EigenVector {
40 // public:
41 // // /**
42 // // Default constructor
43 // // */
44 // EigenVector();
45
46 // // /**
47 // // Destroy
48 // // */
49 // ~EigenVector() {}
50
51 // // /**
52 // // Display the nonzero coefficients of the eigen vector.
53 // // */
54 // void write(std::ostream &s) const;
55
56 // private:
57 // // /**
58 // // The vector
59 // // */
60 // LinearFunctionPtr lf_;
61 // };
62
63
64 // /**
65 // The EigenCalculator class is used to calculate eigen vectors and values
66 // for matrices and other objects that have an associated matrix (like a
67 // quadratic).
68 // */
70 public:
73
76
79
82 EigenPtr findValues(int n, double **H);
83
86
87 // /**
88 // Let qf = x'Ax, lf = cx. First find eigen vectors of the hessian of
89 // qf. Then, x'Ax = x'QRERQ'x, where Q is orthogonal (QQ' = I). R is a
90 // diagonal matrix with i-th diagonal element being the square root of
91 // i-th eigen value. E has entries 1,-1 along the diagonal. Let y =
92 // RQ'x. Then c'x = c'QR^(-1)y = b'y. b = R^(-1)Q'c. This function
93 // calculates Q, RER, b.
94 //
95 // The "x" vectors in qf and lf are not the same. e.g. x0*x0 + x1*x1 +
96 // 2x0*x1 + 2x0 + x2 + x3. here lf does not contain x1 and has extra
97 // variables x2 and x3. The vector 'c' thus corresponds to only 2x0 and
98 // we get: 1*(x0 + x1)^2 + 0*(x0 - x1)^2 + 1*(x0+x1) + 1*(x0-x1) + x2 +
99 // x3. p_terms will thus have (x0 + x1 + 0.5)^2, n_terms will have
100 // terms that have negative eigen values. lin_terms will have
101 // x0-x1+x2+x3 and cb = -0.25.
102 // */
103 void getSumOfSquares(std::vector<LinearFunctionPtr> &p_terms,
104 std::vector<LinearFunctionPtr> &n_terms,
105 std::vector<double> &p_const,
106 std::vector<double> &n_const,
107 LinearFunctionPtr &lin_terms, double &c,
110
111 private:
117
119 size_t n_;
120
125 double *A_;
126
128 int m_;
129
136 double abstol_;
137
139 char findVectors_;
140
142 double *w_;
143
144 // /**
145 // the first M columns of z contain the orthonormal eigenvectors of the
146 // matrix A corresponding to the selected eigenvalues, with the i-th
147 // column of Z holding the eigenvector associated with W(i). If JOBZ =
148 // 'N', then Z is not referenced. Note: the user must ensure that at
149 // least max(1,M) columns are supplied in the array Z; if RANGE = 'V',
150 // the exact value of M is not known in advance and an upper bound must
151 // be used. Supplying N columns is always safe.
152 // */
153 double *z_;
154
155 // /**
156 // The i-th eigenvector is nonzero only in elements
157 // ISUPPZ( 2*i-1 ) through ISUPPZ( 2*i ).
158 // */
159 int *isuppz_;
160
162 std::map<ConstVariablePtr, UInt, CompareVariablePtr> indices_;
163
165 std::vector<ConstVariablePtr> vars_;
166
168 double getDotProduct_(ConstLinearFunctionPtr lf1,
170
172 void calculate_();
173
178 void fillA_();
179
184 EigenPtr getEigen_();
185
187 LinearFunctionPtr getLinearFunction_(const int i);
188 };
189
190 class Eigen {
191 public:
194
196 void add(double value, LinearFunctionPtr e_vector);
197
200
202 UInt numZero() const;
203
206
208 EigenPairConstIterator begin() const;
209
211 EigenPairConstIterator end() const;
212
214 void write(std::ostream &s) const;
215
216 private:
221 std::vector<EigenPair> evPairs_;
222
224 UInt neg_;
225
227 UInt zero_;
228
230 UInt pos_;
231 };
232
233} //namespace Minotaur
234#endif
Declare the class LinearFunction for storing and modifying a linear function.
Construct and manage quadratic functions.
Definition: Eigen.h:69
~EigenCalculator()
Destroy.
Definition: Eigen.h:75
EigenPtr findValues(ConstQuadraticFunctionPtr qf)
Calculate EigenValues only.
EigenCalculator()
Default constructor.
EigenPtr findVectors(ConstQuadraticFunctionPtr qf)
Calculate EigenVectors as well.
EigenPtr findValues(int n, double **H)
Definition: Eigen.h:190
EigenPairConstIterator end() const
Get the last evPair.
Eigen()
Default constructor.
void add(double value, LinearFunctionPtr e_vector)
Add an eigen value and an eigen vector to the current list.
UInt numPositive() const
Get the number of positive eigen values.
UInt numZero() const
Get the number of zero eigen values.
UInt numNegative() const
Get the number of negative eigen values.
EigenPairConstIterator begin() const
Get the first evPair.
void write(std::ostream &s) const
Display the values and the vectors.
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Definition: QuadraticFunction.h:38
Definition: ActiveNodeStore.h:20
unsigned int UInt
Unsigned integer.
Definition: Types.h:30

Minotaur source code documented by Doxygen 1.9.4 on Thu Apr 24 2025