Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double Min_ost::best_way() {
- double ans = numeric_limits<double>::max();
- vector <int> shuffle(graph.VerticesCount());
- for (size_t j = 0; j < graph.VerticesCount(); ++j) {
- shuffle[j] = j;
- }
- double cur_ans = 0;//вес очередного пути (перебор по всем возможным путям)
- do {//перебор всех перестановок
- for (int i = 1; i < graph.VerticesCount(); ++i) {
- cur_ans += graph.GetWeight(shuffle[i], shuffle[i - 1]);//weight of edge from shuffle[i-1] to shuffle[i]
- }
- cur_ans += graph.GetWeight(shuffle[graph.VerticesCount() - 1], shuffle[0]); //возвращение в исходную точку
- ans = min(ans, cur_ans)
- }
- while(next_permutation(shuffle.begin(), shuffle.end()));
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement