00001 #pragma ident "$Id: ARMLambda.cpp 2620 2011-05-26 14:42:13Z yanweignss $"
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "ARMLambda.hpp"
00031
00032
00033 namespace gpstk
00034 {
00035
00036 int ARMLambda::search( const Matrix<double>& L,
00037 const Vector<double>& D,
00038 const Vector<double>& zs,
00039 Matrix<double>& zn,
00040 Vector<double>& s,
00041 const int& m )
00042 {
00043
00044
00045
00046
00047
00048
00049
00050
00051 const int LOOPMAX = 10000;
00052 const int n = L.rows();
00053
00054 zn.resize(n,m,0.0);
00055 s.resize(m,0.0);
00056
00057 Matrix<double> S(n,n,0.0);
00058 Vector<double> dist(n,0.0),zb(n,0.0),z(n,0.0),step(n,0.0);
00059
00060 int k=n-1; dist[k]=0.0;
00061 zb(k)=zs(k);
00062 z(k)=round(zb(k));
00063 double y=zb(k)-z(k);
00064 step(k)=sign(y);
00065
00066 int c(0),nn(0),imax(0);
00067 double maxdist=1E99;
00068 for(int c=0;c<LOOPMAX;c++)
00069 {
00070 double newdist=dist(k)+y*y/D(k);
00071 if(newdist<maxdist)
00072 {
00073 if(k!=0)
00074 {
00075 dist(--k)=newdist;
00076 for(int i=0;i<=k;i++)
00077 {
00078 S(k,i)=S(k+1,i)+(z(k+1)-zb(k+1))*L(k+1,i);
00079 }
00080 zb(k)=zs(k)+S(k,k);
00081 z(k)=round(zb(k)); y=zb(k)-z(k); step(k)=sign(y);
00082 }
00083 else
00084 {
00085 if(nn<m)
00086 {
00087 if(nn==0||newdist>s(imax)) imax=nn;
00088 for(int i=0;i<n;i++) zn(i,nn)=z(i);
00089 s(nn++)=newdist;
00090 }
00091 else
00092 {
00093 if(newdist<s(imax))
00094 {
00095 for(int i=0;i<n;i++) zn(i,imax)=z(i);
00096 s(imax)=newdist;
00097 for(int i=imax=0;i<m;i++) if (s(imax)<s(i)) imax=i;
00098 }
00099 maxdist=s(imax);
00100 }
00101 z(0)+=step(0); y=zb(0)-z(0); step(0)=-step(0)-sign(step(0));
00102 }
00103 }
00104 else
00105 {
00106 if(k==n-1) break;
00107 else
00108 {
00109 k++;
00110 z(k)+=step(k); y=zb(k)-z(k); step(k)=-step(k)-sign(step(k));
00111 }
00112 }
00113 }
00114 for(int i=0;i<m-1;i++)
00115 {
00116 for(int j=i+1;j<m;j++)
00117 {
00118 if(s(i)<s(j)) continue;
00119 swap(s(i),s(j));
00120 for(k=0;k<n;k++) swap(zn(k,i),zn(k,j));
00121 }
00122 }
00123
00124 if (c>=LOOPMAX)
00125 {
00126 return -1;
00127 }
00128
00129 return 0;
00130
00131 }
00132
00133
00134 }
00135