ADMB Documentation  11.1.1890
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2nv1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2nv1.cpp 1834 2014-04-04 00:31:32Z 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 
00018  df1b2_init_bounded_number_vector::df1b2_init_bounded_number_vector()
00019  {
00020    it=NULL;
00021  }
00022 
00023 #if !defined(OPT_LIB)
00024 
00028 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator[](int i)
00029  {
00030    if (i < indexmin() || i > indexmax())
00031    {
00032      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00033      "df1b2_init_bounded_number_vector::operator [] (int i)",
00034      indexmin(), indexmax(), i);
00035    }
00036    return v[i];
00037  }
00038 
00043 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator()(int i)
00044  {
00045    if (i < indexmin() || i > indexmax())
00046    {
00047      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00048      "df1b2_init_bounded_number_vector::operator () (int i)",
00049      indexmin(), indexmax(), i);
00050    }
00051    return v[i];
00052  }
00053 #endif
00054 
00059  df1b2_init_bounded_number_vector::~df1b2_init_bounded_number_vector()
00060  {
00061    deallocate();
00062  }
00063 
00068  void df1b2_init_bounded_number_vector::deallocate(void)
00069  {
00070    if(it)
00071    {
00072      delete it;
00073      it=NULL;
00074    }
00075    if (v)
00076    {
00077      v+=indexmin();
00078      delete [] v;
00079      v=NULL;
00080    }
00081  }
00082 
00087  void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00088    const double_index_type & bmin,const double_index_type & bmax,const char * s)
00089  {
00090    allocate(min1,max1,bmin,bmax,1,s);
00091  }
00092 
00097  void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00098    const double_index_type & bmin,const double_index_type & bmax,
00099    const index_type& phase_start,const char * s)
00100  {
00101    index_min=min1;
00102    index_max=max1;
00103    int size=indexmax()-indexmin()+1;
00104    if (size>0)
00105    {
00106      if (!(v=new df1b2_init_bounded_number[size]))
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      if (!(v=new df1b2_init_number[size]))
00300      {
00301         cerr << " error trying to allocate memory in "
00302           "df1b2_init_number_vector " << endl;
00303         exit(1);
00304      }
00305      v-=indexmin();
00306      for (int i=indexmin();i<=indexmax();i++)
00307      {
00308        //if (it) v[i].set_initial_value(ad_double((*it)[i]));
00309        adstring ss=s + adstring("[") + str(i) + adstring("]");
00310        v[i].allocate(ad_integer(phase_start[i]),(char*)(ss) );
00311      }
00312    }
00313    else
00314      v=NULL;
00315  }