QUBO++ Library with QUBO Solver APIs
Author: Koji Nakano, License: Non-commercial research and evaluation purposes without any guarantees.
Public Member Functions | Private Attributes | List of all members
qbpp::tsp::TSPMap Class Reference

Class to generates a random map for the TSP with n nodes. More...

#include <qbpp_tsp.hpp>

Public Member Functions

 TSPMap (uint32_t grid_size=100)
 Constructor: Creates an empty map. More...
 
void gen_random_map (uint32_t n)
 Generate a random map with n nodes. More...
 
void add_node (uint32_t x, uint32_t y)
 Add a node to the map. More...
 
uint32_t dist (const std::pair< int32_t, int32_t > &p1, const std::pair< int32_t, int32_t > &p2) const
 Compute the Euclidean distance between two nodes. More...
 
uint32_t dist (uint32_t i, uint32_t j) const
 Compute the Euclidean distance between two nodes. More...
 
uint32_t min_dist (uint32_t x, uint32_t y) const
 Compute the minimum distance between a new node and all other nodes. More...
 
uint32_t node_count () const
 Gets the number of nodes in the map. More...
 
uint32_t get_grid_size () const
 Gets the size of the grid. More...
 
std::pair< int32_t, int32_t > & operator[] (uint32_t index)
 Get the position of the node at index i. More...
 

Private Attributes

const uint32_t grid_size
 Size of the grid. grid_size x grid_size coordinates are used for the map. More...
 
std::vector< std::pair< int32_t, int32_t > > nodes
 List of nodes with coordinate (x, y) More...
 

Detailed Description

Class to generates a random map for the TSP with n nodes.

The map is a grid of size grid_size x grid_size

Note
The nodes are randomly placed on the grid so that nodes are not too close to each other

Definition at line 30 of file qbpp_tsp.hpp.

Constructor & Destructor Documentation

◆ TSPMap()

qbpp::tsp::TSPMap::TSPMap ( uint32_t  grid_size = 100)
inline

Constructor: Creates an empty map.

Parameters
grid_sizeSize of the grid. grid_size x grid_size coordinates are used for the map.

Definition at line 41 of file qbpp_tsp.hpp.

Member Function Documentation

◆ gen_random_map()

void qbpp::tsp::TSPMap::gen_random_map ( uint32_t  n)
inline

Generate a random map with n nodes.

Parameters
nNumber of nodes

Definition at line 284 of file qbpp_tsp.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_node()

void qbpp::tsp::TSPMap::add_node ( uint32_t  x,
uint32_t  y 
)
inline

Add a node to the map.

Parameters
xx-coordinate of the node
yy-coordinate of the node

Definition at line 50 of file qbpp_tsp.hpp.

Here is the caller graph for this function:

◆ dist() [1/2]

uint32_t qbpp::tsp::TSPMap::dist ( const std::pair< int32_t, int32_t > &  p1,
const std::pair< int32_t, int32_t > &  p2 
) const
inline

Compute the Euclidean distance between two nodes.

Parameters
p1First node
p2Second node
Returns
Euclidean distance between the two nodes
Note
The distance is rounded to the nearest integer

Definition at line 57 of file qbpp_tsp.hpp.

Here is the caller graph for this function:

◆ dist() [2/2]

uint32_t qbpp::tsp::TSPMap::dist ( uint32_t  i,
uint32_t  j 
) const
inline

Compute the Euclidean distance between two nodes.

Parameters
iIndex of the first node
jIndex of the second node
Returns
Euclidean distance between the two nodes

Definition at line 68 of file qbpp_tsp.hpp.

Here is the call graph for this function:

◆ min_dist()

uint32_t qbpp::tsp::TSPMap::min_dist ( uint32_t  x,
uint32_t  y 
) const
inline

Compute the minimum distance between a new node and all other nodes.

Parameters
xx-coordinate of the node
yy-coordinate of the node
Returns
Minimum distance between the node and all other nodes

Definition at line 77 of file qbpp_tsp.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ node_count()

uint32_t qbpp::tsp::TSPMap::node_count ( ) const
inline

Gets the number of nodes in the map.

Returns
Number of nodes in the map

Definition at line 87 of file qbpp_tsp.hpp.

Here is the caller graph for this function:

◆ get_grid_size()

uint32_t qbpp::tsp::TSPMap::get_grid_size ( ) const
inline

Gets the size of the grid.

Returns
Size of the grid

Definition at line 91 of file qbpp_tsp.hpp.

Here is the caller graph for this function:

◆ operator[]()

std::pair<int32_t, int32_t>& qbpp::tsp::TSPMap::operator[] ( uint32_t  index)
inline

Get the position of the node at index i.

Parameters
indexIndex of the node
Returns
Pair of coordinates (x, y) of the node

Definition at line 96 of file qbpp_tsp.hpp.

Member Data Documentation

◆ grid_size

const uint32_t qbpp::tsp::TSPMap::grid_size
private

Size of the grid. grid_size x grid_size coordinates are used for the map.

Definition at line 33 of file qbpp_tsp.hpp.

◆ nodes

std::vector<std::pair<int32_t, int32_t> > qbpp::tsp::TSPMap::nodes
private

List of nodes with coordinate (x, y)

Definition at line 35 of file qbpp_tsp.hpp.


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