15 #ifndef PAAL_CUSTOM_COMPONENTS_HPP
16 #define PAAL_CUSTOM_COMPONENTS_HPP
45 : m_gain(std::move(
gain)), m_condition(std::move(cond)) {}
54 template <
typename... Args>
56 ->decltype(std::declval<Gain>()(std::forward<Args>(args)...)) {
57 if (!m_condition(std::forward<Args>(args)...)) {
60 return m_gain(std::forward<Args>(args)...);
65 Condition m_condition;
80 conditional_gain_adaptor<Gain, Condition>
82 Condition cond = Condition()) {
106 : m_gain(std::move(gain)), m_curr_opt(currOpt), m_epsilon(epsilon) {}
117 template <
typename... Args> ValueType
operator()(Args &&... args) {
118 ValueType dist = m_gain(std::forward<Args>(args)...);
119 if (dist > m_epsilon * m_curr_opt) {
142 ValueType m_curr_opt;
165 template <
typename... Args>
bool operator()(Args &&...)
const {
166 return ++m_cnt >= m_limit;
170 mutable unsigned m_cnt;
171 const unsigned m_limit;
177 template <
typename duration = std::chrono::seconds,
178 typename clock = std::chrono::system_clock>
187 : m_duration(d), m_start(clock::now()) {}
198 return m_start + m_duration < clock::now();
207 typename clock::time_point m_start;
208 const duration m_duration;
227 : m_gain(gain), m_val(val) {}
237 template <
typename... Args> ValueType
operator()(Args &&... args) {
238 auto diff = m_gain(std::forward<Args>(args)...);
274 AspirationCriteria aspirationCriteria =
275 AspirationCriteria())
276 : m_tabu_list(std::move(tabuList)),
277 m_aspiration_criteria_gain(std::move(
gain),
278 std::move(aspirationCriteria)) {}
287 template <
typename... Args>
289 ->decltype(std::declval<Gain>()(std::forward<Args>(args)...)) {
290 if (!m_tabu_list.is_tabu(std::forward<Args>(args)...)) {
291 auto diff = m_aspiration_criteria_gain(std::forward<Args>(args)...);
292 if (detail::positive_delta(diff)) {
293 m_tabu_list.accept(std::forward<Args>(args)...);
297 return decltype(std::declval<Gain>()(std::forward<Args>(args)...)){};
301 TabuList m_tabu_list;
303 m_aspiration_criteria_gain;
320 tabu_gain_adaptor<TabuList, Gain, AspirationCriteria>
322 AspirationCriteria aspirationCriteria =
323 AspirationCriteria()) {
325 std::move(tabuList), std::move(
gain), std::move(aspirationCriteria));
338 template <
typename Commit,
typename Solution,
typename Comparator = utils::less>
349 Comparator comparator = Comparator{})
350 : m_solution(&solution), m_commit(std::move(
commit)),
351 m_comparator(std::move(comparator)) {}
361 auto ret = m_commit(sol, move);
362 if (m_comparator(*m_solution, sol)) {
383 Solution *m_solution;
385 Comparator m_comparator;
400 template <
typename Commit,
typename Solution,
typename Condition>
401 record_solution_commit_adapter<Commit, Solution, Condition>
404 s, std::move(commit), std::move(c));
410 #endif // PAAL_CUSTOM_COMPONENTS_HPP
ValueType operator()(Args &&...args)
transfers arguments to original gain, if the value is to small it is changed to 0.
This is custom StopCondition, it returns true after given time limit.
auto operator()(Args &&...args) -> decltype(std::declval< Gain >()(std::forward< Args >(args)...))
tabu_gain_adaptor< TabuList, Gain, AspirationCriteria > make_tabu_gain_adaptor(TabuList tabuList, Gain gain=Gain(), AspirationCriteria aspirationCriteria=AspirationCriteria())
make function for tabu_gain_adaptor
bool operator()(Args &&...)
Checks if the time is up.
This is adaptor on Commit which allows to record solution basing on condition It is particularly usef...
record_solution_commit_adapter(Solution &solution, Commit commit=Commit{}, Comparator comparator=Comparator{})
constructor
Solution & get_solution()
Access to the stored solution (non-const version)
record_solution_commit_adapter< Commit, Solution, Condition > make_record_solution_commit_adapter(Solution &s, Commit commit, Condition c)
make function for record_solution_commit_adapter
void set_current_opt(ValueType opt)
sets current Opt
This is custom StopCondition , it returns true after given count limit.
ValueType get_val() const
Returns sum of the improvements.
This file contains set of simple useful functors or functor adapters.
void set_epsilon(double e)
sets epsilon
void restart()
resets the start point
bool operator()(Solution &sol, const Move &move)
operator
This is the gain adapter which accepts gains improving the current solution by more than epsilon...
gain_cut_small_improves(Gain gain, ValueType currOpt, double epsilon)
Constructor,.
ValueType operator()(Args &&...args)
forwards args to original gain. Sum up the improvements.
compute_gain_wrapper(compute_gain_wrapper gain, ValueType &val)
Constructor.
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
Adapts gain to implement tabu search.
This wrapper counts sum of the improvements. It makes sense to use it only when ChooseFirstBetter str...
conditional_gain_adaptor< Gain, Condition > make_conditional_gain_adaptor(Gain gain=Gain(), Condition cond=Condition())
make for conditional_gain_adaptor
conditional_gain_adaptor(Gain gain=Gain(), Condition cond=Condition())
constructor
bool operator()(Args &&...) const
increment the counter and checks if the given limit is reached.
stop_condition_time_limit(duration d)
Constructor.
if the condition is not fulfilled this gain adaptor returns 0
tabu_gain_adaptor(TabuList tabuList=TabuList(), Gain gain=Gain(), AspirationCriteria aspirationCriteria=AspirationCriteria())
constructor
stop_condition_count_limit(unsigned limit)
Constructor.
const Solution & get_solution() const
Access to the stored solution (const version)
auto operator()(Args &&...args) -> decltype(std::declval< Gain >()(std::forward< Args >(args)...))
operator()