All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LCP.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_PROBLEMS_LCP_H_
23 #define _BLAZE_MATH_PROBLEMS_LCP_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <cmath>
33 #include <blaze/math/Functions.h>
34 #include <blaze/math/Infinity.h>
35 #include <blaze/system/Precision.h>
36 #include <blaze/util/Types.h>
37 
38 
39 namespace blaze {
40 
41 //=================================================================================================
42 //
43 // CLASS DEFINITION
44 //
45 //=================================================================================================
46 
47 //*************************************************************************************************
54 struct LCP
55 {
56  public:
57  //**Utility functions***************************************************************************
60  inline size_t size () const;
61  inline void project ( size_t index );
62  inline real lbound ( size_t index ) const;
63  inline real ubound ( size_t index ) const;
64  inline real residual( size_t index ) const;
65  inline real residual() const;
67  //**********************************************************************************************
68 
69  //**Member variables****************************************************************************
73  VecN b_;
74  VecN x_;
75 
76  //**********************************************************************************************
77 };
78 //*************************************************************************************************
79 
80 
81 
82 
83 //=================================================================================================
84 //
85 // UTILITY FUNCTIONS
86 //
87 //=================================================================================================
88 
89 //*************************************************************************************************
94 inline size_t LCP::size() const
95 {
96  return x_.size();
97 }
98 //*************************************************************************************************
99 
100 
101 //*************************************************************************************************
107 inline void LCP::project( size_t index )
108 {
109  x_[index] = max( 0, x_[index] );
110 }
111 //*************************************************************************************************
112 
113 
114 //*************************************************************************************************
120 inline real LCP::lbound( size_t /*index*/ ) const
121 {
122  return real( 0 );
123 }
124 //*************************************************************************************************
125 
126 
127 //*************************************************************************************************
133 inline real LCP::ubound( size_t /*index*/ ) const
134 {
135  return inf;
136 }
137 //*************************************************************************************************
138 
139 
140 //*************************************************************************************************
146 inline real LCP::residual( size_t index ) const
147 {
148  return min( x_[index], ( A_ * x_ )[index] + b_[index] );
149 }
150 //*************************************************************************************************
151 
152 
153 //*************************************************************************************************
158 inline real LCP::residual() const
159 {
160  real rmax( 0 );
161 
162  for( size_t i=0; i<size(); ++i )
163  rmax = max( rmax, std::fabs( residual( i ) ) );
164 
165  return rmax;
166 }
167 //*************************************************************************************************
168 
169 } // namespace blaze
170 
171 #endif