PaGMO  1.1.5
neighbourhood.cpp
1 # include <cstdlib>
2 # include <iostream>
3 # include <iomanip>
4 # include <fstream>
5 # include <cmath>
6 # include <ctime>
7 # include <cstring>
8 
9 # include "neighbourhood.h"
10 
11 using namespace std;
12 namespace pagmo{ namespace util {namespace neighbourhood {
13 
20 void euclidian::compute_neighbours(std::vector<std::vector<pagmo::population::size_type> > &retval, const std::vector<std::vector<double> > &weights) {
21  for(unsigned int i = 0; i < weights.size(); ++i) {
22  std::vector<double> distances;
23  for(unsigned int j = 0; j < weights.size(); ++j) {
24  distances.push_back(distance(weights[i],weights[j]));
25  }
26  retval.push_back(order(distances));
27  }
28 }
29 
36 double euclidian::distance(const std::vector<double> &a, const std::vector<double> &b) {
37  double rtr = 0.0;
38  for(std::vector<double>::size_type i = 0; i < a.size(); ++i) {
39  rtr += pow(a[i]-b[i], 2);
40  }
41  return sqrt(rtr);
42 }
43 
44 }}} //namespaces
Root PaGMO namespace.
STL namespace.
std::vector< population::size_type > order(const std::vector< T > &values)
Sort according the the values in the values vector but return the permutation.
Definition: neighbourhood.h:55