1 // Copyright 2020, 2021 PaGMO development team
2 //
3 // This file is part of the pygmo library.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla
6 // Public License v. 2.0. If a copy of the MPL was not distributed
7 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <pybind11/pybind11.h>
10 
11 #include <pagmo/r_policies/fair_replace.hpp>
12 #include <pagmo/r_policy.hpp>
13 #include <pagmo/types.hpp>
14 
15 #include "docstrings.hpp"
16 #include "expose_r_policies.hpp"
17 #include "sr_policy_add_rate_constructor.hpp"
18 
19 namespace pygmo
20 {
21 
22 namespace py = pybind11;
23 
24 namespace detail
25 {
26 
27 namespace
28 {
29 
30 // A test r_policy.
31 struct test_r_policy {
replacepygmo::detail::__anonf7ac1e1f0111::test_r_policy32     pagmo::individuals_group_t replace(const pagmo::individuals_group_t &inds, const pagmo::vector_double::size_type &,
33                                        const pagmo::vector_double::size_type &, const pagmo::vector_double::size_type &,
34                                        const pagmo::vector_double::size_type &, const pagmo::vector_double::size_type &,
35                                        const pagmo::vector_double &, const pagmo::individuals_group_t &) const
36     {
37         return inds;
38     }
39     // Set/get an internal value to test extraction semantics.
set_npygmo::detail::__anonf7ac1e1f0111::test_r_policy40     void set_n(int n)
41     {
42         m_n = n;
43     }
get_npygmo::detail::__anonf7ac1e1f0111::test_r_policy44     int get_n() const
45     {
46         return m_n;
47     }
48     int m_n = 1;
49 };
50 
51 } // namespace
52 
53 } // namespace detail
54 
expose_r_policies(py::module & m,py::class_<pagmo::r_policy> & r_pol,py::module & r_module)55 void expose_r_policies(py::module &m, py::class_<pagmo::r_policy> &r_pol, py::module &r_module)
56 {
57     // Test r_policy.
58     auto t_r_policy
59         = expose_r_policy<detail::test_r_policy>(m, r_pol, r_module, "_test_r_policy", "A test replacement policy.");
60     t_r_policy.def("get_n", &detail::test_r_policy::get_n);
61     t_r_policy.def("set_n", &detail::test_r_policy::set_n);
62 
63     // Fair replacement policy.
64     auto fair_replace_
65         = expose_r_policy<pagmo::fair_replace>(m, r_pol, r_module, "fair_replace", fair_replace_docstring().c_str());
66     detail::sr_policy_add_rate_constructor(fair_replace_);
67 }
68 
69 } // namespace pygmo
70