ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
model48.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: model48.cpp 1701 2014-02-28 01:22:35Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <admodel.h>
00008 
00009 void param_init_bounded_number_vector::set_initial_value(
00010   const double_index_type& _it)
00011  {
00012     it=new double_index_type(_it);
00013  }
00014 
00018 param_init_bounded_number_vector::param_init_bounded_number_vector():
00019   v(NULL), it(NULL)
00020 {
00021 }
00025 param_init_bounded_number_vector::~param_init_bounded_number_vector()
00026 {
00027   deallocate();
00028 }
00032 void param_init_bounded_number_vector::deallocate(void)
00033 {
00034   if(it)
00035   {
00036     delete it;
00037     it = NULL;
00038   }
00039   if (v)
00040   {
00041     v += indexmin();
00042     delete [] v;
00043     v = NULL;
00044   }
00045 }
00050 void param_init_bounded_number_vector::allocate(const data_matrix &m,
00051   const char *s)
00052 {
00053   int min1 = m.rowmin();
00054   int max1 = m.rowmax();
00055   double_index_type bmin = column(m,1);
00056   double_index_type bmax = column(m,2);
00057   index_type phz1 = ivector(column(m,3));
00058   allocate(min1,max1,bmin,bmax,phz1,s);
00059 }
00060 
00061  void param_init_bounded_number_vector::allocate(int min1,int max1,
00062    const double_index_type & bmin,const double_index_type & bmax,const char * s)
00063  {
00064    allocate(min1,max1,bmin,bmax,1,s);
00065  }
00066 
00067  void param_init_bounded_number_vector::allocate(int min1,int max1,
00068    const double_index_type & bmin,const double_index_type & bmax,
00069    const index_type& phase_start,const char * s)
00070  {
00071    index_min=min1;
00072    index_max=max1;
00073    int size=indexmax()-indexmin()+1;
00074    if (size>0)
00075    {
00076      if (!(v=new param_init_bounded_number[size]))
00077      {
00078         cerr << " error trying to allocate memory in "
00079           "param_init_bounded_number_vector " << endl;
00080         exit(1);
00081      }
00082      v-=indexmin();
00083      for (int i=indexmin();i<=indexmax();i++)
00084      {
00085        if (it) v[i].set_initial_value(ad_double((*it)[i]));
00086        adstring ss=s + adstring("[") + str(i) + adstring("]");
00087        v[i].allocate(ad_double(bmin[i]),ad_double(bmax[i]),
00088          ad_integer(phase_start[i]),(char*)(ss) );
00089      }
00090    }
00091    else
00092      v=NULL;
00093  }
00094 
00095 dvector param_init_number_vector::get_scalefactor(void)
00096 {
00097   int mmin=indexmin();
00098   int mmax=indexmax();
00099   dvector s(mmin,mmax);
00100   for (int i=mmin;i<=mmax;i++)
00101   {
00102     s(i)=(*this)(i).get_scalefactor();
00103   }
00104   return s;
00105 }
00106 void param_init_number_vector::set_scalefactor(const dvector& s)
00107 {
00108   int mmin=indexmin();
00109   int mmax=indexmax();
00110   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00111   {
00112     cerr << "non matching vector bounds in"
00113      " init_number_vector::set_scalefactor" << endl;
00114     ad_exit(1);
00115   }
00116 
00117   for (int i=mmin;i<=mmax;i++)
00118   {
00119     (*this)(i).set_scalefactor(s(i));
00120   }
00121 }
00122 
00123 void param_init_number_vector::set_scalefactor(double s)
00124 {
00125   int mmin=indexmin();
00126   int mmax=indexmax();
00127   for (int i=mmin;i<=mmax;i++)
00128   {
00129     (*this)(i).set_scalefactor(s);
00130   }
00131 }
00132 
00133 
00134 
00135 dvector param_init_vector_vector::get_scalefactor(void)
00136 {
00137   int mmin=indexmin();
00138   int mmax=indexmax();
00139   dvector s(mmin,mmax);
00140   for (int i=mmin;i<=mmax;i++)
00141   {
00142     s(i)=(*this)(i).get_scalefactor();
00143   }
00144   return s;
00145 }
00146 void param_init_vector_vector::set_scalefactor(const dvector& s)
00147 {
00148   int mmin=indexmin();
00149   int mmax=indexmax();
00150   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00151   {
00152     cerr << "non matching vector bounds in"
00153      " init_vector_vector::set_scalefactor" << endl;
00154     ad_exit(1);
00155   }
00156 
00157   for (int i=mmin;i<=mmax;i++)
00158   {
00159     (*this)(i).set_scalefactor(s(i));
00160   }
00161 }
00162 
00163 void param_init_vector_vector::set_scalefactor(double s)
00164 {
00165   int mmin=indexmin();
00166   int mmax=indexmax();
00167   for (int i=mmin;i<=mmax;i++)
00168   {
00169     (*this)(i).set_scalefactor(s);
00170   }
00171 }
00172 
00173 
00174 
00175 
00176 dvector param_init_matrix_vector::get_scalefactor(void)
00177 {
00178   int mmin=indexmin();
00179   int mmax=indexmax();
00180   dvector s(mmin,mmax);
00181   for (int i=mmin;i<=mmax;i++)
00182   {
00183     s(i)=(*this)(i).get_scalefactor();
00184   }
00185   return s;
00186 }
00187 void param_init_matrix_vector::set_scalefactor(const dvector& s)
00188 {
00189   int mmin=indexmin();
00190   int mmax=indexmax();
00191   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00192   {
00193     cerr << "non matching vector bounds in"
00194      " init_matrix_vector::set_scalefactor" << endl;
00195     ad_exit(1);
00196   }
00197 
00198   for (int i=mmin;i<=mmax;i++)
00199   {
00200     (*this)(i).set_scalefactor(s(i));
00201   }
00202 }
00203 
00204 void param_init_matrix_vector::set_scalefactor(double s)
00205 {
00206   int mmin=indexmin();
00207   int mmax=indexmax();
00208   for (int i=mmin;i<=mmax;i++)
00209   {
00210     (*this)(i).set_scalefactor(s);
00211   }
00212 }
00213 
00214 
00215 
00216 dvector param_init_bounded_number_vector::get_scalefactor(void)
00217 {
00218   int mmin=indexmin();
00219   int mmax=indexmax();
00220   dvector s(mmin,mmax);
00221   for (int i=mmin;i<=mmax;i++)
00222   {
00223     s(i)=(*this)(i).get_scalefactor();
00224   }
00225   return s;
00226 }
00227 void param_init_bounded_number_vector::set_scalefactor(const dvector& s)
00228 {
00229   int mmin=indexmin();
00230   int mmax=indexmax();
00231   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00232   {
00233     cerr << "non matching vector bounds in"
00234      " init_bounded_number_vector::set_scalefactor" << endl;
00235     ad_exit(1);
00236   }
00237 
00238   for (int i=mmin;i<=mmax;i++)
00239   {
00240     (*this)(i).set_scalefactor(s(i));
00241   }
00242 }
00243 
00244 void param_init_bounded_number_vector::set_scalefactor(double s)
00245 {
00246   int mmin=indexmin();
00247   int mmax=indexmax();
00248   for (int i=mmin;i<=mmax;i++)
00249   {
00250     (*this)(i).set_scalefactor(s);
00251   }
00252 }
00253 
00254 
00255 
00256 dvector param_init_bounded_vector_vector::get_scalefactor(void)
00257 {
00258   int mmin=indexmin();
00259   int mmax=indexmax();
00260   dvector s(mmin,mmax);
00261   for (int i=mmin;i<=mmax;i++)
00262   {
00263     s(i)=(*this)(i).get_scalefactor();
00264   }
00265   return s;
00266 }
00267 void param_init_bounded_vector_vector::set_scalefactor(const dvector& s)
00268 {
00269   int mmin=indexmin();
00270   int mmax=indexmax();
00271   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00272   {
00273     cerr << "non matching vector bounds in"
00274      " init_bounded_vector_vector::set_scalefactor" << endl;
00275     ad_exit(1);
00276   }
00277 
00278   for (int i=mmin;i<=mmax;i++)
00279   {
00280     (*this)(i).set_scalefactor(s(i));
00281   }
00282 }
00283 
00284 void param_init_bounded_vector_vector::set_scalefactor(double s)
00285 {
00286   int mmin=indexmin();
00287   int mmax=indexmax();
00288   for (int i=mmin;i<=mmax;i++)
00289   {
00290     (*this)(i).set_scalefactor(s);
00291   }
00292 }
00293 
00294 
00295 
00296 
00297 dvector param_init_bounded_matrix_vector::get_scalefactor(void)
00298 {
00299   int mmin=indexmin();
00300   int mmax=indexmax();
00301   dvector s(mmin,mmax);
00302   for (int i=mmin;i<=mmax;i++)
00303   {
00304     s(i)=(*this)(i).get_scalefactor();
00305   }
00306   return s;
00307 }
00308 void param_init_bounded_matrix_vector::set_scalefactor(const dvector& s)
00309 {
00310   int mmin=indexmin();
00311   int mmax=indexmax();
00312   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00313   {
00314     cerr << "non matching vector bounds in"
00315      " init_bounded_matrix_vector::set_scalefactor" << endl;
00316     ad_exit(1);
00317   }
00318 
00319   for (int i=mmin;i<=mmax;i++)
00320   {
00321     (*this)(i).set_scalefactor(s(i));
00322   }
00323 }
00324 
00325 void param_init_bounded_matrix_vector::set_scalefactor(double s)
00326 {
00327   int mmin=indexmin();
00328   int mmax=indexmax();
00329   for (int i=mmin;i<=mmax;i++)
00330   {
00331     (*this)(i).set_scalefactor(s);
00332   }
00333 }