ARMLambda.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: ARMLambda.cpp 2620 2011-05-26 14:42:13Z yanweignss $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Wei Yan - Chinese Academy of Sciences . 2011
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       // TODO: CHECK UNEXPECTED INPUT
00044       // n - number of float parameters
00045       // m - number of fixed solutions
00046       // L - nxn
00047       // D - nx1
00048       // zs - nxn
00049       // zn - nxm
00050       // s  - m
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    }  // End of method 'ARMLambda::search()'
00132    
00133 
00134 }   // End of namespace gpstk
00135 

Generated on Tue May 22 03:30:56 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1