Exemple #1
0
/**@function to verify the search result is or not right

* @brief to verify the search result is or not right


* @param rawData raw data set. 

* @param metric to calculate the distance between two objects.

* @param q a query object.

* @param queryResultList mvp search result.

* @param output out stream.


* @post when there is an error, message will export to result file; if there is no error, nothing will export to result file.

*/
void verifySearchResult(vector<shared_ptr<CMetricData> > *&rawData,CMetricDistance *metric,CRangeQuery q, list<shared_ptr<CMetricData> > *queryResultList,ofstream &output)
{
    vector<shared_ptr<CMetricData> > linerSearchResults ;

    //linear traversal to get a result which must be true
    for (vector<CMetricData*>::size_type ii=0;ii!=rawData->size();ii++)
    {

        double objectDistance = metric->getDistance(q.getQueryObject().get(),rawData->at(ii).get());

        if(objectDistance<=q.getRadius())
            linerSearchResults.push_back(rawData->at(ii));

    }

    //check two results'length. if length is not same, it must be an error.
    if(queryResultList->size()!=linerSearchResults.size())
    {
        output<<"radius="<<q.getRadius()<<"  has an error:  "<<"mvptreeSearchResults->size()!=linerSearchResults.size() : "<<queryResultList->size()<<"   "<<linerSearchResults.size()<<endl;
    }

    list<shared_ptr<CMetricData> >::iterator mvp_iter = queryResultList->begin();


    for(;mvp_iter!=queryResultList->end();mvp_iter++)
    {
        vector<shared_ptr<CMetricData> >::size_type jj=0 ;
        for(;jj!=linerSearchResults.size();jj++)//"jj=linerSearchResults.size()" has only one situation which this loop has caught out, but failed to find the result
        {
            if(metric->getDistance((*mvp_iter).get(),linerSearchResults[jj].get())==0.0) break;//get out of loop right now after finding out the result
        }
        if(jj==linerSearchResults.size()) break;//means failing to find the result
    }
    if(mvp_iter!=queryResultList->end()) //get out of loop in the halfway because a result hasn't found.
        output<<"when radius is "<<q.getRadius()<<"  has an error!"<<endl;
}
Exemple #2
0
/**traversal from this internal node to its every child to search out the proper objects based on the parameters
* @para q this object is given by the user according which kind of query does the user want to do later, there is some basic information packaged in the object  like the search radius if the user want do a range query search latter.
* @para metric this object will be use to calculate the distance of two objects
* @return the proper objects address list through a vector
*/
vector<CIndexObject*> CMVPLeafNode::search(CRangeQuery &q,CMetric &metric)
{
    vector<CIndexObject*> rs;
    int numpivots = pivots.size();


    int i,j,p=-1;
    double* tempd = new double[numpivots];
    double r = q.getRadius();

    for(i=0;i<numpivots;i++)
    {
        tempd[i] = metric.getDistance(pivots[i],q.getQueryObject());
        if (tempd[i]<=r)
        {
            rs.push_back(pivots.at(i));
            if (tempd[i]==0)
                p = i;
        }

    }

    if (p>=0&&tempd[p]==0)
    {
        for(j=0;j<dataObjects.size();j++)
        {
            if(distance.at(p).at(j)<=r)
                rs.push_back(dataObjects.at(j));
        }
        return rs;
    }


    /* for(i=0;i<numpivots;i++)
    {
    for(j=0;j<dataObjects.size();j++)
    {
    if(abs(tempd[i]+r)<distance.at(i).at(j)||abs(tempd[i]-r)>distance.at(i).at(j))
    break;
    if(metric.getDistance(dataObjects.at(j),q.getQueryObject())<=r)
    rs.push_back(dataObjects.at(j));
    }
    }*/

    for(i=0;i<dataObjects.size();i++)
    {			
        for(j=0;j<numpivots;j++)
        {           

            if(abs(tempd[j]-distance.at(j).at(i))>r)
                break;
            /* else if(abs(tempd[j]+distance.at(j).at(i)<r))
            rs.push_back(dataObjects.at(i));*/
            else if(metric.getDistance(dataObjects.at(i),q.getQueryObject())<=r)
            {
                rs.push_back(dataObjects.at(i));
                break;
            }

        }
    }

    return rs;
}