Open anayyee opened 5 months ago
vector permutations; do { vector perm = {"Riverside"}; perm.insert(perm.end(), cities.begin(), cities.end()); perm.push_back("Riverside"); permutations.push_back(perm); } while (next_permutation(cities.begin(), cities.end()));
// Calculate the weight for each permutation and print them out for (int i = 0; i < permutations.size(); ++i) { float totalWeight = 0; for (int j = 0; j < permutations[i].size() - 1; ++j) { totalWeight += G.getWeight(permutations[i][j], permutations[i][j+1]); } cout << "Trip " << i+1 << ": "; for (int k = 0; k < permutations[i].size(); ++k) { cout << permutations[i][k]; if (k < permutations[i].size() - 1) cout << " -> "; } cout << " (Total Weight: " << totalWeight << ")" << endl; }
return 0; }
vector permutations;
do {
vector perm = {"Riverside"};
perm.insert(perm.end(), cities.begin(), cities.end());
perm.push_back("Riverside");
permutations.push_back(perm);
} while (next_permutation(cities.begin(), cities.end()));
// Calculate the weight for each permutation and print them out for (int i = 0; i < permutations.size(); ++i) { float totalWeight = 0; for (int j = 0; j < permutations[i].size() - 1; ++j) { totalWeight += G.getWeight(permutations[i][j], permutations[i][j+1]); } cout << "Trip " << i+1 << ": "; for (int k = 0; k < permutations[i].size(); ++k) { cout << permutations[i][k]; if (k < permutations[i].size() - 1) cout << " -> "; } cout << " (Total Weight: " << totalWeight << ")" << endl; }
return 0; }