ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2loc.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 <df1b2loc.h>
00013 
00018   int operator >= (const double& x,const df1b2variable& y)
00019   {
00020     if (x>=value(y))
00021       return 1;
00022     else
00023       return 0;
00024   }
00025 
00030   int operator >= (double x,const df1b2variable& y)
00031   {
00032     if (value(x)>=value(y))
00033       return 1;
00034     else
00035       return 0;
00036   }
00037 
00042   int operator >= (const df1b2variable& x,double y)
00043   {
00044     if (value(x)>=y)
00045       return 1;
00046     else
00047       return 0;
00048   }
00049 
00054   int operator > (const double& x,const df1b2variable& y)
00055   {
00056     if (x>value(y))
00057       return 1;
00058     else
00059       return 0;
00060   }
00061 
00066   int operator > (double x,const df1b2variable& y)
00067   {
00068     if (value(x)>value(y))
00069       return 1;
00070     else
00071       return 0;
00072   }
00073 
00078   int operator > (const df1b2variable& x,double y)
00079   {
00080     if (value(x)>y)
00081       return 1;
00082     else
00083       return 0;
00084   }
00085 
00090   int operator <= (const double& x,const df1b2variable& y)
00091   {
00092     if (x<=value(y))
00093       return 1;
00094     else
00095       return 0;
00096   }
00097 
00102   int operator <= (double x,const df1b2variable& y)
00103   {
00104     if (value(x)<=value(y))
00105       return 1;
00106     else
00107       return 0;
00108   }
00109 
00114   int operator <= (const df1b2variable& x,double y)
00115   {
00116     if (value(x)<=y)
00117       return 1;
00118     else
00119       return 0;
00120   }
00121 
00126   int operator < (const double& x,const df1b2variable& y)
00127   {
00128     if (x<value(y))
00129       return 1;
00130     else
00131       return 0;
00132   }
00133 
00138   int operator < (double x,const df1b2variable& y)
00139   {
00140     if (value(x)<value(y))
00141       return 1;
00142     else
00143       return 0;
00144   }
00145 
00150   int operator < (const df1b2variable& x,double y)
00151   {
00152     if (value(x)<y)
00153       return 1;
00154     else
00155       return 0;
00156   }
00157 
00162   int operator == (const double& x,const df1b2variable& y)
00163   {
00164     if (x==value(y))
00165       return 1;
00166     else
00167       return 0;
00168   }
00169 
00174   int operator == (double x,const df1b2variable& y)
00175   {
00176     if (value(x)==value(y))
00177       return 1;
00178     else
00179       return 0;
00180   }
00181 
00186   int operator == (const df1b2variable& x,double y)
00187   {
00188     if (value(x)==y)
00189       return 1;
00190     else
00191       return 0;
00192   }
00193 
00198 df1b2vector posfun(const df1b2vector& x,double eps,
00199   const df1b2variable& _pen)
00200 {
00201   int mmin=x.indexmin();
00202   int mmax=x.indexmax();
00203   df1b2vector tmp(mmin,mmax);
00204   for (int i=mmin;i<=mmax;i++)
00205   {
00206     tmp(i)=posfun(x(i),eps,_pen);
00207   }
00208   return tmp;
00209 }
00210 
00215 df1b2variable posfun(const df1b2variable&x,const double eps,
00216   const df1b2variable& _pen)
00217 {
00218   df1b2variable& pen= (df1b2variable&) _pen;
00219   if (x>=eps)
00220   {
00221     return x;
00222   }
00223   else
00224   {
00225     pen+=.01*square(x-eps);
00226     return eps/(2-x/eps);
00227   }
00228 }
00229 
00234 df1b2variable dfposfun(const df1b2variable&x,const double eps)
00235 {
00236   if (x>=eps)
00237   {
00238     return 1;
00239   }
00240   else
00241   {
00242     //double z=eps/(2-x/eps);
00243     df1b2variable dfx=1.0/square(2-x/eps);
00244     return dfx;
00245   }
00246 }
00247 
00252 df1b2variable posfun(const df1b2variable&x,const double eps)
00253 {
00254   if (x>=eps)
00255   {
00256     return x;
00257   }
00258   else
00259   {
00260     return eps/(2-x/eps);
00261   }
00262 }
00263 
00268 df1b2variable posfun2(const df1b2variable&x,const double eps,
00269   const df1b2variable& _pen)
00270 {
00271   df1b2variable& pen= (df1b2variable&) _pen;
00272   if (x>=eps)
00273   {
00274     return x;
00275   }
00276   else
00277   {
00278     df1b2variable y=eps-x;
00279     df1b2variable  tmp=y/eps;
00280     df1b2variable  tmp2=tmp*tmp;
00281     df1b2variable  tmp3=tmp2*tmp;
00282     pen+=.01*tmp3;
00283     return eps/(1.0+tmp+tmp2+tmp3);
00284   }
00285 }