ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2nv1.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  */
00011 #include <df1b2fun.h>
00012 #include "admb_messages.h"
00013 
00017 df1b2_init_bounded_number_vector::df1b2_init_bounded_number_vector():
00018   v(NULL),
00019   index_min(1),
00020   index_max(0),
00021   it(NULL)
00022 {
00023 }
00024 
00025 #if !defined(OPT_LIB)
00026 
00030 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator[](int i)
00031  {
00032    if (i < indexmin() || i > indexmax())
00033    {
00034      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00035      "df1b2_init_bounded_number_vector::operator [] (int i)",
00036      indexmin(), indexmax(), i);
00037    }
00038    return v[i];
00039  }
00040 
00045 df1b2_init_bounded_number& df1b2_init_bounded_number_vector::operator()(int i)
00046  {
00047    if (i < indexmin() || i > indexmax())
00048    {
00049      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00050      "df1b2_init_bounded_number_vector::operator () (int i)",
00051      indexmin(), indexmax(), i);
00052    }
00053    return v[i];
00054  }
00055 #endif
00056 
00061  df1b2_init_bounded_number_vector::~df1b2_init_bounded_number_vector()
00062  {
00063    deallocate();
00064  }
00065 
00070  void df1b2_init_bounded_number_vector::deallocate(void)
00071  {
00072    if(it)
00073    {
00074      delete it;
00075      it=NULL;
00076    }
00077    if (v)
00078    {
00079      v+=indexmin();
00080      delete [] v;
00081      v=NULL;
00082    }
00083  }
00084 
00089  void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00090    const double_index_type & bmin,const double_index_type & bmax,const char * s)
00091  {
00092    allocate(min1,max1,bmin,bmax,1,s);
00093  }
00094 
00099  void df1b2_init_bounded_number_vector::allocate(int min1,int max1,
00100    const double_index_type & bmin,const double_index_type & bmax,
00101    const index_type& phase_start,const char * s)
00102  {
00103    index_min=min1;
00104    index_max=max1;
00105    int size=indexmax()-indexmin()+1;
00106    if (size>0)
00107    {
00108      v = new df1b2_init_bounded_number[size];
00109      if (!v)
00110      {
00111         cerr << " error trying to allocate memory in "
00112           "df1b2_init_bounded_number_vector " << endl;
00113         exit(1);
00114      }
00115      v-=indexmin();
00116      for (int i=indexmin();i<=indexmax();i++)
00117      {
00118        //if (it) v[i].set_initial_value(ad_double((*it)[i]));
00119        adstring ss=s + adstring("[") + str(i) + adstring("]");
00120        v[i].allocate(ad_double(bmin[i]),ad_double(bmax[i]),
00121          ad_integer(phase_start[i]),(char*)(ss) );
00122      }
00123    }
00124    else
00125      v=NULL;
00126  }
00127 
00128 /*
00129 dvector df1b2_init_number_vector::get_scalefactor(void)
00130 {
00131   int mmin=indexmin();
00132   int mmax=indexmax();
00133   dvector s(mmin,mmax);
00134   for (int i=mmin;i<=mmax;i++)
00135   {
00136     s(i)=(*this)(i).get_scalefactor();
00137   }
00138   return s;
00139 }
00140 void df1b2_init_number_vector::set_scalefactor(const dvector& s)
00141 {
00142   int mmin=indexmin();
00143   int mmax=indexmax();
00144   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00145   {
00146     cerr << "non matching vector bounds in"
00147      " init_number_vector::set_scalefactor" << endl;
00148     ad_exit(1);
00149   }
00150 
00151   for (int i=mmin;i<=mmax;i++)
00152   {
00153     (*this)(i).set_scalefactor(s(i));
00154   }
00155 }
00156 
00157 void df1b2_init_number_vector::set_scalefactor(double s)
00158 {
00159   int mmin=indexmin();
00160   int mmax=indexmax();
00161   for (int i=mmin;i<=mmax;i++)
00162   {
00163     (*this)(i).set_scalefactor(s);
00164   }
00165 }
00166 
00167 dvector df1b2_init_bounded_number_vector::get_scalefactor(void)
00168 {
00169   int mmin=indexmin();
00170   int mmax=indexmax();
00171   dvector s(mmin,mmax);
00172   for (int i=mmin;i<=mmax;i++)
00173   {
00174     s(i)=(*this)(i).get_scalefactor();
00175   }
00176   return s;
00177 }
00178 void df1b2_init_bounded_number_vector::set_scalefactor(const dvector& s)
00179 {
00180   int mmin=indexmin();
00181   int mmax=indexmax();
00182   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00183   {
00184     cerr << "non matching vector bounds in"
00185      " init_bounded_number_vector::set_scalefactor" << endl;
00186     ad_exit(1);
00187   }
00188 
00189   for (int i=mmin;i<=mmax;i++)
00190   {
00191     (*this)(i).set_scalefactor(s(i));
00192   }
00193 }
00194 
00195 void df1b2_init_bounded_number_vector::set_scalefactor(double s)
00196 {
00197   int mmin=indexmin();
00198   int mmax=indexmax();
00199   for (int i=mmin;i<=mmax;i++)
00200   {
00201     (*this)(i).set_scalefactor(s);
00202   }
00203 }
00204 
00205 void df1b2_init_bounded_number_vector::set_initial_value(
00206   const double_index_type& _it)
00207  {
00208     it=new double_index_type(_it);
00209  }
00210 */
00211 #if !defined(OPT_LIB)
00212 
00216  df1b2_init_number& df1b2_init_number_vector::operator [] (int i)
00217  {
00218    if (i < indexmin() || i > indexmax())
00219    {
00220      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00221      "df1b2_init_number_vector::operator [] (int i)",
00222      indexmin(), indexmax(), i);
00223    }
00224    return v[i];
00225  }
00226 
00231  df1b2_init_number& df1b2_init_number_vector::operator () (int i)
00232  {
00233    if (i < indexmin() || i > indexmax())
00234    {
00235      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00236      "df1b2_init_number_vector::operator () (int i)",
00237      indexmin(), indexmax(), i);
00238    }
00239    return v[i];
00240  }
00241 #endif
00242 
00246 df1b2_init_number_vector::df1b2_init_number_vector():
00247   v(NULL),
00248   index_min(0),
00249   index_max(-1),
00250   it(NULL)
00251 {
00252 }
00256 df1b2_init_number_vector::~df1b2_init_number_vector()
00257 {
00258   deallocate();
00259 }
00260 
00265  void df1b2_init_number_vector::deallocate(void)
00266  {
00267    if(it)
00268    {
00269      delete it;
00270      it=NULL;
00271    }
00272    if (v)
00273    {
00274      v+=indexmin();
00275      delete [] v;
00276      v=NULL;
00277    }
00278  }
00279 
00284  void df1b2_init_number_vector::allocate(int min1,int max1,
00285    const char * s)
00286  {
00287    allocate(min1,max1,1,s);
00288  }
00289 
00294  void df1b2_init_number_vector::allocate(int min1,int max1,
00295    const index_type& phase_start,const char * s)
00296  {
00297    index_min=min1;
00298    index_max=max1;
00299    int size=indexmax()-indexmin()+1;
00300    if (size>0)
00301    {
00302      v = new df1b2_init_number[size];
00303      if (!v)
00304      {
00305         cerr << " error trying to allocate memory in "
00306           "df1b2_init_number_vector " << endl;
00307         exit(1);
00308      }
00309      v-=indexmin();
00310      for (int i=indexmin();i<=indexmax();i++)
00311      {
00312        //if (it) v[i].set_initial_value(ad_double((*it)[i]));
00313        adstring ss=s + adstring("[") + str(i) + adstring("]");
00314        v[i].allocate(ad_integer(phase_start[i]),(char*)(ss) );
00315      }
00316    }
00317    else
00318      v=NULL;
00319  }