ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
model46.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: model46.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_matrix_vector::set_initial_value(
00010   const double_index_type& _it)
00011  {
00012     it=new double_index_type(_it);
00013  }
00014 
00015  param_init_bounded_matrix_vector::param_init_bounded_matrix_vector()
00016  {
00017    it=NULL;
00018  }
00019 
00020  void param_init_bounded_matrix_vector::allocate(int min1,int max1,
00021    const index_type& min, const index_type& max, const index_type& min2,
00022    const index_type& max2, const double_index_type& dmin,
00023    const double_index_type& dmax,
00024    const char * s)
00025  {
00026    allocate(min1,max1,min,max,min2,max2,dmin,dmax,1,s);
00027  }
00028 
00029  void param_init_bounded_matrix_vector::allocate(int min1,int max1,
00030    const index_type& min, const index_type& max, const index_type& min2,
00031    const index_type& max2, const double_index_type& dmin,
00032    const double_index_type& dmax, const index_type& phase_start,
00033    const char * s)
00034  {
00035    index_min=min1;
00036    index_max=max1;
00037    int size=indexmax()-indexmin()+1;
00038    if (size>0)
00039    {
00040      if (!(v=new param_init_bounded_matrix[size]))
00041      {
00042         cerr << " error trying to allocate memory in "
00043           "param_init_vector_vector " << endl;
00044         exit(1);
00045      }
00046      v-=indexmin();
00047      for (int i=indexmin();i<=indexmax();i++)
00048      {
00049        if (it) v[i].set_initial_value(ad_double((*it)[i]));
00050        adstring ss=s + adstring("[") + str(i) + adstring("]");
00051        v[i].allocate(
00052           min[i],
00053           max[i],
00054           min2[i],
00055           max2[i],
00056           dmin[i],
00057           dmax[i],
00058           phase_start[i],
00059           (char*)(ss) );
00060      }
00061    }
00062    else
00063      v=NULL;
00064  }
00065 
00066  void param_init_bounded_matrix::allocate(const ad_integer& imin,
00067    const ad_integer& imax, const ad_integer& imin2,
00068    const ad_integer& imax2, const ad_double& _bmin,
00069    const ad_double& _bmax, const ad_integer& phase_start,
00070    const char * s)
00071  {
00072    minb=_bmin;
00073    maxb=_bmax;
00074    named_dvar_matrix::allocate(imin,imax,imin2,imax2,s);
00075    if (!(!(*this)))
00076    {
00077      initial_params::allocate(phase_start);
00078      if (ad_comm::global_bparfile)
00079      {
00080        *(ad_comm::global_bparfile) >> dvar_matrix(*this);
00081      }
00082      else if (ad_comm::global_parfile)
00083      {
00084        *(ad_comm::global_parfile) >> dvar_matrix(*this);
00085      }
00086      else
00087      {
00088        if ((!initial_value_flag) || initial_value <=minb
00089             || initial_value >= maxb)
00090        {
00091          //cerr << "Initial value out of bounds -- using halfway value" << endl;
00092          initial_value=(minb+maxb)/2.;
00093        }
00094        dvar_matrix::operator=(initial_value);
00095      }
00096    }
00097    else
00098    {
00099      initial_params::allocate(-1);
00100    }
00101  }
00102 
00103    param_init_bounded_matrix_vector::~param_init_bounded_matrix_vector()
00104    {
00105      deallocate();
00106    }
00107 
00108    void param_init_bounded_matrix_vector::deallocate(void)
00109    {
00110      if(it)
00111      {
00112        delete it;
00113        it=NULL;
00114      }
00115      if (v)
00116      {
00117        v+=indexmin();
00118        delete [] v;
00119        v=NULL;
00120      }
00121    }