Project
Classes | Functions
utils.h File Reference

utility functions used by our programs. More...

#include "../extsrc/pugixml/src/pugixml.hpp"
#include "types/AlternativesPerformance.h"
#include "types/Profiles.h"
#include <matplot/matplot.h>
#include "types/Category.h"
#include "types/Criteria.h"
#include "types/Perf.h"
#include <algorithm>
#include <chrono>
#include <fstream>
#include <iostream>
#include <numeric>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/stat.h>
#include <thread>
#include <time.h>
#include <typeinfo>
#include <unistd.h>
#include <unordered_map>
#include <utility>
#include <vector>
Include dependency graph for utils.h:

Go to the source code of this file.

Classes

struct  simple_walker
 

Functions

template<typename T >
std::ostream & operator<< (std::ostream &out, const std::vector< T > &vec)
 
template<typename T >
std::vector< T > subVector (std::vector< T > const &v, int m, int n)
 
bool fileExists (const std::string &name)
 
int getRandomUniformInt (unsigned long int seed=0, int min=0, int max=100)
 
float getRandomUniformFloat (unsigned long int seed=time(NULL), float min=0, float max=1)
 
std::vector< float > randomCategoriesLimits (int nbCategories, unsigned long int seed=time(NULL))
 
std::vector< std::string > getCriterionIds (std::vector< Perf > vectPerf)
 
Perf getPerfOfCrit (std::vector< Perf > &vectPerf, std::string critId)
 
std::vector< std::string > getNameIds (std::vector< Perf > vectPerf)
 
std::vector< PerfcreateVectorPerf (std::string id, Criteria &criteria, std::vector< float > &given_perf)
 
std::vector< PerfcreateVectorPerfWithNoPerf (std::string id, Criteria &criteria)
 
std::vector< double > getPerfFromPerfVect (std::vector< Perf > &p)
 
bool checkKey (std::unordered_map< int, int > &map, int key)
 
void plotGlobalData (AlternativesPerformance &ap)
 
void plotProfile (Profiles &p)
 

Detailed Description

utility functions used by our programs.

All utility fonctions are referenced and implemented inside this file.

Function Documentation

◆ checkKey()

bool checkKey ( std::unordered_map< int, int > &  map,
int  key 
)
inline

Check if a key is present in a unordered map

Parameters
mapunordered map of <int,int>

◆ createVectorPerf()

std::vector<Perf> createVectorPerf ( std::string  id,
Criteria criteria,
std::vector< float > &  given_perf 
)
inline

createVectorPerf creates a vector of performances given the id, criteria and values

Parameters
idof the performance
criteriacriteria vector on which to associate the performances
given_perfperformances values in the same order as criteria vect
Returns
vect<Perf> performance vector

◆ createVectorPerfWithNoPerf()

std::vector<Perf> createVectorPerfWithNoPerf ( std::string  id,
Criteria criteria 
)
inline

createVectorPerf creates a vector of performances with random values given the id and criteria

Parameters
idof the performance
criteriacriteria vector on which to associate the performances
Returns
vect<Perf> performance vector

◆ getCriterionIds()

std::vector<std::string> getCriterionIds ( std::vector< Perf vectPerf)
inline

getCriterionIds get vector of criterions ids of a performance vector

Parameters
vectPerfperformance vector
Returns
vector of criterion ids

◆ getNameIds()

std::vector<std::string> getNameIds ( std::vector< Perf vectPerf)
inline

getNameIds get the names of each perfomance in a perfomance vector

Parameters
vectPerfPerformance vector from which we want the ids
Returns
vector of names (ids)

◆ getPerfFromPerfVect()

std::vector<double> getPerfFromPerfVect ( std::vector< Perf > &  p)
inline

Extract only performance values from a vector of Perf objects

Parameters
pvector of Perf objects

◆ getPerfOfCrit()

Perf getPerfOfCrit ( std::vector< Perf > &  vectPerf,
std::string  critId 
)
inline

getPerfOfCrit get the performance for a given criterion in a performance vector.

Parameters
critIdcriterion for which we want the perf
Returns
Perf for given critId

◆ getRandomUniformFloat()

float getRandomUniformFloat ( unsigned long int  seed = time(NULL),
float  min = 0,
float  max = 1 
)
inline

Random float number generator

Parameters
seedto initiate the generator, default 0
minmin of generated number, default 0
maxmax of generated number, default 1
Returns
random float number between min and max

◆ getRandomUniformInt()

int getRandomUniformInt ( unsigned long int  seed = 0,
int  min = 0,
int  max = 100 
)
inline

Random int number generator

Parameters
seedto initiate the generator, default 0
minmin of generated number, default 0
maxmax of generated number, default 100
Returns
random int number between min and max

◆ operator<<()

template<typename T >
std::ostream& operator<< ( std::ostream &  out,
const std::vector< T > &  vec 
)

Overloading << operator for std::vector object

Parameters
outostream
vecstd::vector object

◆ plotGlobalData()

void plotGlobalData ( AlternativesPerformance ap)
inline

Plots data distribution for a AlternativesPerformance object in order to see if populations are separable. This is useful for ProfileInitialization for example.

Parameters
apAlternativesPerformance object

◆ plotProfile()

void plotProfile ( Profiles p)
inline

Plots a visualization of a Profiles object. Profile object must be set in "alt" mode in order to correctly plot.

Parameters
pProfiles object

◆ randomCategoriesLimits()

std::vector<float> randomCategoriesLimits ( int  nbCategories,
unsigned long int  seed = time(NULL) 
)
inline

randomCategoriesLimits creates random categories limits given the number of categories

Parameters
nbCategoriesnumber of categories (and of limits) to create
seedseed for random
Returns
vector of float representing categories limits

◆ subVector()

template<typename T >
std::vector<T> subVector ( std::vector< T > const &  v,
int  m,
int  n 
)

subVector get a sub-vector of a vector

Parameters
vvector from which we want the sub vector
mindex of the beginning of subvector
nindex of the end of subvector
Returns
subvector