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