A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/de/d88/travelling__salesman__problem_8cpp_source.html below:

TheAlgorithms/C++: graph/travelling_salesman_problem.cpp Source File

Go to the documentation of this file. 42

int32_t src, uint32_t V) {

44

std::vector<uint32_t> vtx;

45 for

(uint32_t i = 0; i < V; i++) {

52

int32_t min_path = 2147483647;

55

int32_t curr_weight = 0;

60

curr_weight += (*cities)[k][i];

63

curr_weight += (*cities)[k][src];

66

min_path = std::min(min_path, curr_weight);

68

}

while

(next_permutation(vtx.begin(), vtx.end()));

79

std::cout <<

"Initiatinig Predefined Tests..."

<< std::endl;

80

std::cout <<

"Initiating Test 1..."

<< std::endl;

81

std::vector<std::vector<uint32_t>> cities = {

82

{0, 20, 42, 35}, {20, 0, 30, 34}, {42, 30, 0, 12}, {35, 34, 12, 0}};

83

uint32_t V = cities.size();

85

std::cout <<

"1st test passed..."

<< std::endl;

87

std::cout <<

"Initiating Test 2..."

<< std::endl;

88

cities = {{0, 5, 10, 15}, {5, 0, 20, 30}, {10, 20, 0, 35}, {15, 30, 35, 0}};

91

std::cout <<

"2nd test passed..."

<< std::endl;

93

std::cout <<

"Initiating Test 3..."

<< std::endl;

95

{0, 10, 15, 20}, {10, 0, 35, 25}, {15, 35, 0, 30}, {20, 25, 30, 0}};

98

std::cout <<

"3rd test passed..."

<< std::endl;

107

std::vector<std::vector<uint32_t>> cities = {

108

{0, 5, 10, 15}, {5, 0, 20, 30}, {10, 20, 0, 35}, {15, 30, 35, 0}};

109

uint32_t V = cities.size();

int TravellingSalesmanProblem(std::vector< std::vector< uint32_t > > *cities, int32_t src, uint32_t V)

Function calculates the minimum path distance that will cover all the cities starting from the source...

static void tests()

Self-test implementations.

int main()

Main function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4