All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ModifiedBoxLCP.h
Go to the documentation of this file.
1 //=================================================================================================
20 //=================================================================================================
21 
22 #ifndef _BLAZE_MATH_PROBLEMS_MODIFIEDBOXLCP_H_
23 #define _BLAZE_MATH_PROBLEMS_MODIFIEDBOXLCP_H_
24 
25 
26 //*************************************************************************************************
27 // Includes
28 //*************************************************************************************************
29 
30 #include <cmath>
33 #include <blaze/math/Functions.h>
34 #include <blaze/system/Precision.h>
35 #include <blaze/util/Types.h>
36 
37 
38 namespace blaze {
39 
40 //=================================================================================================
41 //
42 // CLASS DEFINITION
43 //
44 //=================================================================================================
45 
46 //*************************************************************************************************
60 {
61  //**Utility functions***************************************************************************
64  inline size_t size () const;
65  inline void project ( size_t index );
66  inline real lbound ( size_t index ) const;
67  inline real ubound ( size_t index ) const;
68  inline real residual( size_t index ) const;
69  inline real residual() const;
71  //**********************************************************************************************
72 
73  //**Member variables****************************************************************************
77  VecN b_;
78  VecN x_;
85 
86  //**********************************************************************************************
87 };
88 //*************************************************************************************************
89 
90 
91 
92 
93 //=================================================================================================
94 //
95 // UTILITY FUNCTIONS
96 //
97 //=================================================================================================
98 
99 //*************************************************************************************************
104 inline size_t ModifiedBoxLCP::size() const
105 {
106  return x_.size();
107 }
108 //*************************************************************************************************
109 
110 
111 //*************************************************************************************************
117 inline void ModifiedBoxLCP::project( size_t index )
118 {
119  x_[index] = min( xmax_[index], max( xmin_[index], x_[index] ) );
120 }
121 //*************************************************************************************************
122 
123 
124 //*************************************************************************************************
130 inline real ModifiedBoxLCP::lbound( size_t index ) const
131 {
132  return ( xmin_[index] + lambdamin_[index] * x_[ jmin_[index] ] );
133 }
134 //*************************************************************************************************
135 
136 
137 //*************************************************************************************************
143 inline real ModifiedBoxLCP::ubound( size_t index ) const
144 {
145  return ( xmax_[index] + lambdamax_[index] * x_[ jmax_[index] ] );
146 }
147 //*************************************************************************************************
148 
149 
150 //*************************************************************************************************
156 inline real ModifiedBoxLCP::residual( size_t index ) const
157 {
158  // Computing the residual using max( x - xmax, min( x - xmin, Ax+b ) )
159  return max( x_[index] - ubound( index ),
160  min( x_[index] - lbound( index ), ( A_ * x_ )[index] + b_[index] ) );
161 }
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
171 {
172  real rmax( 0 );
173 
174  for( size_t i=0; i<size(); ++i )
175  rmax = max( rmax, std::fabs( residual( i ) ) );
176 
177  return rmax;
178 }
179 //*************************************************************************************************
180 
181 } // namespace blaze
182 
183 #endif