PGROUTING  2.6
pgrouting::tsp::Tour Class Reference

#include "tour.h"

Collaboration diagram for pgrouting::tsp::Tour:

Public Member Functions

 Tour (const Tour &)=default
 
 Tour (const std::vector< size_t > &cities_order)
 
 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
 

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.

Constructor & Destructor Documentation

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

Definition at line 46 of file tour.h.

46  :
47  cities(cities_order) {
48  }
std::vector< size_t > cities
Definition: tour.h:154
pgrouting::tsp::Tour::Tour ( size_t  n)
inlineexplicit

Definition at line 50 of file tour.h.

References cities.

50  {
51  cities.resize(n);
52  std::iota(std::begin(cities), std::end(cities), 0);
53  }
std::vector< size_t > cities
Definition: tour.h:154

Member Function Documentation

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

Definition at line 47 of file tour.cpp.

References cities, and pgassert.

Referenced by size().

49  {
50  pgassert(c1 < c2 && c2 < cities.size());
51  std::reverse(
52  cities.begin() + (c1 + 1),
53  cities.begin() + (c2 + 1));
54 }
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::vector< size_t > cities
Definition: tour.h:154

Here is the caller graph for this function:

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

Definition at line 77 of file tour.cpp.

References cities, and pgassert.

Referenced by size().

80  {
81  pgassert(c1 < c2 && c2 < c3 && c3 < cities.size());
82 
83  std::rotate(
84  cities.begin() + (c1 + 1),
85  cities.begin() + (c2 + 1),
86  cities.begin() + (c3 + 1));
87 }
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::vector< size_t > cities
Definition: tour.h:154

Here is the caller graph for this function:

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

Definition at line 55 of file tour.h.

References cities, operator<<, reverse(), rotate(), slide(), swap(), and pgrouting::tsp::Dmatrix::tourCost().

55 {return cities.size();}
std::vector< size_t > cities
Definition: tour.h:154

Here is the call graph for this function:

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

Definition at line 56 of file tour.cpp.

References cities, and pgassert.

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

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() + (place + 1),
67  cities.begin() + (first + 1),
68  cities.begin() + (last + 1));
69  } else {
70  std::rotate(
71  cities.begin() + (first + 1),
72  cities.begin() + (last + 1),
73  cities.begin() + (place + 1));
74  }
75 }
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::vector< size_t > cities
Definition: tour.h:154

Here is the caller graph for this function:

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

Definition at line 90 of file tour.cpp.

References cities, and pgassert.

Referenced by size().

92  {
93  pgassert(c1 < c2);
94 
95  std::iter_swap(cities.begin() + c1, cities.begin() + c2);
96 }
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
std::vector< size_t > cities
Definition: tour.h:154

Here is the caller graph for this function:

Friends And Related Function Documentation

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

Definition at line 36 of file tour.cpp.

Referenced by size().

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

Member Data Documentation


The documentation for this class was generated from the following files: