00001 #ifndef OPENTISSUE_CORE_MATH_OPTIMIZATION_MAKE_CONSTANT_BOUNDS_H 00002 #define OPENTISSUE_CORE_MATH_OPTIMIZATION_MAKE_CONSTANT_BOUNDS_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/math/big/big_types.h> 00013 00014 namespace OpenTissue 00015 { 00016 namespace math 00017 { 00018 namespace optimization 00019 { 00020 namespace detail 00021 { 00022 00023 template <typename T> 00024 class ConstantVectorBoundFunctor 00025 { 00026 public: 00027 00028 typedef T value_type; 00029 00030 protected: 00031 00032 ublas::vector<T> const & m_values; 00033 00034 public: 00035 00042 class vector_iterator 00043 { 00044 public: 00045 00046 vector_iterator(){} 00047 vector_iterator(vector_iterator const & i) { *this = i; } 00048 bool const operator==(vector_iterator const & i) const { return true; } 00049 bool const operator!=(vector_iterator const & i) const { return !( (*this) == i); } 00050 size_t const index() const { return 0; } 00051 T operator*() const { return 0; } 00052 vector_iterator & operator=(vector_iterator const & i) { return *this; } 00053 vector_iterator const & operator++(){ return *this; } 00054 }; 00055 00056 public: 00057 00058 ConstantVectorBoundFunctor( 00059 ublas::vector<T> const & values 00060 ) 00061 : m_values(values) 00062 {} 00063 00064 template<typename vector_type> 00065 T operator()(vector_type const & x, size_t const & i) const { return m_values(i); } 00066 vector_iterator partial_begin(size_t const & i) const { return vector_iterator(); } 00067 vector_iterator partial_end(size_t const & i) const { return vector_iterator(); } 00068 00069 size_t size() const { return m_values.size(); } 00070 }; 00071 00072 template <typename T> 00073 class ConstantValueBoundFunctor 00074 { 00075 public: 00076 00077 typedef T value_type; 00078 00079 protected: 00080 00081 T m_value; 00082 size_t m_size; 00083 00084 public: 00085 00092 class vector_iterator 00093 { 00094 public: 00095 00096 vector_iterator(){} 00097 vector_iterator(vector_iterator const & i) { *this = i; } 00098 bool const operator==(vector_iterator const & i) const { return true; } 00099 bool const operator!=(vector_iterator const & i) const { return !( (*this) == i); } 00100 size_t const index() const { return 0; } 00101 T operator*() const { return 0; } 00102 vector_iterator & operator=(vector_iterator const & i) { return *this; } 00103 vector_iterator const & operator++(){ return *this; } 00104 }; 00105 00106 public: 00107 00108 ConstantValueBoundFunctor( T const & value, size_t const & size ) 00109 : m_value(value) 00110 , m_size(size) 00111 {} 00112 00113 template<typename vector_type> 00114 T operator()(vector_type const & x, size_t const & i) const { return m_value; } 00115 vector_iterator partial_begin(size_t const & i) const { return vector_iterator(); } 00116 vector_iterator partial_end(size_t const & i) const { return vector_iterator(); } 00117 00118 size_t size() const { return m_size; } 00119 }; 00120 00121 00122 } // namespace detail 00123 00131 template<typename T> 00132 inline detail::ConstantVectorBoundFunctor<T> make_constant_bounds( ublas::vector<T> const & val ) 00133 { 00134 return detail::ConstantVectorBoundFunctor<T>( val ); 00135 } 00136 00145 template<typename T> 00146 inline detail::ConstantValueBoundFunctor<T> make_constant_bounds( T const & value, size_t const & size ) 00147 { 00148 return detail::ConstantValueBoundFunctor<T>( value, size ); 00149 } 00150 00151 } // namespace optimization 00152 } // namespace math 00153 } // namespace OpenTissue 00154 00155 // OPENTISSUE_CORE_MATH_OPTIMIZATION_MAKE_CONSTANT_BOUNDS_H 00156 #endif