All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
tabu_list.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_TABU_LIST_HPP
16 #define PAAL_TABU_LIST_HPP
17 
18 #include <boost/functional/hash.hpp>
19 
20 #include <unordered_set>
21 #include <queue>
22 
23 namespace paal {
24 namespace data_structures {
25 
31 template <typename Move> struct tabu_list_remember_move {
32 
39  : m_size(size), m_forbiden_moves_set(size) {}
40 
49  template <typename Solution>
50  bool is_tabu(const Solution &, Move move) const {
51  return is_tabu(std::move(move));
52  }
53 
60  template <typename Solution> void accept(const Solution &, Move move) {
61  assert(!is_tabu(move));
62  m_forbiden_moves_set.insert(move);
63  if (m_forbiden_moves_fifo.size() == m_size) {
64  m_forbiden_moves_set.erase(m_forbiden_moves_fifo.front());
65  m_forbiden_moves_fifo.pop_front();
66  }
67  m_forbiden_moves_fifo.push_back(std::move(move));
68  }
69 
70  private:
78  bool is_tabu(const Move &move) const {
79  return m_forbiden_moves_set.find(move) != m_forbiden_moves_set.end();
80  }
81 
82  unsigned m_size;
83  std::unordered_set<Move, boost::hash<Move>> m_forbiden_moves_set;
84  std::deque<Move> m_forbiden_moves_fifo;
85 };
86 
95 template <typename Solution, typename Move>
97  : tabu_list_remember_move<std::pair<Solution, Move>> {
99 
100  public:
107 
116  bool is_tabu(Solution s, Move move) const {
117  return base::is_tabu(nullptr,
118  std::make_pair(std::move(s), std::move(move)));
119  }
120 
127  void accept(Solution &s, const Move &move) {
128  base::accept(nullptr, std::make_pair(std::move(s), std::move(move)));
129  }
130 };
131 
132 }
133 }
134 
135 #endif // PAAL_TABU_LIST_HPP
void accept(const Solution &, Move move)
accept member function
Definition: tabu_list.hpp:60
Computes size of TypesVector.
bool is_tabu(Solution s, Move move) const
is_tabu redirects work to base class
Definition: tabu_list.hpp:116
bool is_tabu(const Solution &, Move move) const
is tabu member function
Definition: tabu_list.hpp:50
tabu_list_remember_move(unsigned size)
tabu_list_remember_move constructor
Definition: tabu_list.hpp:38
This Tabu list remember both current solution and move It is implemented as tabu_list_remember_move&lt;p...
Definition: tabu_list.hpp:96
This Tabu list remember some number of last moves.
Definition: tabu_list.hpp:31
void accept(Solution &s, const Move &move)
accept redirects work to base class
Definition: tabu_list.hpp:127