ADMB Documentation  11.1.2490
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2nv1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2nv1.cpp 2482 2014-10-13 23:43:46Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <df1b2fun.h>
00012 #include "admb_messages.h"
00013 
00017 df1b2_init_bounded_number_vector::df1b2_init_bounded_number_vector()
00018 {
00019   it = NULL;
00020 }
00021 
00022 #if !defined(OPT_LIB)
00023 
00027 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator[](int i)
00028  {
00029    if (i < indexmin() || i > indexmax())
00030    {
00031      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00032      "df1b2_init_bounded_number_vector::operator [] (int i)",
00033      indexmin(), indexmax(), i);
00034    }
00035    return v[i];
00036  }
00037 
00042 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator()(int i)
00043  {
00044    if (i < indexmin() || i > indexmax())
00045    {
00046      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00047      "df1b2_init_bounded_number_vector::operator () (int i)",
00048      indexmin(), indexmax(), i);
00049    }
00050    return v[i];
00051  }
00052 #endif
00053 
00058  df1b2_init_bounded_number_vector::~df1b2_init_bounded_number_vector()
00059  {
00060    deallocate();
00061  }
00062 
00067  void df1b2_init_bounded_number_vector::deallocate(void)
00068  {
00069    if(it)
00070    {
00071      delete it;
00072      it=NULL;
00073    }
00074    if (v)
00075    {
00076      v+=indexmin();
00077      delete [] v;
00078      v=NULL;
00079    }
00080  }
00081 
00086  void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00087    const double_index_type & bmin,const double_index_type & bmax,const char * s)
00088  {
00089    allocate(min1,max1,bmin,bmax,1,s);
00090  }
00091 
00096  void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00097    const double_index_type & bmin,const double_index_type & bmax,
00098    const index_type& phase_start,const char * s)
00099  {
00100    index_min=min1;
00101    index_max=max1;
00102    int size=indexmax()-indexmin()+1;
00103    if (size>0)
00104    {
00105      v = new df1b2_init_bounded_number[size];
00106      if (!v)
00107      {
00108         cerr << " error trying to allocate memory in "
00109           "df1b2_init_bounded_number_vector " << endl;
00110         exit(1);
00111      }
00112      v-=indexmin();
00113      for (int i=indexmin();i<=indexmax();i++)
00114      {
00115        //if (it) v[i].set_initial_value(ad_double((*it)[i]));
00116        adstring ss=s + adstring("[") + str(i) + adstring("]");
00117        v[i].allocate(ad_double(bmin[i]),ad_double(bmax[i]),
00118          ad_integer(phase_start[i]),(char*)(ss) );
00119      }
00120    }
00121    else
00122      v=NULL;
00123  }
00124 
00125 /*
00126 dvector df1b2_init_number_vector::get_scalefactor(void)
00127 {
00128   int mmin=indexmin();
00129   int mmax=indexmax();
00130   dvector s(mmin,mmax);
00131   for (int i=mmin;i<=mmax;i++)
00132   {
00133     s(i)=(*this)(i).get_scalefactor();
00134   }
00135   return s;
00136 }
00137 void df1b2_init_number_vector::set_scalefactor(const dvector& s)
00138 {
00139   int mmin=indexmin();
00140   int mmax=indexmax();
00141   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00142   {
00143     cerr << "non matching vector bounds in"
00144      " init_number_vector::set_scalefactor" << endl;
00145     ad_exit(1);
00146   }
00147 
00148   for (int i=mmin;i<=mmax;i++)
00149   {
00150     (*this)(i).set_scalefactor(s(i));
00151   }
00152 }
00153 
00154 void df1b2_init_number_vector::set_scalefactor(double s)
00155 {
00156   int mmin=indexmin();
00157   int mmax=indexmax();
00158   for (int i=mmin;i<=mmax;i++)
00159   {
00160     (*this)(i).set_scalefactor(s);
00161   }
00162 }
00163 
00164 dvector df1b2_init_bounded_number_vector::get_scalefactor(void)
00165 {
00166   int mmin=indexmin();
00167   int mmax=indexmax();
00168   dvector s(mmin,mmax);
00169   for (int i=mmin;i<=mmax;i++)
00170   {
00171     s(i)=(*this)(i).get_scalefactor();
00172   }
00173   return s;
00174 }
00175 void df1b2_init_bounded_number_vector::set_scalefactor(const dvector& s)
00176 {
00177   int mmin=indexmin();
00178   int mmax=indexmax();
00179   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00180   {
00181     cerr << "non matching vector bounds in"
00182      " init_bounded_number_vector::set_scalefactor" << endl;
00183     ad_exit(1);
00184   }
00185 
00186   for (int i=mmin;i<=mmax;i++)
00187   {
00188     (*this)(i).set_scalefactor(s(i));
00189   }
00190 }
00191 
00192 void df1b2_init_bounded_number_vector::set_scalefactor(double s)
00193 {
00194   int mmin=indexmin();
00195   int mmax=indexmax();
00196   for (int i=mmin;i<=mmax;i++)
00197   {
00198     (*this)(i).set_scalefactor(s);
00199   }
00200 }
00201 
00202 void df1b2_init_bounded_number_vector::set_initial_value(
00203   const double_index_type& _it)
00204  {
00205     it=new double_index_type(_it);
00206  }
00207 */
00208 #if !defined(OPT_LIB)
00209 
00213  df1b2_init_number& df1b2_init_number_vector::operator [] (int i)
00214  {
00215    if (i < indexmin() || i > indexmax())
00216    {
00217      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00218      "df1b2_init_number_vector::operator [] (int i)",
00219      indexmin(), indexmax(), i);
00220    }
00221    return v[i];
00222  }
00223 
00228  df1b2_init_number& df1b2_init_number_vector::operator () (int i)
00229  {
00230    if (i < indexmin() || i > indexmax())
00231    {
00232      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00233      "df1b2_init_number_vector::operator () (int i)",
00234      indexmin(), indexmax(), i);
00235    }
00236    return v[i];
00237  }
00238 #endif
00239 
00244  df1b2_init_number_vector::df1b2_init_number_vector()
00245  {
00246    it=NULL;
00247  }
00248 
00253  df1b2_init_number_vector::~df1b2_init_number_vector()
00254  {
00255    deallocate();
00256  }
00257 
00262  void df1b2_init_number_vector::deallocate(void)
00263  {
00264    if(it)
00265    {
00266      delete it;
00267      it=NULL;
00268    }
00269    if (v)
00270    {
00271      v+=indexmin();
00272      delete [] v;
00273      v=NULL;
00274    }
00275  }
00276 
00281  void df1b2_init_number_vector::allocate(int min1,int max1,
00282    const char * s)
00283  {
00284    allocate(min1,max1,1,s);
00285  }
00286 
00291  void df1b2_init_number_vector::allocate(int min1,int max1,
00292    const index_type& phase_start,const char * s)
00293  {
00294    index_min=min1;
00295    index_max=max1;
00296    int size=indexmax()-indexmin()+1;
00297    if (size>0)
00298    {
00299      v = new df1b2_init_number[size];
00300      if (!v)
00301      {
00302         cerr << " error trying to allocate memory in "
00303           "df1b2_init_number_vector " << endl;
00304         exit(1);
00305      }
00306      v-=indexmin();
00307      for (int i=indexmin();i<=indexmax();i++)
00308      {
00309        //if (it) v[i].set_initial_value(ad_double((*it)[i]));
00310        adstring ss=s + adstring("[") + str(i) + adstring("]");
00311        v[i].allocate(ad_integer(phase_start[i]),(char*)(ss) );
00312      }
00313    }
00314    else
00315      v=NULL;
00316  }