[Positioner] Fix "interval" similarity algorithm

The "interval" similarity algorithm now handles the case where no packet
is found within the interval.
This commit is contained in:
Matteo Cypriani 2012-06-20 18:39:21 +02:00
parent 1f22ece3d9
commit 8f3bf50aa5
1 changed files with 16 additions and 2 deletions

View File

@ -128,6 +128,13 @@ void Measurement::clear()
/* *** Operations *** */
/**
* @returns The similarity score. A small number means an important
* similarity, a big number means an important dissimilarity. The
* scale of this score depends on the similarity method used (option
* positioning.ss-similarity); the similarity scores are therefore
* not comparable across the various methods.
*/
float Measurement::similarity(const Measurement &source) const
{
assert(! ss_list.empty()) ;
@ -140,8 +147,15 @@ float Measurement::similarity(const Measurement &source) const
return ss_square_distance(source) ;
if (algorithm == "interval")
return 1 / nb_in_interval(source, get_std_deviation_mw()) ;
/* Note: this score ranges from 0 (excluded) to 1 (obviously). */
{
unsigned int nb = nb_in_interval(source, get_std_deviation_mw()) ;
if (nb != 0)
return 1 / nb ;
return 2 ;
}
/* Note: this score ranges from 0 (excluded) to 1 if at least one
* packet was found within the interval. It is equals to 2 if no
* packet was found in the interval. */
if (algorithm == "interval2")
{