ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
model47.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
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_number_vector::set_initial_value(const double_index_type& _it)
00010  {
00011     it=new double_index_type(_it);
00012  }
00016 param_init_number_vector::param_init_number_vector():
00017   v(NULL),
00018   index_min(0),
00019   index_max(0),
00020   it(NULL)
00021 {
00022 }
00026 param_init_number_vector::~param_init_number_vector()
00027 {
00028   deallocate();
00029 }
00033 void param_init_number_vector::deallocate(void)
00034 {
00035   if(it)
00036   {
00037     delete it;
00038     it = NULL;
00039   }
00040   if (v)
00041   {
00042     v+=indexmin();
00043     delete [] v;
00044     v = NULL;
00045   }
00046 }
00047 
00048 void param_init_number_vector::allocate(
00049   int min1,
00050   int max1,
00051   const char* s)
00052 {
00053   allocate(min1,max1,1,s);
00054 }
00055 
00056 void param_init_number_vector::allocate(
00057   int min1,
00058   int max1,
00059   const index_type& phase_start,
00060   const char* s)
00061 {
00062   int size = max1 - min1 + 1;
00063   if (size > 0)
00064   {
00065     v = new param_init_number[size];
00066     if (!v)
00067     {
00068         cerr << " error trying to allocate memory in "
00069           "param_init_vector_vector " << endl;
00070         exit(1);
00071     }
00072 
00073     index_min=min1;
00074     index_max=max1;
00075     v-=indexmin();
00076     for (int i=indexmin();i<=indexmax();i++)
00077     {
00078        if (it) v[i].set_initial_value(ad_double((*it)[i]));
00079        adstring ss=s + adstring("[") + str(i) + adstring("]");
00080        v[i].allocate(ad_integer(phase_start[i]),(char*)(ss) );
00081     }
00082   }
00083 }
00084 
00085   dvector value(const param_init_number_vector& _t)
00086   {
00087     ADUNCONST(param_init_number_vector, t);
00088     const int min = t.indexmin();
00089     const int max = t.indexmax();
00090     dvector vt(min, max);
00091     for (int i = min; i <= max; i++)
00092     {
00093        vt(i) = value(t(i));
00094     }
00095     return vt;
00096   }
00097 
00098   dvector value(const param_init_bounded_number_vector& _t)
00099   {
00100     ADUNCONST(param_init_bounded_number_vector, t);
00101     const int min = t.indexmin();
00102     const int max = t.indexmax();
00103     dvector vt(min, max);
00104     for (int i = min; i <= max; i++)
00105     {
00106        vt(i) = value(t(i));
00107     }
00108     return vt;
00109   }