EquationSystem.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: EquationSystem.cpp 2939 2011-10-23 19:55:11Z 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 //  Dagoberto Salazar - gAGE ( http://www.gage.es ). 2009
00027 //
00028 //============================================================================
00029 
00030 
00031 #include "EquationSystem.hpp"
00032 #include <iterator>
00033 
00034 namespace gpstk
00035 {
00036 
00037 
00038 
00039       // General white noise stochastic model
00040    WhiteNoiseModel EquationSystem::whiteNoiseModel;
00041 
00042 
00043 
00044       /* Add a new equation to be managed.
00045        *
00046        * @param equation   Equation object to be added.
00047        *
00048        */
00049    EquationSystem& EquationSystem::addEquation( const Equation& equation )
00050    {
00051 
00052          // Add "equation" to "equationDescriptionList"
00053       equationDescriptionList.push_back(equation);
00054 
00055          // We must "Prepare()" this EquationSystem
00056       isPrepared = false;
00057 
00058       return (*this);
00059 
00060    }  // End of method 'EquationSystem::addEquation()'
00061 
00062 
00063 
00064       /* Remove an Equation being managed. In this case the equation is
00065        * identified by its independent term.
00066        *
00067        * @param indterm  Variable object of the equation independent term
00068        *                 (measurement type).
00069        *
00070        * \warning All Equations with the same independent term will be
00071        *          erased.
00072        */
00073    EquationSystem& EquationSystem::removeEquation( const Variable& indterm )
00074    {
00075 
00076          // Create a backup list
00077       std::list<Equation> backupList;
00078 
00079          // Visit each "Equation" in "equationDescriptionList"
00080       for( std::list<Equation>::const_iterator itEq =
00081                                                 equationDescriptionList.begin();
00082            itEq != equationDescriptionList.end();
00083            ++itEq )
00084       {
00085 
00086             // If current equation has a different independent term, save it
00087          if ( (*itEq).getIndependentTerm() != indterm )
00088          {
00089             backupList.push_back(*itEq);
00090          }
00091 
00092       }
00093 
00094          // Clear the full contents of this object
00095       clearEquations();
00096 
00097          // Add each "Equation" in the backup equation list
00098       for( std::list<Equation>::const_iterator itEq = backupList.begin();
00099            itEq != backupList.end();
00100            ++itEq )
00101       {
00102          addEquation(*itEq);
00103       }
00104 
00105          // We must "Prepare()" this EquationSystem again
00106       isPrepared = false;
00107 
00108       return (*this);
00109 
00110    }  // End of method 'EquationSystem::removeEquation()'
00111 
00112 
00113 
00114       // Remove all Equation objects from this EquationSystem.
00115    EquationSystem& EquationSystem::clearEquations()
00116    {
00117          // First, clear the "equationDescriptionList"
00118       equationDescriptionList.clear();
00119 
00120       isPrepared = false;
00121 
00122       return (*this);
00123 
00124    }  // End of method 'EquationSystem::clearEquations()'
00125 
00126 
00127 
00128       /* Prepare this object to carry out its work.
00129        *
00130        * @param gData   GNSS data structure (GDS).
00131        *
00132        */
00133    EquationSystem& EquationSystem::Prepare( gnssRinex& gData )
00134    {
00135 
00136          // First, create a temporary gnssDataMap
00137       gnssDataMap myGDSMap;
00138 
00139          // Get gData into myGDSMap
00140       myGDSMap.addGnssRinex( gData );
00141 
00142          // Call the map-enabled method, and return the result
00143       return (Prepare(myGDSMap));
00144 
00145    }  // End of method 'EquationSystem::Prepare()'
00146 
00147 
00148 
00149       /* Prepare this object to carry out its work.
00150        *
00151        * @param gdsMap     Map of GNSS data structures (GDS), indexed
00152        *                   by SourceID.
00153        *
00154        */
00155    EquationSystem& EquationSystem::Prepare( gnssDataMap& gdsMap )
00156    {
00157 
00158          // Let's start storing 'current' unknowns set from 'previous' epoch
00159       oldUnknowns = currentUnknowns;
00160 
00161          // Former currentUnknowns will belong to global unknowns set
00162       varUnknowns = currentUnknowns;
00163 
00164          // Prepare set of current unknowns and list of current equations
00165       currentUnknowns = prepareCurrentUnknownsAndEquations(gdsMap);
00166 
00167         // Backup all unknowns and delete not type indexed variable in the 'currentUnknowns'
00168       allUnknowns.clear();
00169       for(VariableSet::const_iterator it = currentUnknowns.begin();
00170           it != currentUnknowns.end();
00171           it++)
00172       { allUnknowns.push_back(*it); }
00173       
00174       currentUnknowns.clear();
00175       rejectUnknowns.clear();
00176       for(std::list<Variable>::const_iterator it = allUnknowns.begin();
00177           it != allUnknowns.end();
00178           it++)
00179       {
00180            if((*it).getTypeIndexed())
00181            {
00182                currentUnknowns.insert(*it);
00183            }
00184            else
00185            {
00186                rejectUnknowns.insert(*it);
00187            }
00188       }
00189       
00190 
00191          // Now, let's update the global set of unknowns with current unknowns
00192       varUnknowns.insert( currentUnknowns.begin(), currentUnknowns.end() );
00193 
00194          // Compute phiMatrix and qMatrix
00195       getPhiQ(gdsMap);
00196 
00197          // Build prefit residuals vector
00198       getPrefit(gdsMap);
00199 
00200          // Get geometry and weights matrices
00201       getGeometryWeights(gdsMap);
00202 
00203          // Handling the ConstraintSystem
00204       imposeConstraints();
00205       
00206       /*
00207       ofstream debugstrm("unknows.debug");
00208       debugstrm << StringUtils::asString(varUnknowns) << endl;
00209       debugstrm.close();
00210 
00211       debugstrm.open("phiMatrix.debug");
00212       debugstrm << phiMatrix << endl;
00213       debugstrm.close();
00214 
00215       debugstrm.open("qMatrix.debug");
00216       debugstrm << qMatrix << endl;
00217       debugstrm.close();
00218 
00219       debugstrm.open("rMatrix.debug");
00220       debugstrm << rMatrix << endl;
00221       debugstrm.close();
00222 
00223       debugstrm.open("measVector.debug");
00224       debugstrm<<measVector<<endl;
00225       debugstrm.close();
00226 
00227       debugstrm.open("hMatrix.debug");
00228       debugstrm<<hMatrix<<endl;
00229       debugstrm.close();
00230       */
00231 
00232          // Set this object as "prepared"
00233       isPrepared = true;
00234 
00235       return (*this);
00236 
00237    }  // End of method 'EquationSystem::Prepare()'
00238 
00239 
00240 
00241       // Get current sources (SourceID's) and satellites (SatID's)
00242    void EquationSystem::prepareCurrentSourceSat( gnssDataMap& gdsMap )
00243    {
00244 
00245          // Clear "currentSatSet" and "currentSourceSet"
00246       currentSatSet.clear();
00247       currentSourceSet.clear();
00248 
00249          // Insert the corresponding SatID's in "currentSatSet"
00250       currentSatSet = gdsMap.getSatIDSet();
00251 
00252          // Insert the corresponding SourceID's in "currentSourceSet"
00253       currentSourceSet = gdsMap.getSourceIDSet();
00254 
00255          // Let's return
00256       return;
00257 
00258    }  // End of method 'EquationSystem::prepareCurrentSourceSat()'
00259 
00260 
00261 
00262       // Prepare set of current unknowns and list of current equations
00263    VariableSet EquationSystem::prepareCurrentUnknownsAndEquations(
00264                                                          gnssDataMap& gdsMap )
00265    {
00266 
00267          // Let's clear the current equations list
00268       currentEquationsList.clear();
00269 
00270          // Let's create 'currentUnkSet' set
00271       VariableSet currentUnkSet;
00272 
00273          // Get "currentSatSet" and "currentSourceSet"
00274          // and stored in currentSourceSet and currentSatSet
00275       prepareCurrentSourceSat( gdsMap );
00276 
00277 
00278          // Visit each "Equation" in "equationDescriptionList"
00279       for( std::list<Equation>::const_iterator itEq =
00280                                                 equationDescriptionList.begin();
00281            itEq != equationDescriptionList.end();
00282            ++itEq )
00283       {
00284 
00285             // First, get the SourceID set for this equation description
00286          SourceIDSet equSourceSet;
00287 
00288             // Check if current equation description is valid for all sources
00289          if ( (*itEq).getEquationSource() == Variable::allSources )
00290          {
00291             equSourceSet = currentSourceSet;
00292          }
00293          else
00294          {
00295 
00296                // Check if equation description is valid for some sources
00297             if ( (*itEq).getEquationSource() == Variable::someSources )
00298             {
00299 
00300                   // We have to find the intersection between equation
00301                   // description SourceID's and available SourceID's.
00302                SourceIDSet tempSourceSet( (*itEq).getSourceSet() );
00303 
00304                   // Declare an 'insert_iterator' to be used by
00305                   // 'set_intersection' algorithm (provided by STL)
00306                std::insert_iterator< SourceIDSet >
00307                                  itOut( equSourceSet, equSourceSet.begin() );
00308 
00309                   // Let's intersect both sets
00310                set_intersection( tempSourceSet.begin(), tempSourceSet.end(),
00311                               currentSourceSet.begin(), currentSourceSet.end(),
00312                               itOut );
00313 
00314             }
00315             else
00316             {
00317                   // In this case, we take directly the source into the
00318                   // equation source set
00319                equSourceSet.insert( (*itEq).getEquationSource() );
00320             }
00321 
00322          }  // End of 'if ( (*itEq).getEquationSource() == ...'
00323          
00324             // Second, get the SatID set for this equation description
00325          SatIDSet equSatSet = (*itEq).getSatSet();
00326          
00327 
00328             // We have the SourceID set that is applicable to this
00329             // equation description.
00330 
00331             // Now we must get the satellites visible from each
00332             // particular SourceID
00333          for( SourceIDSet::const_iterator itSource = equSourceSet.begin();
00334               itSource != equSourceSet.end();
00335               ++itSource )
00336          {
00337 
00338                // Get visible satellites from this SourceID
00339             SatIDSet visibleSatSet;
00340 
00341                // Iterate through all items in the gnssDataMap
00342             for( gnssDataMap::const_iterator it = gdsMap.begin();
00343                  it != gdsMap.end();
00344                  ++it )
00345             {
00346 
00347                   // Look for current SourceID
00348                sourceDataMap::const_iterator sdmIter(
00349                                              (*it).second.find( (*itSource) ) );
00350 
00351                   // If SourceID was found, then look for satellites
00352                if( sdmIter != (*it).second.end() )
00353                {
00354 
00355                      // Iterate through corresponding 'satTypeValueMap'
00356                   for( satTypeValueMap::const_iterator stvmIter =
00357                                                       (*sdmIter).second.begin();
00358                        stvmIter != (*sdmIter).second.end();
00359                        stvmIter++ )
00360                   {
00361                         // for some sat   
00362                      if((equSatSet.size() > 0)                           &&
00363                         (equSatSet.find((*stvmIter).first) == equSatSet.end()))
00364                      {
00365                         continue;
00366                      }
00367 
00368                         // Add current SatID to 'visibleSatSet'
00369                      visibleSatSet.insert( (*stvmIter).first );
00370 
00371                   }  // End of 'for( satTypeValueMap::const_iterator ...'
00372 
00373                }  // End of 'for( sourceDataMap::const_iterator sdmIter = ...'
00374 
00375             }  // End of 'for( gnssDataMap::const_iterator it = ...'
00376 
00377                // We have the satellites visible from this SourceID
00378 
00379                
00380                // We need a copy of current Equation object description
00381             Equation tempEquation( (*itEq) );
00382 
00383                // Remove all variables from current equation
00384             tempEquation.clear();
00385 
00386                // Update equation independent term with SourceID information
00387             tempEquation.header.equationSource = (*itSource);
00388 
00389                // Now, let's visit all Variables in this equation description
00390             for( VariableSet::const_iterator itVar = (*itEq).body.begin();
00391                  itVar != (*itEq).body.end();
00392                  ++itVar )
00393             {
00394 
00395                   // We will work with a copy of current Variable
00396                Variable var( (*itVar) );
00397 
00398                   // Check what type of variable we are working on
00399 
00400                   // If variable is source-indexed, set SourceID
00401                if( var.getSourceIndexed() )
00402                {
00403                   var.setSource( (*itSource) );
00404                }
00405 
00406                   // Add this variable to current equation description. Please
00407                   // be aware that satellite-indexed variables inside current
00408                   // equations will be handled later
00409                tempEquation.addVariable(var);
00410 
00411                   // If variable is not satellite-indexed, we just need to
00412                   // add it to "currentUnkSet
00413                if( !var.getSatIndexed() )
00414                {
00415                      // Insert the result in "currentUnkSet" and
00416                      // current equation
00417                   currentUnkSet.insert(var);
00418                   //tempEquation.addVariable(var);
00419                }
00420                else
00421                {
00422                      // If variable IS satellite-indexed, we have to visit all
00423                      // visible satellites (from current SourceID) and set the
00424                      // satellite before adding variable to "currentUnkSet
00425                   for( SatIDSet::const_iterator itSat = visibleSatSet.begin();
00426                        itSat != visibleSatSet.end();
00427                        ++itSat )
00428                   {
00429 
00430                         // Set satellite
00431                      var.setSatellite( (*itSat) );
00432 
00433                         // Insert the result in "currentUnkSet" and
00434                         // current equation
00435                      currentUnkSet.insert(var);
00436                   }
00437 
00438                }  // End of 'if( !var.getSatIndexed() )...'
00439 
00440             }  // End of 'for( VariableSet::const_iterator itVar = ...'
00441 
00442 
00443                // Let's generate the current equations starting from this
00444                // equation description. Therefore, we update equation
00445                // independent term with SatID information and add each instance
00446                // to 'currentEquationsList'.
00447             for( SatIDSet::const_iterator itSat = visibleSatSet.begin();
00448                  itSat != visibleSatSet.end();
00449                  ++itSat )
00450             {
00451                tempEquation.header.equationSat = (*itSat);
00452 
00453                   // New equation is complete: Add it to 'currentEquationsList'
00454                currentEquationsList.push_back( tempEquation );
00455             }
00456 
00457          }  // End of 'for( SourceIDSet::const_iterator itSource = ...'
00458 
00459       }  // End of 'for( std::list<Equation>::const_iterator itEq = ...'
00460 
00461 
00462          // Now we will take care of satellite-indexed variables inside each
00463          // specific "Equation" in "currentEquationsList"
00464       int eqListSize( currentEquationsList.size() );
00465       for( int i = 0; i < eqListSize; ++i )
00466       {
00467 
00468             // Get a copy of first equation on 'currentEquationsList'
00469          Equation tempEqu( currentEquationsList.front() );
00470 
00471             // Remove the original equation at the beginning of the list.
00472          currentEquationsList.pop_front();
00473 
00474             // Get a copy of variables inside this equation
00475          VariableSet varSet( tempEqu.body );
00476 
00477             // Clear the variables from this equation
00478          tempEqu.clear();
00479 
00480             // Visit each variable inside 'varSet', check if it is
00481             // satellite-indexed, and add it to equation
00482          for( VariableSet::iterator itVar = varSet.begin();
00483               itVar != varSet.end();
00484               ++itVar )
00485          {
00486 
00487                // Check if it is satellite-indexed
00488             if( !(*itVar).getSatIndexed() )
00489             {
00490                   // If not satellite-indexed, just add it back
00491                tempEqu.addVariable( (*itVar) );
00492             }
00493             else
00494             {
00495                // If 'itVar' is satellite-indexed, let's index a copy of it
00496                // and add it to equation
00497                Variable var( (*itVar) );
00498                var.setSatellite( tempEqu.header.equationSat );
00499 
00500                tempEqu.addVariable( var );
00501             }
00502 
00503          }  // End of 'for( VariableSet::iterator itVar = varSet.begin(); ...'
00504 
00505             // Our equation is ready, let's add it to the end of the list
00506          currentEquationsList.push_back( tempEqu );
00507 
00508       }  // End of 'for( int i = 0; i < eqListSize; ++i ) ...'
00509 
00510 
00511          // Return set of current unknowns
00512       return currentUnkSet;
00513 
00514    }  // End of method 'EquationSystem::prepareCurrentUnknownsAndEquations()'
00515 
00516 
00517 
00518       // Compute PhiMatrix
00519    void EquationSystem::getPhiQ( const gnssDataMap& gdsMap )
00520    {
00521 
00522       const int numVar( varUnknowns.size() );
00523 
00524          // Resize phiMatrix and qMatrix
00525       phiMatrix.resize( numVar, numVar, 0.0);
00526       qMatrix.resize( numVar, numVar, 0.0);
00527 
00528          // Set a counter
00529       int i(0);
00530 
00531          // Visit each "Variable" inside "varUnknowns"
00532       for( VariableSet::const_iterator itVar  = varUnknowns.begin();
00533            itVar != varUnknowns.end();
00534            ++itVar )
00535       {
00536 
00537             // Check if (*itVar) is inside 'currentUnknowns'
00538          if( currentUnknowns.find( (*itVar) ) != currentUnknowns.end() )
00539          {
00540 
00541                // Get a 'gnssRinex' data structure
00542             gnssRinex gRin( gdsMap.getGnssRinex( (*itVar).getSource() ) );
00543 
00544                // Prepare variable's stochastic model
00545             (*itVar).getModel()->Prepare( (*itVar).getSatellite(),
00546                                           gRin );
00547 
00548                // Now, check if this is an 'old' variable
00549             if( oldUnknowns.find( (*itVar) ) != oldUnknowns.end() )
00550             {
00551                   // This variable is 'old'; compute its phi and q values
00552                phiMatrix(i,i) = (*itVar).getModel()->getPhi();
00553                qMatrix(i,i)   = (*itVar).getModel()->getQ();
00554             }
00555             else
00556             {
00557                   // This variable is 'new', so let's use its initial variance
00558                   // instead of its stochastic model
00559                phiMatrix(i,i) = 0.0;
00560                qMatrix(i,i)   = (*itVar).getInitialVariance();
00561             }
00562 
00563          }
00564          else
00565          {
00566                // If (*itVar) is NOT inside 'currentUnknowns', then apply it
00567                // a white noise stochastic model to decorrelate it
00568             phiMatrix(i,i) = whiteNoiseModel.getPhi();
00569             qMatrix(i,i)   = whiteNoiseModel.getQ();
00570          }
00571 
00572             // Increment counter
00573          ++i;
00574       }
00575 
00576 
00577       return;
00578 
00579    }  // End of method 'EquationSystem::getPhiQ()'
00580 
00581 
00582 
00583       // Compute prefit residuals vector
00584    void EquationSystem::getPrefit( gnssDataMap& gdsMap )
00585    {
00586 
00587          // Declare temporal storage for values
00588       std::vector<double> tempPrefit;
00589 
00590          // Visit each Equation in "currentEquationsList"
00591       for( std::list<Equation>::const_iterator itEq =
00592                                                    currentEquationsList.begin();
00593            itEq != currentEquationsList.end();
00594            ++itEq )
00595       {
00596 
00597             // Store SourceID, SatID and TypeID of current equation
00598          tempPrefit.push_back( gdsMap.getValue( (*itEq).header.equationSource,
00599                                           (*itEq).header.equationSat,
00600                                           (*itEq).header.indTerm.getType() ) );
00601 
00602 
00603       }  // End of 'for( std::list<Equation>::const_iterator itEq = ...'
00604 
00605          // Then, finally get prefit residuals into appropriate gpstk::Vector
00606       measVector = tempPrefit;
00607 
00608       return;
00609 
00610    }  // End of method 'EquationSystem::getPrefit()'
00611 
00612 
00613 
00614       // Compute hMatrix and rMatrix
00615    void EquationSystem::getGeometryWeights( gnssDataMap& gdsMap )
00616    {
00617 
00618          // Resize hMatrix and rMatrix
00619       hMatrix.resize( measVector.size(), varUnknowns.size(), 0.0);
00620       rMatrix.resize( measVector.size(),  measVector.size(), 0.0);
00621 
00622          // Let's work with the first element of the data structure
00623       gnssDataMap gds2( gdsMap.frontEpoch() );
00624 
00625          // Let's fill weights and geometry matrices
00626       int row(0);                      // Declare a counter for row number
00627       for( std::list<Equation>::const_iterator itRow =
00628                                                    currentEquationsList.begin();
00629            itRow != currentEquationsList.end();
00630            ++itRow )
00631       {
00632 
00633             // Create temporal GDS objects
00634          SourceID source( (*itRow).header.equationSource );
00635          SatID sat( (*itRow).header.equationSat );
00636 
00637             // Get a TypeIDSet with all the data types present in current GDS
00638             // Declare an appropriate object
00639          TypeIDSet typeSet;
00640 
00641             // We need a flag
00642          bool found( false );
00643 
00644             // Iterate through data structure
00645          for( gnssDataMap::const_iterator itGDS = gds2.begin();
00646               itGDS != gds2.end() && !found;
00647               ++itGDS )
00648          {
00649                // Look for source
00650             sourceDataMap::const_iterator itSDM = (*itGDS).second.find(source);
00651             if( itSDM != (*itGDS).second.end() )
00652             {
00653                   // Get the types
00654                typeSet = (*itSDM).second.getTypeID();
00655                found = true;
00656             }
00657          }
00658 
00659 
00660             // First, fill weights matrix
00661             // Check if current GDS has weight info. If you don't want those
00662             // weights to get into equations, please don't put them in GDS
00663          if( typeSet.find(TypeID::weight) != typeSet.end() )
00664          {
00665                // Weights matrix = Equation weight * observation weight
00666             rMatrix(row,row) = (*itRow).header.constWeight
00667                                * gds2.getValue(source, sat, TypeID::weight);
00668          }
00669          else
00670          {
00671                // Weights matrix = Equation weight
00672             rMatrix(row,row) = (*itRow).header.constWeight;
00673          }
00674 
00675             // Second, fill geometry matrix: Look for equation coefficients
00676          int col(0);                   // Declare a counter for column number
00677          for( VariableSet::const_iterator itCol = varUnknowns.begin();
00678               itCol != varUnknowns.end();
00679               ++itCol )
00680          {
00681 
00682                // Check if unknown is in current equation and also is marked
00683                // as a current unknown
00684             if( (*itRow).body.find( (*itCol) ) != (*itRow).body.end() &&
00685                 currentUnknowns.find( (*itCol) ) != currentUnknowns.end() )
00686             {
00687 
00688                   // Check if '(*itCol)' unknown variable enforces a specific
00689                   // coefficient
00690                if( (*itCol).isDefaultForced() )
00691                {
00692                      // Use default coefficient
00693                   hMatrix(row,col) = (*itCol).getDefaultCoefficient();
00694                }
00695                else
00696                {
00697                      // Look the coefficient in provided data
00698 
00699                      // Get type of current varUnknown
00700                   TypeID type( (*itCol).getType() );
00701 
00702                      // Check if this type has an entry in current GDS type set
00703                   if( typeSet.find(type) != typeSet.end() )
00704                   {
00705                         // If type was found, insert value into hMatrix
00706                      hMatrix(row,col) = gds2.getValue(source, sat, type);
00707                   }
00708                   else
00709                   {
00710                         // If value for current type is not in gdsMap, then
00711                         // insert default coefficient for this variable
00712                      hMatrix(row,col) = (*itCol).getDefaultCoefficient();
00713                   }
00714 
00715                }  // End of 'if( (*itCol).isDefaultForced() ) ...'
00716 
00717             }  // End of 'if( (*itRow).body.find( (*itCol) ) != ...'
00718 
00719                // Increment column counter
00720             ++col;
00721 
00722          }  // End of 'for( VariableSet::const_iterator itCol = ...'
00723 
00724             // Handle type index variable
00725          for( VariableSet::const_iterator itCol = (*itRow).body.begin();
00726              itCol != (*itRow).body.end();
00727              ++itCol )
00728          {
00729 
00730             VariableSet::const_iterator itr = rejectUnknowns.find( (*itCol) );
00731             if( itr == rejectUnknowns.end() || (*itr).getTypeIndexed()) continue;
00732 
00733             Variable var(*itr);
00734 
00735             col = 0;            
00736             for( VariableSet::const_iterator it = varUnknowns.begin(); it != varUnknowns.end(); it++)
00737             {
00738                 if(((*itCol).getType() == (*it).getType())                  &&
00739                    ((*itCol).getModel() == (*it).getModel())                &&
00740                    ((*itCol).getSourceIndexed() == (*it).getSourceIndexed())&&
00741                    ((*itCol).getSatIndexed() == (*it).getSatIndexed())      &&
00742                    ((*itCol).getSource() == (*it).getSource())              &&
00743                    ((*itCol).getSatellite() == (*it).getSatellite())        
00744                    )
00745                 {
00746                     break;
00747                 }
00748 
00749                 col++;    
00750             }
00751 
00752             
00753             // Check if '(*itCol)' unknown variable enforces a specific
00754             // coefficient
00755             if( (*itCol).isDefaultForced() )
00756             {
00757                    // Use default coefficient
00758                 hMatrix(row,col) = (*itCol).getDefaultCoefficient();
00759             }
00760             else
00761             {
00762                 // Look the coefficient in provided data
00763 
00764                    // Get type of current varUnknown
00765                 TypeID type( (*itCol).getType() );
00766 
00767                    // Check if this type has an entry in current GDS type set
00768                 if( typeSet.find(type) != typeSet.end() )
00769                 {
00770                        // If type was found, insert value into hMatrix
00771                     hMatrix(row,col) = gds2.getValue(source, sat, type);
00772                 }
00773                 else
00774                 {
00775                       // If value for current type is not in gdsMap, then
00776                       // insert default coefficient for this variable
00777                     hMatrix(row,col) = (*itCol).getDefaultCoefficient();
00778                 }
00779 
00780             }  // End of 'if( (*itCol).isDefaultForced() ) ...'
00781             
00782          }
00783 
00784             // Increment row number
00785          ++row;
00786 
00787       }  // End of 'std::list<Equation>::const_iterator itRow = ...'
00788 
00789 
00790       return;
00791 
00792    }  // End of method 'EquationSystem::getGeometryWeights()'
00793 
00794 
00795       // Impose the constraints system to the equation system
00796       // the prefit residuals vector, hMatrix and rMatrix will be appended.
00797    void EquationSystem::imposeConstraints()
00798    {
00799       if(!equationConstraints.hasConstraints()) return;
00800       
00801       ConstraintList destList;
00802 
00803       ConstraintList tempList = equationConstraints.getConstraintList();
00804       for(ConstraintList::iterator it = tempList.begin();
00805          it != tempList.end();
00806          ++it )
00807       {
00808          VariableDataMap dataMapOk;
00809 
00810          bool validConstraint(true);
00811 
00812          try
00813          {
00814             VariableDataMap dataMap = it->body;
00815             for(VariableDataMap::iterator itv = dataMap.begin();
00816                itv != dataMap.end();
00817                ++itv )
00818             {
00819                bool isFound(false);
00820                
00821                VariableSet::iterator itv2 = varUnknowns.find(itv->first);
00822                if(itv2!=varUnknowns.end())
00823                {
00824                   isFound = true;
00825                   dataMapOk[*itv2] = dataMap[itv->first];
00826                }
00827                else
00828                {
00829                   for(itv2 = varUnknowns.begin();
00830                      itv2 != varUnknowns.end();
00831                      ++itv2 )
00832                   {
00833                      if( (itv->first.getType() == itv2->getType()) &&
00834                         (itv->first.getSource() == itv2->getSource()) &&
00835                         (itv->first.getSatellite() == itv2->getSatellite()) )
00836                      {
00837                         isFound = true;
00838                         dataMapOk[*itv2] = dataMap[itv->first];
00839                         break;
00840                      }
00841                   }
00842                }
00843 
00844                if( !isFound ) validConstraint = false;
00845             }
00846          }
00847          catch(...)
00848          {
00849             validConstraint = false;
00850          }
00851 
00852          if(validConstraint)
00853          {
00854             destList.push_back(Constraint(it->header,dataMapOk));
00855          }
00856          else
00857          {
00858             // we discard all constraints
00859             return;
00860          }
00861          
00862       }
00863          // Update the equation system
00864       equationConstraints.setConstraintList(destList);
00865 
00866 
00867          // Now, we can append the matrix(prefit design and weight)
00868       try
00869       {
00870          Vector<double> meas;
00871          Matrix<double> design;
00872          Matrix<double> cov;
00873          
00874          equationConstraints.constraintMatrix(varUnknowns,
00875             meas, design, cov);
00876          
00877          const int oldSize = measVector.size();
00878          const int newSize = oldSize + meas.size();
00879          const int colSize = hMatrix.cols();
00880 
00881          Vector<double> tempPrefit(newSize,0.0);
00882          Matrix<double> tempGeometry(newSize,colSize,0.0);
00883          Matrix<double> tempWeight(newSize,newSize,0.0);
00884             
00885          for(int i=0; i< newSize; i++)
00886          {  
00887                // prefit
00888             if(i<oldSize) tempPrefit(i) = measVector(i);
00889             else tempPrefit(i) = meas(i-oldSize);
00890 
00891                // geometry
00892             for(int j=0;j<colSize;j++)
00893             {
00894                if(i<oldSize) tempGeometry(i,j) = hMatrix(i,j);
00895                else tempGeometry(i,j) = design(i-oldSize,j);
00896             }
00897             
00898                // weight
00899             if(i<oldSize) tempWeight(i,i) = rMatrix(i,i);
00900             else tempWeight(i,i) = 1.0/cov(i-oldSize,i-oldSize);
00901             
00902          }
00903             // Update these matrix
00904          measVector = tempPrefit;
00905          hMatrix = tempGeometry;
00906          rMatrix = tempWeight;
00907       }
00908       catch(...)
00909       {
00910          return;
00911       }
00912 
00913    }  // End of method 'EquationSystem::imposeConstraints()'
00914 
00915 
00916       /* Return the TOTAL number of variables being processed.
00917        *
00918        * \warning You must call method Prepare() first, otherwise this
00919        * method will throw an InvalidEquationSystem exception.
00920        */
00921    int EquationSystem::getTotalNumVariables() const
00922       throw(InvalidEquationSystem)
00923    {
00924 
00925          // If the object as not ready, throw an exception
00926       if (!isPrepared)
00927       {
00928          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
00929       }
00930 
00931       return varUnknowns.size();
00932 
00933    }  // End of method 'EquationSystem::getTotalNumVariables()'
00934 
00935 
00936 
00937       /* Return the set containing all variables being processed.
00938        *
00939        * \warning You must call method Prepare() first, otherwise this
00940        * method will throw an InvalidEquationSystem exception.
00941        */
00942    VariableSet EquationSystem::getVarUnknowns() const
00943       throw(InvalidEquationSystem)
00944    {
00945 
00946          // If the object as not ready, throw an exception
00947       if (!isPrepared)
00948       {
00949          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
00950       }
00951 
00952       return varUnknowns;
00953 
00954    }  // End of method 'EquationSystem::getVarUnknowns()'
00955 
00956 
00957 
00958       /* Return the CURRENT number of variables, given the current equation
00959        * system definition and the GDS's involved.
00960        *
00961        * \warning You must call method Prepare() first, otherwise this
00962        * method will throw an InvalidEquationSystem exception.
00963        */
00964    int EquationSystem::getCurrentNumVariables() const
00965       throw(InvalidEquationSystem)
00966    {
00967 
00968          // If the object as not ready, throw an exception
00969       if (!isPrepared)
00970       {
00971          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
00972       }
00973 
00974       return currentUnknowns.size();
00975 
00976    }  // End of method 'EquationSystem::getCurrentNumVariables()'
00977 
00978 
00979 
00980       /* Return the set containing variables being currently processed.
00981        *
00982        * \warning You must call method Prepare() first, otherwise this
00983        * method will throw an InvalidEquationSystem exception.
00984        */
00985    VariableSet EquationSystem::getCurrentUnknowns() const
00986       throw(InvalidEquationSystem)
00987    {
00988 
00989          // If the object as not ready, throw an exception
00990       if (!isPrepared)
00991       {
00992          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
00993       }
00994 
00995       return currentUnknowns;
00996 
00997    }  // End of method 'EquationSystem::getCurrentUnknowns()'
00998 
00999 
01000 
01001       /* Return the CURRENT number of sources, given the current equation
01002        * system definition and the GDS's involved.
01003        *
01004        * \warning You must call method Prepare() first, otherwise this
01005        * method will throw an InvalidEquationSystem exception.
01006        */
01007    int EquationSystem::getCurrentNumSources() const
01008       throw(InvalidEquationSystem)
01009    {
01010 
01011          // If the object as not ready, throw an exception
01012       if (!isPrepared)
01013       {
01014          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01015       }
01016 
01017       return currentSourceSet.size();
01018 
01019    }  // End of method 'EquationSystem::getCurrentNumSources()'
01020 
01021 
01022 
01023       /* Return the set containing sources being currently processed.
01024        *
01025        * \warning You must call method Prepare() first, otherwise this
01026        * method will throw an InvalidEquationSystem exception.
01027        */
01028    SourceIDSet EquationSystem::getCurrentSources() const
01029       throw(InvalidEquationSystem)
01030    {
01031 
01032          // If the object as not ready, throw an exception
01033       if (!isPrepared)
01034       {
01035          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01036       }
01037 
01038       return currentSourceSet;
01039 
01040    }  // End of method 'EquationSystem::getCurrentSources()'
01041 
01042 
01043 
01044       /* Return the CURRENT number of satellites, given the current equation
01045        * system definition and the GDS's involved.
01046        *
01047        * \warning You must call method Prepare() first, otherwise this
01048        * method will throw an InvalidEquationSystem exception.
01049        */
01050    int EquationSystem::getCurrentNumSats() const
01051       throw(InvalidEquationSystem)
01052    {
01053 
01054          // If the object as not ready, throw an exception
01055       if (!isPrepared)
01056       {
01057          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01058       }
01059 
01060       return currentSatSet.size();
01061 
01062    }  // End of method 'EquationSystem::getCurrentNumSats()'
01063 
01064 
01065 
01066       /* Return the set containing satellites being currently processed.
01067        *
01068        * \warning You must call method Prepare() first, otherwise this
01069        * method will throw an InvalidEquationSystem exception.
01070        */
01071    SatIDSet EquationSystem::getCurrentSats() const
01072       throw(InvalidEquationSystem)
01073    {
01074 
01075          // If the object as not ready, throw an exception
01076       if (!isPrepared)
01077       {
01078          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01079       }
01080 
01081       return currentSatSet;
01082 
01083    }  // End of method 'EquationSystem::getCurrentSats()'
01084 
01085 
01086 
01087       /* Get prefit residuals GPSTk Vector, given the current equation
01088        *  system definition and the GDS' involved.
01089        *
01090        * \warning You must call method Prepare() first, otherwise this
01091        * method will throw an InvalidEquationSystem exception.
01092        */
01093    Vector<double> EquationSystem::getPrefitsVector() const
01094       throw(InvalidEquationSystem)
01095    {
01096 
01097          // If the object as not ready, throw an exception
01098       if (!isPrepared)
01099       {
01100          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01101       }
01102 
01103       return measVector;
01104 
01105    }  // End of method 'EquationSystem::getPrefitsVector()'
01106 
01107 
01108 
01109       /* Get geometry matrix, given the current equation system definition
01110        *  and the GDS' involved.
01111        *
01112        * \warning You must call method Prepare() first, otherwise this
01113        * method will throw an InvalidEquationSystem exception.
01114        */
01115    Matrix<double> EquationSystem::getGeometryMatrix() const
01116       throw(InvalidEquationSystem)
01117    {
01118 
01119          // If the object as not ready, throw an exception
01120       if (!isPrepared)
01121       {
01122          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01123       }
01124 
01125       return hMatrix;
01126 
01127    }  // End of method 'EquationSystem::getGeometryMatrix()'
01128 
01129 
01130 
01131       /* Get weights matrix, given the current equation system definition
01132        *  and the GDS' involved.
01133        *
01134        * \warning You must call method Prepare() first, otherwise this
01135        * method will throw an InvalidEquationSystem exception.
01136        */
01137    Matrix<double> EquationSystem::getWeightsMatrix() const
01138       throw(InvalidEquationSystem)
01139    {
01140 
01141          // If the object as not ready, throw an exception
01142       if (!isPrepared)
01143       {
01144          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01145       }
01146 
01147       return rMatrix;
01148 
01149    }  // End of method 'EquationSystem::getWeightsMatrix()'
01150 
01151 
01152       /* Get the State Transition Matrix (PhiMatrix), given the current
01153        * equation system definition and the GDS' involved.
01154        *
01155        * \warning You must call method Prepare() first, otherwise this
01156        * method will throw an InvalidEquationSystem exception.
01157        */
01158    Matrix<double> EquationSystem::getPhiMatrix() const
01159       throw(InvalidEquationSystem)
01160    {
01161 
01162          // If the object as not ready, throw an exception
01163       if (!isPrepared)
01164       {
01165          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01166       }
01167 
01168       return phiMatrix;
01169 
01170    }  // End of method 'EquationSystem::getPhiMatrix()'
01171 
01172 
01173 
01174       /* Get the Process Noise Covariance Matrix (QMatrix), given the
01175        * current equation system definition and the GDS' involved.
01176        *
01177        * \warning You must call method Prepare() first, otherwise this
01178        * method will throw an InvalidEquationSystem exception.
01179        */
01180    Matrix<double> EquationSystem::getQMatrix() const
01181       throw(InvalidEquationSystem)
01182    {
01183 
01184          // If the object as not ready, throw an exception
01185       if (!isPrepared)
01186       {
01187          GPSTK_THROW(InvalidEquationSystem("EquationSystem is not prepared"));
01188       }
01189 
01190       return qMatrix;
01191 
01192    }  // End of method 'EquationSystem::getQMatrix()'
01193 
01194 
01195 
01196 }  // End of namespace gpstk

Generated on Fri Feb 3 03:31:00 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1