ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
f1b2fnl6.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 <df1b2fnl.h>
00012 
00017 funnel_init_df1b2matrix::funnel_init_df1b2matrix(const df1b2matrix & _x)
00018 {
00019   //ADUNCONST(df1b2_init_matrix,x)
00020   ADUNCONST(df1b2matrix,x)
00021   p=&_x;
00022   int mmin=p->indexmin();
00023   int mmax=p->indexmax();
00024 
00025   int jmin=(*p)(mmin).indexmin();
00026   int ind_index = x(mmin,jmin).get_ind_index();
00027   if (ind_index<0)
00028   {
00029     add_to_inactive_list();
00030   }
00031   else
00032   {
00033     add_to_list();
00034   }
00035   //int i,j;
00036   int i;
00037   ivector lb(mmin,mmax);
00038   ivector ub(mmin,mmax);
00039   lb(mmin)=(*p)(mmin).indexmin();
00040   ub(mmin)=(*p)(mmin).indexmax();
00041   int lf=0;
00042   int uf=0;
00043   for (i=mmin+1;i<=mmax;i++)
00044   {
00045     lb(i)=(*p)(i).indexmin();
00046     ub(i)=(*p)(i).indexmax();
00047     if (lb(i) !=lb(i-1))
00048       lf=1;
00049     if (ub(i) !=ub(i-1))
00050       uf=1;
00051   }
00052   // do we want this DF 01Nov05
00053   //df1b2variable::noallocate=1;
00054   if (lf ==1)
00055   {
00056     if (uf==1)
00057     {
00058       df1b2matrix::allocate(mmin,mmax,lb,ub);
00059     }
00060     else
00061     {
00062       df1b2matrix::allocate(mmin,mmax,lb,ub(mmin));
00063     }
00064   }
00065   else
00066   {
00067     if (uf==1)
00068     {
00069       df1b2matrix::allocate(mmin,mmax,lb(mmin),ub);
00070     }
00071     else
00072     {
00073       df1b2matrix::allocate(mmin,mmax,lb(mmin),ub(mmin));
00074     }
00075   }
00076   df1b2variable::noallocate=0;
00077 }
00078 
00083 int funnel_init_df1b2matrix::nvar_calc(void)
00084 {
00085   int mmin=p->indexmin();
00086   int mmax=p->indexmax();
00087   int n=0;
00088   for (int i=mmin;i<=mmax;i++)
00089   {
00090     n+=(*p)(i).indexmax()-(*p)(i).indexmin()+1;
00091   }
00092   return n;
00093 }
00094 
00099 void funnel_init_df1b2matrix::xinit(init_df1b2vector& y,int& ii)
00100 {
00101   df1b2_init_matrix * vp = (df1b2_init_matrix *) p;
00102   int mmin=vp->indexmin();
00103   int mmax=vp->indexmax();
00104   int i,j;
00105   for (i=mmin;i<=mmax;i++)
00106   {
00107     int jmin=(*vp)(i).indexmin();
00108     int jmax=(*vp)(i).indexmax();
00109     for (j=jmin;j<=jmax;j++)
00110     {
00111       y(ii)= value((*vp)(i,j));
00112       ii++;
00113     }
00114   }
00115 }
00116 
00121 void funnel_init_df1b2matrix::set_index(imatrix& y,int& ii)
00122 {
00123   df1b2_init_matrix * vp = (df1b2_init_matrix *) p;
00124   int mmin=vp->indexmin();
00125   int mmax=vp->indexmax();
00126   int i,j;
00127   for (i=mmin;i<=mmax;i++)
00128   {
00129     int jmin=(*vp)(i).indexmin();
00130     int jmax=(*vp)(i).indexmax();
00131     for (j=jmin;j<=jmax;j++)
00132     {
00133       y(ii,1)= ( *vp)(i,j).get_ind_index();
00134       y(ii,2)= ii;
00135       ii++;
00136     }
00137   }
00138 }
00139 
00144 void funnel_init_df1b2matrix::set_value(const init_df1b2vector& _x,
00145   const int& _ii,const df1b2variable& _pen)
00146 {
00147   ADUNCONST(int,ii)
00148   ADUNCONST(init_df1b2vector,x)
00149   int mmin=p->indexmin();
00150   int mmax=p->indexmax();
00151   int i,j;
00152   for (i=mmin;i<=mmax;i++)
00153   {
00154     int jmin=(*p)(i).indexmin();
00155     int jmax=(*p)(i).indexmax();
00156     for (j=jmin;j<=jmax;j++)
00157     {
00158       (*this)(i,j) = (x(ii++));
00159     }
00160   }
00161 }
00162 // *****************************************************************
00163 // *****************************************************************
00164 // *****************************************************************
00165 /*
00166 funnel_init_bounded_df1b2vector::funnel_init_bounded_df1b2vector(const df1b2_init_bounded_vector & _x)
00167 {
00168   ADUNCONST(df1b2_init_bounded_vector,x)
00169   //type=0;
00170   //pointer=0;
00171   p=&_x;
00172   int mmin=x.indexmin();
00173   int mmax=x.indexmax();
00174   int ind_index = x(mmin).get_ind_index();
00175   if (ind_index<0)
00176   {
00177     add_to_inactive_list();
00178   }
00179   else
00180   {
00181     add_to_list();
00182   }
00183   df1b2variable::noallocate=1;
00184   df1b2vector::allocate(mmin,mmax);
00185   df1b2variable::noallocate=0;
00186 }
00187 
00188 
00189 int funnel_init_bounded_df1b2vector::nvar_calc(void)
00190 {
00191   return p->indexmax()-p->indexmin()+1;
00192 }
00193 
00194 void funnel_init_bounded_df1b2vector::xinit(init_df1b2vector& y,int& ii)
00195 {
00196   df1b2_init_bounded_vector * vp = (df1b2_init_bounded_vector *) p;
00197   int mmin=p->indexmin();
00198   int mmax=p->indexmax();
00199   int i;
00200   for (i=mmin;i<=mmax;i++)
00201   {
00202     y(ii)= value((*vp)(i));
00203     ii++;
00204   }
00205 }
00206 
00207 void funnel_init_bounded_df1b2vector::set_index(imatrix& y,int& ii)
00208 {
00209   int mmin=p->indexmin();
00210   int mmax=p->indexmax();
00211   int i;
00212   for (i=mmin;i<=mmax;i++)
00213   {
00214     y(ii,1)= ( *(df1b2_init_bounded_vector *)(p) )(i).get_ind_index();
00215     y(ii,2)= ii;
00216     ii++;
00217   }
00218 }
00219 
00220 void funnel_init_bounded_df1b2vector::set_value(const init_df1b2vector& _x,
00221   const int& _ii,const df1b2variable& _pen)
00222 {
00223   ADUNCONST(int,ii)
00224   ADUNCONST(init_df1b2vector,x)
00225   df1b2_init_bounded_vector * vp = (df1b2_init_bounded_vector *) p;
00226   int mmin=p->indexmin();
00227   int mmax=p->indexmax();
00228   int i;
00229   for (i=mmin;i<=mmax;i++)
00230   {
00231     (*this)(i) = (x(ii++));
00232     if (!initial_params::straight_through_flag)
00233     {
00234       // df1b2variable& tmp = boundp(x(ii++),b.getminb(),b.getmaxb(),pen);
00235       // df1b2variable::operator = (tmp);
00236       (*this)(i) = (boundp(x(ii++),vp->getminb(),vp->getmaxb()));
00237     }
00238     else
00239     {
00240       (*this)(i) = (x(ii));
00241       *((*this)(i).get_u()) =
00242         boundp(*(x(ii++).get_u()),vp->getminb(),vp->getmaxb());
00243     }
00244   }
00245 }
00246 */