Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_COMPUTE_INDEX_SETS_H
00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_COMPUTE_INDEX_SETS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/big/big_types.h>
00013 #include <OpenTissue/core/math/optimization/optimization_constants.h>
00014 #include <OpenTissue/core/math/math_value_traits.h>
00015 #include <cmath>
00016 #include <cassert>
00017
00018 namespace OpenTissue
00019 {
00020 namespace math
00021 {
00022 namespace optimization
00023 {
00038 template < typename T, typename bound_function_type>
00039 inline void compute_index_sets(
00040 ublas::vector<T> const & y
00041 , ublas::vector<T> const & x
00042 , bound_function_type const & l
00043 , bound_function_type const & u
00044 , ublas::vector<size_t> & bitmask
00045 , size_t & cnt_active
00046 , size_t & cnt_inactive
00047 )
00048 {
00049 using std::min;
00050 using std::max;
00051
00052 typedef OpenTissue::math::ValueTraits<T> value_traits;
00053
00054 size_t n = x.size();
00055 bitmask.resize(n);
00056
00057 cnt_active = 0;
00058 cnt_inactive = 0;
00059 size_t cnt_lower = 0;
00060 size_t cnt_upper = 0;
00061
00062 for (size_t i = 0; i < n; ++i)
00063 {
00064 if(y(i) > (x(i) - l(x,i)))
00065 {
00066 bitmask(i) = IN_LOWER;
00067 ++cnt_lower;
00068 ++cnt_inactive;
00069 }
00070 else if(y(i) < (x(i) - u(x,i)))
00071 {
00072 bitmask(i) = IN_UPPER;
00073 ++cnt_upper;
00074 ++cnt_inactive;
00075 }
00076 else
00077 {
00078
00079 bitmask(i) = IN_ACTIVE;
00080 ++cnt_active;
00081 }
00082 }
00083 assert( (cnt_active + cnt_inactive) == n || !"compute_index_sets(): index sets were inconsistent");
00084 assert( (cnt_lower + cnt_upper) == cnt_inactive || !"compute_index_sets(): index sets were inconsistent");
00085 }
00086
00087 }
00088 }
00089 }
00090
00091
00092 #endif