double ratios(vector<Point2f> &p, vector<Point2f> &q, double sigma = 0.5) {
        vector<vector<int> > idx_perm = getCombination(3, 2);
        vector<double> sides_p;
        vector<double> sides_q;
        for (size_t k = 0; k < idx_perm.size(); k++) {
            int i = idx_perm[k][0];
            int j = idx_perm[k][1];
            double side_p = norm(p[i] - p[j]);
            double side_q = norm(q[i] - q[j]);
            sides_p.push_back(side_p);
            sides_q.push_back(side_q);
        }

        sort(sides_q.begin(), sides_q.end());
        double min_err = 1E30;
        do {
            vector<double> r(3);
            double sum = 0;
            for (int i = 0; i < 3; ++i) {
                r[i] = sides_p[i] / sides_q[i];
            }

            for (size_t k = 0; k < idx_perm.size(); k++) {
                sum += fabs(r[idx_perm[k][0]] - r[idx_perm[k][1]]);
            }
            min_err = min(sum, min_err);
        } while (next_permutation(sides_q.begin(), sides_q.end()));
        return exp(- min_err / sigma);
    }
 vector<string> generateParenthesis(int n) {
     vector<string> result;
     string s;
     if (n!=0)
         getCombination(result, s, n, n);
     return result;
 }
      /* Returns a satTypeValueMap object, adding the new data generated
       *  when calling this object.
       *
       * @param gData     Data object holding the data.
       */
   satTypeValueMap& ComputeMelbourneWubbena::Process(satTypeValueMap& gData)
      throw(ProcessingException)
   {

      try
      {

         double value1(0.0);
         double value2(0.0);
         double value3(0.0);
         double value4(0.0);

         SatIDSet satRejectedSet;

            // Loop through all the satellites
         satTypeValueMap::iterator it;
         for (it = gData.begin(); it != gData.end(); ++it) 
         {
            try
            {
                  // Try to extract the values
               value1 = (*it).second(type1);
               value2 = (*it).second(type2);
               value3 = (*it).second(type3);
               value4 = (*it).second(type4);
            }
            catch(...)
            {
                  // If some value is missing, then schedule this satellite
                  // for removal
               satRejectedSet.insert( (*it).first );
               continue;
            }

               // If everything is OK, then get the new value inside
               // the structure
            (*it).second[resultType] = getCombination( value1,
                                                       value2,
                                                       value3,
                                                       value4 );
         }

            // Remove satellites with missing data
         gData.removeSatID(satRejectedSet);

         return gData;

      }
      catch(Exception& u)
      {
            // Throw an exception if something unexpected happens
         ProcessingException e( getClassName() + ":"
                                + StringUtils::asString( getIndex() ) + ":"
                                + u.what() );

         GPSTK_THROW(e);

      }

   }  // End of method 'ComputeMelbourneWubbena::Process()'
Beispiel #4
0
    vector<vector<int> > subsets(vector<int> &S) {
        vector<vector<int> > res;
        vector<int> temp;
        sort(S.begin(), S.end());
        for(int i=0; i<= S.size(); i++) {
            getCombination(S, i, 0, 0, temp, res);
			temp.clear();
        }
        return res;
    }
 //remember to use reference for result
 void getCombination(vector<string>& result, string& s, int left, int right) {
     if (left == 0 && right == 0) {
         result.push_back(s);
         return;
     }
     
     if (left > 0) {
         s.push_back('(');
         getCombination(result, s, left-1, right);
         //remember to resize the string
         s.resize(s.size()-1);
     }
     
     //only add the right Parentheses when it is larger than number of the left one
     if (right > left) {
         s.push_back(')');
         getCombination(result, s, left, right-1);
         s.resize(s.size()-1);
     }
 }
Beispiel #6
0
 void getCombination(vector<int> &S, int k, int start, int cur, vector<int> temp, vector<vector<int> > &res) {
     if(cur == k) {
         res.push_back(temp);
         return;
     }
     for(int i=start; i<S.size(); i++) {
         temp.push_back(S[i]);
         getCombination(S, k, i+1, cur+1, temp, res);
         temp.pop_back();
     }
 }
        /** Pull out the combination of observations from a RinexObsData object
         * @param rinexData     The Rinex data set holding the observations
         * @param typeObs1      The #1 type of observation we want to get
         * @param typeObs2      The #2 type of observation we want to get
         *
         * @return
         *  Number of satellites with this combination of observable data available
         */
        virtual int getData(const RinexObsData& rinexData, RinexObsHeader::RinexObsType typeObs1,  RinexObsHeader::RinexObsType typeObs2) throw(InvalidData)
        {
        try {
            // Let's make sure each time we start with clean Vectors
            availableSV.resize(0);
            obsData.resize(0);

            // Create a CheckPRData object with the given limits
            CheckPRData checker(minPRange, maxPRange);

            // Let's define the "it" iterator to visit the observations PRN map
            // RinexSatMap is a map from SatID to RinexObsTypeMap: 
            //      std::map<SatID, RinexObsTypeMap>
            RinexObsData::RinexSatMap::const_iterator it;
            for (it = rinexData.obs.begin(); it!= rinexData.obs.end(); it++) 
            {
                // RinexObsTypeMap is a map from RinexObsType to RinexDatum:
                //   std::map<RinexObsHeader::RinexObsType, RinexDatum>
                RinexObsData::RinexObsTypeMap otmap;
                // Let's define a iterator to visit the observations type map
                RinexObsData::RinexObsTypeMap::const_iterator itObs1;
                // The "second" field of a RinexSatMap (it) is a RinexObsTypeMap (otmap)
                otmap = (*it).second;

                // Let's find the observation type inside the RinexObsTypeMap that is "otmap"
                itObs1 = otmap.find(typeObs1);

                // Let's check if we found this type of observation
                if (itObs1!=otmap.end())
                {
                    // Find an itObs2 observation inside the RinexObsTypeMap that is "otmap"
                    // Let's define a iterator to visit the observations type map
                    RinexObsData::RinexObsTypeMap::const_iterator itObs2;
                    itObs2 = otmap.find(typeObs2);
                    // If we indeed found a typeObs2 observation, let's compute the combination
                    if (itObs2!=otmap.end()) 
                    {
                        // The "second" part of a RinexObsTypeMap is a RinexDatum, whose public
                        // attribute "data" indeed holds the actual numerical data
                        double combinationValue = getCombination((*itObs1).second.data, (*itObs2).second.data);

                        // Let's check that the combination is between the limits
                        if (checker.check(combinationValue) || !(checkData) ) 
                        {
                            // Store all relevant data of this epoch
                            availableSV = availableSV && (*it).first;
                            obsData = obsData && combinationValue;
                        }
                    }
                }
            } // End of data extraction from this epoch
        }
        catch(...) {
            InvalidData e("Unable to get combination data from RinexObsData object");
            GPSTK_THROW(e);
        }

        // Let's record the number of SV with this type of data available
        numSV = (int)obsData.size();

        // If everything is fine so far, then the results should be valid
        valid = true;

        return numSV;

        };  // end ExtractCombinationData::getData()