ADMB Documentation  11.1x.2730
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2fn2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2fn2.cpp 2637 2014-11-13 05:58:08Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <cstring>
00012 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
00013 #include <inttypes.h>
00014 #endif
00015 #include <df1b2fun.h>
00016 #include "admb_messages.h"
00017 #ifndef OPT_LIB
00018   #include <cassert>
00019   #include <climits>
00020 #endif
00021 
00022 do_naught_kludge df1b2_init_number::do_naught_kludge_a;
00023 
00024 //#define  ADDEBUG_PRINT
00025 #if defined(ADDEBUG_PRINT)
00026     int addebug_count=0;
00027 #endif
00028 
00029 //df1b2_gradlist * f1b2gradlist = NULL;
00030 int max_num_init_df1b2variable=500;
00031 
00032 char AD_allocation_error_message[]="Error tryng to allocate memory for ";
00033 
00034 unsigned int get_f1b2buffer_size(const char* s);
00035 
00036 #if defined(CHECK_COUNT)
00037   int df1b2_gradlist::ncount_check=-1;
00038 #endif
00039 
00040 adpool * df1b2variable::pool= new adpool();
00041 
00046 df1b2function1::df1b2function1(double (*_f)(double),double (*_df)(double),
00047     double (*_d2f)(double),double (*_d3f)(double), const adstring& _s )
00048 {
00049   f=_f;
00050   df=_df;
00051   d2f=_d2f;
00052   d3f=_d3f;
00053   funname=_s;
00054 }
00055 
00060 ad_dstar::~ad_dstar(void)
00061 {
00062   if (p) delete []p;
00063   p = 0;
00064 }
00065 
00070 unsigned int df1b2variable::get_blocksize()
00071 {
00072   return get_blocksize(nvar);
00073 }
00074 
00079 unsigned int df1b2variable::get_blocksize(const unsigned int n)
00080 {
00081   return 6*n+5;
00082   //return 6*n+4;
00083 }
00084 
00089 void df1b2variable::set_blocksize()
00090 {
00091   blocksize=get_blocksize();
00092   pool->set_size(sizeof(double)*blocksize);
00093   pool->nvar=df1b2variable::get_nvar();
00094 }
00095 
00096 //init_df1b2variable * init_df1b2variable::list[max_num_init_df1b2variable];
00097 init_df1b2variable ** init_df1b2variable::list=0;
00098 unsigned int df1b2variable::nvar = 0;
00099 int df1b2variable::minder=0;
00100 int df1b2variable::maxder=0;
00101 unsigned int df1b2variable::blocksize=0;
00102 int init_df1b2variable::num_variables=0;
00103 int df1b2_gradlist::no_derivatives=0;
00104 int df1b2variable::passnumber=0;
00105 unsigned int ad_dstar::n=0;
00106 
00107 void ad_read_pass2(void);
00108 // should inline this
00109 #if !defined(__BORLANDC__)
00110 int adptr_diff(void* x, void* y)
00111 {
00112   intptr_t a = (intptr_t)x;
00113   intptr_t b = (intptr_t)y;
00114   ptrdiff_t diff = a - b;
00115 #ifndef OPT_LIB
00116   assert(diff <= INT_MAX);
00117 #endif
00118   return (int)diff;
00119 }
00120 #endif
00121 
00122 #if defined(__CHECK_MEMORY__)
00123   int sanity_flag=0;
00124 #endif
00125 
00129 void df1b2variable::initialize(void)
00130 {
00131 #if defined(__CHECK_MEMORY__)
00132   if (sanity_flag)
00133   {
00134     df1b2variable::pool->sanity_check();
00135   }
00136 #endif
00137   unsigned int nvar=((twointsandptr*)ptr)->ptr->nvar;
00138   initialize(nvar);
00139 }
00140 
00146 void df1b2variable::initialize(const unsigned int n)
00147 {
00148   //int bs=get_blocksize(n);
00149   //for (double * tmp=ptr+2;tmp<ptr+bs-1;*tmp++=0);
00150   size_t nbytes = (get_blocksize(n) - 2) * sizeof(double);
00151   memset(ptr + 2, 0, nbytes);
00152 }
00153 
00158   void init_df1b2variable::set_u_dot(void)
00159   {
00160     //int j;
00161     double uvalue=*get_u();
00162     initialize();
00163     int nder=maxder-minder+1;
00164     for (int i=0;i<nder;i++)
00165     {
00166       u_dot[i]=0.0;
00167     }
00168     if (ind_index>=minder && ind_index<=maxder)
00169     {
00170       int offset= ind_index-minder;
00171       u_dot[offset]=1.0;
00172     }
00173     *get_u()=uvalue;
00174   }
00175 
00180   void init_df1b2variable::operator = (double d)
00181   {
00182     //int nc=*ncopies;
00183     initialize();
00184     //*ncopies=nc;
00185     if (ind_index>=minder && ind_index<=maxder)
00186     {
00187       int offset= ind_index-minder;
00188       u_dot[offset]=1.0;
00189     }
00190     get_ind_index()=-1;
00191     *u=d;
00192   }
00193 
00198   df1b2variable::df1b2variable(const df1b2variable& v)
00199   {
00200 #if defined(__CHECK_MEMORY__)
00201     if (pchecker)
00202     {
00203       if (v.ptr == pchecker)
00204       {
00205         cout << " copy constructor called  " << endl;
00206       }
00207     }
00208 #endif
00209     if (v.ptr)
00210     {
00211       ptr=v.ptr;
00212       ncopies=v.ncopies;
00213       (*ncopies)++;
00214       u=v.u;
00215       u_dot=v.u_dot;
00216       u_bar=v.u_bar;
00217       u_dot_bar=v.u_dot_bar;
00218       u_tilde=v.u_tilde;
00219       u_dot_tilde=v.u_dot_tilde;
00220       u_bar_tilde=v.u_bar_tilde;
00221       u_dot_bar_tilde=v.u_dot_bar_tilde;
00222     }
00223     else
00224     {
00225       ptr=NULL;
00226       ncopies=NULL;
00227       u=NULL;
00228       u_dot=NULL;
00229       u_bar=NULL;
00230       u_dot_bar=NULL;
00231       u_tilde=NULL;
00232       u_dot_tilde=NULL;
00233       u_bar_tilde=NULL;
00234       u_dot_bar_tilde=NULL;
00235     }
00236   }
00237 
00238   adkludge1 * adkludgexxx;
00239 
00240 typedef init_df1b2variable * PINIT_DF1B2VARIABLE;
00241 
00246   init_df1b2variable::init_df1b2variable(double v) : df1b2variable(adkludgexxx)
00247   {
00248     ++num_variables;
00249    /*
00250     if (list==0)
00251     {
00252       list =new PINIT_DF1B2VARIABLE[max_num_init_df1b2variable];
00253     }
00254     if (++num_variables>= max_num_init_df1b2variable)
00255     {
00256       cerr << "Need to increase the maximum number of init_df1b2variables"
00257        << endl << "Use command line option -mni N" << endl;
00258     }
00259 
00260     if (num_variables>=df1b2variable::nvar)
00261     {
00262       cerr << "Maximum number of independent variables exceeded"
00263            << endl;
00264       cerr << "current max is " << df1b2variable::nvar << endl;
00265     }
00266     list[num_variables]=this;
00267     */
00268     ind_index=num_variables;
00269     *get_u()=v;
00270     if (num_variables>=minder && num_variables<=maxder)
00271     {
00272       //int offset= num_variables-minder;
00273       //u_dot[offset]=1.0;
00274     }
00275   }
00276 
00277   int no_destruct=0;
00278 
00282 df1b2variable::~df1b2variable()
00283 {
00284     deallocate();
00285 }
00286 
00290 void df1b2variable::deallocate(void)
00291 {
00292   if (ptr)
00293   {
00294 #if defined(__CHECK_MEMORY__)
00295     if (pchecker)
00296     {
00297       if (ptr == pchecker)
00298       {
00299         cout << "destructor called  " << endl;
00300       }
00301     }
00302 #endif
00303     if (ncopies && *ncopies)
00304     {
00305       (*ncopies)--;
00306     }
00307     else
00308     {
00309       if (!df1b2_gradlist::no_derivatives)
00310         f1b2gradlist->write_save_pass2_tilde_values(this);
00311       ((twointsandptr*)ptr)->ptr->free(ptr);
00312 
00313       ptr = 0;
00314     }
00315   }
00316 }
00317 
00322   void init_df1b2vector::set_value(const dvector& v)
00323   {
00324     int mmin=indexmin();
00325     int mmax=indexmax();
00326     if (v.indexmin() != mmin || v.indexmax() != mmax )
00327     {
00328       cerr << "incompatible shape in "
00329         "init_df1b2vector::set_value(const dvector& v)" << endl;
00330     }
00331 
00332     for (int i=mmin;i<=mmax;i++)
00333     {
00334       (*this)(i)=v(i);
00335     }
00336   }
00337 
00342   init_df1b2vector::init_df1b2vector(void)
00343   {
00344     allocate();
00345   }
00346 
00351   init_df1b2vector::init_df1b2vector(int lb,int ub)
00352   {
00353     allocate(lb,ub);
00354   }
00355 
00360   void init_df1b2vector::allocate(int lb,int ub)
00361   {
00362     init_df1b2variable::num_variables= 0;
00363     index_min=lb;
00364     index_max=ub;
00365     ncopies=new int;
00366     *ncopies=0;
00367     int size=indexmax()-indexmin()+1;
00368     if (init_df1b2variable::list==0)
00369     {
00370       max_num_init_df1b2variable
00371         =max(size,max_num_init_df1b2variable);
00372 
00373       init_df1b2variable::list =
00374         new PINIT_DF1B2VARIABLE [max_num_init_df1b2variable];
00375       if (init_df1b2variable::list==0)
00376       {
00377         cerr << "Error allocating memory for init_df1b2variable::list"
00378          << endl;
00379         exit(1);
00380       }
00381     }
00382 
00383   // ****************************************
00384     trueptr=new init_df1b2variable[size];
00385     if (trueptr == 0)
00386     {
00387       cerr << "Error allocating memory for init_df1b2variable"
00388            << endl;
00389       ad_exit(1);
00390     }
00391     //AD_ALLOCATE(trueptr,init_df1b2variable,size,df1b2_gradlist)
00392   // ****************************************
00393 
00394     ptr=trueptr;
00395     ptr-=lb;
00396   }
00397 
00402   void init_df1b2vector::reallocate()
00403   {
00404     int mmin=indexmin();
00405     int mmax=indexmax();
00406     for (int i=mmin;i<=mmax;i++)
00407     {
00408       ptr[i].allocate();
00409     }
00410   }
00411 
00416   void init_df1b2vector::allocate(void)
00417   {
00418     //deallocate(); a// don;t know why this was ever here DF 6june09
00419     index_min=0;
00420     index_max=-1;
00421     ncopies=0;
00422     ptr=0;
00423   }
00424 
00429   init_df1b2vector::~init_df1b2vector()
00430   {
00431     if (ncopies)
00432     {
00433       if (*ncopies)
00434         (*ncopies)--;
00435       else
00436       {
00437         if (trueptr)
00438         {
00439           delete [] trueptr;
00440           trueptr=0;
00441         }
00442         delete ncopies;
00443         ncopies=0;
00444       }
00445     }
00446   }
00447 
00452   void init_df1b2vector::deallocate(void)
00453   {
00454     if (ncopies)
00455     {
00456       if (*ncopies)
00457         (*ncopies)--;
00458       else
00459       {
00460         delete [] trueptr;
00461         trueptr=0;
00462         delete ncopies;
00463         ncopies=0;
00464       }
00465     }
00466   }
00467 
00472   init_df1b2vector::init_df1b2vector(const init_df1b2vector & v)
00473   {
00474     ncopies=v.ncopies;
00475     if (v.ncopies)
00476     {
00477       (*ncopies)++;
00478       trueptr=v.trueptr;
00479       ptr=v.ptr;
00480       index_min=v.index_min;
00481       index_max=v.index_max;
00482     }
00483     else
00484     {
00485       trueptr=0;
00486       index_min=1;
00487       index_max=0;
00488     }
00489     //cout << *ncopies << endl;
00490   }
00491 
00496   double& value(const df1b2variable& _x)
00497   {
00498     ADUNCONST(df1b2variable,x)
00499     return *x.u;
00500   }
00501 
00506   df1b2function2::df1b2function2(double (*_f)(double,double),
00507   double (*_df1)(double,double),double (*_df2)(double,double),
00508   double (*_d2f11)(double,double),
00509     double (*_d2f12)(double,double),
00510     double (*_d2f22)(double,double),
00511     double (*_d3f111)(double,double),
00512     double (*_d3f112)(double,double),
00513     double (*_d3f122)(double,double),
00514     double (*_d3f222)(double,double), const adstring& _s)
00515   {
00516     f=_f;
00517     df1=_df1; df2=_df2;
00518     d2f11=_d2f11; d2f12=_d2f12; d2f22=_d2f22;
00519     d3f111=_d3f111;
00520     d3f112=_d3f112;
00521     d3f122=_d3f122;
00522     d3f222=_d3f222;
00523     funname=_s;
00524   }
00525   typedef double (* PTDF)(double);
00526 
00531   PTDF tan_address()
00532   {
00533     return &tan;
00534   }
00535 
00540   df1b2variable df1b2function1::operator () (const df1b2variable& _x)
00541   {
00542     ADUNCONST(df1b2variable,x)
00543     df1b2variable z;
00544     double xu=*x.get_u();
00545     double * xd=x.get_u_dot();
00546     double * zd=z.get_u_dot();
00547     *z.get_u()=(*f)(xu);
00548     double dfx=(*df)(xu);
00549     for (unsigned int i=0;i<df1b2variable::nvar;i++)
00550     {
00551       *zd++ =dfx * *xd++;
00552     }
00553 
00554     // WRITE WHATEVER ON TAPE
00555     //df1b2tape->set_tapeinfo_header(&x,&z,this,xd);
00556     // save stuff for first reverse pass
00557     // need &x, &z, this,
00558     if (!df1b2_gradlist::no_derivatives)
00559     {
00560       if ((void*)(f)==tan_address())
00561         f1b2gradlist->write_pass1x(&x,&z,this);
00562       else
00563         f1b2gradlist->write_pass1(&x,&z,this);
00564     }
00565     return z;
00566   }
00567 
00572   df1b2variable df1b2function2::operator () (const df1b2variable& _x,
00573     const df1b2variable& _y)
00574   {
00575     ADUNCONST(df1b2variable,x)
00576     ADUNCONST(df1b2variable,y)
00577     df1b2variable z;
00578     double xu=*x.get_u();
00579     double yu=*y.get_u();
00580     double * xd=x.get_u_dot();
00581     double * yd=y.get_u_dot();
00582     double * zd=z.get_u_dot();
00583     *z.get_u()=(*f)(xu,yu);
00584     double dfx=(*df1)(xu,yu);
00585     double dfy=(*df2)(xu,yu);
00586     for (unsigned int i=0;i<df1b2variable::nvar;i++)
00587     {
00588       *zd++ =dfx * *xd++ + dfy * *yd++;
00589     }
00590 
00591     // WRITE WHATEVER ON TAPE
00592     if (!df1b2_gradlist::no_derivatives)
00593       f1b2gradlist->write_pass1(&x,&y,&z,this);
00594     return z;
00595   }
00596 
00601 void df1b2_gradlist::reset(void)
00602 {
00603   ncount=0;
00604   list.reset();
00605   nlist.reset();
00606   list2.reset();
00607   nlist2.reset();
00608   list3.reset();
00609   nlist3.reset();
00610 }
00611 
00616 df1b2_gradlist::df1b2_gradlist
00617 (
00618   unsigned int _bs, unsigned int _nbs,
00619   unsigned int _bs2, unsigned int _nbs2,
00620   unsigned int _bs3, unsigned int _nbs3,
00621   const adstring& _filename
00622 )
00623 {
00624   unsigned int bs=get_f1b2buffer_size("-l1");
00625   if (!bs) bs=_bs;
00626   list.allocate(bs,_filename);
00627 
00628   unsigned int nbs=get_f1b2buffer_size("-nl1");
00629   if (!nbs) nbs=_nbs;
00630   nlist.allocate(nbs,"n"+_filename);
00631 
00632   unsigned int bs2=get_f1b2buffer_size("-l2");
00633   if (!bs2) bs2=_bs2;
00634   list2.allocate(bs2,_filename+"2");
00635 
00636   unsigned int nbs2=get_f1b2buffer_size("-nl2");
00637   if (!nbs2) nbs2=_nbs2;
00638   nlist2.allocate(nbs2,"n"+_filename+"2");
00639 
00640   unsigned int bs3=get_f1b2buffer_size("-l3");
00641   if (!bs3) bs3=_bs3;
00642   list3.allocate(bs3,_filename+"3");
00643 
00644   unsigned int nbs3=get_f1b2buffer_size("-nl3");
00645   if (!nbs3) nbs3=_nbs3;
00646   nlist3.allocate(nbs3,"n"+_filename+"3");
00647 
00648   list3.set_noreadflag(1);
00649   nlist3.set_noreadflag(1);
00650 
00651   ncount=0;
00652 }
00653 /*
00654 smartlist::smartlist(void)
00655 {
00656   bufsize=0;
00657   filename=0;
00658   buffer=0;
00659   buffend=0;
00660   bptr=buffer;
00661   fp=-1;
00662 }
00663 */
00664 
00669 smartlist::smartlist(unsigned int _bufsize,const adstring& _filename)
00670 {
00671 #ifndef OPT_LIB
00672   //cerr << "need to modify smartlist class for multibyte char" << endl;
00673   assert(sizeof(char) == 1);
00674 #endif
00675 
00676   bufsize=_bufsize;
00677   filename=_filename;
00678   AD_ALLOCATE(buffer,char,bufsize,df1b2_gradlist)
00679   buffend=buffer+bufsize-1;
00680   bptr=buffer;
00681   fp = open((char*)filename,
00682     O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE);
00683   if (fp == -1)
00684   {
00685     cerr << "Error trying to open file " << filename
00686          << " in class smartlist " << endl;
00687     exit(1);
00688   }
00689 }
00690 
00691 void ad_dstar::allocate(const unsigned int _n)
00692 {
00693   n = _n;
00694 }
00695 
00700 ad_dstar::ad_dstar(void)
00701 {
00702   if (!n)
00703   {
00704     cerr << "need to initialize size in class ad_dstar" << endl;
00705     exit(1);
00706   }
00707   p = new double[n];
00708 }
00709 
00714 void set_dependent_variable(const df1b2variable& _x)
00715 {
00716   df1b2variable& x=(df1b2variable&) (_x);
00717   //cout << "dep " << int(x.u) << endl;
00718   for (unsigned int i=0;i<df1b2variable::nvar;i++)
00719   {
00720     x.u_dot_bar[i]=1.0;
00721   }
00722 }
00723 
00728 dmatrix get_hessian(const init_df1b2vector& _x)
00729 {
00730   ADUNCONST(init_df1b2vector,x)
00731 #ifdef OPT_LIB
00732   int nvar = (int)df1b2variable::nvar;
00733 #else
00734   unsigned int _nvar=df1b2variable::nvar;
00735   assert(_nvar <= INT_MAX);
00736   int nvar = (int)_nvar;
00737 #endif
00738   dmatrix h(1,nvar,1,nvar);
00739   for (int i=1;i<=nvar;i++)
00740   {
00741     for (int j=1;j<=nvar;j++)
00742     {
00743       h(i,j)=x(i).u_bar[j-1];
00744     }
00745   }
00746   return h;
00747 }
00748 
00749 typedef df1b2variable (*P_USER_FUNCTION)(const init_df1b2vector& x);
00750 
00755 double d1F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,double _delta)
00756 {
00757   ADUNCONST(init_df1b2vector,x)
00758   double delta=.3*_delta;
00759   double xsave=value(x(i));
00760   x(i)=xsave+delta;
00761   double fp=value(pu(x));
00762   x(i)=xsave-delta;
00763   double fm=value(pu(x));
00764   x(i)=xsave;
00765   double d1fa=(fp-fm)/(2.0*delta);
00766   x(i)=xsave+2.0*delta;
00767   fp=value(pu(x));
00768   x(i)=xsave-2.0*delta;
00769   fm=value(pu(x));
00770   x(i)=xsave;
00771   double d1fb=(fp-fm)/(4.0*delta);
00772   double d1f=(8.0*d1fa-d1fb)/7.0;
00773   return d1f;
00774 }
00775 
00780 double d2F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,int j,
00781   double delta)
00782 {
00783   ADUNCONST(init_df1b2vector,x)
00784   double xsave=value(x(i));
00785   x(i)=xsave+delta;
00786   double fp=d1F(pu,x,j,delta);
00787   x(i)=xsave-delta;
00788   double fm=d1F(pu,x,j,delta);
00789   double d1fa=(fp-fm)/(2.0*delta);
00790   x(i)=xsave+2.0*delta;
00791   fp=d1F(pu,x,j,delta);
00792   x(i)=xsave-2.0*delta;
00793   fm=d1F(pu,x,j,delta);
00794   x(i)=xsave;
00795   double d1fb=(fp-fm)/(4.0*delta);
00796   double d1f=(8.0*d1fa-d1fb)/7.0;
00797   return d1f;
00798 }
00799 
00804 double d3F(P_USER_FUNCTION pu,const init_df1b2vector& _x,int i,int j,int k,
00805   double delta)
00806 {
00807   ADUNCONST(init_df1b2vector,x)
00808   double xsave=value(x(i));
00809   x(i)=xsave+delta;
00810   double fp=d2F(pu,x,j,k,delta);
00811   x(i)=xsave-delta;
00812   double fm=d2F(pu,x,j,k,delta);
00813   x(i)=xsave;
00814   double d1f=(fp-fm)/(2.0*delta);
00815   return d1f;
00816 }
00817 
00822 dmatrix check_second_derivatives(const init_df1b2vector& x)
00823 {
00824   f1b2gradlist->set_no_derivatives();
00825 #ifdef OPT_LIB
00826   int nvar = (int)df1b2variable::nvar;
00827 #else
00828   unsigned int _nvar=df1b2variable::nvar;
00829   assert(_nvar <= INT_MAX);
00830   int nvar = (int)_nvar;
00831 #endif
00832   dmatrix h(1, nvar, 1, nvar);
00833   //const double delta=1.e-3;
00834   h.initialize();
00835   for (int i=1;i<=init_df1b2variable::num_variables;i++)
00836   {
00837     for (int j=1;j<=init_df1b2variable::num_variables;j++)
00838     {
00839       //h(i,j)=d2F(user_function,x,i,j,delta);
00840     }
00841   }
00842   return h;
00843 }
00844 
00849 d3_array check_third_derivatives(const init_df1b2vector& x)
00850 {
00851   f1b2gradlist->set_no_derivatives();
00852 #ifdef OPT_LIB
00853   int nvar = (int)df1b2variable::nvar;
00854 #else
00855   unsigned int _nvar=df1b2variable::nvar;
00856   assert(_nvar <= INT_MAX);
00857   int nvar = (int)_nvar;
00858 #endif
00859   d3_array h(1, nvar, 1, nvar, 1, nvar);
00860   //const double delta=2.e-4;
00861   h.initialize();
00862   for (int i=1;i<=init_df1b2variable::num_variables;i++)
00863   {
00864     for (int j=1;j<=init_df1b2variable::num_variables;j++)
00865     {
00866       for (int k=1;k<=init_df1b2variable::num_variables;k++)
00867       {
00868         //h(i,j,k)=d3F(user_function,x,i,j,k,delta);
00869       }
00870     }
00871   }
00872   return h;
00873 }
00874 
00875 #if defined(__DERCHECK__)
00876 
00881 dercheck_info::dercheck_info(int _node_number,double _delta,int _index) :
00882   node_number(_node_number), delta(_delta), index(_index)
00883 {
00884   der_value=0.0;
00885   pass_number=0;
00886   counter=0;
00887   f1=0.0;
00888   f2=0.0;
00889 }
00890 dercheck_info * derchecker;
00891 
00892 #endif
00893 
00894 
00895 re_objective_function_value * re_objective_function_value::pobjfun=0;
00896 
00901 re_objective_function_value::re_objective_function_value(void)
00902 {
00903   pobjfun=this;
00904 }
00905 
00910 re_objective_function_value::~re_objective_function_value()
00911 {
00912   pobjfun=0;
00913 }
00914 
00919 re_objective_function_value& re_objective_function_value::operator =
00920   (const df1b2variable& v)
00921 {
00922   df1b2variable::operator = (v);
00923   return *this;
00924 }
00925 
00930 re_objective_function_value& re_objective_function_value::operator =
00931   (double v)
00932 {
00933   df1b2variable::operator = (v);
00934   return *this;
00935 }
00936 
00941 void re_objective_function_value::allocate(void)
00942 {
00943   df1b2variable::allocate();
00944 }
00945 
00950 void re_objective_function_value::allocate(const char * s)
00951 {
00952   pobjfun=this;
00953   df1b2variable::allocate();
00954 }
00955 
00956 #if !defined(OPT_LIB)
00957 
00961 init_df1b2variable& init_df1b2vector::operator () (int i)
00962 {
00963   if (i < indexmin())
00964   {
00965     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00966     "init_df1b2variable& init_df1b2vector::operator () (int i)",
00967     indexmin(), indexmax(), i);
00968   }
00969   if (i > indexmax())
00970   {
00971     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00972     "init_df1b2variable& init_df1b2vector::operator () (int i)",
00973     indexmin(), indexmax(), i);
00974   }
00975   return ptr[i];
00976 }
00977 
00982 init_df1b2variable& init_df1b2vector::operator [] (int i)
00983 {
00984   if (i < indexmin())
00985   {
00986     ADMB_ARRAY_BOUNDS_ERROR("Index too low",
00987     "init_df1b2variable& init_df1b2vector::operator [] (int i)",
00988     indexmin(), indexmax(), i);
00989   }
00990   if (i > indexmax())
00991   {
00992     ADMB_ARRAY_BOUNDS_ERROR("Index too high",
00993     "init_df1b2variable& init_df1b2vector::operator [] (int i)",
00994     indexmin(), indexmax(), i);
00995   }
00996   return ptr[i];
00997 }
00998 #endif
00999 
01002 unsigned int get_f1b2buffer_size(const char* s)
01003 {
01004   unsigned int n = 0;
01005   int on1=-1;
01006   int nopt=0;
01007   if ( (on1=option_match(ad_comm::argc,ad_comm::argv,s,nopt))>-1)
01008   {
01009     if (!nopt)
01010     {
01011       cerr << "Usage " << s << " option needs integer  -- ignored" << endl;
01012     }
01013     else
01014     {
01015       int i = atoi(ad_comm::argv[on1+1]);
01016       if (i > 0)
01017       {
01018         n = (unsigned int)i;
01019       }
01020     }
01021   }
01022   return n;
01023 }
01024 
01029 df1b2variable::df1b2variable(const random_effects_bounded_vector_info& rebv)
01030 {
01031   df1b2variable& v= *(rebv.pv->v+rebv.i);
01032   if (v.ptr)
01033   {
01034     ptr=v.ptr;
01035     ncopies=v.ncopies;
01036     (*ncopies)++;
01037     u=v.u;
01038     u_dot=v.u_dot;
01039     u_bar=v.u_bar;
01040     u_dot_bar=v.u_dot_bar;
01041     u_tilde=v.u_tilde;
01042     u_dot_tilde=v.u_dot_tilde;
01043     u_bar_tilde=v.u_bar_tilde;
01044     u_dot_bar_tilde=v.u_dot_bar_tilde;
01045   }
01046   else
01047   {
01048     ptr=NULL;
01049     ncopies=NULL;
01050     u=NULL;
01051     u_dot=NULL;
01052     u_bar=NULL;
01053     u_dot_bar=NULL;
01054     u_tilde=NULL;
01055     u_dot_tilde=NULL;
01056     u_bar_tilde=NULL;
01057     u_dot_bar_tilde=NULL;
01058   }
01059 }