PaGMO  1.1.5
racing.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_RACING_H
26 #define PAGMO_UTIL_RACING_H
27 
28 #include <iostream>
29 #include <string>
30 #include <vector>
31 
32 #include "../config.h"
33 #include "../serialization.h"
34 #include "../population.h"
35 
38 
39 namespace pagmo{ namespace util {
40 
41 namespace racing{
42 
43  class __PAGMO_VISIBLE racing_population : public population
44  {
45  public:
46  racing_population(const population &);
47  racing_population(const problem::base &);
48  void set_x_noeval(const size_type, const decision_vector &);
49  void set_fc(const size_type, const fitness_vector &, const constraint_vector &);
50  void push_back_noeval(const decision_vector &);
51  std::vector<double> get_rankings() const;
52  };
53 
54  struct racer_type
55  {
56  public:
57  racer_type(): m_mean(0), active(false) { }
58 
59  // Using double type to cater for tied ranks
60  std::vector<double> m_hist;
61  double m_mean;
62  bool active;
63 
64  unsigned int length()
65  {
66  return m_hist.size();
67  }
68 
69  void reset()
70  {
71  m_hist.clear();
72  m_mean = 0;
73  active = false;
74  }
75 
76 
77  private:
78  friend class boost::serialization::access;
79  template <class Archive>
80  void serialize(Archive &ar, const unsigned int)
81  {
82  ar & m_hist;
83  ar & m_mean;
84  ar & active;
85  }
86  };
87 
88  struct stat_test_result{
89  public:
90  stat_test_result(unsigned int N = 0): trivial(true), is_better(N, std::vector<bool>(N, false)) { }
91  bool trivial;
92  std::vector<std::vector<bool> > is_better;
93  };
94 
95  // F-Race routines
96  stat_test_result friedman_test(std::vector<racer_type> &,
97  const std::vector<population::size_type> &,
98  const racing_population&,
99  double);
100 
101  stat_test_result core_friedman_test(const std::vector<std::vector<double> > &,
102  double delta);
103 
104  void f_race_assign_ranks(std::vector<racer_type> &,
105  const racing_population &);
106 
107  void f_race_adjust_ranks(std::vector<racer_type> &,
108  const std::vector<population::size_type> &);
109 
110  // Wilcoxon rank-sum routines
111  stat_test_result wilcoxon_ranksum_test(std::vector<racer_type> &,
112  const std::vector<population::size_type> &,
113  const racing_population&,
114  double);
115 
116  stat_test_result core_wilcoxon_ranksum_test(const std::vector<std::vector<double> > &X,
117  double delta);
118 }}} //Namespaces
119 
121 
122 #endif
Root PaGMO namespace.
std::vector< double > decision_vector
Decision vector type.
Definition: types.h:40
STL namespace.
std::vector< double > fitness_vector
Fitness vector type.
Definition: types.h:42
std::vector< double > constraint_vector
Constraint vector type.
Definition: types.h:44