15 #ifndef PAAL_LOCAL_SEARCH_OBJ_FUNCTION_HPP
16 #define PAAL_LOCAL_SEARCH_OBJ_FUNCTION_HPP
24 #include <boost/range/adaptor/transformed.hpp>
34 template <
typename SearchComponentsObjFun>
37 SearchComponentsObjFun>::template type<GetMoves>::type;
39 SearchComponentsObjFun>::template type<ObjFunction>::type;
41 SearchComponentsObjFun>::template type<Commit>::type;
46 template <
typename F,
typename GetMoves,
typename Commit>
49 GetMoves
const m_get_moves;
50 Commit
const m_commit;
56 m_get_moves(std::move(get_moves)),
57 m_commit(std::move(commit)) {}
59 template <
typename Solution>
60 auto operator()(Solution
const &solution) {
61 using move =
typename move_type_from_get_moves<GetMoves, Solution>::reference;
62 return m_get_moves(solution) | boost::adaptors::transformed(
63 [&solution,
this](move m) {
64 Solution new_solution(solution);
65 m_commit(new_solution, m);
66 return std::make_pair(m, m_f(new_solution));
71 template <
typename Fitness>
73 Fitness & m_current_res;
78 : m_current_res(current_res) {}
80 template <
typename Solution,
typename Move>
81 auto operator()(Solution
const &solution,
Move const &move) {
82 return move.second - m_current_res;
86 template <
typename Commit,
typename Fitness>
88 Commit
const m_commit;
89 Fitness & m_current_res;
94 : m_commit(std::move(commit)), m_current_res(current_res) {}
96 template <
typename Solution,
typename Move>
97 auto operator()(Solution &solution,
Move const &move) {
98 if (!m_commit(solution, move.first)) {
101 m_current_res = move.second;
106 template <
typename Solution,
typename SearchObjFunctionComponents,
108 typename F =
typename Traits::obj_function_t,
110 auto convert_comps(Solution & sol, SearchObjFunctionComponents
components, Fitness & current_res) {
111 using commit_t =
typename Traits::commit_t;
112 using get_moves_t =
typename Traits::get_moves_t;
118 auto get_moves = std::move(components.template get<GetMoves>());
119 auto commit = std::move(components.template get<Commit>());
120 auto obj_fun = std::move(components.template get<ObjFunction>());
132 template <
typename SearchStrategy,
typename ContinueOnSuccess,
133 typename ContinueOnFail,
typename Solution,
134 typename SearchObjFunctionComponent,
135 typename... SearchObjFunctionComponents>
137 ContinueOnSuccess on_success, ContinueOnFail on_fail,
138 SearchObjFunctionComponent component,
139 SearchObjFunctionComponents ... components) {
141 auto cur_res = component.template call<ObjFunction>(solution);
143 return local_search(solution, searchStrategy, std::move(on_success),
144 std::move(on_fail), detail::convert_comps(solution, std::move(component ), cur_res),
145 detail::convert_comps(solution, std::move(components), cur_res)...);
149 template <
typename Solution,
typename... Components>
153 std::move(comps)...);
157 template <
typename Solution,
typename... Components>
161 std::move(comps)...);
167 #endif // PAAL_LOCAL_SEARCH_OBJ_FUNCTION_HPP
traits class for search_componentsObjFun
This strategy chooses the best possible move and if it is improving applies it to the solution...
auto make_search_components(Args &&...args)
make function for search components
bool local_search_obj_fun(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess on_success, ContinueOnFail on_fail, SearchObjFunctionComponent component, SearchObjFunctionComponents...components)
local search function for objective function case.
bool obj_fun_first_improving(Solution &solution, Components...comps)
simple version of local_search_obj_fun - first improving strategy
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
bool obj_fun_best_improving(Solution &solution, Components...comps)
simple version of local_search_obj_fun - best improving strategy
typename std::decay< typename std::result_of< F >::type >::type pure_result_of_t
return pure type of function (decays const and reference)
This strategy uses find_positive_predicate as stop condition.