PGROUTING  3.2
pgrouting::tsp::Tour Class Reference

#include "tour.h"

Collaboration diagram for pgrouting::tsp::Tour:

Public Member Functions

 Tour (const std::vector< size_t > &cities_order)
 
 Tour (const Tour &)=default
 
 Tour (size_t n)
 
void reverse (size_t c1, size_t c2)
 
void rotate (size_t c1, size_t c2, size_t c3)
 
size_t size () const
 
void slide (size_t place, size_t first, size_t last)
 
void swap (size_t c1, size_t c2)
 

Public Attributes

std::vector< size_t > cities
 

Private Types

using difference_type = std::vector< size_t >::difference_type
 

Friends

double Dmatrix::tourCost (const Tour &tour) const
 
std::ostream & operator<< (std::ostream &log, const Tour &tour)
 

Detailed Description

Definition at line 42 of file tour.h.

Member Typedef Documentation

◆ difference_type

using pgrouting::tsp::Tour::difference_type = std::vector<size_t>::difference_type
private

Definition at line 43 of file tour.h.

Constructor & Destructor Documentation

◆ Tour() [1/3]

pgrouting::tsp::Tour::Tour ( const Tour )
default

◆ Tour() [2/3]

pgrouting::tsp::Tour::Tour ( const std::vector< size_t > &  cities_order)
inlineexplicit

Definition at line 48 of file tour.h.

48  :
49  cities(cities_order) {
50  }

◆ Tour() [3/3]

pgrouting::tsp::Tour::Tour ( size_t  n)
inlineexplicit

Definition at line 52 of file tour.h.

52  {
53  cities.resize(n);
54  std::iota(std::begin(cities), std::end(cities), 0);
55  }

References cities.

Member Function Documentation

◆ reverse()

void pgrouting::tsp::Tour::reverse ( size_t  c1,
size_t  c2 
)

Definition at line 47 of file tour.cpp.

49  {
50  pgassert(c1 < c2 && c2 < cities.size());
51  std::reverse(
52  cities.begin() + static_cast<difference_type>(c1 + 1),
53  cities.begin() + static_cast<difference_type>(c2 + 1));
54 }

References cities, and pgassert.

◆ rotate()

void pgrouting::tsp::Tour::rotate ( size_t  c1,
size_t  c2,
size_t  c3 
)

Definition at line 77 of file tour.cpp.

80  {
81  pgassert(c1 < c2 && c2 < c3 && c3 < cities.size());
82 
83  std::rotate(
84  cities.begin() + static_cast<difference_type>(c1 + 1),
85  cities.begin() + static_cast<difference_type>(c2 + 1),
86  cities.begin() + static_cast<difference_type>(c3 + 1));
87 }

References cities, and pgassert.

◆ size()

size_t pgrouting::tsp::Tour::size ( ) const
inline

Definition at line 57 of file tour.h.

57 {return cities.size();}

References cities.

◆ slide()

void pgrouting::tsp::Tour::slide ( size_t  place,
size_t  first,
size_t  last 
)

Definition at line 56 of file tour.cpp.

59  {
60  pgassert(first < cities.size());
61  pgassert(last < cities.size());
62  pgassert(place < cities.size());
63 
64  if (place < first) {
65  std::rotate(
66  cities.begin() + static_cast<difference_type>(place + 1),
67  cities.begin() + static_cast<difference_type>(first + 1),
68  cities.begin() + static_cast<difference_type>(last + 1));
69  } else {
70  std::rotate(
71  cities.begin() + static_cast<difference_type>(first + 1),
72  cities.begin() + static_cast<difference_type>(last + 1),
73  cities.begin() + static_cast<difference_type>(place + 1));
74  }
75 }

References cities, and pgassert.

Referenced by pgrouting::tsp::TSP< MATRIX >::getDeltaSlide().

◆ swap()

void pgrouting::tsp::Tour::swap ( size_t  c1,
size_t  c2 
)

Definition at line 90 of file tour.cpp.

92  {
93  pgassert(c1 < c2);
94 
95  std::iter_swap(
96  cities.begin() +
97  static_cast<difference_type>(c1), cities.begin() +
98  static_cast<difference_type>(c2));
99 }

References cities, and pgassert.

Friends And Related Function Documentation

◆ Dmatrix::tourCost

double Dmatrix::tourCost ( const Tour tour) const
friend

◆ operator<<

std::ostream& operator<< ( std::ostream &  log,
const Tour tour 
)
friend

Definition at line 36 of file tour.cpp.

38  {
39  for (const auto &city : tour.cities) {
40  log << city << ", ";
41  }
42  return log;
43 }

Member Data Documentation

◆ cities


The documentation for this class was generated from the following files:
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::tsp::Tour::difference_type
std::vector< size_t >::difference_type difference_type
Definition: tour.h:43
pgrouting::tsp::Tour::cities
std::vector< size_t > cities
Definition: tour.h:156