ADMB Documentation  11.1.2192
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2nv1.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2nv1.cpp 1967 2014-04-30 23:36:04Z 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      if (!(v=new df1b2_init_bounded_number[size]))
00106      {
00107         cerr << " error trying to allocate memory in "
00108           "df1b2_init_bounded_number_vector " << endl;
00109         exit(1);
00110      }
00111      v-=indexmin();
00112      for (int i=indexmin();i<=indexmax();i++)
00113      {
00114        //if (it) v[i].set_initial_value(ad_double((*it)[i]));
00115        adstring ss=s + adstring("[") + str(i) + adstring("]");
00116        v[i].allocate(ad_double(bmin[i]),ad_double(bmax[i]),
00117          ad_integer(phase_start[i]),(char*)(ss) );
00118      }
00119    }
00120    else
00121      v=NULL;
00122  }
00123 
00124 /*
00125 dvector df1b2_init_number_vector::get_scalefactor(void)
00126 {
00127   int mmin=indexmin();
00128   int mmax=indexmax();
00129   dvector s(mmin,mmax);
00130   for (int i=mmin;i<=mmax;i++)
00131   {
00132     s(i)=(*this)(i).get_scalefactor();
00133   }
00134   return s;
00135 }
00136 void df1b2_init_number_vector::set_scalefactor(const dvector& s)
00137 {
00138   int mmin=indexmin();
00139   int mmax=indexmax();
00140   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00141   {
00142     cerr << "non matching vector bounds in"
00143      " init_number_vector::set_scalefactor" << endl;
00144     ad_exit(1);
00145   }
00146 
00147   for (int i=mmin;i<=mmax;i++)
00148   {
00149     (*this)(i).set_scalefactor(s(i));
00150   }
00151 }
00152 
00153 void df1b2_init_number_vector::set_scalefactor(double s)
00154 {
00155   int mmin=indexmin();
00156   int mmax=indexmax();
00157   for (int i=mmin;i<=mmax;i++)
00158   {
00159     (*this)(i).set_scalefactor(s);
00160   }
00161 }
00162 
00163 dvector df1b2_init_bounded_number_vector::get_scalefactor(void)
00164 {
00165   int mmin=indexmin();
00166   int mmax=indexmax();
00167   dvector s(mmin,mmax);
00168   for (int i=mmin;i<=mmax;i++)
00169   {
00170     s(i)=(*this)(i).get_scalefactor();
00171   }
00172   return s;
00173 }
00174 void df1b2_init_bounded_number_vector::set_scalefactor(const dvector& s)
00175 {
00176   int mmin=indexmin();
00177   int mmax=indexmax();
00178   if (s.indexmin()!=mmin || s.indexmax() != mmax)
00179   {
00180     cerr << "non matching vector bounds in"
00181      " init_bounded_number_vector::set_scalefactor" << endl;
00182     ad_exit(1);
00183   }
00184 
00185   for (int i=mmin;i<=mmax;i++)
00186   {
00187     (*this)(i).set_scalefactor(s(i));
00188   }
00189 }
00190 
00191 void df1b2_init_bounded_number_vector::set_scalefactor(double s)
00192 {
00193   int mmin=indexmin();
00194   int mmax=indexmax();
00195   for (int i=mmin;i<=mmax;i++)
00196   {
00197     (*this)(i).set_scalefactor(s);
00198   }
00199 }
00200 
00201 void df1b2_init_bounded_number_vector::set_initial_value(
00202   const double_index_type& _it)
00203  {
00204     it=new double_index_type(_it);
00205  }
00206 */
00207 #if !defined(OPT_LIB)
00208 
00212  df1b2_init_number& df1b2_init_number_vector::operator [] (int i)
00213  {
00214    if (i < indexmin() || i > indexmax())
00215    {
00216      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00217      "df1b2_init_number_vector::operator [] (int i)",
00218      indexmin(), indexmax(), i);
00219    }
00220    return v[i];
00221  }
00222 
00227  df1b2_init_number& df1b2_init_number_vector::operator () (int i)
00228  {
00229    if (i < indexmin() || i > indexmax())
00230    {
00231      ADMB_ARRAY_BOUNDS_ERROR("Index out of range",
00232      "df1b2_init_number_vector::operator () (int i)",
00233      indexmin(), indexmax(), i);
00234    }
00235    return v[i];
00236  }
00237 #endif
00238 
00243  df1b2_init_number_vector::df1b2_init_number_vector()
00244  {
00245    it=NULL;
00246  }
00247 
00252  df1b2_init_number_vector::~df1b2_init_number_vector()
00253  {
00254    deallocate();
00255  }
00256 
00261  void df1b2_init_number_vector::deallocate(void)
00262  {
00263    if(it)
00264    {
00265      delete it;
00266      it=NULL;
00267    }
00268    if (v)
00269    {
00270      v+=indexmin();
00271      delete [] v;
00272      v=NULL;
00273    }
00274  }
00275 
00280  void df1b2_init_number_vector::allocate(int min1,int max1,
00281    const char * s)
00282  {
00283    allocate(min1,max1,1,s);
00284  }
00285 
00290  void df1b2_init_number_vector::allocate(int min1,int max1,
00291    const index_type& phase_start,const char * s)
00292  {
00293    index_min=min1;
00294    index_max=max1;
00295    int size=indexmax()-indexmin()+1;
00296    if (size>0)
00297    {
00298      if (!(v=new df1b2_init_number[size]))
00299      {
00300         cerr << " error trying to allocate memory in "
00301           "df1b2_init_number_vector " << endl;
00302         exit(1);
00303      }
00304      v-=indexmin();
00305      for (int i=indexmin();i<=indexmax();i++)
00306      {
00307        //if (it) v[i].set_initial_value(ad_double((*it)[i]));
00308        adstring ss=s + adstring("[") + str(i) + adstring("]");
00309        v[i].allocate(ad_integer(phase_start[i]),(char*)(ss) );
00310      }
00311    }
00312    else
00313      v=NULL;
00314  }