PaGMO  1.1.5
neighbourhood.h
1 /*****************************************************************************
2  * Copyright (C) 2004-2015 The PaGMO development team, *
3  * Advanced Concepts Team (ACT), European Space Agency (ESA) *
4  * *
5  * https://github.com/esa/pagmo *
6  * *
7  * act@esa.int *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  *****************************************************************************/
24 
25 #ifndef PAGMO_UTIL_NEIGHBOURHOOD_H
26 #define PAGMO_UTIL_NEIGHBOURHOOD_H
27 
28 #include <iostream>
29 #include <vector>
30 #include <math.h>
31 #include <algorithm>
32 #include <boost/shared_ptr.hpp>
33 
34 #include "../config.h"
35 #include "../population.h"
36 #include "../exceptions.h"
37 
38 namespace pagmo{ namespace util {
39 
44 namespace neighbourhood {
45 
46 template<class T> class __PAGMO_VISIBLE sorter {
47 public:
48  sorter(const std::vector<T> &v) : values(v) {}
49  bool operator()(int a, int b) { return values[a] < values[b]; }
50 private:
51  const std::vector<T> &values;
52 };
53 
55 template<class T> std::vector<population::size_type> order(const std::vector<T> &values)
56 {
57  std::vector<pagmo::population::size_type> rv(values.size());
58  int idx = 0;
59  for (std::vector<pagmo::population::size_type>::iterator i = rv.begin(); i != rv.end(); i++)
60  *i = idx++;
61  std::sort(rv.begin(), rv.end(), sorter<T>(values));
62  return rv;
63 }
64 
69 class __PAGMO_VISIBLE euclidian {
70 public:
71  static void compute_neighbours(std::vector<std::vector<pagmo::population::size_type> > &, const std::vector<std::vector<double> > &);
72  static double distance(const std::vector<double> &, const std::vector<double> &);
73 };
74 
75 }}}
76 
77 #endif
Root PaGMO 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