TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation to [Travelling Salesman problem using bit-masking] (https://www.geeksforgeeks.org/travelling-salesman-problem-set-1/) More...
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <limits>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | bit_manipulation |
for assert | |
namespace | travellingSalesman_bitmanipulation |
Functions for the Travelling Salesman Bitmask implementation. | |
Functions | |
std::uint64_t | bit_manipulation::travelling_salesman_using_bit_manipulation::travelling_salesman_using_bit_manipulation (std::vector< std::vector< uint32_t > > dist, std::uint64_t setOfCities, std::uint64_t city, std::uint64_t n, std::vector< std::vector< uint32_t > > &dp) |
The function implements travellingSalesman using bitmanipulation. | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
Implementation to [Travelling Salesman problem using bit-masking] (https://www.geeksforgeeks.org/travelling-salesman-problem-set-1/)
Given the distance/cost(as and adjacency matrix) between each city/node to the other city/node , the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point or we can say the minimum cost of whole tour.
Explanation: INPUT -> You are given with a adjacency matrix A = {} which contains the distance between two cities/node.
OUTPUT -> Minimum cost of whole tour from starting point
Worst Case Time Complexity: O(n^2 * 2^n) Space complexity: O(n)
Definition in file travelling_salesman_using_bit_manipulation.cpp.
int main | ( | void | ) |
Main function.
Definition at line 139 of file travelling_salesman_using_bit_manipulation.cpp.
|
static |
Self-test implementations.
Definition at line 100 of file travelling_salesman_using_bit_manipulation.cpp.
std::uint64_t bit_manipulation::travelling_salesman_using_bit_manipulation::travelling_salesman_using_bit_manipulation | ( | std::vector< std::vector< uint32_t > > | dist, |
std::uint64_t | setOfCities, | ||
std::uint64_t | city, | ||
std::uint64_t | n, | ||
std::vector< std::vector< uint32_t > > & | dp ) |
The function implements travellingSalesman using bitmanipulation.
dist | is the cost to reach between two cities/nodes |
setOfCitites | represents the city in bit form.\ |
city | is taken to track the current city movement. |
n | is the no of citys . |
dp | vector is used to keep a record of state to avoid the recomputation. |
Definition at line 53 of file travelling_salesman_using_bit_manipulation.cpp.