Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_BLOCKING_CONSTRAINT_SEARCH_H
00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_BLOCKING_CONSTRAINT_SEARCH_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/math_value_traits.h>
00014 #include <OpenTissue/core/math/math_is_number.h>
00015 #include <cmath>
00016 #include <stdexcept>
00017 #include <cassert>
00018
00019 namespace OpenTissue
00020 {
00021 namespace math
00022 {
00023 namespace optimization
00024 {
00025
00040 template <
00041 typename T
00042 , typename bound_function_type
00043 >
00044 inline bool blocking_constraint_search(
00045 boost::numeric::ublas::vector<T> const & x
00046 , boost::numeric::ublas::vector<T> const & p
00047 , bound_function_type const & c
00048 , T & tau
00049 , size_t & blocking_idx
00050 )
00051 {
00052 typedef OpenTissue::math::ValueTraits<T> value_traits;
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 size_t const n = x.size();
00116
00117 if(n<=0)
00118 throw std::invalid_argument("x was empty");
00119
00120 if(n != p.size())
00121 throw std::invalid_argument("line-search direction was incompatible with the iterate");
00122
00123 bool is_blocked = false;
00124 tau = value_traits::one();
00125 blocking_idx = n + 1;
00126
00127 for (size_t i = 0; i < n; ++ i)
00128 {
00129 T denom = value_traits::zero();
00130 typename bound_function_type::vector_iterator e = c.partial_begin(i);
00131 typename bound_function_type::vector_iterator end = c.partial_end(i);
00132 for(; e!=end; ++e)
00133 denom += p(e.index())*(*e);
00134
00135 assert( is_number( denom ) || !"blocking_constraint_search() NAN encounted!");
00136
00137 if(denom<value_traits::zero())
00138 {
00139 T num = -c(x,i);
00140 assert( is_number( num ) || !"blocking_constraint_search() NAN encounted!");
00141
00142 T tau_i = num / denom;
00143 assert( is_number( tau_i ) || !"blocking_constraint_search() NAN encounted!");
00144
00145 if(tau_i < tau)
00146 {
00147 tau = tau_i;
00148 blocking_idx = i;
00149 is_blocked = true;
00150 }
00151 }
00152
00153 }
00154 return is_blocked;
00155 }
00156
00157 }
00158 }
00159 }
00160
00161
00162 #endif