ADMB Documentation  11.1x.2711
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2fnl.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2fnl.cpp 2631 2014-11-12 21:24:35Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <df1b2fnl.h>
00012 #ifndef OPT_LIB
00013   #include <cassert>
00014   #include <climits>
00015 #endif
00016 
00017 #define USE_BARD_PEN
00018 class newadkludge;
00019 newadkludge * newadkl=0;
00020 
00021 
00022 typedef funnel_init_var  * PFUNNEL_INIT_VAR;
00023 
00024 class laplace_approximation_calculator;
00025 laplace_approximation_calculator * funnel_init_var::lapprox=0;
00026 df1b2variable * funnel_init_var::funnel_constraints_penalty=0;
00027 unsigned int funnel_init_var::num_vars=0;
00028 //int funnel_init_var::num_all_vars=0;
00029 int funnel_init_var::num_inactive_vars=0;
00030 unsigned int funnel_init_var::num_active_parameters=0;
00031 //funnel_init_var ** funnel_init_var::all_list=new PFUNNEL_INIT_VAR[2000];
00032 funnel_init_var ** funnel_init_var::list=new PFUNNEL_INIT_VAR[2000];
00033 funnel_init_var ** funnel_init_var::inactive_list=new PFUNNEL_INIT_VAR[2000];
00034 init_df1b2vector * funnel_init_var::py=0;
00035 imatrix * funnel_init_var::plist=0;
00036 
00037   int funnel_check_flag=0;
00038 
00043 void funnel_init_var::add_to_list(void)
00044 {
00045 #ifndef OPT_LIB
00046   assert(num_vars <= INT_MAX);
00047 #endif
00048   index = (int)num_vars;
00049   list[num_vars++]=this;
00050   //all_list[num_all_vars++]=this;
00051 }
00052 
00057 void funnel_init_var::delete_from_list(void)
00058 {
00059 #ifndef OPT_LIB
00060   assert(num_vars <= INT_MAX);
00061 #endif
00062   if (index != (int)(num_vars - 1))
00063   {
00064     cerr << "can only delete last member" << endl;
00065     ad_exit(1);
00066   }
00067   num_vars--;
00068   index=-1;
00069 }
00070 
00075 void funnel_init_var::add_to_inactive_list(void)
00076 {
00077   index=-1;
00078   inactive_list[num_inactive_vars++]=this;
00079 }
00080 
00085 void funnel_init_var::allocate(void)
00086 {
00087   //cout << "In allocate" << endl;
00088 }
00089 
00094 void check_pool_depths(void)
00095 {
00096   for (int i=0;i<df1b2variable::adpool_counter;i++)
00097   {
00098     cout << " Pool depth " << i << "  "
00099          << df1b2variable::adpool_vector[i]->depth_check()
00100          << "  " << df1b2variable::adpool_vector[i]  << endl;
00101   }
00102 }
00103 
00107 void funnel_init_var::deallocate_all(void)
00108 {
00109   if (plist)
00110   {
00111 #ifndef OPT_LIB
00112   assert(num_active_parameters <= INT_MAX);
00113 #endif
00114     if (plist->indexmax() != (int)num_active_parameters)
00115     {
00116       delete plist;
00117       plist = 0;
00118     }
00119   }
00120   if (py)
00121   {
00122     delete py;
00123     py = 0;
00124   }
00125 }
00126 
00131 void funnel_init_var::allocate_all(void)
00132 {
00133   re_objective_function_value::pobjfun->deallocate();
00134   if (lapprox)
00135   {
00136     if (lapprox->calling_set)
00137     {
00138       (*lapprox->calling_set)(0,0)++;
00139     }
00140   }
00141   num_active_parameters=funnel_init_var::nvarcalc_all();
00142 #ifndef OPT_LIB
00143   assert(num_active_parameters <= INT_MAX);
00144 #endif
00145   if (py)
00146   {
00147     if (py->indexmax() != (int)num_active_parameters)
00148     {
00149       delete py;
00150       py=0;
00151     }
00152   }
00153   f1b2gradlist->reset();
00154 
00155   adpool * tmppool=df1b2variable::pool;
00156   if (tmppool)
00157   {
00158     //cout << tmppool << endl;
00159     // check if current pool is the right size
00160     if (tmppool->nvar != num_active_parameters)
00161     {
00162       // check sizes of other pools
00163       int found_pool_flag=0;
00164       for (int i=0;i<df1b2variable::adpool_counter;i++)
00165       {
00166         if (df1b2variable::adpool_vector[i]->nvar == num_active_parameters)
00167         {
00168           df1b2variable::pool=df1b2variable::adpool_vector[i];
00169           found_pool_flag=1;
00170           break;
00171         }
00172       }
00173       if (!found_pool_flag)
00174       {
00175         df1b2variable::pool=new adpool();
00176         if (!df1b2variable::pool)
00177         {
00178           cerr << "Memory allocation error" << endl;
00179           ad_exit(1);
00180         }
00181         if (df1b2variable::adpool_counter>df1b2variable::adpool_vectorsize)
00182         {
00183           //cerr << "Need to increase adpool_vectorsize" << endl;
00184           //ad_exit(1);
00185           //int offset=get_unused_pool_index();
00186           int offset=1;
00187           adpool * tmp= df1b2variable::adpool_vector[offset];
00188           delete tmp;
00189           df1b2variable::adpool_vector[offset]=df1b2variable::pool;
00190           df1b2variable::nvar_vector[offset]=num_active_parameters;
00191           df1b2variable::adpool_use_index[offset]=
00192             df1b2variable::current_allocation_index;
00193         }
00194         else
00195         {
00196           df1b2variable::adpool_vector[df1b2variable::adpool_counter]=
00197             df1b2variable::pool;
00198           df1b2variable::nvar_vector[df1b2variable::adpool_counter]=
00199             num_active_parameters;
00200           //df1b2variable::adpool_counter++;
00201           df1b2variable::increment_adpool_counter();
00202         }
00203       }
00204     }
00205   }
00206   else
00207   {
00208     df1b2variable::pool=new adpool();
00209     if (!df1b2variable::pool)
00210     {
00211       cerr << "Memory allocation error" << endl;
00212       ad_exit(1);
00213     }
00214     if (df1b2variable::adpool_counter>df1b2variable::adpool_vectorsize)
00215     {
00216       int offset=1;
00217       adpool * tmp= df1b2variable::adpool_vector[offset];
00218       delete tmp;
00219       df1b2variable::adpool_vector[offset]=df1b2variable::pool;
00220       df1b2variable::nvar_vector[offset]=num_active_parameters;
00221       df1b2variable::adpool_use_index[offset]=
00222         df1b2variable::current_allocation_index;
00223     }
00224     else
00225     {
00226       df1b2variable::adpool_use_index[df1b2variable::adpool_counter]=
00227         df1b2variable::current_allocation_index;
00228       df1b2variable::adpool_vector[df1b2variable::adpool_counter]=
00229         df1b2variable::pool;
00230       df1b2variable::nvar_vector[df1b2variable::adpool_counter]=
00231         num_active_parameters;
00232       //df1b2variable::adpool_counter++;
00233       df1b2variable::increment_adpool_counter();
00234     }
00235   }
00236   df1b2variable::current_allocation_index++;
00237   df1b2variable::nvar=num_active_parameters;
00238   df1b2variable::set_blocksize();
00239 
00240   re_objective_function_value::pobjfun->allocate();
00241   //if (funnel_check_flag)
00242    // check_pool_depths();
00243   df1b2variable::minder=1;
00244   int maxdersave=df1b2variable::maxder;
00245   df1b2variable::maxder=(int)num_active_parameters;
00246   if (!py)
00247   {
00248     py = new init_df1b2vector(1,(int)num_active_parameters);
00249   }
00250   //if (funnel_check_flag)
00251   //  check_pool_depths();
00252   if (!py)
00253   {
00254     cerr << "memory allocation error" << endl;
00255     ad_exit(1);
00256   }
00257   //init_df1b2vector& tmp = *py;
00258 
00259 
00260   if (plist)
00261   {
00262     if (plist->indexmax() != (int)num_active_parameters)
00263     {
00264       delete plist;
00265       plist=0;
00266     }
00267   }
00268   if (!plist)
00269   {
00270     plist = new imatrix(1,(int)num_active_parameters,1,2);
00271   }
00272   if (!plist)
00273   {
00274     cerr << "memory allocation error" << endl;
00275     ad_exit(1);
00276   }
00277 
00278   int ii=1;
00279   for(unsigned int i=0;i<num_vars;i++)
00280   {
00281     list[i]->xinit(*py,ii);
00282   }
00283 
00284   ii=1;
00285   for(unsigned int i=0;i<num_vars;i++)
00286   {
00287     list[i]->set_index(*plist,ii);
00288   }
00289 
00290   for(int i=0;i<num_inactive_vars;i++)
00291   {
00292     inactive_list[i]->allocate();
00293   }
00294 
00295   funnel_init_var::reset(*py);
00296   //if (funnel_check_flag)
00297   //  check_pool_depths();
00298   df1b2variable::maxder=maxdersave;
00299 }
00300 
00305 funnel_init_df1b2variable::funnel_init_df1b2variable
00306   (const df1b2_init_number & _x) : df1b2variable(newadkl)
00307   //(df1b2_init_number & x) : df1b2variable()
00308 {
00309   ADUNCONST(df1b2_init_number,x)
00310   type=0;
00311   pointer=0;
00312   ind_index=x.get_ind_index();
00313   if (ind_index<0)
00314   {
00315     add_to_inactive_list();
00316   }
00317   else
00318   {
00319     add_to_list();
00320     if (lapprox==0)
00321     {
00322       cout << "This can't happen" << endl;
00323       ad_exit(1);
00324     }
00325     lapprox->used_flags(ind_index)+=1;
00326   }
00327   //cout << "ind_index = " << ind_index << endl;
00328   xu=*(x.get_u());
00329 }
00330 
00335 funnel_init_df1b2variable::funnel_init_df1b2variable
00336   (const random_effects_bounded_vector_info & _u)
00337   : df1b2variable(newadkl)
00338 {
00339   ADUNCONST(random_effects_bounded_vector_info,u)
00340   df1b2variable& x = (*(u.pv)).df1b2vector::operator () (u.i);
00341 
00342   type=1;
00343   pointer=u.pv;
00344   ind_index = x.get_ind_index();
00345   if (ind_index<0)
00346   {
00347     add_to_inactive_list();
00348   }
00349   else
00350   {
00351     add_to_list();
00352     lapprox->used_flags(ind_index)+=1;
00353   }
00354   xu=*(x.get_u());
00355 }
00356 
00361 void funnel_init_df1b2variable::allocate(const df1b2variable& x)
00362 {
00363   cerr << "Haven't defined htis yet" << endl;
00364   ad_exit(1);
00365 }
00366 
00371 funnel_init_df1b2variable::funnel_init_df1b2variable
00372   (void) : df1b2variable(newadkl)
00373 {
00374   type=0;
00375   pointer=0;
00376   ind_index = -1;
00377   if (ind_index<0)
00378   {
00379     add_to_inactive_list();
00380   }
00381   else
00382   {
00383     add_to_list();
00384   }
00385 }
00386 
00391 void funnel_init_df1b2variable::
00392   preallocate(const df1b2variable & _x)
00393 {
00394   ADUNCONST(df1b2variable,x)
00395   type=0;
00396   pointer=0;
00397   ind_index = x.get_ind_index();
00398   if (ind_index<0)
00399   {
00400     add_to_inactive_list();
00401   }
00402   else
00403   {
00404     add_to_list();
00405     lapprox->used_flags(ind_index)+=1;
00406   }
00407   xu=*(x.get_u());
00408 }
00409 
00414 funnel_init_df1b2variable::funnel_init_df1b2variable
00415   (const funnel_init_df1b2variable& x):
00416   funnel_init_var(),
00417   df1b2variable(x)
00418 {}
00419 
00424 funnel_init_df1b2variable::funnel_init_df1b2variable
00425   (const df1b2variable & _x) : df1b2variable(newadkl)
00426 {
00427   ADUNCONST(df1b2variable,x)
00428   type=0;
00429   pointer=0;
00430   ind_index = x.get_ind_index();
00431   get_ind_index() = x.get_ind_index();
00432   if (ind_index<0)
00433   {
00434     add_to_inactive_list();
00435   }
00436   else
00437   {
00438     add_to_list();
00439     lapprox->used_flags(ind_index)+=1;
00440     if (lapprox->calling_set)
00441     {
00442       int j=++(*lapprox->calling_set)(ind_index,0);
00443       int k=lapprox->used_flags(ind_index);
00444       if (j != k)
00445       {
00446         cerr << "This can't happen" << endl;
00447         ad_exit(1);
00448       }
00449       (*lapprox->calling_set)(ind_index,j)=(*lapprox->calling_set)(0,0);
00450     }
00451   }
00452   xu=*(x.get_u());
00453 }
00454 
00459 void funnel_init_df1b2variable::allocate(void)
00460 {
00461   df1b2variable::allocate();
00462   *(get_u())=xu;
00463   if (index>=0)
00464     get_u_dot()[index]=1.0;
00465 }
00466 
00471 funnel_dependent_df1b2variable::funnel_dependent_df1b2variable
00472   (const df1b2variable& x)
00473 {
00474   df1b2variable::operator = (x);
00475   if (!df1b2_gradlist::no_derivatives)
00476   {
00477     //df1b2variable * tmp = (df1b2variable *) (this);
00478     //set_dependent_variable(*tmp);
00479   }
00480   df1b2_gradlist::set_no_derivatives();
00481 }
00482 
00487 void funnel_init_df1b2variable::set_value(const init_df1b2vector& _x,
00488   const int& _ii)
00489 {
00490   df1b2variable pen=0.0;
00491   ADUNCONST(init_df1b2vector,x)
00492   ADUNCONST(int,ii)
00493   if (!pointer)
00494   {
00495     df1b2variable::operator = (x(ii++));
00496   }
00497   else
00498   {
00499     switch (type)
00500     {
00501       case 1:   // vector
00502       {
00503         df1b2_init_bounded_vector & b = *(df1b2_init_bounded_vector*)pointer;
00504         if (!initial_params::straight_through_flag)
00505         {
00506           // df1b2variable& tmp = boundp(x(ii++),b.getminb(),b.getmaxb(),pen);
00507           // df1b2variable::operator = (tmp);
00508           df1b2variable::operator =
00509             (boundp(x(ii++),b.getminb(),b.getmaxb()));
00510         }
00511         else
00512         {
00513           df1b2variable::operator = (x(ii));
00514           *get_u()=boundp(*(x(ii++).get_u()),b.getminb(),b.getmaxb());
00515         }
00516         break;
00517       }
00518       case 2:  // matrix
00519       default:
00520       {
00521         cerr << "the bounded matrix case in "
00522           " void funnel_init_df1b2variable::xinit  has not bee implemented"
00523           << endl;
00524           ad_exit(1);
00525       }
00526     }
00527   }
00528 }
00529 
00534 void funnel_init_df1b2variable::set_value(const init_df1b2vector& _x,
00535   const int& _ii,const df1b2variable& _pen)
00536 {
00537   ADUNCONST(init_df1b2vector,x)
00538   ADUNCONST(int,ii)
00539   ADUNCONST(df1b2variable,pen)
00540   if (!pointer)
00541   {
00542     df1b2variable::operator = (x(ii++));
00543   }
00544   else
00545   {
00546     switch (type)
00547     {
00548       case 1:   // vector
00549       {
00550         df1b2_init_bounded_vector & b = *(df1b2_init_bounded_vector*)pointer;
00551         laplace_approximation_calculator * l =lapprox;
00552         int uf=-1;
00553         if (ind_index>0)
00554         {
00555           uf=l->used_flags(ind_index);
00556         }
00557         if (uf > 1 && (l->hesstype ==2))
00558         {
00559           if (ind_index <=lapprox->xsize )
00560           {
00561             cout << " fixed effect used " << uf << " times" << endl;
00562             df1b2variable::operator = (boundp(x(ii++),b.getminb(),
00563               b.getmaxb()));
00564           }
00565           else
00566           {
00567              cout << lapprox->hesstype << endl;
00568              cout << " Error random effect used " << uf << " times" << endl;
00569              ad_exit(1);
00570           }
00571         }
00572         else
00573         {
00574           if (!initial_params::straight_through_flag)
00575           {
00576             df1b2variable::operator = (boundp(x(ii++),b.getminb(),b.getmaxb(),
00577               pen));
00578           }
00579           else
00580           {
00581             df1b2variable::operator = (x(ii++));
00582             *get_u()=boundp(*get_u(),b.getminb(),b.getmaxb());
00583             double diff=b.getmaxb()-b.getminb();
00584             df1b2variable ss=((*this)-b.getminb())/diff;
00585 #           ifdef USE_BARD_PEN
00586               const double l4=log(4.0);
00587               double wght=.000001/diff;
00588               pen-=wght*(log(ss+double(1.e-40))+log((double(1.0)-ss)
00589                 +double(1.e-40))+l4);
00590 #           else
00591              XXXX
00592 #           endif
00593           }
00594         }
00595         break;
00596       }
00597       case 2:  // matrix
00598       default:
00599       {
00600         cerr << "the bounded matrix case in "
00601           " void funnel_init_df1b2variable::xinit  has not bee implemented"
00602           << endl;
00603           ad_exit(1);
00604       }
00605     }
00606   }
00607 }
00608 
00613 unsigned int funnel_init_var::nvarcalc_all(void)
00614 {
00615   int n = 0;
00616   for (unsigned int i=0;i<num_vars;i++)
00617   {
00618     n += list[i]->nvar_calc();
00619   }
00620 #ifndef OPT_LIB
00621   assert(n >= 0);
00622 #endif
00623   return (unsigned int)n;
00624 }
00625 
00630 void funnel_init_df1b2variable::xinit(init_df1b2vector& y,int& ii)
00631 {
00632   if (!pointer)
00633   {
00634     y(ii)= xu;
00635   }
00636   else
00637   {
00638     switch (type)
00639     {
00640       case 1:   // vector
00641       {
00642         df1b2_init_bounded_vector & b = *(df1b2_init_bounded_vector*)pointer;
00643         y(ii)=boundpin(xu,b.getminb(),b.getmaxb());
00644         //cout << setprecision(15) <<  << b.getminb() << " "
00645          // << b.getmaxb() << " " << y(ii) << " " << xu << endl;
00646         break;
00647       }
00648       case 2:  // matrix
00649       default:
00650       {
00651         cerr << "the bounded matrix case in "
00652           " void funnel_init_df1b2variable::xinit  has not bee implemented"
00653           << endl;
00654           ad_exit(1);
00655       }
00656     }
00657   }
00658   ii++;
00659 }
00660 
00665 void funnel_init_df1b2variable::xinit(dvector& y,int& ii)
00666 {
00667   if (!pointer)
00668   {
00669     y(ii)= xu;
00670   }
00671   else
00672   {
00673     switch (type)
00674     {
00675       case 1:   // vector
00676       {
00677         df1b2_init_bounded_vector & b = *(df1b2_init_bounded_vector*)pointer;
00678         y(ii)=boundpin(xu,b.getminb(),b.getmaxb());
00679         break;
00680       }
00681       case 2:  // matrix
00682       default:
00683       {
00684         cerr << "the bounded matrix case in "
00685           " void funnel_init_df1b2variable::xinit  has not bee implemented"
00686           << endl;
00687           ad_exit(1);
00688       }
00689     }
00690   }
00691   ii++;
00692 }
00693 
00694 /*
00695 void funnel_init_df1b2variable::xinit(dvector& y,int& ii)
00696 {
00697   y(ii)= xu;
00698   ii++;
00699 }
00700 */
00701 
00706 void funnel_init_df1b2variable::set_index(imatrix& y,int& ii)
00707 {
00708   //cout << ind_index << " " << ii << endl;
00709   y(ii,1)= ind_index;
00710   y(ii,2)= ii;
00711   ii++;
00712 }
00713 
00718 void funnel_init_var::reset(init_df1b2vector& x)
00719 {
00720   int ii=1;
00721   df1b2variable pen=0.0;
00722   for (unsigned int i=0;i<num_vars;i++)
00723   {
00724     list[i]->set_value(x,ii,pen);
00725     //list[i]->set_value(x,ii);
00726   }
00727   if (funnel_init_var::funnel_constraints_penalty)
00728   {
00729     delete funnel_init_var::funnel_constraints_penalty;
00730   }
00731   funnel_init_var::funnel_constraints_penalty=new df1b2variable(pen);
00732 }
00733 
00734 
00735 /*
00736 funnel_init_df1b2vector::funnel_init_df1b2vector(const df1b2_init_vector & _x)
00737 {
00738   ADUNCONST(df1b2_init_vector,x)
00739   //type=0;
00740   //pointer=0;
00741   p=&_x;
00742   int mmin=p->indexmin();
00743   int mmax=p->indexmax();
00744   int ind_index = (*p)(mmin).get_ind_index();
00745   if (ind_index<0)
00746   {
00747     add_to_inactive_list();
00748   }
00749   else
00750   {
00751     add_to_list();
00752   }
00753   df1b2variable::noallocate=1;
00754   df1b2vector::allocate(mmin,mmax);
00755   df1b2variable::noallocate=0;
00756 }
00757 */
00758 
00763 funnel_init_df1b2vector::funnel_init_df1b2vector(const df1b2vector & _x)
00764 {
00765   //ADUNCONST(df1b2_init_vector,x)
00766   // this seems to be right and not the above although it seemed to work
00767   ADUNCONST(df1b2_init_vector,x)
00768   p=&_x;
00769   int mmin=p->indexmin();
00770   int mmax=p->indexmax();
00771   int ind_index = x(mmin).get_ind_index();
00772   if (ind_index<0)
00773   {
00774     add_to_inactive_list();
00775   }
00776   else
00777   {
00778     add_to_list();
00779     for (int i=mmin;i<=mmax;i++)
00780     {
00781       ind_index = x(i).get_ind_index();
00782       lapprox->used_flags(ind_index)+=1;
00783     }
00784   }
00785   df1b2variable::noallocate=1;
00786   df1b2vector::allocate(mmin,mmax);
00787   df1b2variable::noallocate=0;
00788 }
00789 
00793 funnel_init_df1b2vector::~funnel_init_df1b2vector()
00794 {
00795   //df1b2vector::deallocate();
00796 }
00797 
00802 int funnel_init_df1b2vector::nvar_calc(void)
00803 {
00804   return p->indexmax()-p->indexmin()+1;
00805 }
00806 
00811 void funnel_init_df1b2vector::xinit(init_df1b2vector& y,int& ii)
00812 {
00813   //df1b2_init_vector * vp = (df1b2_init_vector *) p;
00814   //int mmin=vp->indexmin();
00815   //int mmax=vp->indexmax();
00816   int mmin=p->indexmin();
00817   int mmax=p->indexmax();
00818   int i;
00819   for (i=mmin;i<=mmax;i++)
00820   {
00821     //y(ii)= value((*vp)(i));
00822     y(ii)= value((*p)(i));
00823     ii++;
00824   }
00825 }
00826 
00831 void funnel_init_df1b2vector::set_index(imatrix& y,int& ii)
00832 {
00833   df1b2_init_vector * vp = (df1b2_init_vector *) p;
00834   int mmin=vp->indexmin();
00835   int mmax=vp->indexmax();
00836   int i;
00837   for (i=mmin;i<=mmax;i++)
00838   {
00839     y(ii,1)= ( *vp)(i).get_ind_index();
00840     y(ii,2)= ii;
00841     ii++;
00842   }
00843 }
00844 
00849 void funnel_init_df1b2vector::set_value(const init_df1b2vector& _x,
00850   const int& _ii,const df1b2variable& _pen)
00851 {
00852   ADUNCONST(int,ii)
00853   ADUNCONST(init_df1b2vector,x)
00854   int mmin=p->indexmin();
00855   int mmax=p->indexmax();
00856   int i;
00857   for (i=mmin;i<=mmax;i++)
00858   {
00859     (*this)(i) = (x(ii++));
00860   }
00861 }
00862 // *****************************************************************
00863 // *****************************************************************
00864 // *****************************************************************
00865 
00870 funnel_init_bounded_df1b2vector::funnel_init_bounded_df1b2vector(
00871   const df1b2_init_bounded_vector& _x)
00872 {
00873   ADUNCONST(df1b2_init_bounded_vector,x)
00874   //type=0;
00875   //pointer=0;
00876   p=&_x;
00877   int mmin=x.indexmin();
00878   int mmax=x.indexmax();
00879   int ind_index = x(mmin).get_ind_index();
00880   if (ind_index<0)
00881   {
00882     add_to_inactive_list();
00883   }
00884   else
00885   {
00886     add_to_list();
00887   }
00888   df1b2variable::noallocate=1;
00889   df1b2vector::allocate(mmin,mmax);
00890   df1b2variable::noallocate=0;
00891 }
00892 
00897 int funnel_init_bounded_df1b2vector::nvar_calc(void)
00898 {
00899   return p->indexmax()-p->indexmin()+1;
00900 }
00901 
00906 void funnel_init_bounded_df1b2vector::xinit(init_df1b2vector& y,int& ii)
00907 {
00908   df1b2_init_bounded_vector * vp = (df1b2_init_bounded_vector *) p;
00909   int mmin=p->indexmin();
00910   int mmax=p->indexmax();
00911   int i;
00912   for (i=mmin;i<=mmax;i++)
00913   {
00914     y(ii)= value((*vp)(i));
00915     ii++;
00916   }
00917 }
00918 
00923 void funnel_init_bounded_df1b2vector::set_index(imatrix& y,int& ii)
00924 {
00925   int mmin=p->indexmin();
00926   int mmax=p->indexmax();
00927   int i;
00928   for (i=mmin;i<=mmax;i++)
00929   {
00930     y(ii,1)= ( *(df1b2_init_bounded_vector *)(p) )(i).get_ind_index();
00931     y(ii,2)= ii;
00932     ii++;
00933   }
00934 }
00935 
00940 void funnel_init_bounded_df1b2vector::set_value(const init_df1b2vector& _x,
00941   const int& _ii,const df1b2variable& _pen)
00942 {
00943   ADUNCONST(int,ii)
00944   ADUNCONST(init_df1b2vector,x)
00945   df1b2_init_bounded_vector * vp = (df1b2_init_bounded_vector *) p;
00946   int mmin=p->indexmin();
00947   int mmax=p->indexmax();
00948   int i;
00949   for (i=mmin;i<=mmax;i++)
00950   {
00951     (*this)(i) = (x(ii++));
00952     if (!initial_params::straight_through_flag)
00953     {
00954       // df1b2variable& tmp = boundp(x(ii++),b.getminb(),b.getmaxb(),pen);
00955       // df1b2variable::operator = (tmp);
00956       (*this)(i) = (boundp(x(ii++),vp->getminb(),vp->getmaxb()));
00957     }
00958     else
00959     {
00960       (*this)(i) = (x(ii));
00961       *((*this)(i).get_u()) =
00962         boundp(*(x(ii++).get_u()),vp->getminb(),vp->getmaxb());
00963     }
00964   }
00965 }