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...