vrpRouting  0.3
tabu_list.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: tabu_list.h
4 
5 Copyright (c) 2021 pgRouting developers
7 
8 Created by Joseph Percival on 2020/06/15.
9 Modified by Vicky
10 ------
11 
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16 
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21 
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 
26  ********************************************************************PGR-GNU*/
27 
28 #ifndef INCLUDE_OPTIMIZERS_TABU_LIST_H_
29 #define INCLUDE_OPTIMIZERS_TABU_LIST_H_
30 #pragma once
31 
32 #include <iosfwd>
33 #include <string>
34 #include <deque>
35 #include <set>
36 
37 #include "optimizers/move.h"
38 
39 namespace vrprouting {
40 namespace optimizers {
41 namespace tabu {
42 
43 
45 class TabuList {
46  public:
48  typedef std::deque<Move>::iterator iterator;
49 
51  typedef std::deque<Move>::const_iterator const_iterator;
52 
54  void add(const Move &m);
55 
57  void clear();
58 
62  const problem::Order& from_order, double obj1, double obj2) const;
63 
67  const problem::Order&,
68  const problem::Order&, double obj1, double obj2) const;
69 
71  bool is_empty() const;
72 
74  size_t size() const;
75 
77  size_t max_length() const;
78 
80  void set_max_length(size_t length);
81 
83  friend std::ostream& operator<<(std::ostream &, const TabuList &);
84 
86  const_iterator begin() const {return m_tabu_list.begin();}
87 
89  const_iterator end() const {return m_tabu_list.end();}
90 
92  bool has_infeasible(const std::string& candidate);
93 
95  void add_infeasible(const std::string& candidate);
96 
98  bool has_seen(const std::string& candidate);
99 
101  void add_seen(const std::string& candidate);
102 
103  private:
105  bool has(const Move &) const;
106 
108  size_t m_max_length;
109 
111  std::deque<Move> m_tabu_list;
112 
114  std::set<std::string> m_infeasible_list;
115 
117  std::set<std::string> m_seen_list;
118 };
119 
120 
121 } // namespace tabu
122 } // namespace optimizers
123 } // namespace vrprouting
124 
125 #endif // INCLUDE_OPTIMIZERS_TABU_LIST_H_
126 
vrprouting::optimizers::tabu::TabuList::m_seen_list
std::set< std::string > m_seen_list
the seen list
Definition: tabu_list.h:117
vrprouting::optimizers::tabu::TabuList::end
const_iterator end() const
Constant iteratori pointing to the last element of the tabu list.
Definition: tabu_list.h:89
vrprouting::optimizers::tabu::TabuList::has_seen
bool has_seen(const std::string &candidate)
Checks to see if a move candidate has already been done before (in the seen list)
Definition: tabu_list.cpp:158
move.h
vrprouting::optimizers::tabu::TabuList::has_move
bool has_move(const problem::Vehicle_pickDeliver &, const problem::Vehicle_pickDeliver &, const problem::Order &from_order, double obj1, double obj2) const
Checks to see if a "move" move is "tabu" (in the tabu list)
Definition: tabu_list.cpp:73
vrprouting::optimizers::tabu::TabuList::iterator
std::deque< Move >::iterator iterator
iterator type that allows modification
Definition: tabu_list.h:48
vrprouting::optimizers::tabu::TabuList::operator<<
friend std::ostream & operator<<(std::ostream &, const TabuList &)
priting function
Definition: tabu_list.cpp:140
vrprouting::optimizers::tabu::TabuList::m_tabu_list
std::deque< Move > m_tabu_list
the tabu list
Definition: tabu_list.h:111
vrprouting::optimizers::tabu::TabuList::max_length
size_t max_length() const
returns the maximum length (tabu_length) of the tabu list
Definition: tabu_list.cpp:124
vrprouting::optimizers::tabu::Move
The Move class defines moves that are evaluated and set as tabu.
Definition: move.h:46
vrprouting::optimizers::tabu::TabuList::const_iterator
std::deque< Move >::const_iterator const_iterator
iterator type that does not allows modification
Definition: tabu_list.h:51
vrprouting::optimizers::tabu::TabuList::clear
void clear()
removes all moves from the tabu list
Definition: tabu_list.cpp:50
vrprouting::optimizers::tabu::TabuList::size
size_t size() const
returns the current length (number of moves) in the tabu list
Definition: tabu_list.cpp:116
vrprouting::optimizers::tabu::TabuList::is_empty
bool is_empty() const
returns true if the tabu list is empty
Definition: tabu_list.cpp:108
vrprouting::optimizers::tabu::TabuList::add_infeasible
void add_infeasible(const std::string &candidate)
Adds a move candidate to the infeasible list.
Definition: tabu_list.cpp:154
vrprouting::problem::Vehicle_pickDeliver
Definition: vehicle_pickDeliver.h:46
vrprouting::optimizers::tabu::TabuList::has
bool has(const Move &) const
Checks to see if a (general) move is "tabu" (in the tabu list)
Definition: tabu_list.cpp:59
vrprouting::optimizers::tabu::TabuList::has_swap
bool has_swap(const problem::Vehicle_pickDeliver &, const problem::Vehicle_pickDeliver &, const problem::Order &, const problem::Order &, double obj1, double obj2) const
Checks to see if a "swap" move is "tabu" (in the tabu list)
Definition: tabu_list.cpp:91
vrprouting::optimizers::tabu::TabuList::set_max_length
void set_max_length(size_t length)
sets the maximum length (tabu_length) of the tabu list
Definition: tabu_list.cpp:131
vrprouting::optimizers::tabu::TabuList::add_seen
void add_seen(const std::string &candidate)
Adds a move candidate to the seen list.
Definition: tabu_list.cpp:162
vrprouting::optimizers::tabu::TabuList::add
void add(const Move &m)
Make a move "tabu" by adding it to the tabu list.
Definition: tabu_list.cpp:42
vrprouting::problem::Order
Definition: order.h:40
vrprouting::optimizers::tabu::TabuList::m_max_length
size_t m_max_length
the maximum length (tabu_length) of the tabu list
Definition: tabu_list.h:108
vrprouting::optimizers::tabu::TabuList
The TabuList class defines the tabu list to be used in optimization.
Definition: tabu_list.h:45
vrprouting::optimizers::tabu::TabuList::begin
const_iterator begin() const
Constant iterator pointing to the first element of the tabu list.
Definition: tabu_list.h:86
vrprouting::optimizers::tabu::TabuList::has_infeasible
bool has_infeasible(const std::string &candidate)
Checks to see if a move candidate is infeasible (in the infeasible list)
Definition: tabu_list.cpp:150
vrprouting
Definition: base_matrix.cpp:46
vrprouting::optimizers::tabu::TabuList::m_infeasible_list
std::set< std::string > m_infeasible_list
the infeasible list
Definition: tabu_list.h:114