vrpRouting  0.3
vrprouting::optimizers::tabu::TabuList Class Reference

The TabuList class defines the tabu list to be used in optimization. More...

#include "tabu_list.h"

Collaboration diagram for vrprouting::optimizers::tabu::TabuList:

Public Types

typedef std::deque< Move >::const_iterator const_iterator
 iterator type that does not allows modification More...
 
typedef std::deque< Move >::iterator iterator
 iterator type that allows modification More...
 

Public Member Functions

void add (const Move &m)
 Make a move "tabu" by adding it to the tabu list. More...
 
void add_infeasible (const std::string &candidate)
 Adds a move candidate to the infeasible list. More...
 
void add_seen (const std::string &candidate)
 Adds a move candidate to the seen list. More...
 
const_iterator begin () const
 Constant iterator pointing to the first element of the tabu list. More...
 
void clear ()
 removes all moves from the tabu list More...
 
const_iterator end () const
 Constant iteratori pointing to the last element of the tabu list. More...
 
bool has_infeasible (const std::string &candidate)
 Checks to see if a move candidate is infeasible (in the infeasible list) More...
 
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) More...
 
bool has_seen (const std::string &candidate)
 Checks to see if a move candidate has already been done before (in the seen list) More...
 
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) More...
 
bool is_empty () const
 returns true if the tabu list is empty More...
 
size_t max_length () const
 returns the maximum length (tabu_length) of the tabu list More...
 
void set_max_length (size_t length)
 sets the maximum length (tabu_length) of the tabu list More...
 
size_t size () const
 returns the current length (number of moves) in the tabu list More...
 

Private Member Functions

bool has (const Move &) const
 Checks to see if a (general) move is "tabu" (in the tabu list) More...
 

Private Attributes

std::set< std::string > m_infeasible_list
 the infeasible list More...
 
size_t m_max_length
 the maximum length (tabu_length) of the tabu list More...
 
std::set< std::string > m_seen_list
 the seen list More...
 
std::deque< Movem_tabu_list
 the tabu list More...
 

Friends

std::ostream & operator<< (std::ostream &, const TabuList &)
 priting function More...
 

Detailed Description

The TabuList class defines the tabu list to be used in optimization.

Definition at line 45 of file tabu_list.h.

Member Typedef Documentation

◆ const_iterator

iterator type that does not allows modification

Definition at line 51 of file tabu_list.h.

◆ iterator

iterator type that allows modification

Definition at line 48 of file tabu_list.h.

Member Function Documentation

◆ add()

void vrprouting::optimizers::tabu::TabuList::add ( const Move m)

Make a move "tabu" by adding it to the tabu list.

Parameters
[in]mthe move

Definition at line 42 of file tabu_list.cpp.

42  {
43  if (has(m)) return;
44  while (size() >= max_length()) m_tabu_list.pop_front();
45  m_tabu_list.push_back(m);
46 }

References has(), m_tabu_list, max_length(), and size().

Referenced by vrprouting::optimizers::tabu::Optimize::single_pair_insertion(), and vrprouting::optimizers::tabu::Optimize::swap_between_routes().

◆ add_infeasible()

void vrprouting::optimizers::tabu::TabuList::add_infeasible ( const std::string &  candidate)

Adds a move candidate to the infeasible list.

Definition at line 154 of file tabu_list.cpp.

154  {
155  m_infeasible_list.insert(candidate);
156 }

References m_infeasible_list.

Referenced by vrprouting::optimizers::tabu::Optimize::single_pair_insertion(), and vrprouting::optimizers::tabu::Optimize::swap_between_routes().

◆ add_seen()

void vrprouting::optimizers::tabu::TabuList::add_seen ( const std::string &  candidate)

Adds a move candidate to the seen list.

Definition at line 162 of file tabu_list.cpp.

162  {
163  m_seen_list.insert(candidate);
164 }

References m_seen_list.

Referenced by vrprouting::optimizers::tabu::Optimize::single_pair_insertion(), and vrprouting::optimizers::tabu::Optimize::swap_between_routes().

◆ begin()

const_iterator vrprouting::optimizers::tabu::TabuList::begin ( ) const
inline

Constant iterator pointing to the first element of the tabu list.

Definition at line 86 of file tabu_list.h.

86 {return m_tabu_list.begin();}

References m_tabu_list.

◆ clear()

void vrprouting::optimizers::tabu::TabuList::clear ( )

removes all moves from the tabu list

Definition at line 50 of file tabu_list.cpp.

50  {
51  m_tabu_list.clear();
52 }

References m_tabu_list.

Referenced by vrprouting::optimizers::tabu::Optimize::move_2_real().

◆ end()

const_iterator vrprouting::optimizers::tabu::TabuList::end ( ) const
inline

Constant iteratori pointing to the last element of the tabu list.

Definition at line 89 of file tabu_list.h.

89 {return m_tabu_list.end();}

References m_tabu_list.

◆ has()

bool vrprouting::optimizers::tabu::TabuList::has ( const Move m) const
private

Checks to see if a (general) move is "tabu" (in the tabu list)

Parameters
[in]mmove searched for
Returns
true when the move was found in the tabu list
false when the move was not found in the tabu list

Definition at line 59 of file tabu_list.cpp.

59  {
60  return std::find(m_tabu_list.begin(), m_tabu_list.end(), m) != m_tabu_list.end();
61 }

References m_tabu_list.

Referenced by add(), has_move(), and has_swap().

◆ has_infeasible()

bool vrprouting::optimizers::tabu::TabuList::has_infeasible ( const std::string &  candidate)

Checks to see if a move candidate is infeasible (in the infeasible list)

Definition at line 150 of file tabu_list.cpp.

150  {
151  return (m_infeasible_list.find(candidate) != m_infeasible_list.end());
152 }

References m_infeasible_list.

Referenced by vrprouting::optimizers::tabu::Optimize::single_pair_insertion(), and vrprouting::optimizers::tabu::Optimize::swap_between_routes().

◆ has_move()

bool vrprouting::optimizers::tabu::TabuList::has_move ( const problem::Vehicle_pickDeliver from_vehicle,
const problem::Vehicle_pickDeliver to_vehicle,
const problem::Order order,
double  obj1,
double  obj2 
) const

Checks to see if a "move" move is "tabu" (in the tabu list)

Parameters
[in]from_vehicleFirst vehicle of the move
[in]to_vehicleSecond vehicle of the move
[in]orderorder involved on the move
[in]obj1
[in]obj2
Returns
true when the move was found in the tabu list
false when the move was not found in the tabu list

Definition at line 73 of file tabu_list.cpp.

75  {
76  return has({from_vehicle, to_vehicle, order, obj1, obj2}) ||
77  has({to_vehicle, from_vehicle, order, obj1, obj2});
78 }

References has().

Referenced by vrprouting::optimizers::tabu::Optimize::single_pair_insertion().

◆ has_seen()

bool vrprouting::optimizers::tabu::TabuList::has_seen ( const std::string &  candidate)

Checks to see if a move candidate has already been done before (in the seen list)

Definition at line 158 of file tabu_list.cpp.

158  {
159  return (m_seen_list.find(candidate) != m_seen_list.end());
160 }

References m_seen_list.

Referenced by vrprouting::optimizers::tabu::Optimize::single_pair_insertion(), and vrprouting::optimizers::tabu::Optimize::swap_between_routes().

◆ has_swap()

bool vrprouting::optimizers::tabu::TabuList::has_swap ( const problem::Vehicle_pickDeliver from_vehicle,
const problem::Vehicle_pickDeliver to_vehicle,
const problem::Order from_order,
const problem::Order to_order,
double  obj1,
double  obj2 
) const

Checks to see if a "swap" move is "tabu" (in the tabu list)

Parameters
[in]from_vehicleFirst vehicle of the move
[in]to_vehicleSecond vehicle of the move
[in]from_orderinvolved on the swap move
[in]to_orderinvolved on the swap move
[in]obj1
[in]obj2
Returns
true when the move was found in the tabu list
false when the move was not found in the tabu list

Definition at line 91 of file tabu_list.cpp.

94  {
95  return has({from_vehicle, to_vehicle, from_order, to_order, obj1, obj2}) ||
96  has({from_vehicle, to_vehicle, to_order, from_order, obj1, obj2}) ||
97  has({to_vehicle, from_vehicle, from_order, to_order, obj1, obj2}) ||
98  has({to_vehicle, from_vehicle, to_order, from_order, obj1, obj2});
99 }

References has().

Referenced by vrprouting::optimizers::tabu::Optimize::swap_between_routes().

◆ is_empty()

bool vrprouting::optimizers::tabu::TabuList::is_empty ( ) const

returns true if the tabu list is empty

Returns
true when the list is empty
false when the list is not empty

Definition at line 108 of file tabu_list.cpp.

108  {
109  return m_tabu_list.empty();
110 }

References m_tabu_list.

◆ max_length()

size_t vrprouting::optimizers::tabu::TabuList::max_length ( ) const

returns the maximum length (tabu_length) of the tabu list

Returns
the maximum possible number of moves on the tabu list

Definition at line 124 of file tabu_list.cpp.

124  {
125  return m_max_length;
126 }

References m_max_length.

Referenced by add().

◆ set_max_length()

void vrprouting::optimizers::tabu::TabuList::set_max_length ( size_t  length)

sets the maximum length (tabu_length) of the tabu list

Parameters
[in]length

Definition at line 131 of file tabu_list.cpp.

131  {
132  m_max_length = length;
133 }

References m_max_length.

Referenced by vrprouting::optimizers::tabu::Optimize::set_tabu_list_length().

◆ size()

size_t vrprouting::optimizers::tabu::TabuList::size ( ) const

returns the current length (number of moves) in the tabu list

Returns
the number of moves on the tabu list

Definition at line 116 of file tabu_list.cpp.

116  {
117  return m_tabu_list.size();
118 }

References m_tabu_list.

Referenced by add(), and vrprouting::optimizers::tabu::operator<<().

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  log,
const TabuList list 
)
friend

priting function

Parameters
[in,out]logwhere the print takes place
[in]listThe tabu list to be printed

Definition at line 140 of file tabu_list.cpp.

140  {
141  log << "\nTabuList length: " << list.size()
142  << "\n *><* *** tabu list start *** ";
143 
144  for (const auto &m : list) log << m << ' ';
145 
146  log << " *** tabu list end ***\n";
147  return log;
148 }

Member Data Documentation

◆ m_infeasible_list

std::set<std::string> vrprouting::optimizers::tabu::TabuList::m_infeasible_list
private

the infeasible list

Definition at line 114 of file tabu_list.h.

Referenced by add_infeasible(), and has_infeasible().

◆ m_max_length

size_t vrprouting::optimizers::tabu::TabuList::m_max_length
private

the maximum length (tabu_length) of the tabu list

Definition at line 108 of file tabu_list.h.

Referenced by max_length(), and set_max_length().

◆ m_seen_list

std::set<std::string> vrprouting::optimizers::tabu::TabuList::m_seen_list
private

the seen list

Definition at line 117 of file tabu_list.h.

Referenced by add_seen(), and has_seen().

◆ m_tabu_list

std::deque<Move> vrprouting::optimizers::tabu::TabuList::m_tabu_list
private

the tabu list

Definition at line 111 of file tabu_list.h.

Referenced by add(), begin(), clear(), end(), has(), is_empty(), and size().


The documentation for this class was generated from the following files:
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::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::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::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::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::m_infeasible_list
std::set< std::string > m_infeasible_list
the infeasible list
Definition: tabu_list.h:114