11 #include "../extsrc/pugixml/src/pugixml.hpp"
14 #include <matplot/matplot.h>
34 #include <unordered_map>
46 std::ostream &
operator<<(std::ostream &out,
const std::vector<T> &vec) {
48 for (std::size_t i = 0; i < vec.size(); i++) {
49 out << vec[i] << (i == vec.size() - 1 ?
"" :
",");
65 std::vector<T>
subVector(std::vector<T>
const &v,
int m,
int n) {
66 auto first = v.begin() + m;
67 auto last = v.begin() + n + 1;
68 std::vector<T> vector(first, last);
79 virtual bool for_each(pugi::xml_node &node) {
80 for (
int i = 0; i < depth(); ++i)
83 std::cout << node.type() <<
": name='" << node.name() <<
"', value='"
84 << node.value() <<
"'\n";
97 inline bool fileExists(
const std::string &name) {
99 return (stat(name.c_str(), &buffer) == 0);
113 std::mt19937 gen(seed);
114 std::uniform_int_distribution<> dis(min, max);
128 float min = 0,
float max = 1) {
130 std::mt19937 gen(seed);
131 std::uniform_real_distribution<> dis(min, max);
144 inline std::vector<float>
146 std::vector<float> catLimits;
147 for (
int i = 0; i < nbCategories; i++) {
150 sort(catLimits.begin(), catLimits.end());
162 std::vector<std::string> criterionIds;
163 for (
auto p : vectPerf) {
164 criterionIds.push_back(p.crit_);
178 for (
Perf &p : vectPerf) {
179 if (p.crit_ == critId) {
183 throw std::invalid_argument(
"No performance for given criterion found");
193 inline std::vector<std::string>
getNameIds(std::vector<Perf> vectPerf) {
194 std::vector<std::string> NameIds;
195 for (
auto p : vectPerf) {
196 NameIds.push_back(p.name_);
212 std::vector<float> &given_perf) {
215 throw std::invalid_argument(
216 "You must have the same number of performance value and criterias");
218 std::vector<Perf> vp;
220 for (
int i = 0; i < criterion_vect.size(); i++) {
221 vp.push_back(
Perf(
id, criterion_vect[i].getId(), given_perf[i]));
237 std::vector<Perf> vp;
239 for (
int i = 0; i < criterion_vect.size(); i++) {
240 vp.push_back(
Perf(
id, criterion_vect[i].getId(), 0));
251 std::vector<double> values;
252 for (
auto perf : p) {
253 values.push_back(
static_cast<double>(perf.value_));
263 inline bool checkKey(std::unordered_map<int, int> &map,
int key) {
265 if (map.find(key) == map.end())
281 std::unordered_map<std::string, Category> map =
284 std::set<int> cat_set;
285 for (
auto pair : map) {
286 cat_set.insert(pair.second.rank_);
289 std::vector<int> ranks;
290 ranks.assign(cat_set.begin(), cat_set.end());
292 std::vector<std::vector<double>> performances;
293 std::unordered_map<int, int> index;
296 int rank = map[p[0].name_].rank_;
298 nbCriteria = p.size();
302 performances[index[rank]].insert(performances[index[rank]].end(),
303 addPerf.begin(), addPerf.end());
308 index[rank] = performances.size() - 1;
312 std::unordered_map<int, int> reverse_index;
313 for (
auto pair : index) {
314 reverse_index[pair.second] = pair.first;
318 for (
auto catPerf : performances) {
319 int catRank = reverse_index[counter];
320 if (catPerf.size() % nbCriteria != 0) {
321 throw std::invalid_argument(
"Missing some criteria performance values in "
322 "AlternativePerformance object");
324 int nbRepetition = catPerf.size() / nbCriteria - 1;
325 std::vector<double> x(nbCriteria);
326 std::iota(std::begin(x), std::end(x), 1);
327 std::vector<double> x2 = x;
328 for (
int i = 0; i < nbRepetition; ++i) {
329 x2.insert(std::end(x2), std::begin(x), std::end(x));
332 auto l = matplot::scatter(x2, catPerf, 10);
333 l->marker_face(
true);
334 l->marker_style(matplot::line_spec::marker_style::diamond);
335 l->display_name(
"Category " + std::to_string(catRank - 1));
336 matplot::hold(matplot::on);
339 matplot::xlabel(
"Criteria");
340 matplot::ylabel(
"Performance Value");
341 matplot::title(
"Data Distribution Visualization");
359 std::vector<std::vector<double>> prof_performances;
363 std::vector<double> x(prof_performances[0].size());
364 std::iota(std::begin(x), std::end(x), 1);
367 for (
auto proPerf : prof_performances) {
369 auto l = matplot::plot(x, proPerf);
370 l->display_name(
"b" + std::to_string(counter));
371 matplot::hold(matplot::on);
374 matplot::xlabel(
"Criteria");
375 matplot::ylabel(
"Performance Value");
376 matplot::title(
"Profile Visualization");
Datastructure representing a category.
Datastructure representing a set of criterion.
Perf (single performance) data structure.
Set of Criterion datastructure.
Definition: Criteria.h:25
std::vector< Criterion > getCriterionVect() const
Perf (single performance) data structure.
Definition: Perf.h:22
Profiles data structure.
Definition: Profiles.h:41
std::vector< Perf > createVectorPerf(std::string id, Criteria &criteria, std::vector< float > &given_perf)
Definition: utils.h:211
void plotProfile(Profiles &p)
Definition: utils.h:353
float getRandomUniformFloat(unsigned long int seed=time(NULL), float min=0, float max=1)
Definition: utils.h:127
bool checkKey(std::unordered_map< int, int > &map, int key)
Definition: utils.h:263
Perf getPerfOfCrit(std::vector< Perf > &vectPerf, std::string critId)
Definition: utils.h:177
void plotGlobalData(AlternativesPerformance &ap)
Definition: utils.h:278
std::ostream & operator<<(std::ostream &out, const std::vector< T > &vec)
Definition: utils.h:46
std::vector< std::string > getCriterionIds(std::vector< Perf > vectPerf)
Definition: utils.h:161
int getRandomUniformInt(unsigned long int seed=0, int min=0, int max=100)
Definition: utils.h:111
std::vector< Perf > createVectorPerfWithNoPerf(std::string id, Criteria &criteria)
Definition: utils.h:235
std::vector< std::string > getNameIds(std::vector< Perf > vectPerf)
Definition: utils.h:193
std::vector< T > subVector(std::vector< T > const &v, int m, int n)
Definition: utils.h:65
std::vector< float > randomCategoriesLimits(int nbCategories, unsigned long int seed=time(NULL))
Definition: utils.h:145
std::vector< double > getPerfFromPerfVect(std::vector< Perf > &p)
Definition: utils.h:250