00001 00012 // for truncation warning in debug mode 00013 #ifdef _MSC_VER 00014 #include "msdevstudio/MSconfig.h" 00015 #endif 00016 00017 #include "FunctionBase.h" 00018 00019 #include <cassert> 00020 00021 using std::string; 00022 using std::vector; 00023 00024 namespace hippodraw { 00025 00030 FunctionBase::FunctionBase () 00031 { 00032 m_name = "nil"; 00033 } 00034 00038 FunctionBase:: 00039 FunctionBase ( const FunctionBase & fb ) 00040 : m_name ( fb.m_name ), 00041 m_parm_names ( fb.m_parm_names ), 00042 m_parms ( fb.m_parms ), 00043 m_fixed_flags ( fb.m_fixed_flags ) 00044 { 00045 } 00046 00047 FunctionBase::~FunctionBase () 00048 { 00049 } 00050 00051 FunctionBase * 00052 FunctionBase:: 00053 clone () const 00054 { 00055 assert ( false ); 00056 return 0; 00057 } 00058 00059 void 00060 FunctionBase:: 00061 initialParameters ( const FunctionHelper * ) 00062 { 00063 } 00064 00065 void 00066 FunctionBase:: 00067 setName ( const char * name ) 00068 { 00069 m_name = name; 00070 } 00071 00072 void FunctionBase::resize () 00073 { 00074 assert ( ! m_parm_names.empty () ); 00075 00076 size_t size = m_parm_names.size (); 00077 m_parms.resize ( size ); 00078 m_fixed_flags.resize ( size, 0 ); // set to free parameter 00079 } 00080 00081 const string & FunctionBase::name () const 00082 { 00083 return m_name; 00084 } 00085 00086 const vector < string > & FunctionBase::parmNames ( ) const 00087 { 00088 return m_parm_names; 00089 } 00090 00091 void 00092 FunctionBase:: 00093 setParmNames ( const std::vector < std::string > & names ) 00094 { 00095 m_parm_names = names; 00096 resize (); 00097 } 00098 00099 const vector < double > & FunctionBase::getParameters () const 00100 { 00101 return m_parms; 00102 } 00103 00104 const vector < int > & 00105 FunctionBase:: 00106 getFixedFlags ( ) const 00107 { 00108 return m_fixed_flags; 00109 } 00110 00111 void 00112 FunctionBase:: 00113 setFixedFlags ( const vector < int > & flags ) 00114 { 00115 vector < int > :: const_iterator it = flags.begin (); 00116 setFixedFlags ( it ); 00117 } 00118 00119 void 00120 FunctionBase:: 00121 setParameters ( const std::vector< double > & incr ) 00122 { 00123 vector< double >::const_iterator it = incr.begin (); 00124 setParameters ( it ); 00125 } 00126 00127 vector < double > ::const_iterator 00128 FunctionBase:: 00129 setParameters ( std::vector < double > :: const_iterator it ) 00130 { 00131 unsigned int size = m_parms.size(); 00132 for ( unsigned int i = 0; i < size; i++ ) { 00133 m_parms[i] = *it++; 00134 } 00135 00136 return it; 00137 } 00138 00139 vector < int > ::const_iterator 00140 FunctionBase:: 00141 setFixedFlags ( std::vector < int > :: const_iterator it ) 00142 { 00143 00144 unsigned int size = m_parms.size (); 00145 for ( unsigned int i = 0; i < size; i++ ) { 00146 m_fixed_flags[i] = *it++; 00147 } 00148 return it; 00149 } 00150 00151 bool 00152 FunctionBase:: 00153 hasDerivatives () const 00154 { 00155 return true; 00156 } 00157 00165 double FunctionBase::integrate ( double a, double b ) const 00166 { 00167 int n = 10; 00168 double h = (b - a)/n; 00169 double x = a; 00170 double sumt = operator()( a ) / 2; 00171 00172 for( int i = 1; i <= n - 1; i++ ) 00173 { 00174 x += h; 00175 sumt += operator()( x ); 00176 } 00177 00178 sumt = ( sumt + operator()( b ) / 2 ) * h; 00179 00180 return sumt; 00181 } 00182 00183 int FunctionBase::size () const 00184 { 00185 return m_parm_names.size (); 00186 } 00187 00188 bool FunctionBase::isComposite () const 00189 { 00190 return false; 00191 } 00192 00193 void FunctionBase::addToComposite ( FunctionBase * ) 00194 { 00195 } 00196 00197 void FunctionBase::removeFromComposite ( FunctionBase * ) 00198 { 00199 } 00200 00201 int FunctionBase::count() 00202 { 00203 return 0; 00204 } 00205 00206 double 00207 FunctionBase:: 00208 operator () ( const std::vector < double > & v ) const 00209 { 00210 assert ( v.size () == 1 ); 00211 00212 return this -> operator () ( v.front () ); 00213 } 00214 00215 double 00216 FunctionBase:: 00217 derivByParm ( int, double ) const 00218 { 00219 assert ( false ); 00220 return 0.; 00221 } 00222 00223 void 00224 FunctionBase:: 00225 initialize () 00226 { 00227 assert ( false ); 00228 } 00229 00230 double 00231 FunctionBase:: 00232 operator () ( double ) const 00233 { 00234 assert ( false ); 00235 return 0.; 00236 } 00237 00238 unsigned int 00239 FunctionBase:: 00240 dimensions () const 00241 { 00242 return 1; 00243 } 00244 00245 } // namespace hippodraw 00246