[Positioning] Only one occurrence of an algorithm

If an algorithm name is specified more than once (e.g. once in the
configuration file and once on the command line), the algorithm is
now executed only once.
This commit is contained in:
Matteo Cypriani 2011-11-22 15:14:39 +01:00
parent 6aae51ab97
commit 5e0a227905
1 changed files with 47 additions and 16 deletions

View File

@ -12,8 +12,10 @@
#include <owlps.h>
#include <iostream>
#include <boost/tr1/unordered_set.hpp>
using namespace std ;
using std::tr1::unordered_set ;
@ -49,36 +51,65 @@ void Positioning::initialise_algorithms()
const vector<string> &algo_names =
Configuration::string_vector_value("positioning.algorithm") ;
// We will store the names of the stored algorithms in a set, to
// avoid multiple occurrences of the same algorithm:
unordered_set<string> stored_algos ;
for (vector<string>::const_iterator i = algo_names.begin() ;
i != algo_names.end() ; ++i)
{
if (*i == "Real")
/* In order to compute the errors of the other algorithms,
* Real must be the first for each request, so we add it at
* the begining.
*/
algorithms.insert(algorithms.begin(), new RealPosition) ;
{
pair<unordered_set<string>::iterator, bool> stored =
stored_algos.insert("Real") ;
if (stored.second) // Check if there was no previous instance
algorithms.insert(algorithms.begin(), new RealPosition) ;
/* Note: in order to compute the errors of the other
* algorithms, Real must be the first for each request,
* so we add it at the begining. */
}
else if (*i == "FBCM")
{
// Generate the Friis indexes only if the autocalibration is
// not activated (if it is, Friis indexes will be regenerated
// each time FBCM wants to computes a position)
if (! Configuration::
bool_value("positioning.generate-reference-points"))
Stock::update_all_friis_indexes() ;
algorithms.push_back(new FBCM) ;
pair<unordered_set<string>::iterator, bool> stored =
stored_algos.insert("FBCM") ;
if (stored.second) // Check if there was no previous instance
{
/* Generate the Friis indexes only if the autocalibration
* is not activated (if it is, Friis indexes will be
* regenerated each time FBCM wants to computes a position)
*/
if (! Configuration::
bool_value("positioning.generate-reference-points"))
Stock::update_all_friis_indexes() ;
algorithms.push_back(new FBCM) ;
}
}
else if (*i == "FRBHMBasic")
//TODO: Pre-compute all per-ReferencePoint friis indexes?
algorithms.push_back(new FRBHMBasic) ;
{
pair<unordered_set<string>::iterator, bool> stored =
stored_algos.insert("FRBHMBasic") ;
if (stored.second) // Check if there was no previous instance
algorithms.push_back(new FRBHMBasic) ;
// TODO: Pre-compute all per-ReferencePoint friis indexes?
}
else if (*i == "InterlinkNetworks")
algorithms.push_back(new InterlinkNetworks) ;
{
pair<unordered_set<string>::iterator, bool> stored =
stored_algos.insert("InterlinkNetworks") ;
if (stored.second) // Check if there was no previous instance
algorithms.push_back(new InterlinkNetworks) ;
}
else if (*i == "RADAR")
algorithms.push_back(new RADAR) ;
{
pair<unordered_set<string>::iterator, bool> stored =
stored_algos.insert("RADAR") ;
if (stored.second) // Check if there was no previous instance
algorithms.push_back(new RADAR) ;
}
else
throw bad_configuration(