letlovewin / cis7final

Repository for CIS-7 final project (Inland Empire Solar Salesperson)
2 stars 1 forks source link

code continued #3

Open anayyee opened 5 months ago

anayyee commented 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; }