diff --git a/owlps-positioning/src/positioning.cc b/owlps-positioning/src/positioning.cc index f717a4c..4cdeda0 100644 --- a/owlps-positioning/src/positioning.cc +++ b/owlps-positioning/src/positioning.cc @@ -12,8 +12,10 @@ #include #include +#include using namespace std ; +using std::tr1::unordered_set ; @@ -49,36 +51,65 @@ void Positioning::initialise_algorithms() const vector &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 stored_algos ; + for (vector::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::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::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::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::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::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(