16 #ifndef PAAL_LOCAL_SEARCH_HPP
17 #define PAAL_LOCAL_SEARCH_HPP
25 #include <boost/fusion/include/vector.hpp>
26 #include <boost/range/algorithm/max_element.hpp>
36 template <
typename Delta>
37 bool positive_delta(Delta && d) {
38 return d >
typename std::decay<Delta>::type{};
56 template <
typename componentsAndSolution>
57 bool operator()(componentsAndSolution &compsAndSol)
const {
58 auto &solution = compsAndSol.second;
59 auto &comps = compsAndSol.first;
60 auto && adjustmentSet = comps.template call<GetMoves>(solution);
62 for (
auto && move : adjustmentSet) {
63 if (detail::positive_delta(comps.template call<Gain>(solution, move))) {
64 if (comps.template call<Commit>(solution, move)) {
86 template <
typename SearchJoin>
bool operator()(SearchJoin &join)
const {
87 return m_satisfy(m_pred, join);
115 template <
typename componentsAndSolution,
typename AccumulatorFunctor,
116 typename AccumulatorData,
typename Continuation>
118 AccumulatorFunctor accumulatorFunctor,
119 AccumulatorData accumulatorData,
120 Continuation continuation)
const {
121 auto &comps = compsAndSol.first;
122 auto &solution = compsAndSol.second;
123 auto && adjustmentSet = comps.template call<GetMoves>(solution);
126 if (boost::empty(adjustmentSet)) {
127 return continuation(accumulatorFunctor, accumulatorData);
130 auto maxMove = *std::begin(adjustmentSet);
131 auto maxGain = comps.template call<Gain>(solution, maxMove);
133 for (
auto && move : boost::make_iterator_range(
134 ++std::begin(adjustmentSet), std::end(adjustmentSet))) {
135 auto gain = comps.template call<Gain>(solution, move);
136 if (
gain > maxGain) {
142 if (maxGain > accumulatorData) {
143 auto commit = std::bind(std::ref(comps.template get<Commit>()),
144 std::ref(solution), maxMove);
145 return continuation(
commit, maxGain);
147 return continuation(accumulatorFunctor, accumulatorData);
165 template <
typename SearchJoin>
bool operator()(SearchJoin &join)
const {
188 template <
typename SearchJoin>
bool operator()(SearchJoin &join)
const {
199 template <
typename Solution,
typename... SearchComponentsPack>
202 template <
typename Solution,
typename SearchComponents,
203 typename... SearchComponentsPack>
205 Solution, SearchComponents,
207 Solution, SearchComponentsPack...> {
208 BOOST_CONCEPT_ASSERT(
228 template <
typename SearchStrategy,
typename ContinueOnSuccess,
229 typename ContinueOnFail,
typename Solution,
typename...
components>
231 ContinueOnSuccess succ, ContinueOnFail fail,
234 boost::ignore_unused_variable_warning(concepts);
236 using search_components_v =
237 boost::fusion::vector<std::pair<components, Solution &>...>;
239 search_components_v search_comps(
240 std::pair<components, Solution &>(std::move(comps), solution)...);
242 bool success{
false }, ret{
false };
244 while ((success = searchStrategy(search_comps)) || fail(solution)) {
246 if (success && !succ(solution)) {
250 return success | ret;
262 template <
typename Solution,
typename...
components>
266 std::move(comps)...);
280 template <
typename Solution,
typename...
components>
284 std::move(comps)...);
301 template <
typename Solution,
typename ContinueOnSuccess,
typename...
components>
302 bool best(Solution &solution, ContinueOnSuccess on_success,
311 #endif // PAAL_LOCAL_SEARCH_HPP
This strategy chooses the best possible move and if it is improving applies it to the solution...
This strategy chooses the best possible move and applies it to the solution. Note that this strategy ...
class for polymorphic join on boost fusion sequence
data_structures::components< GetMoves, Gain, Commit > components
Definition for the components class for local search usually this class is not directly used...
bool first_improving(Solution &solution, components...comps)
bool operator()(SearchJoin &join) const
operator()
bool best(Solution &solution, ContinueOnSuccess on_success, components...comps)
This local search chooses the best possible move and applies it to the solution. Note that this strat...
bool best_improving(Solution &solution, components...comps)
This local search chooses the best possible move and if the move is improving applies it to the solut...
bool operator()(componentsAndSolution &compsAndSol, AccumulatorFunctor accumulatorFunctor, AccumulatorData accumulatorData, Continuation continuation) const
operator()
this predicates returns true if there is a move with positive gain and the commit was successful ...
if the sign = true, class represents plus_infinity: object bigger than everything if the sign = false...
bool operator()(componentsAndSolution &compsAndSol) const
operator()
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
functor used in fold in order to find the most improving move.
This strategy uses find_positive_predicate as stop condition.
bool operator()(SearchJoin &join) const
operator()
bool operator()(SearchJoin &join) const
operator()